org.apache.commons.validator.routines
public abstract class AbstractFormatValidator extends java.lang.Object implements java.io.Serializable
Abstract class for Format based Validation.
This is a base class for building Date and Number Validators using format parsing.
Modifier and Type | Field and Description |
---|---|
private boolean |
strict |
Constructor and Description |
---|
AbstractFormatValidator(boolean strict)
Construct an instance with the specified strict setting.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format(java.lang.Object value)
Format an object into a
String using
the default Locale. |
protected java.lang.String |
format(java.lang.Object value,
java.text.Format formatter)
Format a value with the specified
Format . |
java.lang.String |
format(java.lang.Object value,
java.util.Locale locale)
Format an object into a
String using
the specified Locale. |
java.lang.String |
format(java.lang.Object value,
java.lang.String pattern)
Format an object into a
String using
the specified pattern. |
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 . |
protected abstract java.text.Format |
getFormat(java.lang.String pattern,
java.util.Locale locale)
Returns a
Format for the specified pattern
and/or Locale . |
boolean |
isStrict()
Indicates whether validated values should adhere
strictly to the
Format used. |
boolean |
isValid(java.lang.String value)
Validate using the default
Locale . |
boolean |
isValid(java.lang.String value,
java.util.Locale locale)
Validate using the specified
Locale . |
boolean |
isValid(java.lang.String value,
java.lang.String pattern)
Validate using the specified pattern.
|
abstract boolean |
isValid(java.lang.String value,
java.lang.String pattern,
java.util.Locale locale)
Validate using the specified pattern and/or
Locale . |
protected java.lang.Object |
parse(java.lang.String value,
java.text.Format formatter)
Parse the value with the specified
Format . |
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.
|
public AbstractFormatValidator(boolean strict)
strict
- true
if strict
Format
parsing should be used.public boolean isStrict()
Indicates whether validated values should adhere
strictly to the Format
used.
Typically implementations of Format
ignore invalid characters at the end of the value
and just stop parsing. For example parsing a date
value of 01/01/20x0
using a pattern
of dd/MM/yyyy
will result in a year
of 20
if strict
is set
to false
, whereas setting strict
to true
will cause this value to fail
validation.
true
if strict Format
parsing should be used.public boolean isValid(java.lang.String value)
Validate using the default Locale
.
value
- The value validation is being performed on.true
if the value is valid.public boolean isValid(java.lang.String value, java.lang.String pattern)
Validate using the specified pattern.
value
- The value validation is being performed on.pattern
- The pattern used to validate the value against.true
if the value is valid.public boolean isValid(java.lang.String value, java.util.Locale locale)
Validate using the specified Locale
.
value
- The value validation is being performed on.locale
- The locale to use for the Format, defaults to the defaulttrue
if the value is valid.public abstract boolean isValid(java.lang.String value, java.lang.String pattern, java.util.Locale locale)
Validate using the specified pattern and/or Locale
.
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 defaulttrue
if the value is valid.public java.lang.String format(java.lang.Object value)
Format an object into a String
using
the default Locale.
value
- The value validation is being performed on.String
.public java.lang.String format(java.lang.Object value, java.lang.String pattern)
Format an object into a String
using
the specified pattern.
value
- The value validation is being performed on.pattern
- The pattern used to format the value.String
.public java.lang.String format(java.lang.Object value, java.util.Locale locale)
Format an object into a String
using
the specified Locale.
value
- The value validation is being performed on.locale
- The locale to use for the Format.String
.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
.
value
- The value validation is being performed on.pattern
- The pattern used to format the value.locale
- The locale to use for the Format.String
.protected java.lang.String format(java.lang.Object value, java.text.Format formatter)
Format a value with the specified Format
.
value
- The value to be formatted.formatter
- The Format to use.protected java.lang.Object parse(java.lang.String value, java.text.Format formatter)
Parse the value with the specified Format
.
value
- The value to be parsed.formatter
- The Format to parse the value with.null
if invalid.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.
value
- The parsed object created.formatter
- The Format used to parse the value with.null
if invalid.protected abstract java.text.Format getFormat(java.lang.String pattern, java.util.Locale locale)
Returns a Format
for the specified pattern
and/or Locale
.
pattern
- The pattern used to validate the value against or
null
to use the default for the Locale
.locale
- The locale to use for the currency format, system default if null.NumberFormat
to created.Copyright (c) 2001-2004 Apache Software Foundation