org.apache.commons.validator
Class ValidatorResources
java.lang.Object
org.apache.commons.validator.ValidatorResources
- Serializable
public class ValidatorResources
extends java.lang.Object
implements Serializable
General purpose class for storing
FormSet
objects based
on their associated
Locale
. Instances of this class are usually
configured through a validation.xml file that is parsed in a constructor.
Note - Classes that extend this class
must be Serializable so that instances may be used in distributable
application server environments.
The use of FastHashMap is deprecated and will be replaced in a future
release.
private static String | ARGS_PATTERN
|
private static String[] | REGISTRATIONS - The set of public identifiers, and corresponding resource names, for
the versions of the configuration file DTDs that we know about.
|
protected FormSet | defaultFormSet - This is the default
FormSet (without locale).
|
protected static Locale | defaultLocale - The default locale on our server.
|
protected FastHashMap | hActions - Subclasses should use getActions() instead.
|
protected FastHashMap | hConstants - Subclasses should use getConstants() instead.
|
protected FastHashMap | hFormSets - Subclasses should use getFormSets() instead.
|
private Log | log
|
void | addConstant(String name, String value) - Add a global constant to the resource.
|
void | addFormSet(FormSet fs) - Add a
FormSet to this ValidatorResources
object.
|
private void | addOldArgRules(Digester digester) - Create a
Rule to handle arg0-arg3
elements.
|
void | addValidatorAction(ValidatorAction va) - Add a
ValidatorAction to the resource.
|
protected String | buildKey(FormSet fs) - Builds a key to store the
FormSet under based on it's
language, country, and variant values.
|
private String | buildLocale(String lang, String country, String variant) - Assembles a Locale code from the given parts.
|
protected Map | getActions() - Returns a Map of String ValidatorAction names to their ValidatorAction.
|
protected Map | getConstants() - Returns a Map of String constant names to their String values.
|
Form | getForm(Locale locale, String formKey) - Gets a
Form based on the name of the form and the
Locale that most closely matches the Locale
passed in.
|
Form | getForm(String language, String country, String variant, String formKey) - Gets a
Form based on the name of the form and the
Locale that most closely matches the Locale
passed in.
|
(package private) FormSet | getFormSet(String language, String country, String variant) - Gets a
FormSet based on the language, country
and variant.
|
protected Map | getFormSets() - Returns a Map of String locale keys to Lists of their FormSets.
|
private Log | getLog() - Accessor method for Log instance.
|
private FormSet | getParent(FormSet fs) - Finds the given formSet's parent.
|
ValidatorAction | getValidatorAction(String key) - Get a
ValidatorAction based on it's name.
|
Map | getValidatorActions() - Get an unmodifiable
Map of the ValidatorAction s.
|
private Digester | initDigester() - Initialize the digester.
|
void | process() - Process the
ValidatorResources object.
|
private void | processForms() - Process the
Form objects.
|
ARGS_PATTERN
private static final String ARGS_PATTERN
REGISTRATIONS
private static final String[] REGISTRATIONS
The set of public identifiers, and corresponding resource names, for
the versions of the configuration file DTDs that we know about. There
MUST be an even number of Strings in this list!
defaultFormSet
protected FormSet defaultFormSet
This is the default FormSet
(without locale). (We probably don't need
the defaultLocale anymore.)
defaultLocale
protected static Locale defaultLocale
The default locale on our server.
hActions
protected FastHashMap hActions
Subclasses should use getActions() instead.
Map
of ValidatorAction
s with
the name of the ValidatorAction
as the key.
hConstants
protected FastHashMap hConstants
Subclasses should use getConstants() instead.
Map
of global constant values with
the name of the constant as the key.
hFormSets
protected FastHashMap hFormSets
Subclasses should use getFormSets() instead.
Map
of FormSet
s stored under
a Locale
key.
ValidatorResources
public ValidatorResources()
Create an empty ValidatorResources object.
ValidatorResources
public ValidatorResources(InputStream in)
throws IOException,
SAXException
Create a ValidatorResources object from an InputStream.
in
- InputStream to a validation.xml configuration file. It's the client's
responsibility to close this stream.
ValidatorResources
public ValidatorResources(InputStream[] streams)
throws IOException,
SAXException
Create a ValidatorResources object from an InputStream.
streams
- An array of InputStreams to several validation.xml
configuration files that will be read in order and merged into this object.
It's the client's responsibility to close these streams.
ValidatorResources
public ValidatorResources(String uri)
throws IOException,
SAXException
Create a ValidatorResources object from an uri
uri
- The location of a validation.xml configuration file.
ValidatorResources
public ValidatorResources(String[] uris)
throws IOException,
SAXException
Create a ValidatorResources object from several uris
uris
- An array of uris to several validation.xml
configuration files that will be read in order and merged into this object.
addConstant
public void addConstant(String name,
String value)
Add a global constant to the resource.
name
- The constant name.value
- The constant value.
addFormSet
public void addFormSet(FormSet fs)
Add a FormSet
to this ValidatorResources
object. It will be associated with the Locale
of the
FormSet
.
fs
- The form set to add.
addOldArgRules
private void addOldArgRules(Digester digester)
Create a Rule
to handle arg0-arg3
elements. This will allow validation.xml files that use the
versions of the DTD prior to Validator 1.2.0 to continue
working.
addValidatorAction
public void addValidatorAction(ValidatorAction va)
Add a ValidatorAction
to the resource. It also creates an
instance of the class based on the ValidatorAction
s
classname and retrieves the Method
instance and sets them
in the ValidatorAction
.
va
- The validator action.
buildKey
protected String buildKey(FormSet fs)
Builds a key to store the FormSet
under based on it's
language, country, and variant values.
- generated key for a formset.
buildLocale
private String buildLocale(String lang,
String country,
String variant)
Assembles a Locale code from the given parts.
getActions
protected Map getActions()
Returns a Map of String ValidatorAction names to their ValidatorAction.
getConstants
protected Map getConstants()
Returns a Map of String constant names to their String values.
getForm
public Form getForm(Locale locale,
String formKey)
Gets a
Form
based on the name of the form and the
Locale
that most closely matches the
Locale
passed in. The order of
Locale
matching is:
- language + country + variant
- language + country
- language
- default locale
locale
- The Locale.formKey
- The key for the Form.
getForm
public Form getForm(String language,
String country,
String variant,
String formKey)
Gets a
Form
based on the name of the form and the
Locale
that most closely matches the
Locale
passed in. The order of
Locale
matching is:
- language + country + variant
- language + country
- language
- default locale
language
- The locale's language.country
- The locale's country.variant
- The locale's language variant.formKey
- The key for the Form.
getFormSet
(package private) FormSet getFormSet(String language,
String country,
String variant)
Gets a FormSet
based on the language, country
and variant.
language
- The locale's language.country
- The locale's country.variant
- The locale's language variant.
- The FormSet for a locale.
getFormSets
protected Map getFormSets()
Returns a Map of String locale keys to Lists of their FormSets.
getLog
private Log getLog()
Accessor method for Log instance.
The Log instance variable is transient and
accessing it through this method ensures it
is re-initialized when this instance is
de-serialized.
getParent
private FormSet getParent(FormSet fs)
Finds the given formSet's parent. ex: A formSet with locale en_UK_TEST1
has a direct parent in the formSet with locale en_UK. If it doesn't
exist, find the formSet with locale en, if no found get the
defaultFormSet.
fs
- the formSet we want to get the parent from
getValidatorAction
public ValidatorAction getValidatorAction(String key)
Get a ValidatorAction
based on it's name.
key
- The validator action key.
getValidatorActions
public Map getValidatorActions()
Get an unmodifiable Map
of the ValidatorAction
s.
- Map of validator actions.
initDigester
private Digester initDigester()
Initialize the digester.
process
public void process()
Process the ValidatorResources
object. Currently sets the
FastHashMap
s to the 'fast' mode and call the processes
all other resources. Note : The framework calls this
automatically when ValidatorResources is created from an XML file. If you
create an instance of this class by hand you must call
this method when finished.
processForms
private void processForms()
Process the Form
objects. This clones the Field
s
that don't exist in a FormSet
compared to its parent
FormSet
.
Copyright (c) 2001-2004 Apache Software Foundation