Class ValidatorResources
- java.lang.Object
-
- org.apache.commons.validator.ValidatorResources
-
- All Implemented Interfaces:
java.io.Serializable
public class ValidatorResources extends java.lang.Object implements java.io.SerializableGeneral purpose class for storing
FormSetobjects based on their associatedLocale. 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringARGS_PATTERNprotected FormSetdefaultFormSetThis is the defaultFormSet(without locale).protected static java.util.LocaledefaultLocaleThe default locale on our server.protected org.apache.commons.collections.FastHashMaphActionsDeprecated.Subclasses should use getActions() instead.protected org.apache.commons.collections.FastHashMaphConstantsDeprecated.Subclasses should use getConstants() instead.protected org.apache.commons.collections.FastHashMaphFormSetsDeprecated.Subclasses should use getFormSets() instead.private org.apache.commons.logging.Loglogprivate static java.lang.String[]REGISTRATIONSThe set of public identifiers, and corresponding resource names, for the versions of the configuration file DTDs that we know about.private static longserialVersionUIDprivate static java.lang.StringVALIDATOR_RULESName of the digester validator rules file
-
Constructor Summary
Constructors Constructor Description ValidatorResources()Create an empty ValidatorResources object.ValidatorResources(java.io.InputStream in)Create a ValidatorResources object from an InputStream.ValidatorResources(java.io.InputStream[] streams)Create a ValidatorResources object from an InputStream.ValidatorResources(java.lang.String uri)Create a ValidatorResources object from an uriValidatorResources(java.lang.String[] uris)Create a ValidatorResources object from several urisValidatorResources(java.net.URL url)Create a ValidatorResources object from a URL.ValidatorResources(java.net.URL[] urls)Create a ValidatorResources object from several URL.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConstant(java.lang.String name, java.lang.String value)Add a global constant to the resource.voidaddFormSet(FormSet fs)Add aFormSetto thisValidatorResourcesobject.private voidaddOldArgRules(org.apache.commons.digester.Digester digester)Create aRuleto handlearg0-arg3elements.voidaddValidatorAction(ValidatorAction va)Add aValidatorActionto the resource.protected java.lang.StringbuildKey(FormSet fs)Builds a key to store theFormSetunder based on it's language, country, and variant values.private java.lang.StringbuildLocale(java.lang.String lang, java.lang.String country, java.lang.String variant)Assembles a Locale code from the given parts.protected java.util.Map<java.lang.String,ValidatorAction>getActions()Returns a Map of String ValidatorAction names to their ValidatorAction.protected java.util.Map<java.lang.String,java.lang.String>getConstants()Returns a Map of String constant names to their String values.FormgetForm(java.lang.String language, java.lang.String country, java.lang.String variant, java.lang.String formKey)Gets aFormbased on the name of the form and theLocalethat most closely matches theLocalepassed in.FormgetForm(java.util.Locale locale, java.lang.String formKey)Gets aFormbased on the name of the form and theLocalethat most closely matches theLocalepassed in.(package private) FormSetgetFormSet(java.lang.String language, java.lang.String country, java.lang.String variant)Gets aFormSetbased on the language, country and variant.protected java.util.Map<java.lang.String,FormSet>getFormSets()Returns a Map of String locale keys to Lists of their FormSets.private org.apache.commons.logging.LoggetLog()Accessor method for Log instance.private FormSetgetParent(FormSet fs)Finds the given formSet's parent.ValidatorActiongetValidatorAction(java.lang.String key)Get aValidatorActionbased on it's name.java.util.Map<java.lang.String,ValidatorAction>getValidatorActions()Get an unmodifiableMapof theValidatorActions.private org.apache.commons.digester.DigesterinitDigester()Initialize the digester.voidprocess()Process theValidatorResourcesobject.private voidprocessForms()Process theFormobjects.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
VALIDATOR_RULES
private static final java.lang.String VALIDATOR_RULES
Name of the digester validator rules file- See Also:
- Constant Field Values
-
REGISTRATIONS
private static final java.lang.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!
-
log
private transient org.apache.commons.logging.Log log
-
hFormSets
protected org.apache.commons.collections.FastHashMap hFormSets
Deprecated.Subclasses should use getFormSets() instead.MapofFormSets stored under aLocalekey (expressed as a String).
-
hConstants
protected org.apache.commons.collections.FastHashMap hConstants
Deprecated.Subclasses should use getConstants() instead.Mapof global constant values with the name of the constant as the key.
-
hActions
protected org.apache.commons.collections.FastHashMap hActions
Deprecated.Subclasses should use getActions() instead.MapofValidatorActions with the name of theValidatorActionas the key.
-
defaultLocale
protected static java.util.Locale defaultLocale
The default locale on our server.
-
defaultFormSet
protected FormSet defaultFormSet
This is the defaultFormSet(without locale). (We probably don't need the defaultLocale anymore.)
-
ARGS_PATTERN
private static final java.lang.String ARGS_PATTERN
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ValidatorResources
public ValidatorResources()
Create an empty ValidatorResources object.
-
ValidatorResources
public ValidatorResources(java.io.InputStream in) throws java.io.IOException, org.xml.sax.SAXExceptionCreate 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:
org.xml.sax.SAXException- if the validation XML files are not valid or well formed.java.io.IOException- if an I/O error occurs processing the XML files- Since:
- Validator 1.1
-
ValidatorResources
public ValidatorResources(java.io.InputStream[] streams) throws java.io.IOException, org.xml.sax.SAXExceptionCreate 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:
org.xml.sax.SAXException- if the validation XML files are not valid or well formed.java.io.IOException- if an I/O error occurs processing the XML files- Since:
- Validator 1.1
-
ValidatorResources
public ValidatorResources(java.lang.String uri) throws java.io.IOException, org.xml.sax.SAXExceptionCreate a ValidatorResources object from an uri- Parameters:
uri- The location of a validation.xml configuration file.- Throws:
org.xml.sax.SAXException- if the validation XML files are not valid or well formed.java.io.IOException- if an I/O error occurs processing the XML files- Since:
- Validator 1.2
-
ValidatorResources
public ValidatorResources(java.lang.String[] uris) throws java.io.IOException, org.xml.sax.SAXExceptionCreate 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:
org.xml.sax.SAXException- if the validation XML files are not valid or well formed.java.io.IOException- if an I/O error occurs processing the XML files- Since:
- Validator 1.2
-
ValidatorResources
public ValidatorResources(java.net.URL url) throws java.io.IOException, org.xml.sax.SAXExceptionCreate a ValidatorResources object from a URL.- Parameters:
url- The URL for the validation.xml configuration file that will be read into this object.- Throws:
org.xml.sax.SAXException- if the validation XML file are not valid or well formed.java.io.IOException- if an I/O error occurs processing the XML files- Since:
- Validator 1.3.1
-
ValidatorResources
public ValidatorResources(java.net.URL[] urls) throws java.io.IOException, org.xml.sax.SAXExceptionCreate 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:
org.xml.sax.SAXException- if the validation XML files are not valid or well formed.java.io.IOException- if an I/O error occurs processing the XML files- Since:
- Validator 1.3.1
-
-
Method Detail
-
initDigester
private org.apache.commons.digester.Digester initDigester()
Initialize the digester.
-
addOldArgRules
private void addOldArgRules(org.apache.commons.digester.Digester digester)
Create aRuleto handlearg0-arg3elements. This will allow validation.xml files that use the versions of the DTD prior to Validator 1.2.0 to continue working.
-
addFormSet
public void addFormSet(FormSet fs)
Add aFormSetto thisValidatorResourcesobject. It will be associated with theLocaleof theFormSet.- Parameters:
fs- The form set to add.- Since:
- Validator 1.1
-
addConstant
public void addConstant(java.lang.String name, java.lang.String value)Add a global constant to the resource.- Parameters:
name- The constant name.value- The constant value.
-
addValidatorAction
public void addValidatorAction(ValidatorAction va)
Add aValidatorActionto the resource. It also creates an instance of the class based on theValidatorActions classname and retrieves theMethodinstance and sets them in theValidatorAction.- Parameters:
va- The validator action.
-
getValidatorAction
public ValidatorAction getValidatorAction(java.lang.String key)
Get aValidatorActionbased on it's name.- Parameters:
key- The validator action key.- Returns:
- The validator action.
-
getValidatorActions
public java.util.Map<java.lang.String,ValidatorAction> getValidatorActions()
Get an unmodifiableMapof theValidatorActions.- Returns:
- Map of validator actions.
-
buildKey
protected java.lang.String buildKey(FormSet fs)
Builds a key to store theFormSetunder based on it's language, country, and variant values.- Parameters:
fs- The Form Set.- Returns:
- generated key for a formset.
-
buildLocale
private java.lang.String buildLocale(java.lang.String lang, java.lang.String country, java.lang.String variant)Assembles a Locale code from the given parts.
-
getForm
public Form getForm(java.util.Locale locale, java.lang.String formKey)
Gets a
Formbased on the name of the form and theLocalethat most closely matches theLocalepassed in. The order ofLocalematching 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
public Form getForm(java.lang.String language, java.lang.String country, java.lang.String variant, java.lang.String formKey)
Gets a
Formbased on the name of the form and theLocalethat most closely matches theLocalepassed in. The order ofLocalematching 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 theValidatorResourcesobject. Currently sets theFastHashMaps 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
Formobjects. This clones theFields that don't exist in aFormSetcompared to its parentFormSet.
-
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.- Parameters:
fs- the formSet we want to get the parent from- Returns:
- fs's parent
-
getFormSet
FormSet getFormSet(java.lang.String language, java.lang.String country, java.lang.String variant)
Gets a
FormSetbased 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
protected java.util.Map<java.lang.String,FormSet> getFormSets()
Returns a Map of String locale keys to Lists of their FormSets.- Returns:
- Map of Form sets
- Since:
- Validator 1.2.0
-
getConstants
protected java.util.Map<java.lang.String,java.lang.String> getConstants()
Returns a Map of String constant names to their String values.- Returns:
- Map of Constants
- Since:
- Validator 1.2.0
-
getActions
protected java.util.Map<java.lang.String,ValidatorAction> 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.
-
-