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 | - *
|---|---|---|---|
| message | - *yes | - *- * | field error message | - *
| key | - *no | - *- * | i18n key from language specific properties file. | - *
| messageParams | - *no | - *- * | Additional params to be used to customize message - will be evaluated against the Value Stack | - *
| fieldName | - *no | - *- * | - * |
| shortCircuit | - *no | - *false | - *If this validator should be used as shortCircuit. | - *
| type | - *yes | - *ValidatorType.FIELD | - *Enum value from ValidatorType. Either FIELD or SIMPLE can be used here. | - *
- * * @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 ""; + }