From e66a3062992fac588cf3f570a224bbe7d9ce5ef5 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sun, 9 Mar 2014 21:04:11 +0100 Subject: [PATCH] Extends annotation to support new URL regex parameters --- ...otationValidationConfigurationBuilder.java | 6 ++ .../validator/annotations/UrlValidator.java | 74 +++---------------- 2 files changed, 16 insertions(+), 64 deletions(-) diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java index 6ab06a94c..dbd897524 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationValidationConfigurationBuilder.java @@ -528,6 +528,12 @@ public class AnnotationValidationConfigurationBuilder { } else if (v.fieldName() != null && v.fieldName().length() > 0) { params.put("fieldName", v.fieldName()); } + if (StringUtils.isNotEmpty(v.urlRegex())) { + params.put("urlRegex", v.urlRegex()); + } + if (StringUtils.isNotEmpty(v.urlRegexExpression())) { + params.put("urlRegexExpression", v.urlRegexExpression()); + } validatorFactory.lookupRegisteredValidatorType(validatorType); return new ValidatorConfig.Builder(validatorType) diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/UrlValidator.java b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/UrlValidator.java index fb6fa3c86..a06db1259 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/UrlValidator.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/annotations/UrlValidator.java @@ -22,75 +22,12 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * * This validator checks that a field is a valid URL. - * - * - *

Annotation usage: - * - * - *

The annotation must be applied at method level. - * - * - *

Annotation parameters: - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
Parameter Required Default Notes
messageyes field error message
keyno i18n key from language specific properties file.
messageParamsno Additional params to be used to customize message - will be evaluated against the Value Stack
fieldNameno  
shortCircuitnofalseIf this validator should be used as shortCircuit.
typeyesValidatorType.FIELDEnum value from ValidatorType. Either FIELD or SIMPLE can be used here.
- * - * - *

Example code: * *

- * 
  * @UrlValidator(message = "Default message", key = "i18n.key", shortCircuit = true)
- * 
  * 
* - * @author Rainer Hermanns - * @version $Id$ */ @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @@ -121,7 +58,6 @@ public @interface UrlValidator { * If this is activated, the validator will be used as short-circuit. * * Adds the short-circuit="true" attribute value if true. - * */ boolean shortCircuit() default false; @@ -130,4 +66,14 @@ public @interface UrlValidator { */ ValidatorType type() default ValidatorType.FIELD; + /** + * Defines regex to use to validate url + */ + String urlRegex() default ""; + + /** + * Defines regex as an expression which will be evaluated to string and used to validate url + */ + String urlRegexExpression() default ""; + }