struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1431115 - in /struts/struts2/trunk: core/src/main/resources/template/xhtml/ core/src/test/resources/org/apache/struts2/views/jsp/ui/ xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ xwork-core/src/test/java/com/opensy...
Date Wed, 09 Jan 2013 22:21:56 GMT
Author: lukaszlenart
Date: Wed Jan  9 22:21:56 2013
New Revision: 1431115

URL: http://svn.apache.org/viewvc?rev=1431115&view=rev
Log:
WW-2923 refactors validators to use dedicated params to define expressions

Modified:
    struts/struts2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl
    struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/DoubleValidationAction-validation.xml
    struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-24.txt
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DoubleRangeFieldValidator.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java

Modified: struts/struts2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl (original)
+++ struts/struts2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl Wed
Jan  9 22:21:56 2013
@@ -98,10 +98,10 @@ END SNIPPET: supported-validators
             }
             <#elseif validator.validatorType = "int">
             if (continueValidation && field.value != null) {
-                if (<#if validator.minComparatorValue??>parseInt(field.value) <
-                     ${validator.minComparatorValue?c}<#else>false</#if> ||
-                        <#if validator.maxComparatorValue??>parseInt(field.value) >
-                           ${validator.maxComparatorValue?c}<#else>false</#if>)
{
+                if (<#if validator.min??>parseInt(field.value) <
+                     ${validator.min?c}<#else>false</#if> ||
+                        <#if validator.max??>parseInt(field.value) >
+                           ${validator.max?c}<#else>false</#if>) {
                     addError(field, error);
                     errors = true;
                     <#if validator.shortCircuit>continueValidation = false;</#if>
@@ -110,10 +110,10 @@ END SNIPPET: supported-validators
             <#elseif validator.validatorType = "double">
             if (continueValidation && field.value != null) {
                 var value = parseFloat(field.value);
-                if (<#if validator.minInclusive??>value < ${validator.minInclusive}<#else>false</#if>
||
-                        <#if validator.maxInclusive??>value > ${validator.maxInclusive}<#else>false</#if>
||
-                        <#if validator.minExclusive??>value <= ${validator.minExclusive}<#else>false</#if>
||
-                        <#if validator.maxExclusive??>value >= ${validator.maxExclusive}<#else>false</#if>)
{
+                if (<#if validator.minInclusive??>value < ${validator.minInclusive?c}<#else>false</#if>
||
+                        <#if validator.maxInclusive??>value > ${validator.maxInclusive?c}<#else>false</#if>
||
+                        <#if validator.minExclusive??>value <= ${validator.minExclusive?c}<#else>false</#if>
||
+                        <#if validator.maxExclusive??>value >= ${validator.maxExclusive?c}<#else>false</#if>)
{
                     addError(field, error);
                     errors = true;
                     <#if validator.shortCircuit>continueValidation = false;</#if>

Modified: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/DoubleValidationAction-validation.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/DoubleValidationAction-validation.xml?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/DoubleValidationAction-validation.xml
(original)
+++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/DoubleValidationAction-validation.xml
Wed Jan  9 22:21:56 2013
@@ -2,8 +2,8 @@
 <validators>
     <field name="myUpDownSelectTag">
         <field-validator type="double">
-            <param name="minInclusive">6000.10</param>
-            <param name="maxInclusive">10000.10</param>
+            <param name="minInclusive">6000.1</param>
+            <param name="maxInclusive">10000.1</param>
             <message>bar must be between ${minInclusive} and ${maxInclusive}.</message>
         </field-validator>
     </field>

Modified: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-24.txt
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-24.txt?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-24.txt
(original)
+++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-24.txt
Wed Jan  9 22:21:56 2013
@@ -42,10 +42,10 @@
          //validatorname:double
          if(form.elements['myUpDownSelectTag']){
             field=form.elements['myUpDownSelectTag'];
-            var error="bar must be between 6000.10 and 10000.10.";
+            var error="bar must be between 6000.1 and 10000.1.";
             if(continueValidation && field.value!=null){
                 var value = parseFloat(field.value);
-                if(value<6000.10||value>10000.10||false||false){
+                if(value<6000.1||value>10000.1||false||false){
                     addError(field,error);
                     errors=true;
                  }

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
Wed Jan  9 22:21:56 2013
@@ -15,6 +15,8 @@
  */
 package com.opensymphony.xwork2.validator.validators;
 
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
 import com.opensymphony.xwork2.validator.ValidationException;
 
 
@@ -26,14 +28,13 @@ import com.opensymphony.xwork2.validator
  */
 public abstract class AbstractRangeValidator<T extends Comparable> extends FieldValidatorSupport
{
 
-    protected final Class<T> type;
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractRangeValidator.class);
+
+    private final Class<T> type;
 
     private T min;
     private T max;
 
-    private String minExpression;
-    private String maxExpression;
-
     protected AbstractRangeValidator(Class<T> type) {
         this.type = type;
     }
@@ -49,25 +50,18 @@ public abstract class AbstractRangeValid
         }
 
         // only check for a minimum value if the min parameter is set
-        T minComparatorValue = getMinComparatorValue();
+        T minComparatorValue = getMin();
         if ((minComparatorValue != null) && (value.compareTo(minComparatorValue)
< 0)) {
             addFieldError(getFieldName(), object);
         }
 
         // only check for a maximum value if the max parameter is set
-        T maxComparatorValue = getMaxComparatorValue();
+        T maxComparatorValue = getMax();
         if ((maxComparatorValue != null) && (value.compareTo(maxComparatorValue)
> 0)) {
             addFieldError(getFieldName(), object);
         }
     }
 
-    public T getMinComparatorValue() {
-        if (parse) {
-            return (T) parse(getMinExpression(), type);
-        }
-        return getMin();
-    }
-
     public void setMin(T min) {
         this.min = min;
     }
@@ -76,12 +70,11 @@ public abstract class AbstractRangeValid
         return min;
     }
 
-    public String getMinExpression() {
-        return minExpression;
-    }
-
     public void setMinExpression(String minExpression) {
-        this.minExpression = minExpression;
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("${minExpression} was defined as [#0]", minExpression);
+        }
+        this.min = (T) parse(minExpression, type);
     }
 
     public void setMax(T max) {
@@ -92,19 +85,11 @@ public abstract class AbstractRangeValid
         return max;
     }
 
-    public String getMaxExpression() {
-        return maxExpression;
-    }
-
     public void setMaxExpression(String maxExpression) {
-        this.maxExpression = maxExpression;
-    }
-
-    public T getMaxComparatorValue() {
-        if (parse) {
-            return (T) parse(getMaxExpression(), type);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("${maxExpression} was defined as [#0]", maxExpression);
         }
-        return getMax();
+        this.max = (T) parse(maxExpression, type);
     }
 
 }

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
Wed Jan  9 22:21:56 2013
@@ -73,10 +73,9 @@ import java.util.Date;
  *     &lt;!-- Field Validator Syntax with expression --&gt;
  *     &lt;field name="birthday"&gt;
  *         &lt;field-validator type="date"&gt;
- *             &lt;param name="parse"&gt;true&lt;/param&gt;
  *             &lt;param name="minExpression"&gt;${minValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Date getMinValue() --&gt;
  *             &lt;param name="maxExpression"&gt;${maxValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Date getMaxValue() --&gt;
- *             &lt;message&gt;Age needs to be between ${minExpression} and ${maxExpression}&lt;/message&gt;
+ *             &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
  *         &lt;/field-validator&gt;
  *     &lt;/field&gt;
  * &lt;/validators&gt;

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DoubleRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DoubleRangeFieldValidator.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DoubleRangeFieldValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DoubleRangeFieldValidator.java
Wed Jan  9 22:21:56 2013
@@ -31,14 +31,21 @@ import com.opensymphony.xwork2.validator
  *     <li>maxInclusive - the maximum inclusive value in FloatValue format specified
by Java language (if none is specified, it will not be checked) </li>
  *     <li>minExclusive - the minimum exclusive value in FloatValue format specified
by Java language (if none is specified, it will not be checked) </li>
  *     <li>maxExclusive - the maximum exclusive value in FloatValue format specified
by Java language (if none is specified, it will not be checked) </li>
+ *     <li>minInclusiveExpression - the minimum inclusive value specified as a OGNL
expression (if none is specified, it will not be checked) </li>
+ *     <li>maxInclusiveExpression - the maximum inclusive value specified as a OGNL
expression (if none is specified, it will not be checked) </li>
+ *     <li>minExclusiveExpression - the minimum exclusive value specified as a OGNL
expression (if none is specified, it will not be checked) </li>
+ *     <li>maxExclusiveExpression - the maximum exclusive value specified as a OGNL
expression (if none is specified, it will not be checked) </li>
  * </ul>
  *
- * You can specify minInclusive, maxInclusive, minExclusive and maxExclusive as a OGNL expression,
see example below.
+ * You can specify either minInclusive, maxInclusive, minExclusive and maxExclusive or minInclusiveExpression,
maxInclusiveExpression,
+ * minExclusiveExpression and maxExclusiveExpression as a OGNL expression, see example below.
You can always try to mix params
+ * but be aware that such behaviour was not tested.
  * <!-- END SNIPPET: parameters -->
  *
  *
  * <!-- START SNIPPET: parameters-warning -->
- * Do not use ${minInclusive}, ${maxInclusive}, ${minExclusive} and ${maxExclusive} as an
expression as this will turn into infinitive loop!
+ * Do not use ${minInclusiveExpression}, ${maxInclusiveExpression}, ${minExclusiveExpressionExpression}
and ${maxExclusive}
+ * as an expression as this will turn into infinitive loop!
  * <!-- END SNIPPET: parameters-warning -->
  *
  *
@@ -65,9 +72,8 @@ import com.opensymphony.xwork2.validator
  *     &lt;!-- Field Validator Syntax with expression --&gt;
  *     &lt;field name="percentage"&gt;
  *         &lt;field-validator type="double"&gt;
- *             &lt;param name="parse"&gt;true&lt;/param&gt;
- *             &lt;param name="minExclusive"&gt;${minExclusiveValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Double getMinExclusiveValue() --&gt;
- *             &lt;param name="maxExclusive"&gt;${maxExclusive}&lt;/param&gt;
&lt;!-- will be evaluated as: Double getMaxExclusive() --&gt;
+ *             &lt;param name="minExclusiveExpression"&gt;${minExclusiveValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Double getMinExclusiveValue() --&gt;
+ *             &lt;param name="maxExclusiveExpression"&gt;${maxExclusiveValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Double getMaxExclusiveValue() --&gt;
  *             &lt;message&gt;Percentage needs to be between ${minExclusive} and
${maxExclusive} (exclusive)&lt;/message&gt;
  *         &lt;/field-validator&gt;
  *     &lt;/field&gt;
@@ -82,15 +88,10 @@ import com.opensymphony.xwork2.validator
  */
 public class DoubleRangeFieldValidator extends FieldValidatorSupport {
     
-    String maxInclusive = null;
-    String minInclusive = null;
-    String minExclusive = null;
-    String maxExclusive = null;
-
-    Double maxInclusiveValue = null;
-    Double minInclusiveValue = null;
-    Double minExclusiveValue = null;
-    Double maxExclusiveValue = null;
+    private Double maxInclusive = null;
+    private Double minInclusive = null;
+    private Double minExclusive = null;
+    private Double maxExclusive = null;
 
     public void validate(Object object) throws ValidationException {
         String fieldName = getFieldName();
@@ -105,73 +106,60 @@ public class DoubleRangeFieldValidator e
             return;
         }
 
-        parseParameterValues();
-        if ((maxInclusiveValue != null && value.compareTo(maxInclusiveValue) >
0) ||
-                (minInclusiveValue != null && value.compareTo(minInclusiveValue)
< 0) ||
-                (maxExclusiveValue != null && value.compareTo(maxExclusiveValue)
>= 0) ||
-                (minExclusiveValue != null && value.compareTo(minExclusiveValue)
<= 0)) {
+        if ((maxInclusive != null && value.compareTo(maxInclusive) > 0) ||
+                (minInclusive != null && value.compareTo(minInclusive) < 0) ||
+                (maxExclusive != null && value.compareTo(maxExclusive) >= 0) ||
+                (minExclusive != null && value.compareTo(minExclusive) <= 0))
{
             addFieldError(fieldName, object);
         }
     }
 
-    protected void parseParameterValues() {
-        this.minInclusiveValue = parseValue(minInclusive);
-        this.maxInclusiveValue = parseValue(maxInclusive);
-        this.minExclusiveValue = parseValue(minExclusive);
-        this.maxExclusiveValue = parseValue(maxExclusive);
-    }
-
-    protected Double parseValue(String value) {
-        if (parse) {
-            return (Double) parse(value, Double.class);
-        } else {
-            return parseDouble(value);
-        }
-    }
-
-    protected Double parseDouble (String value) {
-        if (value != null) {
-            try {
-                return Double.valueOf(value);
-            } catch (NumberFormatException e) {
-                if (log.isWarnEnabled()) {
-                    log.warn("DoubleRangeFieldValidator - [parseDouble]: Unable to parse
given double parameter " + value);
-                }
-            }
-        }
-        return null;
-    }
-
-    public void setMaxInclusive(String maxInclusive) {
+    public void setMaxInclusive(Double maxInclusive) {
         this.maxInclusive = maxInclusive;
     }
 
-    public String getMaxInclusive() {
+    public Double getMaxInclusive() {
         return maxInclusive;
     }
 
-    public void setMinInclusive(String minInclusive) {
+    public void setMinInclusive(Double minInclusive) {
         this.minInclusive = minInclusive;
     }
 
-    public String getMinInclusive() {
+    public Double getMinInclusive() {
         return minInclusive;
     }
 
-    public String getMinExclusive() {
+    public Double getMinExclusive() {
         return minExclusive;
     }
 
-    public void setMinExclusive(String minExclusive) {
+    public void setMinExclusive(Double minExclusive) {
         this.minExclusive = minExclusive;
     }
 
-    public String getMaxExclusive() {
+    public Double getMaxExclusive() {
         return maxExclusive;
     }
 
-    public void setMaxExclusive(String maxExclusive) {
+    public void setMaxExclusive(Double maxExclusive) {
         this.maxExclusive = maxExclusive;
     }
 
+    public void setMinInclusiveExpression(String minInclusiveExpression) {
+        this.minInclusive = (Double) parse(minInclusiveExpression, Double.class);
+    }
+
+    public void setMaxInclusiveExpression(String maxInclusiveExpression) {
+        this.maxInclusive = (Double) parse(maxInclusiveExpression, Double.class);
+    }
+
+    public void setMinExclusiveExpression(String minExclusiveExpression) {
+        this.minExclusive = (Double) parse(minExclusiveExpression, Double.class);
+    }
+
+    public void setMaxExclusiveExpression(String maxExclusiveExpression) {
+        this.maxExclusive = (Double) parse(maxExclusiveExpression, Double.class);
+    }
+
 }

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
Wed Jan  9 22:21:56 2013
@@ -62,10 +62,9 @@ package com.opensymphony.xwork2.validato
  *      &lt;!-- Field Validator Syntax with expression --&gt;
  *      &lt;field name="age"&gt;
  *          &lt;field-validator type="int"&gt;
- *              &lt;param name="parse"&gt;true&lt;/param&gt;
  *              &lt;param name="minExpression"&gt;${minValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Integer getMinValue() --&gt;
  *              &lt;param name="maxExpression"&gt;${maxValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Integer getMaxValue() --&gt;
- *              &lt;message&gt;Age needs to be between ${minExpression} and ${maxExpression}&lt;/message&gt;
+ *              &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
  *          &lt;/field-validator&gt;
  *      &lt;/field&gt;
  * &lt;/validators&gt;

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
Wed Jan  9 22:21:56 2013
@@ -62,10 +62,9 @@ package com.opensymphony.xwork2.validato
  *      &lt;!-- Field Validator Syntax with expression --&gt;
  *      &lt;field name="age"&gt;
  *          &lt;field-validator type="long"&gt;
- *              &lt;param name="parse"&gt;true&lt;/param&gt;
  *              &lt;param name="minExpression"&gt;${minValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Long getMinValue() --&gt;
  *              &lt;param name="maxExpression"&gt;${maxValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Long getMaxValue() --&gt;
- *              &lt;message&gt;Age needs to be between ${minExpression} and ${maxExpression}&lt;/message&gt;
+ *              &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
  *          &lt;/field-validator&gt;
  *      &lt;/field&gt;
  * &lt;/validators&gt;

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
Wed Jan  9 22:21:56 2013
@@ -25,8 +25,7 @@ import java.util.regex.Pattern;
  * <!-- START SNIPPET: javadoc -->
  * Validates a string field using a regular expression.
  * <!-- END SNIPPET: javadoc -->
- * <p/>
- * 
+ *
  * 
  * <!-- START SNIPPET: parameters -->
  * <ul>
@@ -40,20 +39,20 @@ import java.util.regex.Pattern;
  * 
  * <pre>
  * <!-- START SNIPPET: example -->
- *    &lt;validators&gt;
- *        &lt;!-- Plain Validator Syntax --&gt;
- *        &lt;validator type="regex"&gt;
- *            &lt;param name="fieldName"&gt;myStrangePostcode&lt;/param&gt;
- *            &lt;param name="expression"&gt;&lt;![CDATA[([aAbBcCdD][123][eEfFgG][456])]]&lt;&gt;/param&gt;
- *        &lt;/validator&gt;
- *    
- *        &lt;!-- Field Validator Syntax --&gt;
- *        &lt;field name="myStrangePostcode"&gt;
- *            &lt;field-validator type="regex"&gt;
- *               &lt;param name="expression"&gt;&lt;![CDATA[([aAbBcCdD][123][eEfFgG][456])]]&gt;&lt;/param&gt;
- *            &lt;/field-validator&gt;
- *        &lt;/field&gt;
- *    &lt;/validators&gt;
+ * &lt;validators&gt;
+ *     &lt;!-- Plain Validator Syntax --&gt;
+ *     &lt;validator type="regex"&gt;
+ *         &lt;param name="fieldName"&gt;myStrangePostcode&lt;/param&gt;
+ *         &lt;param name="expression"&gt;&lt;![CDATA[([aAbBcCdD][123][eEfFgG][456])]]&lt;&gt;/param&gt;
+ *     &lt;/validator&gt;
+ *
+ *     &lt;!-- Field Validator Syntax --&gt;
+ *     &lt;field name="myStrangePostcode"&gt;
+ *         &lt;field-validator type="regex"&gt;
+ *             &lt;param name="expression"&gt;&lt;![CDATA[([aAbBcCdD][123][eEfFgG][456])]]&gt;&lt;/param&gt;
+ *         &lt;/field-validator&gt;
+ *     &lt;/field&gt;
+ * &lt;/validators&gt;
  * <!-- END SNIPPET: example -->
  * </pre>
  *

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
Wed Jan  9 22:21:56 2013
@@ -62,10 +62,9 @@ package com.opensymphony.xwork2.validato
  *      &lt;!-- Field Validator Syntax with expression --&gt;
  *      &lt;field name="age"&gt;
  *          &lt;field-validator type="short"&gt;
- *              &lt;param name="parse"&gt;true&lt;/param&gt;
  *              &lt;param name="minExpression"&gt;${minValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Short getMinValue() --&gt;
  *              &lt;param name="maxExpression"&gt;${maxValue}&lt;/param&gt;
&lt;!-- will be evaluated as: Short getMaxValue() --&gt;
- *              &lt;message&gt;Age needs to be between ${minExpression} and ${maxExpression}&lt;/message&gt;
+ *              &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
  *          &lt;/field-validator&gt;
  *      &lt;/field&gt;
  *  &lt;/validators&gt;

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
Wed Jan  9 22:21:56 2013
@@ -59,6 +59,7 @@ public class MockConfigurationProvider i
     public static final String VALIDATION_ACTION_NAME = "validationInterceptorTest";
     public static final String VALIDATION_ALIAS_NAME = "validationAlias";
     public static final String VALIDATION_SUBPROPERTY_NAME = "subproperty";
+    public static final String EXPRESSION_VALIDATION_ACTION = "expressionValidationAction";
 
     private static final Map<String,String> EMPTY_STRING_MAP = Collections.emptyMap();
 
@@ -177,6 +178,12 @@ public class MockConfigurationProvider i
                 .build();
         defaultPackageContext.addActionConfig(barActionConfig.getName(), barActionConfig);
 
+        ActionConfig expressionValidationActionConfig = new ActionConfig.Builder("defaultPackage",
EXPRESSION_VALIDATION_ACTION, SimpleAction.class.getName())
+                .addInterceptors(interceptors)
+                .addResultConfigs(results)
+                .build();
+        defaultPackageContext.addActionConfig(EXPRESSION_VALIDATION_ACTION, expressionValidationActionConfig);
+
         configuration.addPackageConfig("defaultPackage", defaultPackageContext.build());
     }
 

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
Wed Jan  9 22:21:56 2013
@@ -38,7 +38,6 @@ public class DoubleRangeValidatorTest ex
         assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
 
         Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
-        Iterator it = errors.entrySet().iterator();
 
         List<String> errorMessages = errors.get("percentage");
         assertNotNull("Expected double range validation error message.", errorMessages);
@@ -82,8 +81,8 @@ public class DoubleRangeValidatorTest ex
         stack.push(prod);
         ActionContext.getContext().setValueStack(stack);
 
-        val.setMinInclusive("0");
-        val.setMaxInclusive("10");
+        val.setMinInclusive(0d);
+        val.setMaxInclusive(10d);
         val.setFieldName("price");
         val.validate(prod);
     }
@@ -92,14 +91,14 @@ public class DoubleRangeValidatorTest ex
         MyTestProduct prod = new MyTestProduct();
         prod.setName("coca cola");
         prod.setPrice(5.99);
-        prod.setVolume(new Double(12.34));
+        prod.setVolume(12.34d);
 
         ValueStack stack = ActionContext.getContext().getValueStack();
         stack.push(prod);
         ActionContext.getContext().setValueStack(stack);
 
-        val.setMinInclusive("0");
-        val.setMaxInclusive("30");
+        val.setMinInclusive(0d);
+        val.setMaxInclusive(30d);
         val.setFieldName("volume");
         val.validate(prod);
     }
@@ -112,8 +111,8 @@ public class DoubleRangeValidatorTest ex
         stack.push(prod);
         ActionContext.getContext().setValueStack(stack);
 
-        val.setMinInclusive("0");
-        val.setMaxInclusive("10");
+        val.setMinInclusive(0d);
+        val.setMaxInclusive(10d);
         val.setFieldName("name");
 
         DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport());
@@ -121,8 +120,8 @@ public class DoubleRangeValidatorTest ex
 
         val.validate(prod);
 
-        assertEquals("0", val.getMinInclusive());
-        assertEquals("10", val.getMaxInclusive());
+        assertEquals(0d, val.getMinInclusive());
+        assertEquals(10d, val.getMaxInclusive());
     }
 
     public void testEdgeOfMaxRange() throws Exception {
@@ -139,15 +138,15 @@ public class DoubleRangeValidatorTest ex
         DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport());
         val.setValidatorContext(context);
 
-        val.setMaxInclusive("9.95");
+        val.setMaxInclusive(9.95d);
         val.validate(prod); // should pass
         assertTrue(!context.hasErrors());
-        assertEquals("9.95", val.getMaxInclusive());
+        assertEquals(9.95d, val.getMaxInclusive());
 
-        val.setMaxExclusive("9.95");
+        val.setMaxExclusive(9.95d);
         val.validate(prod); // should not pass
         assertTrue(context.hasErrors());
-        assertEquals("9.95", val.getMaxExclusive());
+        assertEquals(9.95d, val.getMaxExclusive());
     }
 
     public void testEdgeOfMinRange() throws Exception {
@@ -164,11 +163,11 @@ public class DoubleRangeValidatorTest ex
         DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport());
         val.setValidatorContext(context);
 
-        val.setMinInclusive("9.95");
+        val.setMinInclusive(9.95d);
         val.validate(prod); // should pass
         assertTrue(!context.hasErrors());
 
-        val.setMinExclusive("9.95");
+        val.setMinExclusive(9.95d);
         val.validate(prod); // should not pass
         assertTrue(context.hasErrors());
     }
@@ -182,11 +181,38 @@ public class DoubleRangeValidatorTest ex
         DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport());
         val.setValidatorContext(context);
 
-        val.setMinInclusive("9.95");
+        val.setMinInclusive(9.95d);
         val.validate(null);
         assertTrue(!context.hasErrors()); // should pass as null value passed in
     }
 
+    public void testRangeValidationWithExpressionsFail() throws Exception {
+        //Explicitly set an out-of-range double for DoubleRangeValidatorTest
+        Map<String, Object> context = new HashMap<String, Object>();
+        HashMap<String, Object> params = new HashMap<String, Object>();
+        params.put("percentage", 100.0123d);
+        context.put(ActionContext.PARAMETERS, params);
+
+        // must set a locale to US as error message contains a locale dependent number (see
XW-490)
+        Locale defLocale = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+
+        ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.EXPRESSION_VALIDATION_ACTION,
context);
+        proxy.execute();
+        assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
+
+        Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
+        List<String> errorMessages = errors.get("percentage");
+        assertNotNull("Expected double range validation error message.", errorMessages);
+        assertEquals(1, errorMessages.size());
+
+        String errorMessage = errorMessages.get(0);
+        assertNotNull("Expecting: percentage must be between 0.1 and 10.1, current value
is 100.0123.", errorMessage);
+        assertEquals("percentage must be between 0.1 and 10.1, current value is 100.0123.",
errorMessage);
+
+        Locale.setDefault(defLocale);
+    }
+
     public void testExpressionParams() throws Exception {
         ValueStack stack = ActionContext.getContext().getValueStack();
         ActionSupport action = new ActionSupport() {
@@ -201,10 +227,10 @@ public class DoubleRangeValidatorTest ex
         stack.push(action);
 
         val.setParse(true);
-        val.setMinInclusive("${minInclusiveValue}");
-        val.setMaxInclusive("${maxInclusiveValue}");
-        val.setMinExclusive("${minExclusiveValue}");
-        val.setMaxExclusive("${maxExclusiveValue}");
+        val.setMinInclusiveExpression("${minInclusiveValue}");
+        val.setMaxInclusiveExpression("${maxInclusiveValue}");
+        val.setMinExclusiveExpression("${minExclusiveValue}");
+        val.setMaxExclusiveExpression("${maxExclusiveValue}");
 
         val.setFieldName("price");
         val.setDefaultMessage("Price is wrong!");

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java
Wed Jan  9 22:21:56 2013
@@ -67,16 +67,19 @@ public class DateRangeFieldValidatorTest
     }
 
     private DateRangeFieldValidator prepareValidator(ValidationAction action, ValidatorContext
context) {
-        DateRangeFieldValidator validator = new DateRangeFieldValidator();
-        validator.setMaxExpression("${dateMaxValue}");
-        validator.setMinExpression("${dateMinValue}");
         ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
         valueStack.push(action);
+
+        DateRangeFieldValidator validator = new DateRangeFieldValidator();
         validator.setValueStack(valueStack);
+        validator.setParse(true);
+
+        validator.setMaxExpression("${dateMaxValue}");
+        validator.setMinExpression("${dateMinValue}");
         validator.setValidatorContext(context);
         validator.setFieldName("dateRange");
-        validator.setParse(true);
         validator.setDefaultMessage("Max is ${dateMaxValue}, min is ${dateMinValue} but value
is ${dateRange}");
+
         return validator;
     }
 

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java
Wed Jan  9 22:21:56 2013
@@ -58,16 +58,19 @@ public class IntRangeFieldValidatorTest 
     }
 
     private IntRangeFieldValidator prepareValidator(ValidationAction action, ValidatorContext
context) {
-        IntRangeFieldValidator validator = new IntRangeFieldValidator();
-        validator.setMaxExpression("${intMaxValue}");
-        validator.setMinExpression("${intMinValue}");
         ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
         valueStack.push(action);
+
+        IntRangeFieldValidator validator = new IntRangeFieldValidator();
         validator.setValueStack(valueStack);
+        validator.setParse(true);
+
+        validator.setMaxExpression("${intMaxValue}");
+        validator.setMinExpression("${intMinValue}");
         validator.setValidatorContext(context);
         validator.setFieldName("intRange");
-        validator.setParse(true);
         validator.setDefaultMessage("Max is ${intMaxValue}, min is ${intMinValue} but value
is ${intRange}");
+
         return validator;
     }
 

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java
Wed Jan  9 22:21:56 2013
@@ -58,16 +58,19 @@ public class LongRangeFieldValidatorTest
     }
 
     private LongRangeFieldValidator prepareValidator(ValidationAction action, ValidatorContext
context) {
-        LongRangeFieldValidator validator = new LongRangeFieldValidator();
-        validator.setMaxExpression("${longMaxValue}");
-        validator.setMinExpression("${longMinValue}");
         ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
         valueStack.push(action);
+
+        LongRangeFieldValidator validator = new LongRangeFieldValidator();
         validator.setValueStack(valueStack);
+        validator.setParse(true);
+
+        validator.setMaxExpression("${longMaxValue}");
+        validator.setMinExpression("${longMinValue}");
         validator.setValidatorContext(context);
         validator.setFieldName("longRange");
-        validator.setParse(true);
         validator.setDefaultMessage("Max is ${longMaxValue}, min is ${longMinValue} but value
is ${longRange}");
+
         return validator;
     }
 

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java?rev=1431115&r1=1431114&r2=1431115&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java
Wed Jan  9 22:21:56 2013
@@ -58,16 +58,19 @@ public class ShortRangeFieldValidatorTes
     }
 
     private ShortRangeFieldValidator prepareValidator(ValidationAction action, ValidatorContext
context) {
-        ShortRangeFieldValidator validator = new ShortRangeFieldValidator();
-        validator.setMaxExpression("${shortMaxValue}");
-        validator.setMinExpression("${shortMinValue}");
         ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
         valueStack.push(action);
+
+        ShortRangeFieldValidator validator = new ShortRangeFieldValidator();
         validator.setValueStack(valueStack);
+        validator.setParse(true);
+
+        validator.setMaxExpression("${shortMaxValue}");
+        validator.setMinExpression("${shortMinValue}");
         validator.setValidatorContext(context);
         validator.setFieldName("shortRange");
-        validator.setParse(true);
         validator.setDefaultMessage("Max is ${shortMaxValue}, min is ${shortMinValue} but
value is ${shortRange}");
+
         return validator;
     }
 



Mime
View raw message