You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2008/05/25 15:58:55 UTC

svn commit: r659986 - in /turbine/fulcrum/trunk/intake: src/java/org/apache/fulcrum/intake/model/ src/java/org/apache/fulcrum/intake/validator/ xdocs/

Author: tv
Date: Sun May 25 06:58:54 2008
New Revision: 659986

URL: http://svn.apache.org/viewvc?rev=659986&view=rev
Log:
Port latest changes from Turbine 2.3.

Modified:
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java
    turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/BooleanValidator.java
    turbine/fulcrum/trunk/intake/xdocs/changes.xml

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BigDecimalField.java Sun May 25 06:58:54 2008
@@ -35,7 +35,7 @@
  * @version $Id$
  */
 public class BigDecimalField
-        extends AbstractNumberField
+        extends Field
 {
     /**
      * Constructor.
@@ -104,19 +104,21 @@
     {
         if (isMultiValued)
         {
-            String[] inputs = parser.getStrings(getKey());
-            BigDecimal[] values = new BigDecimal[inputs.length];
-            for (int i = 0; i < inputs.length; i++)
+            BigDecimal[] values = parser.getBigDecimals(getKey());
+
+            for (int i = 0; i < values.length; i++)
             {
-                values[i] = StringUtils.isNotEmpty(inputs[i])
-                        ? new BigDecimal(canonicalizeDecimalInput(inputs[i])) : (BigDecimal) getEmptyValue();
+                if (values[i] == null)
+                {
+                    values[i] = (BigDecimal) getEmptyValue();
+                }
             }
+
             setTestValue(values);
         }
         else
         {
-            String val = parser.getString(getKey());
-            setTestValue(StringUtils.isNotEmpty(val) ? new BigDecimal(canonicalizeDecimalInput(val)) : (BigDecimal) getEmptyValue());
+            setTestValue(parser.getBigDecimal(getKey(), (BigDecimal)getEmptyValue()));
         }
     }
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/BooleanField.java Sun May 25 06:58:54 2008
@@ -19,8 +19,6 @@
  * under the License.
  */
 
-import java.text.ParseException;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.fulcrum.intake.IntakeException;
 import org.apache.fulcrum.intake.validator.BooleanValidator;
@@ -61,7 +59,7 @@
             return;
         }
 
-        defaultValue = new Boolean(prop);
+        defaultValue = Boolean.valueOf(prop);
     }
 
     /**
@@ -81,7 +79,7 @@
             return;
         }
 
-        emptyValue = new Boolean(prop);
+        emptyValue = Boolean.valueOf(prop);
     }
 
     /**
@@ -123,58 +121,22 @@
     {
         if (isMultiValued)
         {
-            String[] inputs = parser.getStrings(getKey());
+            Boolean[] inputs = parser.getBooleanObjects(getKey());
             boolean[] values = new boolean[inputs.length];
+
             for (int i = 0; i < inputs.length; i++)
             {
-                values[i] = StringUtils.isNotEmpty(inputs[i])
-                        ? getBoolean(inputs[i]).booleanValue()
-                        : ((Boolean) getEmptyValue()).booleanValue();
+                values[i] = inputs[i] == null 
+                        ? ((Boolean) getEmptyValue()).booleanValue() 
+                        : inputs[i].booleanValue();
             }
-            setTestValue(values);
-        }
-        else
-        {
-            String val = parser.getString(getKey());
-            setTestValue(StringUtils.isNotEmpty(val)
-                    ? getBoolean(val) : (Boolean) getEmptyValue());
-        }
-    }
 
-    /**
-     * Parses a string into a Boolean object.  If the field has a validator
-     * and the validator is an instance of BooleanValidator, the parse()
-     * method is used to convert the string into the Boolean.  Otherwise,
-     * the string value is passed to the constructor to the Boolean
-     * object.
-     *
-     * @param stringValue string to parse
-     * @return a <code>Boolean</code> object
-     */
-    private Boolean getBoolean(String stringValue)
-    {
-        Boolean result = null;
-
-        if (validator != null && validator instanceof BooleanValidator)
-        {
-            BooleanValidator bValidator = (BooleanValidator) validator;
-            try
-            {
-                result = bValidator.parse(stringValue);
-            }
-            catch (ParseException e)
-            {
-                // do nothing.  This should never be thrown since this method will not be
-                // executed unless the Validator has already been able to parse the
-                // string value
-            }
+            setTestValue(values);
         }
         else
         {
-            result = new Boolean(stringValue);
+            setTestValue(parser.getBooleanObject(getKey(), (Boolean)getEmptyValue()));
         }
-
-        return result;
     }
 
     /**

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/DoubleField.java Sun May 25 06:58:54 2008
@@ -31,7 +31,7 @@
  * @version $Id$
  */
 public class DoubleField
-        extends AbstractNumberField
+        extends Field
 {
     /**
      * Constructor.
@@ -123,22 +123,21 @@
     {
         if (isMultiValued)
         {
-            String[] inputs = parser.getStrings(getKey());
+            Double[] inputs = parser.getDoubleObjects(getKey());
             double[] values = new double[inputs.length];
+
             for (int i = 0; i < inputs.length; i++)
             {
-                values[i] = StringUtils.isNotEmpty(inputs[i])
-                        ? new Double(canonicalizeDecimalInput(inputs[i])).doubleValue()
-                        : ((Double) getEmptyValue()).doubleValue();
+                values[i] = inputs[i] == null 
+                        ? ((Double) getEmptyValue()).doubleValue() 
+                        : inputs[i].doubleValue();
             }
+
             setTestValue(values);
         }
         else
         {
-            String val = parser.getString(getKey());
-            setTestValue(StringUtils.isNotEmpty(val)
-                    ? new Double(canonicalizeDecimalInput(val))
-                    : (Double) getEmptyValue());
+            setTestValue(parser.getDoubleObject(getKey(), (Double)getEmptyValue()));
         }
     }
 

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/FloatField.java Sun May 25 06:58:54 2008
@@ -31,7 +31,7 @@
  * @version $Id$
  */
 public class FloatField
-        extends AbstractNumberField
+        extends Field
 {
     /**
      * Constructor.
@@ -123,22 +123,21 @@
     {
         if (isMultiValued)
         {
-            String[] inputs = parser.getStrings(getKey());
+            Float[] inputs = parser.getFloatObjects(getKey());
             float[] values = new float[inputs.length];
+
             for (int i = 0; i < inputs.length; i++)
             {
-                values[i] = StringUtils.isNotEmpty(inputs[i])
-                        ? new Float(canonicalizeDecimalInput(inputs[i])).floatValue()
-                        : ((Float) getEmptyValue()).floatValue();
+                values[i] = inputs[i] == null 
+                        ? ((Float) getEmptyValue()).floatValue() 
+                        : inputs[i].floatValue();
             }
+
             setTestValue(values);
         }
         else
         {
-            String val = parser.getString(getKey());
-            setTestValue(StringUtils.isNotEmpty(val)
-                    ? new Float(canonicalizeDecimalInput(val))
-                    : getEmptyValue());
+            setTestValue(parser.getFloatObject(getKey(), (Float)getEmptyValue()));
         }
     }
 

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/IntegerField.java Sun May 25 06:58:54 2008
@@ -67,7 +67,7 @@
      * Set the empty Value. This value is used if Intake
      * maps a field to a parameter returned by the user and
      * the corresponding field is either empty (empty string)
-     * or non-existant.
+     * or non-existent.
      *
      * @param prop The value to use if the field is empty.
      */
@@ -123,21 +123,21 @@
     {
         if (isMultiValued)
         {
-            String[] inputs = parser.getStrings(getKey());
+            Integer[] inputs = parser.getIntObjects(getKey());
             int[] values = new int[inputs.length];
+
             for (int i = 0; i < inputs.length; i++)
             {
-                values[i] = StringUtils.isNotEmpty(inputs[i])
-                        ? new Integer(inputs[i]).intValue()
-                        : ((Integer) getEmptyValue()).intValue();
+                values[i] = inputs[i] == null 
+                        ? ((Integer) getEmptyValue()).intValue() 
+                        : inputs[i].intValue();
             }
+
             setTestValue(values);
         }
         else
         {
-            String val = parser.getString(getKey());
-            setTestValue(StringUtils.isNotEmpty(val)
-                    ? new Integer(val) : (Integer) getEmptyValue());
+            setTestValue(parser.getIntObject(getKey(), (Integer)getEmptyValue()));
         }
     }
 

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/LongField.java Sun May 25 06:58:54 2008
@@ -123,22 +123,21 @@
     {
         if (isMultiValued)
         {
-            String[] inputs = parser.getStrings(getKey());
+            Long[] inputs = parser.getLongObjects(getKey());
             long[] values = new long[inputs.length];
+
             for (int i = 0; i < inputs.length; i++)
             {
-                values[i] = StringUtils.isNotEmpty(inputs[i])
-                        ? new Long(inputs[i]).longValue()
-                        : ((Long) getEmptyValue()).longValue();
+                values[i] = inputs[i] == null 
+                        ? ((Long) getEmptyValue()).longValue() 
+                        : inputs[i].longValue();
             }
+
             setTestValue(values);
         }
         else
         {
-            String val = parser.getString(getKey());
-            setTestValue(StringUtils.isNotEmpty(val)
-                    ? new Long(val) : (Long) getEmptyValue());
+            setTestValue(parser.getLongObject(getKey(), (Long)getEmptyValue()));
         }
     }
-
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/model/ShortField.java Sun May 25 06:58:54 2008
@@ -123,22 +123,30 @@
     {
         if (isMultiValued)
         {
-            String[] inputs = parser.getStrings(getKey());
+            Integer[] inputs = parser.getIntObjects(getKey());
             short[] values = new short[inputs.length];
+
             for (int i = 0; i < inputs.length; i++)
             {
-                values[i] = StringUtils.isNotEmpty(inputs[i])
-                        ? new Short(inputs[i]).shortValue()
-                        : ((Short) getEmptyValue()).shortValue();
+                values[i] = inputs[i] == null 
+                        ? ((Short) getEmptyValue()).shortValue() 
+                        : inputs[i].shortValue();
             }
+
             setTestValue(values);
         }
         else
         {
-            String val = parser.getString(getKey());
-            setTestValue(StringUtils.isNotEmpty(val)
-                    ? new Short(val) : (Short) getEmptyValue());
+            Integer value = parser.getIntObject(getKey());
+            
+            if (value == null)
+            {
+                setTestValue((Short)getEmptyValue());
+            }
+            else
+            {
+                setTestValue(new Short(value.shortValue()));
+            }
         }
     }
-
 }

Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/BooleanValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/BooleanValidator.java?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/BooleanValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/BooleanValidator.java Sun May 25 06:58:54 2008
@@ -39,6 +39,7 @@
  * <li>YES</li>
  * <li>Y</li>
  * <li>1</li>
+ * <li>ON</li>
  * </ul>
  * Valid values for Boolean.FALSE:
  * <ul>
@@ -47,6 +48,7 @@
  * <li>NO</li>
  * <li>N</li>
  * <li>0</li>
+ * <li>OFF</li>
  * </ul>
  *
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
@@ -58,10 +60,10 @@
         extends DefaultValidator
 {
     /** String values which would evaluate to Boolean.TRUE */
-    private static String[] trueValues = {"TRUE","T","YES","Y","1"};
+    private static String[] trueValues = {"TRUE","T","YES","Y","1","ON"};
 
     /** String values which would evaluate to Boolean.FALSE */
-    private static String[] falseValues = {"FALSE","F","NO","N","0"};
+    private static String[] falseValues = {"FALSE","F","NO","N","0","OFF"};
 
     /**
      * Default Constructor

Modified: turbine/fulcrum/trunk/intake/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/xdocs/changes.xml?rev=659986&r1=659985&r2=659986&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/xdocs/changes.xml (original)
+++ turbine/fulcrum/trunk/intake/xdocs/changes.xml Sun May 25 06:58:54 2008
@@ -27,6 +27,11 @@
   <body>
   	 <release version="1.0.4-dev" date="in Subversion">
       <action type="update" dev="tv">
+        Use the localize features of the parser to simplify the value assignment
+        in Intake fields. Made handling of empty values consistent over all number
+        field types.
+      </action>
+      <action type="update" dev="tv">
         Updated locale handling to use the new localized parameter parser. This
         removes the dependency from LocalizationService
       </action>
@@ -40,7 +45,7 @@
       <action type="fix" dev="seade" issue="TRB-9" due-to="J&#252;rgen Hoffmann">
         Intake was not handling empty values correctly.
       </action>
-      <action type="fix" dev="eade" issue="TRB-14" due-to="J&#252;rgen Hoffmann">
+      <action type="fix" dev="seade" issue="TRB-14" due-to="J&#252;rgen Hoffmann">
       	Intake was not loading the correct Default Validators when the rules for
       	a field are empty.
       </action>