Class AbstractFormatValidator
java.lang.Object
org.apache.commons.validator.routines.AbstractFormatValidator
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractCalendarValidator, AbstractNumberValidator
Abstracts class for Format based Validation.
This is a base class for building Date and Number Validators using format parsing.
- Since:
- 1.3.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractFormatValidator(boolean strict) Constructs an instance with the specified strict setting. -
Method Summary
Modifier and TypeMethodDescriptionFormats an object into aStringusing the default Locale.Formats an object into aStringusing the specified pattern.Formats an object using the specified pattern and/orLocale.protected StringFormats a value with the specifiedFormat.Formats an object into aStringusing the specified Locale.protected abstract Formatget aFormatfor the specified pattern and/orLocale.booleanisStrict()Tests whether validated values should adhere strictly to theFormatused.booleanValidates using the defaultLocale.booleanValidates using the specified pattern.abstract booleanValidates using the specified pattern and/orLocale.booleanValidates using the specifiedLocale.protected ObjectParses the value with the specifiedFormat.protected abstract ObjectprocessParsedValue(Object value, Format formatter) Processes the parsed value, performing any further validation and type conversion required.
-
Constructor Details
-
AbstractFormatValidator
Constructs an instance with the specified strict setting.- Parameters:
strict-trueif strictFormatparsing should be used.
-
-
Method Details
-
format
-
format
-
format
-
format
-
format
-
getFormat
-
isStrict
Tests whether validated values should adhere strictly to theFormatused.Typically implementations of
Formatignore invalid characters at the end of the value and just stop parsing. For example parsing a date value of01/01/20x0using a pattern ofdd/MM/yyyywill result in a year of20ifstrictis set tofalse, whereas settingstricttotruewill cause this value to fail validation.- Returns:
trueif strictFormatparsing should be used.
-
isValid
-
isValid
-
isValid
-
isValid
Validates using the specified pattern and/orLocale.- Parameters:
value- The value validation is being performed on.pattern- The pattern used to format the value.locale- The locale to use for the Format, defaults to the default- Returns:
trueif the value is valid.
-
parse
-
processParsedValue
Processes the parsed value, performing any further validation and type conversion required.- Parameters:
value- The parsed object created.formatter- The Format used to parse the value with.- Returns:
- The parsed value converted to the appropriate type if valid or
nullif invalid.
-