ConvertUtils

2001-01-27 Thread Ralph Schaer

Hello

Thanks for changing the ConvertUtils class. Unfortunately the class is no
longer able to support
the wrapper types. The attached source file contains this support.


IMHO is also better to user the Boolean.FALSE and Boolean.TRUE constants
instead
of creating new Boolean objects.

 ConvertUtils.java


cvs commit: jakarta-struts/src/share/org/apache/struts/util package.html

2001-01-27 Thread craigmcc

craigmcc01/01/27 21:28:57

  Modified:src/share/org/apache/struts/util package.html
  Log:
  Oops ... forgot the entry in the introduction.
  
  Revision  ChangesPath
  1.4   +3 -0  jakarta-struts/src/share/org/apache/struts/util/package.html
  
  Index: package.html
  ===
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/package.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- package.html  2001/01/28 05:27:21 1.3
  +++ package.html  2001/01/28 05:28:57 1.4
  @@ -31,6 +31,9 @@
   classes for manipulating JavaBeans, as well as getting and setting
   properties, without hard coding the names or data types of the
   property getter and setter methods.
  +Collection Classes - A family of specialized
  +classes supporting the Collections API, designed for use in multithread
  +environments where the vast majority of accesses are read only.
   JDBC Connection Pool - A very simple connection
   pool that can be utilized in web applications or other environments that
   need to share a limited number of JDBC Connections across a much larger
  
  
  



cvs commit: jakarta-struts/src/share/org/apache/struts/util package.html

2001-01-27 Thread craigmcc

craigmcc01/01/27 21:27:23

  Modified:src/share/org/apache/struts/util package.html
  Log:
  Document the specialized collection classes that operate in fast and slow
  mode for multithreaded environments.
  
  Revision  ChangesPath
  1.3   +91 -0 jakarta-struts/src/share/org/apache/struts/util/package.html
  
  Index: package.html
  ===
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/package.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- package.html  2000/12/29 19:16:37 1.2
  +++ package.html  2001/01/28 05:27:21 1.3
  @@ -10,6 +10,7 @@
   
   [Introduction]
   [Beans and Properties]
  +[Collection Classes]
   [JDBC Connection Pool]
   [Message Resources]
   
  @@ -48,6 +49,96 @@
   FIXME
   
   
  +
  +
  +Collection Classes
  +
  +Background
  +
  +Version 1.2 of the Java 2 Standard Edition (J2SE) introduced a powerful
  +set of collection classes that are generally useful in Java programming, based
  +on the fundamental interfaces java.util.Collection,
  +java.util.List, java.util.Map, and
  +java.util.Set.  Compared to the collection classes available in
  +JDK 1.1 (principally java.util.Hashtable and
  +java.util.Vector), the new classes offer much richer functionality
  +as well as the opportunity to improve performance.
  +
  +The performance increase potential comes from the fact that none of the
  +methods used to access the new collection classes are synchronized
  +as were the methods of Hashtable and Vector.  In a
  +single thread application, this means that method calls can execute much more
  +quickly because synchronization is never necessary.  In a multiple thread
  +environment, though, it is up to the developer to ensure that any method calls
  +made while another thread is modifying the collection must be synchronized.
  +
  +
  +There are many cases in multithreaded server environments (such as a web
  +application) where data structures are initialized at application startup
  +time, and are then predominantly accessed in a read-only manner.  An example
  +of this is the Struts controller application, which initializes its collection
  +of ActionMapping instances (each corresponding to an
  + element in the struts-config.xml
  +file) at startup time.  However, it is legal for an application to dynamically
  +change the set of available mappings while the application is running -- so,
  +to be safe, it would normally be necessary to synchronize access to such
  +collections, even though 99% of those accesses are read only and would not
  +otherwise require synchronization.
  +
  +To deal with such scenarios, the Struts utility package includes a series
  +of specialized collection classes designed to operate in a multithread
  +environment where the large majority of accesses are read only, without
  +requiring synchronization on every operation, but still protecting against
  +the possibility of runtime modifications to the underlying collection.
  +
  +Theory of Operation
  +
  +Each of the available collection classes operates in one of two modes:
  +fast or slow.  When first created, the collection operates
  +in slow mode, which is appropriate for initially populating the
  +contents of the collection.  Once the initial population is complete, switch
  +to fast mode by calling setFast(true) for maximum
  +performance when most accesses are read-only.
  +
  +When operating in slow mode, all methods that access this
  +collection, even read-only methods, are synchronized - resulting in impacts on
  +performance similar to that always performed by the Hashtable and
  +Vector classes.  This mode is appropriate when you are
  +initializing the content of the collection, or when you need to perform a large
  +series of updates.
  +
  +Using fast mode, on the other hand, causes method calls to operate
  +in the following manner:
  +
  +Method calls that access information from the collection, but do not
  +modify it, are executed without synchronization.
  +Method calls that modify the structure of a collection do so by
  +synchronizing, cloning the existing collection instance, modifying the
  +cloned instance, and then replacing the current collection instance.
  +
  +
  +As you can see, modification operations are much more
  +expensive when operating in fast mode, but doing things in this way
  +allows read only operations, which should be the vast majority, to operate at
  +maximum speed.
  +
  +If your collection will never be accessed in a multithread
  +environment, you should use one of the standard collection classes instead,
  +without synchronization, for maximum performance.
  +
  +Available Collection Classes
  +
  +The following collection classes, with the ability to operate in either
  +fast or slow mode, are included:
  +
  +org.apache.struts.util.FastArrayList -
  +Similar in functio

cvs commit: jakarta-struts/src/share/org/apache/struts/util BeanUtils.java

2001-01-27 Thread craigmcc

craigmcc01/01/27 20:51:14

  Modified:src/share/org/apache/struts/util BeanUtils.java
  Log:
  Improve the efficiency of BeanUtils.filter() by using a switch statement.
  
  Submitted by:  Matthias Kerkhoff <[EMAIL PROTECTED]>
(an oldie but a goodie ... submitted last October :-)
  
  Revision  ChangesPath
  1.25  +20 -13jakarta-struts/src/share/org/apache/struts/util/BeanUtils.java
  
  Index: BeanUtils.java
  ===
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/BeanUtils.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- BeanUtils.java2001/01/10 01:54:21 1.24
  +++ BeanUtils.java2001/01/28 04:51:13 1.25
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/BeanUtils.java,v 1.24 
2001/01/10 01:54:21 craigmcc Exp $
  - * $Revision: 1.24 $
  - * $Date: 2001/01/10 01:54:21 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/BeanUtils.java,v 1.25 
2001/01/28 04:51:13 craigmcc Exp $
  + * $Revision: 1.25 $
  + * $Date: 2001/01/28 04:51:13 $
*
* 
*
  @@ -83,7 +83,7 @@
* @author Craig R. McClanahan
* @author Ralph Schaer
* @author Chris Audley
  - * @version $Revision: 1.24 $ $Date: 2001/01/10 01:54:21 $
  + * @version $Revision: 1.25 $ $Date: 2001/01/28 04:51:13 $
*/
   
   public final class BeanUtils {
  @@ -164,19 +164,26 @@
   if (value == null)
   return (null);
   
  -StringBuffer result = new StringBuffer();
  -for (int i = 0; i < value.length(); i++) {
  -char ch = value.charAt(i);
  -if (ch == '<')
  +char content[] = new char[value.length()];
  +value.getChars(0, value.length(), content, 0);
  +StringBuffer result = new StringBuffer(content.length + 50);
  +for (int i = 0; i < content.length; i++) {
  +switch (content[i]) {
  +case '<':
   result.append("<");
  -else if (ch == '>')
  +break;
  +case '>':
   result.append(">");
  -else if (ch == '&')
  +break;
  +case '&':
   result.append("&");
  -else if (ch == '"')
  +break;
  +case '"':
   result.append(""");
  -else
  -result.append(ch);
  +break;
  +default:
  +result.append(content[i]);
  +}
   }
   return (result.toString());
   
  
  
  



cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/bean DefineTei.java

2001-01-27 Thread craigmcc

craigmcc01/01/27 19:59:12

  Modified:src/share/org/apache/struts/taglib/bean DefineTei.java
  Log:
  Allow  to work when the "value" attribute is set to an
  arbitrary object (via a runtime expression), and the "type" attribute is
  not specified.  The data type of the scripting variable being craeted will
  be equal to the class of the object created by the runtime expression.
  
  Submitted by:  Incze Lajos <[EMAIL PROTECTED]> and
Joshua Hill <[EMAIL PROTECTED]>
  
  Revision  ChangesPath
  1.4   +7 -6  
jakarta-struts/src/share/org/apache/struts/taglib/bean/DefineTei.java
  
  Index: DefineTei.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/DefineTei.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefineTei.java2000/12/30 21:15:37 1.3
  +++ DefineTei.java2001/01/28 03:59:12 1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/DefineTei.java,v 1.3 
2000/12/30 21:15:37 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/12/30 21:15:37 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/DefineTei.java,v 1.4 
2001/01/28 03:59:12 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/01/28 03:59:12 $
*
* 
*
  @@ -73,7 +73,7 @@
* tag, identifying the scripting object(s) to be made visible.
*
* @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/12/30 21:15:37 $
  + * @version $Revision: 1.4 $ $Date: 2001/01/28 03:59:12 $
*/
   
   public class DefineTei extends TagExtraInfo {
  @@ -85,9 +85,10 @@
   public VariableInfo[] getVariableInfo(TagData data) {
   
   String type = data.getAttributeString("type");
  +Object value = data.getAttribute("value");
   if (type == null) {
  -if (data.getAttributeString("value") != null)
  -type = "java.lang.String";
  +if (value != null)
  +type = value.getClass().getName();
   else
   type = "java.lang.Object";
   }
  
  
  



cvs commit: jakarta-struts/src/doc todo-1.0.xml

2001-01-27 Thread craigmcc

craigmcc01/01/27 19:48:43

  Modified:src/doc  todo-1.0.xml
  Log:
  Remove the  tag from the TODO list, since it has been completed
  and submitted (by Michael Westbay).
  
  Revision  ChangesPath
  1.8   +0 -6  jakarta-struts/src/doc/todo-1.0.xml
  
  Index: todo-1.0.xml
  ===
  RCS file: /home/cvs/jakarta-struts/src/doc/todo-1.0.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- todo-1.0.xml  2001/01/10 22:38:32 1.7
  +++ todo-1.0.xml  2001/01/28 03:48:43 1.8
  @@ -111,12 +111,6 @@
   support for internationalized and localized applications.
   
   
  -
  -  
  -[STRUTS-DEV, Michael Westbay, 12/22/2000]
  -  
  -
  -
 
   
   
  
  
  



cvs commit: jakarta-struts/web/example index.jsp

2001-01-27 Thread craigmcc

craigmcc01/01/27 19:48:03

  Modified:.build.xml
   src/doc  struts-html.xml
   src/share/org/apache/struts/taglib/html
LocalStrings.properties
   web/example index.jsp
  Added:   src/share/org/apache/struts/taglib/html ImgTag.java
  Log:
  Add a  tag that can render an HTML  tag, with the abilities
  to dynamically modify the URLs specified by the "src" and "lowsrc"
  attributes in the same manner that  can.
  
  Submitted by: Michael Westbay <[EMAIL PROTECTED]>
  
  Revision  ChangesPath
  1.34  +2 -0  jakarta-struts/build.xml
  
  Index: build.xml
  ===
  RCS file: /home/cvs/jakarta-struts/build.xml,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- build.xml 2001/01/24 21:57:26 1.33
  +++ build.xml 2001/01/28 03:48:02 1.34
  @@ -57,6 +57,8 @@
   
 
   
  +
 
   
 
  
  
  
  1.5   +378 -0jakarta-struts/src/doc/struts-html.xml
  
  Index: struts-html.xml
  ===
  RCS file: /home/cvs/jakarta-struts/src/doc/struts-html.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- struts-html.xml   2001/01/27 23:21:07 1.4
  +++ struts-html.xml   2001/01/28 03:48:02 1.5
  @@ -1391,6 +1391,384 @@

   
   
  +
  +
  +img
  +Render an HTML img tag
  +org.apache.struts.taglib.html.ImgTag
  + empty
  +
  +
  +Renders an HTML  element with
  +the image at the specified URL.  Like the link tag, URL
  +rewriting will be applied automatically to the value
  +specified in src, to maintain session state
  +in the absence of cookies.  This will allow dynamic
  +generation of an image where the content displayed for this
  +image will be taken from the attributes of this tag.
  +
  +The base URL for this image is calculated based on
  +the value specified in src.
  +
  +Normally, the src you specify will be left
  +unchanged (other than URL rewriting if necessary).  However,
  +there are two ways you can append one or more dynamically
  +defined query parameters to the src URL --
  +specify a single parameter with the paramId
  +attribute (at its associated attributes to select the value),
  +or specify the name (and optional
  +property) attributes to select a
  +java.util.Map bean that contains one or more
  +parameter ids and corresponding values.
  +
  +To specify a single parameter, use the paramId
  +attribute to define the name of the request parameter to be
  +submitted.  To specify the corresponding value, use one of the
  +following approaches:
  +
  +Specify only the paramName attribute
  +- The named JSP bean (optionally scoped by the value of the
  +paramScope attribute) must identify a value
  +that can be converted to a String.
  +Specify both the paramName and
  +paramProperty attributes - The specified
  +property getter will be called on the JSP bean identified
  +by the paramName (and optional
  +paramScope) attributes, in order to select
  +a value that can be converted to a String.
  +
  +
  +If you prefer to specify a java.util.Map that
  +contains all of the request parameters to be added to the
  +hyperlink, use one of the following techniques:
  +
  +Specify only the name attribute -
  +The named JSP bean (optionally scoped by the value of
  +the scope attribute) must identify a
  +java.util.Map containing the parameters.
  +Specify both name and
  +property attributes - The specified
  +property getter method will be called on the bean
  +identified by the name (and optional
  +scope) attributes, in order to return the
  +java.util.Map containing the parameters.
  +
  +
  +As the Map is processed, the keys are assumed
  +to be the names of query parameters to be appended to the
  +src URL.  The value associate

cvs commit: jakarta-struts/src/share/org/apache/struts/action ActionServlet.java

2001-01-27 Thread craigmcc

craigmcc01/01/27 19:04:32

  Modified:src/share/org/apache/struts/action ActionServlet.java
  Log:
  Cause reload() to unload and reload the configured data sources, along with
  all of the other things that are updated.
  
  Submitted by: Johan Compagner <[EMAIL PROTECTED]>
  
  Revision  ChangesPath
  1.56  +7 -4  
jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
  
  Index: ActionServlet.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- ActionServlet.java2001/01/16 03:52:57 1.55
  +++ ActionServlet.java2001/01/28 03:04:32 1.56
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.55 
2001/01/16 03:52:57 craigmcc Exp $
  - * $Revision: 1.55 $
  - * $Date: 2001/01/16 03:52:57 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.56 
2001/01/28 03:04:32 craigmcc Exp $
  + * $Revision: 1.56 $
  + * $Date: 2001/01/28 03:04:32 $
*
* 
*
  @@ -228,7 +228,7 @@
* 
*
* @author Craig R. McClanahan
  - * @version $Revision: 1.55 $ $Date: 2001/01/16 03:52:57 $
  + * @version $Revision: 1.56 $ $Date: 2001/01/28 03:04:32 $
*/
   
   public class ActionServlet
  @@ -719,6 +719,7 @@
   // Shut down our existing environment
   destroyActions();
   destroyApplication();
  +destroyDataSources();
   destroyInternal();
   
   // Restart from our confirmation files
  @@ -727,6 +728,8 @@
   initDebug();
   initApplication();
   initMapping();
  +initUpload();
  +initDataSources();
   initOther();
   
   }
  
  
  



cvs commit: jakarta-struts/web/test bean-define.jsp bean-write.jsp logic-compare.jsp

2001-01-27 Thread craigmcc

craigmcc01/01/27 18:22:52

  Modified:src/test/org/apache/struts/test TestBean.java
   web/test bean-define.jsp bean-write.jsp logic-compare.jsp
  Log:
  Incorporate tests for "short" properties into the unit test suite.
  
  Revision  ChangesPath
  1.5   +18 -4 jakarta-struts/src/test/org/apache/struts/test/TestBean.java
  
  Index: TestBean.java
  ===
  RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/test/TestBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestBean.java 2001/01/10 01:54:21 1.4
  +++ TestBean.java 2001/01/28 02:22:47 1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/test/org/apache/struts/test/TestBean.java,v 1.4 
2001/01/10 01:54:21 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/01/10 01:54:21 $
  + * $Header: 
/home/cvs/jakarta-struts/src/test/org/apache/struts/test/TestBean.java,v 1.5 
2001/01/28 02:22:47 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/01/28 02:22:47 $
*
* 
*
  @@ -72,7 +72,7 @@
* General purpose test bean for Struts custom tag tests.
*
* @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2001/01/10 01:54:21 $
  + * @version $Revision: 1.5 $ $Date: 2001/01/28 02:22:47 $
*/
   
   public class TestBean extends ActionForm {
  @@ -208,6 +208,20 @@
   
   public void setNullProperty(String nullProperty) {
   this.nullProperty = nullProperty;
  +}
  +
  +
  +/**
  + * A short property.
  + */
  +private short shortProperty = (short) 987;
  +
  +public short getShortProperty() {
  +return (this.shortProperty);
  +}
  +
  +public void setShortProperty(short shortProperty) {
  +this.shortProperty = shortProperty;
   }
   
   
  
  
  
  1.3   +12 -0 jakarta-struts/web/test/bean-define.jsp
  
  Index: bean-define.jsp
  ===
  RCS file: /home/cvs/jakarta-struts/web/test/bean-define.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- bean-define.jsp   2000/12/30 21:15:39 1.2
  +++ bean-define.jsp   2001/01/28 02:22:49 1.3
  @@ -19,6 +19,7 @@
   
   
   
  +
   
   
   
  @@ -54,6 +55,11 @@
   <%= test1_long %>
 
 
  +short
  +
  +<%= test1_short %>
  +  
  +  
   string
   
   <%= test1_string %>
  @@ -75,6 +81,7 @@
   
   
   
  +
   
   
   
  @@ -107,6 +114,11 @@
   long
   
   <%= test2_long %>
  +  
  +  
  +short
  +
  +<%= test2_short %>
 
 
   string
  
  
  
  1.3   +16 -0 jakarta-struts/web/test/bean-write.jsp
  
  Index: bean-write.jsp
  ===
  RCS file: /home/cvs/jakarta-struts/web/test/bean-write.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- bean-write.jsp2000/09/23 23:19:36 1.2
  +++ bean-write.jsp2001/01/28 02:22:50 1.3
  @@ -18,6 +18,7 @@
 pageContext.setAttribute("test1.float", new Float((float) 123.0));
 pageContext.setAttribute("test1.int", new Integer(123));
 pageContext.setAttribute("test1.long", new Long(321));
  +  pageContext.setAttribute("test1.short", new Short((short) 987));
 pageContext.setAttribute("test1.string", "This is a string");
   %>
   
  @@ -53,6 +54,11 @@
 
   
   
  +  short
  +  <%= pageContext.getAttribute("test1.short") %>
  +  
  +
  +
 String
 <%= pageContext.getAttribute("test1.string") %>
 
  @@ -95,6 +101,11 @@
 
   
   
  +  short
  +  
  +  
  +
  +
 String
 
 
  @@ -175,6 +186,11 @@
 long
 
 
  +
  +
  +  short
  +  
  +  
   
   
 String
  
  
  
  1.2   +164 -65   jakarta-struts/web/test/logic-compare.jsp
  
  Index: logic-compare.jsp
  ===
  RCS file: /home/cvs/jakarta-struts/web/test/logic-compare.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- logic-compare.jsp 2000/09/07 01:36:36 1.1
  +++ logic-compare.jsp 2001/01/28 02:22:50 1.2
  @@ -19,6 +19,9 @@
 String long1 = "321";
 String long2 = "111";
 String long3 = "333";
  +  String short1 = "987";
  +  String short2 = "654";
  +  String short3 = "999";
 String str1 = "This is a string";
 String str2 = "Less than";
 String str3 = "XYZ greater than";
  @@ -225,225 +228,321 @@
   
 
 
  -long / EQ
  -
  +int / EQ
  +
   <%= long1 %>
  -equal greaterEqual lessEqual
  +lessEqual lessThan notEqual
   
  -  
   equal
 
  -  
   greaterEqual
 
  -  
   greaterThan
 
  -  
   lessEqual
 

cvs commit: jakarta-struts/src/share/org/apache/struts/util ConvertUtils.java

2001-01-27 Thread craigmcc

craigmcc01/01/27 18:22:13

  Modified:src/share/org/apache/struts/util ConvertUtils.java
  Log:
  Provide configurable default values for numeric conversions that suffer from
  a NumberFormatException error.
  
  Submitted by: Ralph Schaer <[EMAIL PROTECTED]>
  
  Revision  ChangesPath
  1.5   +137 -14   
jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java
  
  Index: ConvertUtils.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConvertUtils.java 2001/01/28 01:18:54 1.4
  +++ ConvertUtils.java 2001/01/28 02:22:12 1.5
  @@ -1,13 +1,13 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v 1.4 
2001/01/28 01:18:54 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/01/28 01:18:54 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v 1.5 
2001/01/28 02:22:12 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/01/28 02:22:12 $
*
* 
*
* The Apache Software License, Version 1.1
*
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
  @@ -68,17 +68,136 @@
   
   /**
* Utility methods for converting String values to objects of the specified
  - * class, and vice versa.
  + * class.  If you specify a Java primitive type, or an array of a Java
  + * primitive type, as a destination type, a scalar or array of the coresponding
  + * Java wrapper class will be created instead.  If you attempt to convert an
  + * Object or Object array of a non-String and non-primitive type, it will be
  + * converted to a scalar String or array of Strings, as appropriate.
*
* @author Craig R. McClanahan
* @author Ralph Schaer
* @author Chris Audley
  - * @version $Revision: 1.4 $ $Date: 2001/01/28 01:18:54 $
  + * @version $Revision: 1.5 $ $Date: 2001/01/28 02:22:12 $
*/
   
   public final class ConvertUtils {
   
   
  +// -- Static Properties
  +
  +
  +/**
  + * The default value for Boolean conversions.
  + */
  +private static Boolean defaultBoolean = new Boolean(false);
  +
  +public boolean getDefaultBoolean() {
  +return (defaultBoolean.booleanValue());
  +}
  +
  +public void setDefaultBoolean(boolean defaultBoolean) {
  +this.defaultBoolean = new Boolean(defaultBoolean);
  +}
  +
  +
  +/**
  + * The default value for Byte conversions.
  + */
  +private static Byte defaultByte = new Byte((byte) 0);
  +
  +public byte getDefaultByte() {
  +return (defaultByte.byteValue());
  +}
  +
  +public void setDefaultByte(byte defaultByte) {
  +this.defaultByte = new Byte(defaultByte);
  +}
  +
  +
  +/**
  + * The default value for Character conversions.
  + */
  +private static Character defaultCharacter = new Character(' ');
  +
  +public char getDefaultCharacter() {
  +return (defaultCharacter.charValue());
  +}
  +
  +public void setDefaultCharacter(char defaultCharacter) {
  +this.defaultCharacter = new Character(defaultCharacter);
  +}
  +
  +
  +/**
  + * The default value for Double conversions.
  + */
  +private static Double defaultDouble = new Double((double) 0.0);
  +
  +public double getDefaultDouble() {
  +return (defaultDouble.doubleValue());
  +}
  +
  +public void setDefaultDouble(double defaultDouble) {
  +this.defaultDouble = new Double(defaultDouble);
  +}
  +
  +
  +/**
  + * The default value for Float conversions.
  + */
  +private static Float defaultFloat = new Float((float) 0.0);
  +
  +public float getDefaultFloat() {
  +return (defaultFloat.floatValue());
  +}
  +
  +public void setDefaultFloat(float defaultFloat) {
  +this.defaultFloat = new Float(defaultFloat);
  +}
  +
  +
  +/**
  + * The default value for Integer conversions.
  + */
  +private static Integer defaultInteger = new Integer(0);
  +
  +public int getDefaultInteger() {
  +return (defaultInteger.intValue());
  +}
  +
  +public void setDefaultInteger(int defaultInteger) {
  +this.defaultInteger = new Integer(defaultInteger);
  +}
  +
  +
  +/**
  + * The default value for Long conversions.
  + */
  +private static Long defaultLong = new Long((long) 0);
  +
  +public long getDefaultLong() {
  +return (defaultLong.longValue());
  +}
  +
  +public void set

cvs commit: jakarta-struts/src/share/org/apache/struts/util ConvertUtils.java

2001-01-27 Thread craigmcc

craigmcc01/01/27 17:18:55

  Modified:src/share/org/apache/struts/util ConvertUtils.java
  Log:
  Add support for Short.  TODO: Deal with the "settable default values"
  addition, but implement it slightly differently.
  
  Submitted by: Ralph Schaer <[EMAIL PROTECTED]>
  
  Revision  ChangesPath
  1.4   +27 -4 
jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java
  
  Index: ConvertUtils.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConvertUtils.java 2001/01/28 01:07:57 1.3
  +++ ConvertUtils.java 2001/01/28 01:18:54 1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v 1.3 
2001/01/28 01:07:57 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/01/28 01:07:57 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v 1.4 
2001/01/28 01:18:54 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/01/28 01:18:54 $
*
* 
*
  @@ -73,7 +73,7 @@
* @author Craig R. McClanahan
* @author Ralph Schaer
* @author Chris Audley
  - * @version $Revision: 1.3 $ $Date: 2001/01/28 01:07:57 $
  + * @version $Revision: 1.4 $ $Date: 2001/01/28 01:18:54 $
*/
   
   public final class ConvertUtils {
  @@ -147,6 +147,8 @@
   return (convertByte(value));
   } else if (clazz == Float.TYPE) {
   return (convertFloat(value));
  +} else if (clazz == Short.TYPE) {
  +return (convertShort(value));
   } else {
   if (value == null)
   return ((String) null);
  @@ -215,6 +217,11 @@
   for (int i = 0; i < len; i++)
   array[i] = convertFloat(values[i]).floatValue();
   return (array);
  +} else if (type == Short.TYPE) {
  +short array[] = new short[len];
  +for (int i = 0; i < len; i++)
  +array[i] = convertShort(values[i]).shortValue();
  +return (array);
   } else {
   if (values == null)
   return ((String[]) null);
  @@ -343,6 +350,22 @@
   return (new Long(value));
   } catch (NumberFormatException e) {
   return (new Long(0));
  +}
  +
  +}
  +
  +
  +/**
  + * Convert a String value to a corresponding Short value.
  + *
  + * @param value The string value to convert
  + */
  +private static Short convertShort(String value) {
  +
  +try {
  +return (new Short(value));
  +} catch (NumberFormatException e) {
  +return (new Short((short) 0));
   }
   
   }
  
  
  



Re: ConvertUtils

2001-01-27 Thread Craig R. McClanahan

Elod Horvath wrote:

> craig,
>
> i have efficiency questions about ConvertUtils.convert...
> isn't it true that the vm loads these class object once:
> java.lang.Boolean, java.lang.String, Boolean.TYPE, etc.
>
> isn't it more efficient to just compare class objects rather playing
> with their string representations?
>

Yep ... good idea.  I just submitted a patch that implements both of your
suggestions (comparing class types and ordering the if/else chain)..

Craig





cvs commit: jakarta-struts/src/share/org/apache/struts/util ConvertUtils.java

2001-01-27 Thread craigmcc

craigmcc01/01/27 17:07:58

  Modified:src/share/org/apache/struts/util ConvertUtils.java
  Log:
  Improve the efficiency of type conversions (and fix some bugs in the
  array conversions) as follows:
  * Compare the class objects directly, using "==", which will work because
each class is loaded only once per webapp.
  * Order the if .. else if ... chain in an order of likelihood of the
underlying types being used.
  
  Submitted by: Elod Horvath <[EMAIL PROTECTED]>
  
  Revision  ChangesPath
  1.3   +48 -96
jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java
  
  Index: ConvertUtils.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConvertUtils.java 2001/01/08 20:34:56 1.2
  +++ ConvertUtils.java 2001/01/28 01:07:57 1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v 1.2 
2001/01/08 20:34:56 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/01/08 20:34:56 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/ConvertUtils.java,v 1.3 
2001/01/28 01:07:57 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/01/28 01:07:57 $
*
* 
*
  @@ -73,12 +73,21 @@
* @author Craig R. McClanahan
* @author Ralph Schaer
* @author Chris Audley
  - * @version $Revision: 1.2 $ $Date: 2001/01/08 20:34:56 $
  + * @version $Revision: 1.3 $ $Date: 2001/01/28 01:07:57 $
*/
   
   public final class ConvertUtils {
   
   
  +// --- Static Variables
  +
  +
  +/**
  + * The Class object for java.lang.String.
  + */
  +private static Class stringClass = "".getClass();
  +
  +
   // - Public Classes
   
   
  @@ -114,46 +123,30 @@
* to the correct value) is returned instead.
*
* @param value Value to be converted (may be null)
  - * @param clazz Java class to be converted to (must be String, one of
  - *  the Java primitive types, or one of the primitive wrappers)
  + * @param clazz Java class to be converted to (must be java.lang.String
  + *  or one of the primitive type wrappers)
*/
   public static Object convert(String value, Class clazz) {
   
  -String type = clazz.getName();
  -if ("java.lang.String".equals(type) ||
  -"String".equals(type)) {
  +if (clazz == stringClass) {
   if (value == null)
   return ((String) null);
   else
   return (value);
  -} else if ("java.lang.Boolean".equals(type) ||
  -   Boolean.TYPE.getName().equals(type) ||
  -   "boolean".equals(type)) {
  -return (convertBoolean(value));
  -} else if ("java.lang.Byte".equals(type) ||
  -   Byte.TYPE.getName().equals(type) ||
  -   "byte".equals(type)) {
  -return (convertByte(value));
  -} else if ("java.lang.Character".equals(type) ||
  -   Character.TYPE.getName().equals(type) ||
  -   "char".equals(type)) {
  -return (convertCharacter(value));
  -} else if ("java.lang.Integer".equals(type) ||
  -   Integer.TYPE.getName().equals(type) ||
  -   "int".equals(type)) {
  +} else if (clazz == Integer.TYPE) {
   return (convertInteger(value));
  -} else if ("java.lang.Long".equals(type) ||
  -   Long.TYPE.getName().equals(type) ||
  -   "long".equals(type)) {
  +} else if (clazz == Boolean.TYPE) {
  +return (convertBoolean(value));
  +} else if (clazz == Long.TYPE) {
   return (convertLong(value));
  -} else if ("java.lang.Float".equals(type) ||
  -   Float.TYPE.getName().equals(type) ||
  -   "float".equals(type)) {
  -return (convertFloat(value));
  -} else if ("java.lang.Double".equals(type) ||
  -   Double.TYPE.getName().equals(type) ||
  -   "double".equals(type)) {
  +} else if (clazz == Double.TYPE) {
   return (convertDouble(value));
  +} else if (clazz == Character.TYPE) {
  +return (convertCharacter(value));
  +} else if (clazz == Byte.TYPE) {
  +return (convertByte(value));
  +} else if (clazz == Float.TYPE) {
  +return (convertFloat(value));
   } else {
   if (value == null)
   return ((String) null);
  @@ -172,14 +165,13 @@
* or a Java wrapp

cvs commit: jakarta-struts/web/example logon.jsp registration.jsp subscription.jsp

2001-01-27 Thread craigmcc

craigmcc01/01/27 15:31:18

  Modified:web/example logon.jsp registration.jsp subscription.jsp
  Log:
  Update the example application to the new recommended standard for
  specifying the action property.  Values without a leading slash are
  still accepted, for backwards compatibility.
  
  Revision  ChangesPath
  1.15  +1 -1  jakarta-struts/web/example/logon.jsp
  
  Index: logon.jsp
  ===
  RCS file: /home/cvs/jakarta-struts/web/example/logon.jsp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- logon.jsp 2001/01/23 20:44:54 1.14
  +++ logon.jsp 2001/01/27 23:31:14 1.15
  @@ -11,7 +11,7 @@
   
   
   
  -
  +
   
   
 
  
  
  
  1.17  +1 -1  jakarta-struts/web/example/registration.jsp
  
  Index: registration.jsp
  ===
  RCS file: /home/cvs/jakarta-struts/web/example/registration.jsp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- registration.jsp  2001/01/07 00:16:28 1.16
  +++ registration.jsp  2001/01/27 23:31:15 1.17
  @@ -24,7 +24,7 @@
   
   
   
  -
  +
   
   
   
  
  
  
  1.22  +1 -1  jakarta-struts/web/example/subscription.jsp
  
  Index: subscription.jsp
  ===
  RCS file: /home/cvs/jakarta-struts/web/example/subscription.jsp,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- subscription.jsp  2001/01/07 00:16:29 1.21
  +++ subscription.jsp  2001/01/27 23:31:16 1.22
  @@ -33,7 +33,7 @@
   
   
   
  -
  +
   
   
   
  
  
  



cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/html FormTag.java LocalStrings.properties

2001-01-27 Thread craigmcc

craigmcc01/01/27 15:21:09

  Modified:src/doc  struts-html.xml
   src/share/org/apache/struts/taglib/html FormTag.java
LocalStrings.properties
  Log:
  Improve the mechanism by which the  tag calculates the action
  mapping to which this form will be submitted.  Now, it should work for
  all of the following cases:
  
  * Extension mapped:  "logon.do" or "/logon.do" or "/admin/logon.do"
  
  * Path mapped:  "/execute/logon"
  
  In all cases, a server-relative URL will be generated by prepending the
  context path.
  
  This patch is based on the patch submitted by Chris Smith
  <[EMAIL PROTECTED]>, but modified to work for path mapped
  servlets as well.
  
  Revision  ChangesPath
  1.4   +54 -24jakarta-struts/src/doc/struts-html.xml
  
  Index: struts-html.xml
  ===
  RCS file: /home/cvs/jakarta-struts/src/doc/struts-html.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- struts-html.xml   2001/01/27 20:09:42 1.3
  +++ struts-html.xml   2001/01/27 23:21:07 1.4
  @@ -985,15 +985,25 @@


action
  - false
  + true
true

  - The URL to which this form will be submitted. 
Typically, this will
  - match a mapping for the ActionServlet managing this 
application.
  - URL rewriting will automatically be performed on this 
URL, to
  - maintain session state in the absence of cookies. 
[Form will be
  - submitted to this page itself] 
  - 
  +The URL to which this form will be submitted.  This
  +value is also used to select the ActionMapping we are
  +assumed to be processing, from which we can identify
  +the appropriate form bean and scope.
  +
  +If you are using extension mapping for selecting the
  +controller servlet, this value should be equal to the
  +path attribute of the corresponding
  + element, plus the correct
  +file extension suffix.
  +
  +If you are using path mapping to select the
  +controller servlet, this value should be exactly equal
  +to the path attribute of the corresponding
  + element.
  +



  @@ -1034,14 +1044,22 @@
false
true

  - Name of the request scope or session scope bean (as 
defined by
  - the scope attribute) whose properties will be used to 
populate
  - input field values. If no such bean is found, a new 
bean will
  - be created (and added to the appropriate scope), using 
the Java
  - class name specified by the type attribute. 
  - 
  - 
  - 
  +Name of the request scope or session scope bean
  +(as defined by the scope attribute)
  +whose properties will be used to populate the input
  +field values.  If no such bean is found, a new bean
  +will be created and added to the appropriate scope,
  +using the Java class name specified by the
  +type attribute.
  +
  +If this attribute is not specified, it will be
  +calculated by using the value of the
  +action attribute to look up the
  +corresponding ActionMapping element, from which
  +we will select the specified form bean name.
  +
  +
  +

onreset
false
  @@ -1065,9 +1083,17 @@
false
true

  - JSP scope within which the associated bean will be 
accessed
  - or created (request, session). [session]
  - 
  +Scope within which the form bean associated with
  +this input form will be accessed or created (must be
  +either request or session.
  + 

Re: ErrorsTag

2001-01-27 Thread Craig R. McClanahan

Howard Moore wrote:

> I've modified the ErrorsTag (based on the 2001/01/25 19:18:17 version) to
> support only displaying errors for a given property. It takes an additional
> optional attribute 'property' which identifies which errors to display. If
> 'property' is not specified all errors are displayed.
>
> Any chance of including it?
>

Thanks Howard, as a matter of fact there is :-).  It will be in tonight's
nightly build.

For people who want to submit patches to existing source files, it would be
really helpful if you could create a "unified diff" of the changes between your
proposed code and the current version.  Instructions for doing this are on the
web site at:

http://jakarta.apache.org/site/bugs.html

(On Windows systems, the "diff" command is available from many public domain
sources, including the CYGWIN environment which includes a large subset of the
standard Unix shell tools configured to work on a Win32 based system.)

>
> ---
> Howard Moore
>

Craig





cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/html ErrorsTag.java

2001-01-27 Thread craigmcc

craigmcc01/01/27 12:09:44

  Modified:src/doc  struts-html.xml
   src/share/org/apache/struts/taglib/html ErrorsTag.java
  Log:
  Add a "property" attribute to  so that you can extract just
  the error messages for a particular property.  By default, all error
  messages for all properties are extracted (which was the previous
  behavior).
  
  Submitted by: Howard Moore <[EMAIL PROTECTED]>
  
  Revision  ChangesPath
  1.3   +11 -0 jakarta-struts/src/doc/struts-html.xml
  
  Index: struts-html.xml
  ===
  RCS file: /home/cvs/jakarta-struts/src/doc/struts-html.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- struts-html.xml   2001/01/11 00:29:51 1.2
  +++ struts-html.xml   2001/01/27 20:09:42 1.3
  @@ -714,6 +714,17 @@
 
   
   
  +
  +  property
  +  false
  +  true
  +  
  +  Name of the property for which error messages should be
  +  displayed.  If not specified, all error messages (regardless
  +  of property) are displayed.
  +  
  +
  +
   
   

  
  
  
  1.3   +26 -5 
jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java
  
  Index: ErrorsTag.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ErrorsTag.java2001/01/25 19:18:17 1.2
  +++ ErrorsTag.java2001/01/27 20:09:43 1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v 1.2 
2001/01/25 19:18:17 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/01/25 19:18:17 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v 1.3 
2001/01/27 20:09:43 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/01/27 20:09:43 $
*
* 
*
  @@ -96,7 +96,7 @@
* 
*
* @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2001/01/25 19:18:17 $
  + * @version $Revision: 1.3 $ $Date: 2001/01/27 20:09:43 $
*/
   
   public class ErrorsTag extends TagSupport {
  @@ -126,6 +126,22 @@
   }
   
   
  +/**
  + * The name of the property for which error messages should be returned,
  + * or null to return all errors.
  + */
  +protected String property = null;
  +
  +public String getProperty() {
  +return (this.property);
  +}
  +
  +public void setProperty(String property) {
  +this.property = property;
  +}
  +
  +
  +
   // --- Public Methods
   
   
  @@ -190,7 +206,11 @@
results.append(message);
results.append("\r\n");
}
  -Iterator reports = errors.get();
  +Iterator reports = null;
  +if (property == null)
  +reports = errors.get();
  +else
  +reports = errors.get(property);
   while (reports.hasNext()) {
   ActionError report = (ActionError) reports.next();
   if (messages != null)
  @@ -234,6 +254,7 @@
   
super.release();
name = Action.ERROR_KEY;
  +property = null;
   
   }
   
  
  
  



Re: ConvertUtils

2001-01-27 Thread Elod Horvath

craig,

i have efficiency questions about ConvertUtils.convert...
isn't it true that the vm loads these class object once:
java.lang.Boolean, java.lang.String, Boolean.TYPE, etc.

isn't it more efficient to just compare class objects rather playing
with their string representations?  

for example (Version 1):

if (java.lang.String.class.equals(clazz) {
if (value == null)
return ((String) null);
else
return (value);
} else if (java.lang.Boolean.class.equals(clazz) ||
   java.lang.Boolean.TYPE.equals(clazz) {
return (convertBoolean(value));
} else if (java.lang.Byte.class.equals(clazz) ||
   java.lang.Byte.TYPE.equals(clazz){
return (convertByte(value));
.
.
.

-OR (Version 2):-

if (java.lang.String.class == clazz) {
if (value == null)
return ((String) null);
else
return (value);
} else if (java.lang.Boolean.class == clazz ||
   java.lang.Boolean.TYPE == clazz) {
return (convertBoolean(value));
} else if (java.lang.Byte.class == clazz ||
   java.lang.Byte.TYPE == clazz ){
return (convertByte(value));
.
.
.


are there some issues with the class loader dumping and reloading these
class objects from memory that would make this type of optimization 
in this case dangerous or foolish?

also, since this is a big cascading if/else if statement, shouldn't
the else ifs be ordered according to the practical probability of using
a particular data type.  in my opinion, integer, long, float, and
double are probably used more often than byte and char and should 
therefore be checked ahead of them.


e
-- 
___
Elod Horvath ('e')   /  ITFAIS Records (http://www.itfais.com/)



Re: ConvertUtils

2001-01-27 Thread Ralph Schaer

Hi

I changed the ConvertUtils. Now the wrapper classes get a null value instead
of
a zero when the string is not valid. The native types get a default value,
which
is actually zero, but is changeable through a method.

Also add support for short.


Ralph

>I'm open to suggestion on alternatives.

>The problem is that there is nothing in the range of most of the primitive
types
>(byte, char, int, long) that corresponds to a "null" value for an object
>reference.  The only thing we can do is:
>* Pick one particular value to be ambiguous ("did the user
>  really type a zero or not?").
>* Throw a conversion exception, which just throws the
>  same decision back up a level.





 ConvertUtils.java