Class ValidatorResources
- All Implemented Interfaces:
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.
- Version:
- $Revision: 1713452 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
protected FormSet
This is the defaultFormSet
(without locale).protected static Locale
The default locale on our server.protected org.apache.commons.collections.FastHashMap
Deprecated.Subclasses should use getActions() instead.protected org.apache.commons.collections.FastHashMap
Deprecated.Subclasses should use getConstants() instead.protected org.apache.commons.collections.FastHashMap
Deprecated.Subclasses should use getFormSets() instead.private org.apache.commons.logging.Log
private static final String[]
The set of public identifiers, and corresponding resource names, for the versions of the configuration file DTDs that we know about.private static final long
private static final String
Name of the digester validator rules file -
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty ValidatorResources object.Create a ValidatorResources object from an InputStream.ValidatorResources
(InputStream[] streams) Create a ValidatorResources object from an InputStream.ValidatorResources
(String uri) Create a ValidatorResources object from an uriValidatorResources
(String[] uris) Create a ValidatorResources object from several urisValidatorResources
(URL url) Create a ValidatorResources object from a URL.ValidatorResources
(URL[] urls) Create a ValidatorResources object from several URL. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConstant
(String name, String value) Add a global constant to the resource.void
addFormSet
(FormSet fs) Add aFormSet
to thisValidatorResources
object.private void
addOldArgRules
(org.apache.commons.digester.Digester digester) Create aRule
to handlearg0-arg3
elements.void
Add aValidatorAction
to the resource.protected String
Builds a key to store theFormSet
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
<String, ValidatorAction> Returns a Map of String ValidatorAction names to their ValidatorAction.Returns a Map of String constant names to their String values.Gets aForm
based on the name of the form and theLocale
that most closely matches theLocale
passed in.Gets aForm
based on the name of the form and theLocale
that most closely matches theLocale
passed in.(package private) FormSet
getFormSet
(String language, String country, String variant) Gets aFormSet
based on the language, country and variant.Returns a Map of String locale keys to Lists of their FormSets.private org.apache.commons.logging.Log
getLog()
Accessor method for Log instance.private FormSet
Finds the given formSet's parent.getValidatorAction
(String key) Get aValidatorAction
based on it's name.Get an unmodifiableMap
of theValidatorAction
s.private org.apache.commons.digester.Digester
Initialize the digester.void
process()
Process theValidatorResources
object.private void
Process theForm
objects.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
VALIDATOR_RULES
Name of the digester validator rules file- See Also:
-
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! -
log
private transient org.apache.commons.logging.Log log -
hFormSets
protected org.apache.commons.collections.FastHashMap hFormSetsDeprecated.Subclasses should use getFormSets() instead.Map
ofFormSet
s stored under aLocale
key (expressed as a String). -
hConstants
protected org.apache.commons.collections.FastHashMap hConstantsDeprecated.Subclasses should use getConstants() instead.Map
of global constant values with the name of the constant as the key. -
hActions
protected org.apache.commons.collections.FastHashMap hActionsDeprecated.Subclasses should use getActions() instead.Map
ofValidatorAction
s with the name of theValidatorAction
as the key. -
defaultLocale
The default locale on our server. -
defaultFormSet
This is the defaultFormSet
(without locale). (We probably don't need the defaultLocale anymore.) -
ARGS_PATTERN
- See Also:
-
-
Constructor Details
-
ValidatorResources
public ValidatorResources()Create an empty ValidatorResources object. -
ValidatorResources
Create a ValidatorResources object from an InputStream.- Parameters:
in
- InputStream to a validation.xml configuration file. It's the client's responsibility to close this stream.- Throws:
SAXException
- if the validation XML files are not valid or well formed.IOException
- if an I/O error occurs processing the XML files- Since:
- Validator 1.1
-
ValidatorResources
Create a ValidatorResources object from an InputStream.- Parameters:
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.- Throws:
SAXException
- if the validation XML files are not valid or well formed.IOException
- if an I/O error occurs processing the XML files- Since:
- Validator 1.1
-
ValidatorResources
Create a ValidatorResources object from an uri- Parameters:
uri
- The location of a validation.xml configuration file.- Throws:
SAXException
- if the validation XML files are not valid or well formed.IOException
- if an I/O error occurs processing the XML files- Since:
- Validator 1.2
-
ValidatorResources
Create a ValidatorResources object from several uris- Parameters:
uris
- An array of uris to several validation.xml configuration files that will be read in order and merged into this object.- Throws:
SAXException
- if the validation XML files are not valid or well formed.IOException
- if an I/O error occurs processing the XML files- Since:
- Validator 1.2
-
ValidatorResources
Create a ValidatorResources object from a URL.- Parameters:
url
- The URL for the validation.xml configuration file that will be read into this object.- Throws:
SAXException
- if the validation XML file are not valid or well formed.IOException
- if an I/O error occurs processing the XML files- Since:
- Validator 1.3.1
-
ValidatorResources
Create a ValidatorResources object from several URL.- Parameters:
urls
- An array of URL to several validation.xml configuration files that will be read in order and merged into this object.- Throws:
SAXException
- if the validation XML files are not valid or well formed.IOException
- if an I/O error occurs processing the XML files- Since:
- Validator 1.3.1
-
-
Method Details
-
initDigester
private org.apache.commons.digester.Digester initDigester()Initialize the digester. -
addOldArgRules
private void addOldArgRules(org.apache.commons.digester.Digester digester) Create aRule
to handlearg0-arg3
elements. This will allow validation.xml files that use the versions of the DTD prior to Validator 1.2.0 to continue working. -
addFormSet
Add aFormSet
to thisValidatorResources
object. It will be associated with theLocale
of theFormSet
.- Parameters:
fs
- The form set to add.- Since:
- Validator 1.1
-
addConstant
Add a global constant to the resource.- Parameters:
name
- The constant name.value
- The constant value.
-
addValidatorAction
Add aValidatorAction
to the resource. It also creates an instance of the class based on theValidatorAction
s classname and retrieves theMethod
instance and sets them in theValidatorAction
.- Parameters:
va
- The validator action.
-
getValidatorAction
Get aValidatorAction
based on it's name.- Parameters:
key
- The validator action key.- Returns:
- The validator action.
-
getValidatorActions
Get an unmodifiableMap
of theValidatorAction
s.- Returns:
- Map of validator actions.
-
buildKey
Builds a key to store theFormSet
under based on it's language, country, and variant values.- Parameters:
fs
- The Form Set.- Returns:
- generated key for a formset.
-
buildLocale
Assembles a Locale code from the given parts. -
getForm
Gets a
Form
based on the name of the form and theLocale
that most closely matches theLocale
passed in. The order ofLocale
matching is:- language + country + variant
- language + country
- language
- default locale
- Parameters:
locale
- The Locale.formKey
- The key for the Form.- Returns:
- The validator Form.
- Since:
- Validator 1.1
-
getForm
Gets a
Form
based on the name of the form and theLocale
that most closely matches theLocale
passed in. The order ofLocale
matching is:- language + country + variant
- language + country
- language
- default locale
- Parameters:
language
- The locale's language.country
- The locale's country.variant
- The locale's language variant.formKey
- The key for the Form.- Returns:
- The validator Form.
- Since:
- Validator 1.1
-
process
public void process()Process theValidatorResources
object. Currently sets theFastHashMap
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 theField
s that don't exist in aFormSet
compared to its parentFormSet
. -
getParent
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.- Parameters:
fs
- the formSet we want to get the parent from- Returns:
- fs's parent
-
getFormSet
Gets a
FormSet
based on the language, country and variant.- Parameters:
language
- The locale's language.country
- The locale's country.variant
- The locale's language variant.- Returns:
- The FormSet for a locale.
- Since:
- Validator 1.2
-
getFormSets
Returns a Map of String locale keys to Lists of their FormSets.- Returns:
- Map of Form sets
- Since:
- Validator 1.2.0
-
getConstants
Returns a Map of String constant names to their String values.- Returns:
- Map of Constants
- Since:
- Validator 1.2.0
-
getActions
Returns a Map of String ValidatorAction names to their ValidatorAction.- Returns:
- Map of Validator Actions
- Since:
- Validator 1.2.0
-
getLog
private org.apache.commons.logging.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.- Returns:
- The Log instance.
-