struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1457744 - in /struts/struts2/trunk/xwork-core/src: main/java/com/opensymphony/xwork2/validator/ main/java/com/opensymphony/xwork2/validator/annotations/ test/java/com/opensymphony/xwork2/validator/
Date Mon, 18 Mar 2013 12:54:02 GMT
Author: lukaszlenart
Date: Mon Mar 18 12:54:02 2013
New Revision: 1457744

URL: http://svn.apache.org/r1457744
Log:
WW-4013 Improves UrlValidator annotation to match UrlValidator class

Modified:
    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/UrlValidator.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java

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=1457744&r1=1457743&r2=1457744&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
Mon Mar 18 12:54:02 2013
@@ -535,6 +535,7 @@ public class AnnotationValidationConfigu
                 .shortCircuit(v.shortCircuit())
                 .defaultMessage(v.message())
                 .messageKey(v.key())
+                .messageParams(v.messageParams())
                 .build();
     }
 

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/UrlValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/UrlValidator.java?rev=1457744&r1=1457743&r2=1457744&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/UrlValidator.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/UrlValidator.java
Mon Mar 18 12:54:02 2013
@@ -55,6 +55,12 @@ import java.lang.annotation.Target;
  * <td class='confluenceTd'>i18n key from language specific properties file.</td>
  * </tr>
  * <tr>
+ * <td class='confluenceTd'>messageParams</td>
+ * <td class='confluenceTd'>no</td>
+ * <td class='confluenceTd'>&nbsp;</td>
+ * <td class='confluenceTd'>Additional params to be used to customize message - will
be evaluated against the Value Stack</td>
+ * </tr>
+ * <tr>
  * <td class='confluenceTd'>fieldName</td>
  * <td class='confluenceTd'>no</td>
  * <td class='confluenceTd'>&nbsp;</td>
@@ -102,6 +108,11 @@ public @interface UrlValidator {
     String key() default "";
 
     /**
+     * Additional params to be used to customize message - will be evaluated against the
Value Stack
+     */
+    String[] messageParams() default {};
+
+    /**
      * The optional fieldName for SIMPLE validator types.
      */
     String fieldName() default "";

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java?rev=1457744&r1=1457743&r2=1457744&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationAction.java
Mon Mar 18 12:54:02 2013
@@ -15,6 +15,7 @@ import com.opensymphony.xwork2.validator
 import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
 import com.opensymphony.xwork2.validator.annotations.ShortRangeFieldValidator;
 import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
+import com.opensymphony.xwork2.validator.annotations.UrlValidator;
 import com.opensymphony.xwork2.validator.annotations.ValidationParameter;
 
 /**
@@ -57,6 +58,8 @@ public class AnnotationValidationAction 
             messageParams = {"one", "two", "three"}, shortCircuit = true)
     @StringLengthFieldValidator(fieldName = "foo", key = "stringlength.key", message = "Foo
is too long!",
             maxLength = "10", minLength = "1", shortCircuit = true, trim = false, messageParams
= {"one", "two", "three"})
+    @UrlValidator(fieldName = "foo", key = "url.key", message = "Foo isn't a valid URL!",
shortCircuit = true,
+            messageParams = {"one", "two", "three"})
     public String execute() {
         return SUCCESS;
     }

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java?rev=1457744&r1=1457743&r2=1457744&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilderTest.java
Mon Mar 18 12:54:02 2013
@@ -27,6 +27,7 @@ import com.opensymphony.xwork2.validator
 import com.opensymphony.xwork2.validator.validators.RequiredStringValidator;
 import com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator;
 import com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator;
+import com.opensymphony.xwork2.validator.validators.URLValidator;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -48,7 +49,7 @@ public class AnnotationValidationConfigu
         List<Validator> validators = manager.getValidators(AnnotationValidationAction.class,
null);
 
         // then
-        assertEquals(validators.size(), 14);
+        assertEquals(validators.size(), 15);
         for (Validator validator : validators) {
             validate(validator);
         }
@@ -65,7 +66,7 @@ public class AnnotationValidationConfigu
         ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
         valueStack.push(new AnnotationValidationExpAction());
 
-        assertEquals(validators.size(), 14);
+        assertEquals(validators.size(), 15);
         for (Validator validator : validators) {
             validator.setValueStack(valueStack);
             validate(validator);
@@ -101,9 +102,19 @@ public class AnnotationValidationConfigu
             validateShortRangeFieldValidator((ShortRangeFieldValidator) validator);
         } else if (validator.getValidatorType().equals("stringlength")) {
             validateStringLengthFieldValidator((StringLengthFieldValidator) validator);
+        } else if (validator.getValidatorType().equals("url")) {
+            validateUrlValidator((URLValidator) validator);
         }
     }
 
+    private void validateUrlValidator(URLValidator validator) {
+        assertEquals("foo", validator.getFieldName());
+        assertEquals("Foo isn't a valid URL!", validator.getDefaultMessage());
+        assertEquals("url.key", validator.getMessageKey());
+        assertTrue(Arrays.equals(new String[]{"one", "two", "three"}, validator.getMessageParameters()));
+        assertEquals(true, validator.isShortCircuit());
+    }
+
     private void validateStringLengthFieldValidator(StringLengthFieldValidator validator)
{
         assertEquals("foo", validator.getFieldName());
         assertEquals("stringlength.key", validator.getMessageKey());

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java?rev=1457744&r1=1457743&r2=1457744&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationValidationExpAction.java
Mon Mar 18 12:54:02 2013
@@ -15,6 +15,7 @@ import com.opensymphony.xwork2.validator
 import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
 import com.opensymphony.xwork2.validator.annotations.ShortRangeFieldValidator;
 import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
+import com.opensymphony.xwork2.validator.annotations.UrlValidator;
 import com.opensymphony.xwork2.validator.annotations.ValidationParameter;
 
 import java.text.ParseException;
@@ -65,6 +66,8 @@ public class AnnotationValidationExpActi
     @StringLengthFieldValidator(fieldName = "foo", key = "stringlength.key", message = "Foo
is too long!",
             maxLengthExpression = "${maxLength}", minLengthExpression = "${minLength}", shortCircuit
= true, trimExpression = "${false}",
             messageParams = {"one", "two", "three"})
+    @UrlValidator(fieldName = "foo", key = "url.key", message = "Foo isn't a valid URL!",
shortCircuit = true,
+            messageParams = {"one", "two", "three"})
     public String execute() {
         return SUCCESS;
     }



Mime
View raw message