You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Scott Eade <se...@backstagetech.com.au> on 2003/09/10 04:41:32 UTC

Intake bug: validation continues when required=false

Over on turbine-user somebody has hit upon a problem
with the new validator code in 2.3 (co-incidentally I
hit this at the very same time).

It turns out that the Intake validator enhancements
done as part of 2.3 do not provide a way for
DefaultValidator to communicate back to the sub-classes
that the validation process should stop under certain
circumstances (primarily when the required rule has a
value of false and nothing has been entered).

My question is, what is the best way of communicating
this information back to the subclasses?  Adding a
return value to the assertValidity() methods seems to
go against the method name.  An alternative might be
to throw a ValidationCompletedException (extends
ValidationException) - using an exception to control
processing in this manner seems not quite right to me,
but there is enough of it going on in the validator
code to argue that it is legitimate.  Any other bright
ideas?

Scott

-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au





Re: Deprecated Classes to be removed

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
"Eric Pugh" <ep...@upstate.com> writes:

>Okay,
>I started looking at classes that can be removed, and it seems like a couple
>entire tree's of classes can be removed.

>Both org.apache.turbine.services.jsp.util.JspLink and
>org.apache.turbine.util.DynamicURI both extend down from
>org.apache.turbine.util.uri.URI.  However, while both are deprecated, the

Nah, they don't. They implement URI. 

>interface URI isn't.  However, it seems like it should be marked as
>deprecated for removal in 2.4?  Henning, I believe your stuff replaced this,
>so I leave it up to you.

URI is a "glue" interface to tie the old and new URI code
together. Once the old code is gone, it could go, too. 

>Another one is org.apache.turbine.services.intake.model.NumberKeyField uses
>the deprecated NumberKeyValidator, but itself isn't marked deprecated..  Can
>we delete both since one is reliant on the other?

NumberKey has vanished from Torque, so it can go here, too. IMHO.

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

Java, perl, Solaris, Linux, xSP Consulting, Web Services 
freelance consultant -- Jakarta Turbine Development  -- hero for hire

"Dominate!! Dominate!! Eat your young and aggregate! I have grotty silicon!" 
      -- AOL CD when played backwards  (User Friendly - 200-10-15)

Deprecated Classes to be removed

Posted by Eric Pugh <ep...@upstate.com>.
Okay,
I started looking at classes that can be removed, and it seems like a couple
entire tree's of classes can be removed.

Both org.apache.turbine.services.jsp.util.JspLink and
org.apache.turbine.util.DynamicURI both extend down from
org.apache.turbine.util.uri.URI.  However, while both are deprecated, the
interface URI isn't.  However, it seems like it should be marked as
deprecated for removal in 2.4?  Henning, I believe your stuff replaced this,
so I leave it up to you.


Another one is org.apache.turbine.services.intake.model.NumberKeyField uses
the deprecated NumberKeyValidator, but itself isn't marked deprecated..  Can
we delete both since one is reliant on the other?

Eric






AW: Intake bug: validation continues when required=false

Posted by Jürgen Hoffmann <jh...@byteaction.de>.
Hi,

The question here is why do we use Exceptions anyway. I think we should
have an assertValidity Method that returns boolean that is the unsed to
set valid to false or true. And then have the 

            if (validator != null)
            {
                // set the test value as a String[] which might be
replaced by
                // the correct type if the input is valid.
                setTestValue(parser.getStrings(getKey()));
                for (int i = 0; i < stringValues.length; i++)
                {
                    try
                    {
                        validator.assertValidity(stringValues[i]);
                    }
                    catch (ValidationException ve)
                    {
                        setMessage(ve.getMessage());
                    }
                }
            }

Of Field.java changed to:

            if (validator != null)
            {
                // set the test value as a String[] which might be
replaced by
                // the correct type if the input is valid.
                setTestValue(parser.getStrings(getKey()));
                for (int i = 0; i < stringValues.length; i++)
                {
                    if(!validator.assertValidity(stringValues[i]))
			  {
				setMessage(validator.getMessage());
			  }
                }
            }

Is there some history that made you guys use internal Exceptions?

Kind regards
 
Jürgen Hoffmann



-----Ursprüngliche Nachricht-----
Von: Scott Eade [mailto:seade@backstagetech.com.au] 
Gesendet: Mittwoch, 10. September 2003 04:42
An: Turbine Developers List
Betreff: Intake bug: validation continues when required=false


Over on turbine-user somebody has hit upon a problem
with the new validator code in 2.3 (co-incidentally I
hit this at the very same time).

It turns out that the Intake validator enhancements
done as part of 2.3 do not provide a way for
DefaultValidator to communicate back to the sub-classes
that the validation process should stop under certain circumstances
(primarily when the required rule has a value of false and nothing has
been entered).

My question is, what is the best way of communicating
this information back to the subclasses?  Adding a
return value to the assertValidity() methods seems to
go against the method name.  An alternative might be
to throw a ValidationCompletedException (extends
ValidationException) - using an exception to control
processing in this manner seems not quite right to me,
but there is enough of it going on in the validator
code to argue that it is legitimate.  Any other bright
ideas?

Scott

-- 
Scott Eade
Backstage Technologies Pty. Ltd. http://www.backstagetech.com.au





---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org




Re: AW: Intake bug: validation continues when required=false

Posted by Scott Eade <se...@backstagetech.com.au>.
Jürgen Hoffmann wrote:

>I have patched the new Intake Validator Code. This works for us, and I
>have done some formatting, sorry. I can redo this if you guys want to.
>Formatting is automatically done when we check into cvs. I hope unified
>format is correct.
>  
>
Great!

unidiff is good
    http://jakarta.apache.org/site/source.html#Patches
formatting changes are not good
    http://jakarta.apache.org/turbine/common/code-standards.html

Can you please repost as an attachment so that the line wrapping
does not cause problems and without the formatting changes.

You can mail this directly to me if you like - I will review, test
and commit it tomorrow.

Thanks,

Scott

-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au





AW: Intake bug: validation continues when required=false

Posted by Jürgen Hoffmann <jh...@byteaction.de>.
Hi,

I have patched the new Intake Validator Code. This works for us, and I
have done some formatting, sorry. I can redo this if you guys want to.
Formatting is automatically done when we check into cvs. I hope unified
format is correct.

Index: BigDecimalValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/BigDecimalValidator.java,v
retrieving revision 1.2
diff -u -r1.2 BigDecimalValidator.java
--- BigDecimalValidator.java	19 Jun 2003 16:55:17 -0000	1.2
+++ BigDecimalValidator.java	10 Sep 2003 10:30:16 -0000
@@ -1,5 +1,6 @@
 package org.apache.turbine.services.intake.validator;
 
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,8 +54,8 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
-
 import java.math.BigDecimal;
+
 import java.util.Map;
 
 /**
@@ -73,10 +74,10 @@
  *
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: BigDecimalValidator.java,v 1.2 2003/06/19 16:55:17
henning Exp $
  */
-public class BigDecimalValidator
-        extends NumberValidator
+public class BigDecimalValidator extends NumberValidator
 {
     private BigDecimal minValue = null;
     private BigDecimal maxValue = null;
@@ -87,8 +88,7 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public BigDecimalValidator(Map paramMap)
-            throws InvalidMaskException
+    public BigDecimalValidator(Map paramMap) throws
InvalidMaskException
     {
         invalidNumberMessage = "Entry was not a valid BigDecimal";
         init(paramMap);
@@ -107,25 +107,28 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    public void init(Map paramMap) throws InvalidMaskException
     {
         super.init(paramMap);
 
         Constraint constraint = (Constraint)
paramMap.get(MIN_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            minValue = new BigDecimal(param);
-            minValueMessage = constraint.getMessage();
+
+            minValue            = new BigDecimal(param);
+            minValueMessage     = constraint.getMessage();
         }
 
         constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            maxValue = new BigDecimal(param);
-            maxValueMessage = constraint.getMessage();
+
+            maxValue            = new BigDecimal(param);
+            maxValueMessage     = constraint.getMessage();
         }
     }
 
@@ -137,34 +140,37 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        BigDecimal bd = null;
-        try
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            bd = new BigDecimal(testValue);
-        }
-        catch (RuntimeException e)
-        {
-            errorMessage = invalidNumberMessage;
-            throw new ValidationException(invalidNumberMessage);
-        }
+            BigDecimal bd = null;
 
-        if (minValue != null && bd.compareTo(minValue) < 0)
-        {
-            errorMessage = minValueMessage;
-            throw new ValidationException(minValueMessage);
-        }
-        if (maxValue != null && bd.compareTo(maxValue) > 0)
-        {
-            errorMessage = maxValueMessage;
-            throw new ValidationException(maxValueMessage);
+            try
+            {
+                bd = new BigDecimal(testValue);
+            }
+            catch (RuntimeException e)
+            {
+                errorMessage = invalidNumberMessage;
+                throw new ValidationException(invalidNumberMessage);
+            }
+
+            if ((minValue != null) && (bd.compareTo(minValue) < 0))
+            {
+                errorMessage = minValueMessage;
+                throw new ValidationException(minValueMessage);
+            }
+
+            if ((maxValue != null) && (bd.compareTo(maxValue) > 0))
+            {
+                errorMessage = maxValueMessage;
+                throw new ValidationException(maxValueMessage);
+            }
         }
     }
-
 
     // ************************************************************
     // **                Bean accessor methods                   **
Index: BooleanValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/BooleanValidator.java,v
retrieving revision 1.8
diff -u -r1.8 BooleanValidator.java
--- BooleanValidator.java	19 Jun 2003 16:27:10 -0000	1.8
+++ BooleanValidator.java	10 Sep 2003 10:30:16 -0000
@@ -1,5 +1,6 @@
 package org.apache.turbine.services.intake.validator;
 
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,8 +54,8 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
-
 import java.text.ParseException;
+
 import java.util.Map;
 
 /**
@@ -83,16 +84,16 @@
  *
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: BooleanValidator.java,v 1.8 2003/06/19 16:27:10
henning Exp $
  */
-public class BooleanValidator
-        extends DefaultValidator
+public class BooleanValidator 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"
};
 
     /** 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" };
 
     /**
      * Default Constructor
@@ -107,8 +108,7 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public BooleanValidator(Map paramMap)
-            throws InvalidMaskException
+    public BooleanValidator(Map paramMap) throws InvalidMaskException
     {
         super(paramMap);
     }
@@ -121,18 +121,20 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        try
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            parse(testValue);
-        }
-        catch (ParseException e)
-        {
-            throw new ValidationException(e.getMessage());
+            try
+            {
+                parse(testValue);
+            }
+            catch (ParseException e)
+            {
+                throw new ValidationException(e.getMessage());
+            }
         }
     }
 
@@ -142,35 +144,34 @@
      * @param stringValue the value to parse
      * @return a <code>Boolean</a> object
      */
-    public Boolean parse(String stringValue)
-            throws ParseException
+    public Boolean parse(String stringValue) throws ParseException
     {
         Boolean result = null;
 
-        for (int cnt = 0; 
-             cnt < Math.max(trueValues.length, falseValues.length);
cnt++)
+        for (int cnt = 0;
+            cnt < Math.max(trueValues.length, falseValues.length);
cnt++)
         {
             // Short-cut evaluation or bust!
-            if ((cnt < trueValues.length) && 
-                    stringValue.equalsIgnoreCase(trueValues[cnt]))
+            if ((cnt < trueValues.length) &&
stringValue.equalsIgnoreCase(trueValues[cnt]))
             {
                 result = Boolean.TRUE;
+
                 break;
             }
 
-            if ((cnt < falseValues.length) && 
-                    stringValue.equalsIgnoreCase(falseValues[cnt]))
+            if ((cnt < falseValues.length) &&
stringValue.equalsIgnoreCase(falseValues[cnt]))
             {
                 result = Boolean.FALSE;
+
                 break;
             }
         }
 
         if (result == null)
         {
-            throw new ParseException(stringValue +
-                    " could not be converted to a Boolean", 0);
+            throw new ParseException(stringValue + " could not be
converted to a Boolean", 0);
         }
+
         return result;
     }
 }
Index: DateStringValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/DateStringValidator.java,v
retrieving revision 1.7
diff -u -r1.7 DateStringValidator.java
--- DateStringValidator.java	19 Jun 2003 16:55:17 -0000	1.7
+++ DateStringValidator.java	10 Sep 2003 10:30:16 -0000
@@ -1,5 +1,6 @@
 package org.apache.turbine.services.intake.validator;
 
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,6 +54,9 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.turbine.services.intake.IntakeException;
 
 import java.text.DateFormat;
 import java.text.ParseException;
@@ -63,10 +67,6 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
-
-import org.apache.turbine.services.intake.IntakeException;
-
 /**
  * Validates numbers with the following constraints in addition to
those
  * listed in DefaultValidator.
@@ -87,13 +87,12 @@
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: DateStringValidator.java,v 1.7 2003/06/19 16:55:17
henning Exp $
  */
-public class DateStringValidator
-        extends DefaultValidator
+public class DateStringValidator extends DefaultValidator
 {
-    private static final String DEFAULT_DATE_MESSAGE =
-            "Date could not be parsed";
+    private static final String DEFAULT_DATE_MESSAGE = "Date could not
be parsed";
 
     /**  */
     private List dateFormats = null;
@@ -110,8 +109,7 @@
     /**  */
     private SimpleDateFormat sdf = null;
 
-    public DateStringValidator(Map paramMap)
-            throws IntakeException
+    public DateStringValidator(Map paramMap) throws IntakeException
     {
         init(paramMap);
     }
@@ -130,8 +128,7 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    public void init(Map paramMap) throws InvalidMaskException
     {
         super.init(paramMap);
 
@@ -143,7 +140,7 @@
             setDateFormatMessage(constraint.getMessage());
         }
 
-        for(int i = 1 ;; i++)
+        for (int i = 1;; i++)
         {
             constraint = (Constraint) paramMap.get(FORMAT_RULE_NAME +
i);
 
@@ -154,7 +151,7 @@
 
             dateFormats.add(constraint.getValue());
             setDateFormatMessage(constraint.getMessage());
-        } 
+        }
 
         if (StringUtils.isEmpty(dateFormatMessage))
         {
@@ -168,7 +165,7 @@
             flexible =
Boolean.valueOf(constraint.getValue()).booleanValue();
         }
 
-        if (dateFormats.size() == 0 || flexible)
+        if ((dateFormats.size() == 0) || flexible)
         {
             df = DateFormat.getInstance();
             df.setLenient(true);
@@ -188,19 +185,21 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        try
-        {
-            parse(testValue);
-        }
-        catch (ParseException e)
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            errorMessage = dateFormatMessage;
-            throw new ValidationException(dateFormatMessage);
+            try
+            {
+                parse(testValue);
+            }
+            catch (ParseException e)
+            {
+                errorMessage = dateFormatMessage;
+                throw new ValidationException(dateFormatMessage);
+            }
         }
     }
 
@@ -211,8 +210,7 @@
      * @throws ParseException indicates that the string could not be
      * parsed into a date.
      */
-    public Date parse(String s)
-            throws ParseException
+    public Date parse(String s) throws ParseException
     {
         Date date = null;
 
@@ -221,7 +219,7 @@
             throw new ParseException("Input string was null", -1);
         }
 
-        for (int i = 0; i < dateFormats.size() && date == null; i++)
+        for (int i = 0; (i < dateFormats.size()) && (date == null);
i++)
         {
             sdf.applyPattern((String) dateFormats.get(i));
 
@@ -233,10 +231,9 @@
             {
                 // ignore
             }
-
         }
 
-        if (date == null && df != null)
+        if ((date == null) && (df != null))
         {
             date = df.parse(s);
         }
@@ -261,14 +258,15 @@
     public String format(Date date)
     {
         String s = null;
+
         if (date != null)
         {
             sdf.applyPattern((String) dateFormats.get(0));
             s = sdf.format(date);
         }
+
         return s;
     }
-
 
     // ************************************************************
     // **                Bean accessor methods                   **
Index: DoubleValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/DoubleValidator.java,v
retrieving revision 1.2
diff -u -r1.2 DoubleValidator.java
--- DoubleValidator.java	19 Jun 2003 16:55:17 -0000	1.2
+++ DoubleValidator.java	10 Sep 2003 10:30:17 -0000
@@ -1,5 +1,6 @@
 package org.apache.turbine.services.intake.validator;
 
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,7 +54,6 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
-
 import java.util.Map;
 
 /**
@@ -72,10 +72,10 @@
  *
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: DoubleValidator.java,v 1.2 2003/06/19 16:55:17 henning
Exp $
  */
-public class DoubleValidator
-        extends NumberValidator
+public class DoubleValidator extends NumberValidator
 {
     /* Init the minValue to that for a Double */
     private double minValue = Double.MIN_VALUE;
@@ -89,8 +89,7 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public DoubleValidator(Map paramMap)
-            throws InvalidMaskException
+    public DoubleValidator(Map paramMap) throws InvalidMaskException
     {
         invalidNumberMessage = "Entry was not a valid Double";
         init(paramMap);
@@ -109,25 +108,28 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    public void init(Map paramMap) throws InvalidMaskException
     {
         super.init(paramMap);
 
         Constraint constraint = (Constraint)
paramMap.get(MIN_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            minValue = Double.parseDouble(param);
-            minValueMessage = constraint.getMessage();
+
+            minValue            = Double.parseDouble(param);
+            minValueMessage     = constraint.getMessage();
         }
 
         constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            maxValue = Double.parseDouble(param);
-            maxValueMessage = constraint.getMessage();
+
+            maxValue            = Double.parseDouble(param);
+            maxValueMessage     = constraint.getMessage();
         }
     }
 
@@ -139,35 +141,37 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        double d = 0.0D;
-
-        try
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            d = Double.parseDouble(testValue);
-        }
-        catch (RuntimeException e)
-        {
-            errorMessage = invalidNumberMessage;
-            throw new ValidationException(invalidNumberMessage);
-        }
+            double d = 0.0D;
 
-        if (d < minValue)
-        {
-            errorMessage = minValueMessage;
-            throw new ValidationException(minValueMessage);
-        }
-        if (d > maxValue)
-        {
-            errorMessage = maxValueMessage;
-            throw new ValidationException(maxValueMessage);
+            try
+            {
+                d = Double.parseDouble(testValue);
+            }
+            catch (RuntimeException e)
+            {
+                errorMessage = invalidNumberMessage;
+                throw new ValidationException(invalidNumberMessage);
+            }
+
+            if (d < minValue)
+            {
+                errorMessage = minValueMessage;
+                throw new ValidationException(minValueMessage);
+            }
+
+            if (d > maxValue)
+            {
+                errorMessage = maxValueMessage;
+                throw new ValidationException(maxValueMessage);
+            }
         }
     }
-
 
     // ************************************************************
     // **                Bean accessor methods                   **
Index: FloatValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/FloatValidator.java,v
retrieving revision 1.2
diff -u -r1.2 FloatValidator.java
--- FloatValidator.java	19 Jun 2003 16:55:17 -0000	1.2
+++ FloatValidator.java	10 Sep 2003 10:30:17 -0000
@@ -1,5 +1,6 @@
 package org.apache.turbine.services.intake.validator;
 
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,7 +54,6 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
-
 import java.util.Map;
 
 /**
@@ -72,10 +72,10 @@
  *
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: FloatValidator.java,v 1.2 2003/06/19 16:55:17 henning
Exp $
  */
-public class FloatValidator
-        extends NumberValidator
+public class FloatValidator extends NumberValidator
 {
     /* Init the minValue to that for a Float */
     private float minValue = Float.MIN_VALUE;
@@ -89,8 +89,7 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public FloatValidator(Map paramMap)
-            throws InvalidMaskException
+    public FloatValidator(Map paramMap) throws InvalidMaskException
     {
         invalidNumberMessage = "Entry was not a valid Float";
         init(paramMap);
@@ -109,25 +108,28 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    public void init(Map paramMap) throws InvalidMaskException
     {
         super.init(paramMap);
 
         Constraint constraint = (Constraint)
paramMap.get(MIN_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            minValue = Float.parseFloat(param);
-            minValueMessage = constraint.getMessage();
+
+            minValue            = Float.parseFloat(param);
+            minValueMessage     = constraint.getMessage();
         }
 
         constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            maxValue = Float.parseFloat(param);
-            maxValueMessage = constraint.getMessage();
+
+            maxValue            = Float.parseFloat(param);
+            maxValueMessage     = constraint.getMessage();
         }
     }
 
@@ -139,34 +141,37 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        float f = 0.0f;
-        try
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            f = Float.parseFloat(testValue);
-        }
-        catch (RuntimeException e)
-        {
-            errorMessage = invalidNumberMessage;
-            throw new ValidationException(invalidNumberMessage);
-        }
+            float f = 0.0f;
 
-        if (f < minValue)
-        {
-            errorMessage = minValueMessage;
-            throw new ValidationException(minValueMessage);
-        }
-        if (f > maxValue)
-        {
-            errorMessage = maxValueMessage;
-            throw new ValidationException(maxValueMessage);
+            try
+            {
+                f = Float.parseFloat(testValue);
+            }
+            catch (RuntimeException e)
+            {
+                errorMessage = invalidNumberMessage;
+                throw new ValidationException(invalidNumberMessage);
+            }
+
+            if (f < minValue)
+            {
+                errorMessage = minValueMessage;
+                throw new ValidationException(minValueMessage);
+            }
+
+            if (f > maxValue)
+            {
+                errorMessage = maxValueMessage;
+                throw new ValidationException(maxValueMessage);
+            }
         }
     }
-
 
     // ************************************************************
     // **                Bean accessor methods                   **
Index: IntegerValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/IntegerValidator.java,v
retrieving revision 1.8
diff -u -r1.8 IntegerValidator.java
--- IntegerValidator.java	19 Jun 2003 16:55:17 -0000	1.8
+++ IntegerValidator.java	10 Sep 2003 10:30:17 -0000
@@ -1,5 +1,6 @@
 package org.apache.turbine.services.intake.validator;
 
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,7 +54,6 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
-
 import java.util.Map;
 
 /**
@@ -72,10 +72,10 @@
  *
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: IntegerValidator.java,v 1.8 2003/06/19 16:55:17
henning Exp $
  */
-public class IntegerValidator
-        extends NumberValidator
+public class IntegerValidator extends NumberValidator
 {
     /* Init the minValue to that for a Integer */
     private int minValue = Integer.MIN_VALUE;
@@ -89,8 +89,7 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public IntegerValidator(Map paramMap)
-            throws InvalidMaskException
+    public IntegerValidator(Map paramMap) throws InvalidMaskException
     {
         invalidNumberMessage = "Entry was not a valid Integer";
         init(paramMap);
@@ -109,25 +108,28 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    public void init(Map paramMap) throws InvalidMaskException
     {
         super.init(paramMap);
 
         Constraint constraint = (Constraint)
paramMap.get(MIN_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            minValue = Integer.parseInt(param);
-            minValueMessage = constraint.getMessage();
+
+            minValue            = Integer.parseInt(param);
+            minValueMessage     = constraint.getMessage();
         }
 
         constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            maxValue = Integer.parseInt(param);
-            maxValueMessage = constraint.getMessage();
+
+            maxValue            = Integer.parseInt(param);
+            maxValueMessage     = constraint.getMessage();
         }
     }
 
@@ -139,34 +141,36 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        int i = 0;
-        try
-        {
-            i = Integer.parseInt(testValue);
-        }
-        catch (RuntimeException e)
-        {
-            errorMessage = invalidNumberMessage;
-            throw new ValidationException(invalidNumberMessage);
-        }
-
-        if (i < minValue)
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            errorMessage = minValueMessage;
+            int i = 0;
 
-        }
-        if (i > maxValue)
-        {
-            errorMessage = maxValueMessage;
-            throw new ValidationException(maxValueMessage);
+            try
+            {
+                i = Integer.parseInt(testValue);
+            }
+            catch (RuntimeException e)
+            {
+                errorMessage = invalidNumberMessage;
+                throw new ValidationException(invalidNumberMessage);
+            }
+
+            if (i < minValue)
+            {
+                errorMessage = minValueMessage;
+            }
+
+            if (i > maxValue)
+            {
+                errorMessage = maxValueMessage;
+                throw new ValidationException(maxValueMessage);
+            }
         }
     }
-
 
     // ************************************************************
     // **                Bean accessor methods                   **
Index: LongValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/LongValidator.java,v
retrieving revision 1.2
diff -u -r1.2 LongValidator.java
--- LongValidator.java	19 Jun 2003 16:55:17 -0000	1.2
+++ LongValidator.java	10 Sep 2003 10:30:17 -0000
@@ -1,5 +1,6 @@
 package org.apache.turbine.services.intake.validator;
 
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,7 +54,6 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
-
 import java.util.Map;
 
 /**
@@ -72,10 +72,10 @@
  *
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: LongValidator.java,v 1.2 2003/06/19 16:55:17 henning
Exp $
  */
-public class LongValidator
-        extends NumberValidator
+public class LongValidator extends NumberValidator
 {
     /* Init the minValue to that for a Long */
     private long minValue = Long.MIN_VALUE;
@@ -89,8 +89,7 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public LongValidator(Map paramMap)
-            throws InvalidMaskException
+    public LongValidator(Map paramMap) throws InvalidMaskException
     {
         invalidNumberMessage = "Entry was not a valid Long";
         init(paramMap);
@@ -109,25 +108,28 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    public void init(Map paramMap) throws InvalidMaskException
     {
         super.init(paramMap);
 
         Constraint constraint = (Constraint)
paramMap.get(MIN_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            minValue = Long.parseLong(param);
-            minValueMessage = constraint.getMessage();
+
+            minValue            = Long.parseLong(param);
+            minValueMessage     = constraint.getMessage();
         }
 
         constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            maxValue = Long.parseLong(param);
-            maxValueMessage = constraint.getMessage();
+
+            maxValue            = Long.parseLong(param);
+            maxValueMessage     = constraint.getMessage();
         }
     }
 
@@ -139,34 +141,37 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        long l = 0L;
-        try
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            l = Long.parseLong(testValue);
-        }
-        catch (RuntimeException e)
-        {
-            errorMessage = invalidNumberMessage;
-            throw new ValidationException(invalidNumberMessage);
-        }
+            long l = 0L;
 
-        if (l < minValue)
-        {
-            errorMessage = minValueMessage;
-            throw new ValidationException(minValueMessage);
-        }
-        if (l > maxValue)
-        {
-            errorMessage = maxValueMessage;
-            throw new ValidationException(maxValueMessage);
+            try
+            {
+                l = Long.parseLong(testValue);
+            }
+            catch (RuntimeException e)
+            {
+                errorMessage = invalidNumberMessage;
+                throw new ValidationException(invalidNumberMessage);
+            }
+
+            if (l < minValue)
+            {
+                errorMessage = minValueMessage;
+                throw new ValidationException(minValueMessage);
+            }
+
+            if (l > maxValue)
+            {
+                errorMessage = maxValueMessage;
+                throw new ValidationException(maxValueMessage);
+            }
         }
     }
-
 
     // ************************************************************
     // **                Bean accessor methods                   **
Index: ShortValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/ShortValidator.java,v
retrieving revision 1.2
diff -u -r1.2 ShortValidator.java
--- ShortValidator.java	19 Jun 2003 16:55:17 -0000	1.2
+++ ShortValidator.java	10 Sep 2003 10:30:17 -0000
@@ -1,5 +1,6 @@
 package org.apache.turbine.services.intake.validator;
 
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,7 +54,6 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
-
 import java.util.Map;
 
 /**
@@ -72,10 +72,10 @@
  *
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: ShortValidator.java,v 1.2 2003/06/19 16:55:17 henning
Exp $
  */
-public class ShortValidator
-        extends NumberValidator
+public class ShortValidator extends NumberValidator
 {
     /* Init the minValue to that for a Short */
     private short minValue = Short.MIN_VALUE;
@@ -89,8 +89,7 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public ShortValidator(Map paramMap)
-            throws InvalidMaskException
+    public ShortValidator(Map paramMap) throws InvalidMaskException
     {
         invalidNumberMessage = "Entry was not a valid Short";
         init(paramMap);
@@ -109,25 +108,28 @@
      * @param paramMap
      * @throws InvalidMaskException
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    public void init(Map paramMap) throws InvalidMaskException
     {
         super.init(paramMap);
 
         Constraint constraint = (Constraint)
paramMap.get(MIN_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            minValue = Short.parseShort(param);
-            minValueMessage = constraint.getMessage();
+
+            minValue            = Short.parseShort(param);
+            minValueMessage     = constraint.getMessage();
         }
 
         constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
-            maxValue = Short.parseShort(param);
-            maxValueMessage = constraint.getMessage();
+
+            maxValue            = Short.parseShort(param);
+            maxValueMessage     = constraint.getMessage();
         }
     }
 
@@ -139,34 +141,37 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        short s = 0;
-        try
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            s = Short.parseShort(testValue);
-        }
-        catch (RuntimeException e)
-        {
-            errorMessage = invalidNumberMessage;
-            throw new ValidationException(invalidNumberMessage);
-        }
+            short s = 0;
 
-        if (s < minValue)
-        {
-            errorMessage = minValueMessage;
-            throw new ValidationException(minValueMessage);
-        }
-        if (s > maxValue)
-        {
-            errorMessage = maxValueMessage;
-            throw new ValidationException(maxValueMessage);
+            try
+            {
+                s = Short.parseShort(testValue);
+            }
+            catch (RuntimeException e)
+            {
+                errorMessage = invalidNumberMessage;
+                throw new ValidationException(invalidNumberMessage);
+            }
+
+            if (s < minValue)
+            {
+                errorMessage = minValueMessage;
+                throw new ValidationException(minValueMessage);
+            }
+
+            if (s > maxValue)
+            {
+                errorMessage = maxValueMessage;
+                throw new ValidationException(maxValueMessage);
+            }
         }
     }
-
 
     // ************************************************************
     // **                Bean accessor methods                   **
Index: StringValidator.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/i
ntake/validator/StringValidator.java,v
retrieving revision 1.2
diff -u -r1.2 StringValidator.java
--- StringValidator.java	19 Jun 2003 16:55:17 -0000	1.2
+++ StringValidator.java	10 Sep 2003 10:30:17 -0000
@@ -1,5 +1,10 @@
 package org.apache.turbine.services.intake.validator;
 
+import org.apache.oro.text.regex.MalformedPatternException;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.Perl5Compiler;
+import org.apache.oro.text.regex.Perl5Matcher;
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -53,14 +58,8 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
-
 import java.util.Map;
 
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
-
 /**
  * A validator that will compare a testValue against the following
  * constraints:
@@ -77,10 +76,10 @@
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
  * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin
Chalmers</a>
+ * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  * @version $Id: StringValidator.java,v 1.2 2003/06/19 16:55:17 henning
Exp $
  */
-public class StringValidator
-        extends DefaultValidator
+public class StringValidator extends DefaultValidator
 {
     /** The matching mask String as supplied by the XML input */
     protected String maskString = null;
@@ -91,7 +90,6 @@
     /** The message to report if the mask constraint is not satisfied
*/
     protected String maskMessage = null;
 
-
     /**
      * Constructor
      *
@@ -100,8 +98,7 @@
      * @exception InvalidMaskException An invalid mask was specified
for one of the rules
 
     */
-    public StringValidator(Map paramMap)
-            throws InvalidMaskException
+    public StringValidator(Map paramMap) throws InvalidMaskException
     {
         init(paramMap);
     }
@@ -121,19 +118,19 @@
      * containing constraints on the input.
      * @exception InvalidMaskException An invalid mask was specified
for one of the rules
      */
-    public void init(Map paramMap)
-            throws InvalidMaskException
+    public void init(Map paramMap) throws InvalidMaskException
     {
         super.init(paramMap);
 
         Constraint constraint = (Constraint)
paramMap.get(MASK_RULE_NAME);
+
         if (constraint != null)
         {
             String param = constraint.getValue();
+
             setMask(param);
             maskMessage = constraint.getMessage();
         }
-
     }
 
     /**
@@ -146,6 +143,7 @@
     public boolean isValid(String testValue)
     {
         boolean valid = false;
+
         try
         {
             assertValidity(testValue);
@@ -155,6 +153,7 @@
         {
             valid = false;
         }
+
         return valid;
     }
 
@@ -166,26 +165,26 @@
      * @exception ValidationException containing an error message if
the
      * testValue did not pass the validation tests.
      */
-    public void assertValidity(String testValue)
-            throws ValidationException
+    public void assertValidity(String testValue) throws
ValidationException
     {
         super.assertValidity(testValue);
 
-        /** perl5 matcher */
-        Perl5Matcher patternMatcher = new Perl5Matcher();
-
-        if (maskPattern != null)
+        if ((required) || ((testValue != null) && (testValue.length() >
0)))
         {
-            boolean patternMatch =
-                    patternMatcher.matches(testValue, maskPattern);
-
-            log.debug("Trying to match " + testValue
-                    + " to pattern " + maskString);
+            /** perl5 matcher */
+            Perl5Matcher patternMatcher = new Perl5Matcher();
 
-            if (!patternMatch)
+            if (maskPattern != null)
             {
-                errorMessage = maskMessage;
-                throw new ValidationException(maskMessage);
+                boolean patternMatch =
patternMatcher.matches(testValue, maskPattern);
+
+                log.debug("Trying to match " + testValue + " to pattern
" + maskString);
+
+                if (!patternMatch)
+                {
+                    errorMessage = maskMessage;
+                    throw new ValidationException(maskMessage);
+                }
             }
         }
     }
@@ -210,8 +209,7 @@
      * @param mask  Value to assign to mask.
      * @throws InvalidMaskException the mask could not be compiled.
      */
-    public void setMask(String mask)
-            throws InvalidMaskException
+    public void setMask(String mask) throws InvalidMaskException
     {
         /** perl5 compiler, needed for setting up the masks */
         Perl5Compiler patternCompiler = new Perl5Compiler();

Kind regards
 
Jürgen Hoffmann

-----Ursprüngliche Nachricht-----
Von: Scott Eade [mailto:seade@backstagetech.com.au] 
Gesendet: Mittwoch, 10. September 2003 04:42
An: Turbine Developers List
Betreff: Intake bug: validation continues when required=false


Over on turbine-user somebody has hit upon a problem
with the new validator code in 2.3 (co-incidentally I
hit this at the very same time).

It turns out that the Intake validator enhancements
done as part of 2.3 do not provide a way for
DefaultValidator to communicate back to the sub-classes
that the validation process should stop under certain circumstances
(primarily when the required rule has a value of false and nothing has
been entered).

My question is, what is the best way of communicating
this information back to the subclasses?  Adding a
return value to the assertValidity() methods seems to
go against the method name.  An alternative might be
to throw a ValidationCompletedException (extends
ValidationException) - using an exception to control
processing in this manner seems not quite right to me,
but there is enough of it going on in the validator
code to argue that it is legitimate.  Any other bright
ideas?

Scott

-- 
Scott Eade
Backstage Technologies Pty. Ltd. http://www.backstagetech.com.au





---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org