com.opensymphony.xwork2.validator.validators
public class: URLValidator [javadoc |
source]
java.lang.Object
com.opensymphony.xwork2.validator.validators.ValidatorSupport
com.opensymphony.xwork2.validator.validators.FieldValidatorSupport
com.opensymphony.xwork2.validator.validators.URLValidator
All Implemented Interfaces:
FieldValidator, ShortCircuitableValidator, Validator
URLValidator checks that a given field is a String and a valid URL
- fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required
<validators>
<!-- Plain Validator Syntax -->
<validator type="url">
<param name="fieldName">myHomePage</param>
<message>Invalid homepage url</message>
</validator>
<!-- Field Validator Syntax -->
<field name="myHomepage">
<message>Invalid homepage url</message>
</field>
</validators>
- author:
$ - Author: mrdon $
- version:
$ - Date: 2006-09-10 04:40:12 +0200 (Sun, 10 Sep 2006) $ $Revision: 1123 $
| Method from com.opensymphony.xwork2.validator.validators.URLValidator Summary: |
|---|
|
validate |
| Methods from com.opensymphony.xwork2.validator.validators.ValidatorSupport: |
|---|
|
addActionError, addFieldError, conditionalParse, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getParse, getValidatorContext, getValidatorType, isShortCircuit, setDefaultMessage, setMessageKey, setParse, setShortCircuit, setValidatorContext, setValidatorType, setValueStack |
| Method from com.opensymphony.xwork2.validator.validators.URLValidator Detail: |
public void validate(Object object) throws ValidationException {
String fieldName = getFieldName();
Object value = this.getFieldValue(fieldName, object);
// if there is no value - don't do comparison
// if a value is required, a required validator should be added to the field
if (value == null || value.toString().length() == 0) {
return;
}
if (!(value.getClass().equals(String.class)) || !TextUtils.verifyUrl((String) value)) {
addFieldError(fieldName, object);
}
}
|