Class AbstractFormatValidator
- java.lang.Object
-
- org.apache.commons.validator.routines.AbstractFormatValidator
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
AbstractCalendarValidator,AbstractNumberValidator
public abstract class AbstractFormatValidator extends java.lang.Object implements java.io.SerializableAbstract class for Format based Validation.
This is a base class for building Date and Number Validators using format parsing.
- Since:
- Validator 1.3.0
- Version:
- $Revision: 1649191 $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUIDprivate booleanstrict
-
Constructor Summary
Constructors Constructor Description AbstractFormatValidator(boolean strict)Construct an instance with the specified strict setting.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.Stringformat(java.lang.Object value)Format an object into aStringusing the default Locale.java.lang.Stringformat(java.lang.Object value, java.lang.String pattern)Format an object into aStringusing the specified pattern.java.lang.Stringformat(java.lang.Object value, java.lang.String pattern, java.util.Locale locale)Format an object using the specified pattern and/orLocale.protected java.lang.Stringformat(java.lang.Object value, java.text.Format formatter)Format a value with the specifiedFormat.java.lang.Stringformat(java.lang.Object value, java.util.Locale locale)Format an object into aStringusing the specified Locale.protected abstract java.text.FormatgetFormat(java.lang.String pattern, java.util.Locale locale)Returns aFormatfor the specified pattern and/orLocale.booleanisStrict()Indicates whether validated values should adhere strictly to theFormatused.booleanisValid(java.lang.String value)Validate using the defaultLocale.booleanisValid(java.lang.String value, java.lang.String pattern)Validate using the specified pattern.abstract booleanisValid(java.lang.String value, java.lang.String pattern, java.util.Locale locale)Validate using the specified pattern and/orLocale.booleanisValid(java.lang.String value, java.util.Locale locale)Validate using the specifiedLocale.protected java.lang.Objectparse(java.lang.String value, java.text.Format formatter)Parse the value with the specifiedFormat.protected abstract java.lang.ObjectprocessParsedValue(java.lang.Object value, java.text.Format formatter)Process the parsed value, performing any further validation and type conversion required.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
strict
private final boolean strict
-
-
Method Detail
-
isStrict
public boolean isStrict()
Indicates whether validated values should adhere strictly to the
Formatused.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
public boolean isValid(java.lang.String value)
Validate using the default
Locale.- Parameters:
value- The value validation is being performed on.- Returns:
trueif the value is valid.
-
isValid
public boolean isValid(java.lang.String value, java.lang.String pattern)Validate using the specified pattern.
- Parameters:
value- The value validation is being performed on.pattern- The pattern used to validate the value against.- Returns:
trueif the value is valid.
-
isValid
public boolean isValid(java.lang.String value, java.util.Locale locale)Validate using the specified
Locale.- Parameters:
value- The value validation is being performed on.locale- The locale to use for the Format, defaults to the default- Returns:
trueif the value is valid.
-
isValid
public abstract boolean isValid(java.lang.String value, java.lang.String pattern, java.util.Locale locale)Validate using the specified pattern and/or
Locale.- 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.
-
format
public java.lang.String format(java.lang.Object value)
Format an object into a
Stringusing the default Locale.- Parameters:
value- The value validation is being performed on.- Returns:
- The value formatted as a
String.
-
format
public java.lang.String format(java.lang.Object value, java.lang.String pattern)Format an object into a
Stringusing the specified pattern.- Parameters:
value- The value validation is being performed on.pattern- The pattern used to format the value.- Returns:
- The value formatted as a
String.
-
format
public java.lang.String format(java.lang.Object value, java.util.Locale locale)Format an object into a
Stringusing the specified Locale.- Parameters:
value- The value validation is being performed on.locale- The locale to use for the Format.- Returns:
- The value formatted as a
String.
-
format
public java.lang.String format(java.lang.Object value, java.lang.String pattern, java.util.Locale locale)Format an object using the specified pattern and/or
Locale.- 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.- Returns:
- The value formatted as a
String.
-
format
protected java.lang.String format(java.lang.Object value, java.text.Format formatter)Format a value with the specified
Format.- Parameters:
value- The value to be formatted.formatter- The Format to use.- Returns:
- The formatted value.
-
parse
protected java.lang.Object parse(java.lang.String value, java.text.Format formatter)Parse the value with the specified
Format.- Parameters:
value- The value to be parsed.formatter- The Format to parse the value with.- Returns:
- The parsed value if valid or
nullif invalid.
-
processParsedValue
protected abstract java.lang.Object processParsedValue(java.lang.Object value, java.text.Format formatter)Process 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.
-
getFormat
protected abstract java.text.Format getFormat(java.lang.String pattern, java.util.Locale locale)Returns a
Formatfor the specified pattern and/orLocale.- Parameters:
pattern- The pattern used to validate the value against ornullto use the default for theLocale.locale- The locale to use for the currency format, system default if null.- Returns:
- The
NumberFormatto created.
-
-