struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1424643 - in /struts/struts2/trunk: apps/portlet/src/main/resources/ xwork-core/src/main/java/com/opensymphony/xwork2/validator/ xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/
Date Thu, 20 Dec 2012 19:12:37 GMT
Author: lukaszlenart
Date: Thu Dec 20 19:12:36 2012
New Revision: 1424643

URL: http://svn.apache.org/viewvc?rev=1424643&view=rev
Log:
WW-3891 adds new Short validator and adds support for expression in specifying min and max
constraints

Added:
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/ShortRangeFieldValidator.java
      - copied, changed from r1399395, struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/IntRangeFieldValidator.java
Modified:
    struts/struts2/trunk/apps/portlet/src/main/resources/validators.xml
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/Validations.java

Modified: struts/struts2/trunk/apps/portlet/src/main/resources/validators.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/resources/validators.xml?rev=1424643&r1=1424642&r2=1424643&view=diff
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/resources/validators.xml (original)
+++ struts/struts2/trunk/apps/portlet/src/main/resources/validators.xml Thu Dec 20 19:12:36
2012
@@ -6,6 +6,7 @@
     <validator name="required" class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/>
     <validator name="requiredstring" class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/>
     <validator name="int" class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/>
+    <validator name="short" class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/>
     <validator name="double" class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/>
     <validator name="date" class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/>
     <validator name="expression" class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/>

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java?rev=1424643&r1=1424642&r2=1424643&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java
Thu Dec 20 19:12:36 2012
@@ -149,6 +149,15 @@ public class AnnotationValidationConfigu
                     }
 
                 }
+                // Process ShortRangeFieldValidator
+                else if ( a instanceof ShortRangeFieldValidator) {
+                    ShortRangeFieldValidator v = (ShortRangeFieldValidator) a;
+                    ValidatorConfig temp = processShortRangeFieldValidatorAnnotation(v, fieldName,
methodName);
+                    if ( temp != null) {
+                        result.add(temp);
+                    }
+
+                }
                 // Process DoubleRangeFieldValidator
                 else if ( a instanceof DoubleRangeFieldValidator) {
                     DoubleRangeFieldValidator v = (DoubleRangeFieldValidator) a;
@@ -548,18 +557,14 @@ public class AnnotationValidationConfigu
         SimpleDateFormat d2 = (SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.MEDIUM, Locale.getDefault());
         SimpleDateFormat d3 = (SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.SHORT, Locale.getDefault());
         SimpleDateFormat[] dfs = {d1, d2, d3};
-        DateFormat df = null;
-        for (SimpleDateFormat df1 : dfs) {
+        for (SimpleDateFormat df : dfs)
             try {
-                Date check = df1.parse(value);
-                df = df1;
+                Date check = df.parse(value);
                 if (check != null) {
                     return check;
                 }
+            } catch (ParseException ignore) {
             }
-            catch (ParseException ignore) {
-            }
-        }
         return null;
 
     }
@@ -636,6 +641,34 @@ public class AnnotationValidationConfigu
             .build();
     }
 
+    private ValidatorConfig processShortRangeFieldValidatorAnnotation(ShortRangeFieldValidator
v, String fieldName, String methodName) {
+        String validatorType = "short";
+
+        Map<String, String> params = new HashMap<String, String>();
+
+        if (fieldName != null) {
+            params.put("fieldName", fieldName);
+        } else if (v.fieldName() != null && v.fieldName().length() > 0 ) {
+            params.put("fieldName", v.fieldName());
+        }
+
+        if ( v.min() != null && v.min().length() > 0) {
+            params.put("min", v.min());
+        }
+        if ( v.max() != null && v.max().length() > 0) {
+            params.put("max", v.max());
+        }
+
+        validatorFactory.lookupRegisteredValidatorType(validatorType);
+        return new ValidatorConfig.Builder(validatorType)
+            .addParams(params)
+            .addParam("methodName", methodName)
+            .shortCircuit(v.shortCircuit())
+            .defaultMessage(v.message())
+            .messageKey(v.key())
+            .build();
+    }
+
     private ValidatorConfig processDoubleRangeFieldValidatorAnnotation(DoubleRangeFieldValidator
v, String fieldName, String methodName) {
         String validatorType = "double";
 

Copied: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/ShortRangeFieldValidator.java
(from r1399395, struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/IntRangeFieldValidator.java)
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/ShortRangeFieldValidator.java?p2=struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/ShortRangeFieldValidator.java&p1=struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/IntRangeFieldValidator.java&r1=1399395&r2=1424643&rev=1424643&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/IntRangeFieldValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/ShortRangeFieldValidator.java
Thu Dec 20 19:12:36 2012
@@ -77,13 +77,13 @@ import java.lang.annotation.Target;
  * <td class='confluenceTd'> min </td>
  * <td class='confluenceTd'> no </td>
  * <td class='confluenceTd'>&nbsp;</td>
- * <td class='confluenceTd'> Integer property. The minimum the number must be. Can
be an expression. Don't use ${min} as this can turn into infinitive loop!</td>
+ * <td class='confluenceTd'> Short property. The minimum the number must be. Can be
an expression. Don't use ${min} as this can turn into infinitive loop!</td>
  * </tr>
  * <tr>
  * <td class='confluenceTd'> max </td>
  * <td class='confluenceTd'> no </td>
  * <td class='confluenceTd'>&nbsp;</td>
- * <td class='confluenceTd'> Integer property. The maximum number can be. Can be an
expression. Don't use ${max} as this can turn into infinitive loop!</td>
+ * <td class='confluenceTd'> Short property. The maximum number can be. Can be an expression.
Don't use ${max} as this can turn into infinitive loop!</td>
  * </tr>
  * <tr>
  * <td class='confluenceTd'>parse</td>
@@ -108,13 +108,10 @@ import java.lang.annotation.Target;
  * <!-- END SNIPPET: example -->
  * </pre>
  *
- *
- * @author Rainer Hermanns
- * @version $Id$
  */
 @Target({ElementType.METHOD})
 @Retention(RetentionPolicy.RUNTIME)
-public @interface IntRangeFieldValidator {
+public @interface ShortRangeFieldValidator {
 
     /**
      *  Integer property. The minimum the number must be.

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/Validations.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/Validations.java?rev=1424643&r1=1424642&r2=1424643&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/Validations.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/Validations.java
Thu Dec 20 19:12:36 2012
@@ -129,6 +129,8 @@ import java.lang.annotation.Target;
  *                   {&#64;StringLengthFieldValidator(type = ValidatorType.SIMPLE, trim
= true, minLength="10" , maxLength = "12", fieldName = "needstringlength", message = "You
must enter a stringlength.")},
  *           intRangeFields =
  *                   { &#64;IntRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName
= "intfield", min = "6", max = "10", message = "bar must be between ${min} and ${max}, current
value is ${bar}.")},
+ *           shortRangeFields =
+ *                   { &#64;ShortRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName
= "shortfield", min = "1", max = "128", message = "bar must be between ${min} and ${max},
current value is ${bar}.")},
  *           dateRangeFields =
  *                   {&#64;DateRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName
= "datefield", min = "-1", max = "99", message = "bar must be between ${min} and ${max}, current
value is ${bar}.")},
  *           expressions = {



Mime
View raw message