org.apache.commons.validator

Class ValidatorResources

public class ValidatorResources extends 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.

Field Summary
protected static LocaledefaultLocale
The default locale on our server.
protected FastHashMaphActions
FastHashMap of ValidatorActions with the name of the ValidatorAction as the key.
protected FastHashMaphConstants
FastHashMap of global constant values with the name of the constant as the key.
protected FastHashMaphFormSets
FastHashMap of FormSets stored under a Locale key.
protected static Loglog
Logger.
static String[]registrations
The set of public identifiers, and corresponding resource names, for the versions of the configuration file DTDs that we know about.
Constructor Summary
ValidatorResources()
Create an empty ValidatorResources object.
ValidatorResources(InputStream in)
Create a ValidatorResources object from an InputStream.
ValidatorResources(InputStream[] streams)
Create a ValidatorResources object from an InputStream.
Method Summary
voidaddConstant(Constant c)
Add a global constant to the resource.
voidaddConstant(String name, String value)
Add a global constant to the resource.
voidaddConstantParam(String name, String value)
Add a global constant to the resource.
voidaddFormSet(FormSet fs)
Add a FormSet to this ValidatorResources object.
voidaddValidatorAction(ValidatorAction va)
Add a ValidatorAction to the resource.
protected StringbuildKey(FormSet fs)
Builds a key to store the FormSet under based on it's language, country, and variant values.
StringbuildLocale(String lang, String country, String variant)
Assembles a Locale code from the given parts.
Formget(Locale locale, Object formKey)

Gets a Form based on the name of the form and the Locale that most closely matches the Locale passed in.

Formget(String language, String country, String variant, Object formKey)

Gets a Form based on the name of the form and the Locale that most closely matches the Locale passed in.

protected FieldgetClosestLocaleField(FormSet fs, String formKey, String fieldKey)
Retrieves the closest matching Field based on FormSet's locale.
FormgetForm(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.

FormgetForm(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.

ValidatorActiongetValidatorAction(String key)
Get a ValidatorAction based on it's name.
MapgetValidatorActions()
Get an unmodifiable Map of the ValidatorActions.
voidinternalProcessForms()

Process the Form objects.

voidprocess()
Process the ValidatorResources object.
voidprocessForms()

Process the Form objects.

voidput(FormSet fs)
Add a FormSet to this ValidatorResources object.

Field Detail

defaultLocale

protected static Locale defaultLocale
The default locale on our server.

hActions

protected FastHashMap hActions
FastHashMap of ValidatorActions with the name of the ValidatorAction as the key.

hConstants

protected FastHashMap hConstants
FastHashMap of global constant values with the name of the constant as the key.

hFormSets

protected FastHashMap hFormSets
FastHashMap of FormSets stored under a Locale key.

log

protected static Log log

Deprecated: Subclasses should use their own logging instance.

Logger.

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!

Constructor Detail

ValidatorResources

public ValidatorResources()
Create an empty ValidatorResources object.

ValidatorResources

public ValidatorResources(InputStream in)
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: IOException SAXException if the validation XML files are not valid or well formed.

Since: Validator 1.1

ValidatorResources

public ValidatorResources(InputStream[] streams)
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: IOException SAXException if the validation XML files are not valid or well formed.

Since: Validator 1.1

Method Detail

addConstant

public void addConstant(Constant c)

Deprecated: Use addConstant(String, String) instead.

Add a global constant to the resource.

addConstant

public void addConstant(String name, String value)
Add a global constant to the resource.

addConstantParam

public void addConstantParam(String name, String value)

Deprecated: Use addConstant(String, String) instead.

Add a global constant to the resource.

addFormSet

public void addFormSet(FormSet fs)
Add a FormSet to this ValidatorResources object. It will be associated with the Locale of the FormSet.

Since: Validator 1.1

addValidatorAction

public void addValidatorAction(ValidatorAction va)
Add a ValidatorAction to the resource. It also creates an instance of the class based on the ValidatorActions classname and retrieves the Method instance and sets them in the ValidatorAction.

buildKey

protected String buildKey(FormSet fs)
Builds a key to store the FormSet under based on it's language, country, and variant values.

buildLocale

private String buildLocale(String lang, String country, String variant)
Assembles a Locale code from the given parts.

get

public Form get(Locale locale, Object formKey)

Deprecated: Use getForm() instead.

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:

  1. language + country + variant
  2. language + country
  3. language
  4. default locale

get

public Form get(String language, String country, String variant, Object formKey)

Deprecated: Use getForm() instead.

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:

  1. language + country + variant
  2. language + country
  3. language
  4. default locale

getClosestLocaleField

protected Field getClosestLocaleField(FormSet fs, String formKey, String fieldKey)
Retrieves the closest matching Field based on FormSet's locale. This is used when constructing a clone, field by field, of partial FormSet.

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:

  1. language + country + variant
  2. language + country
  3. language
  4. default locale

Since: Validator 1.1

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:

  1. language + country + variant
  2. language + country
  3. language
  4. default locale

Since: Validator 1.1

getValidatorAction

public ValidatorAction getValidatorAction(String key)
Get a ValidatorAction based on it's name.

getValidatorActions

public Map getValidatorActions()
Get an unmodifiable Map of the ValidatorActions.

internalProcessForms

private void internalProcessForms()

Process the Form objects. This clones the Fields that don't exist in a FormSet compared to the default FormSet.

TODO When processForms() is removed from the public interface, rename this private method back to "processForms".

process

public void process()
Process the ValidatorResources object. Currently sets the FastHashMaps 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

public void processForms()

Deprecated: This is an internal method that client classes need not call directly.

Process the Form objects. This clones the Fields that don't exist in a FormSet compared to the default FormSet.

put

public void put(FormSet fs)

Deprecated: Use addFormSet() instead.

Add a FormSet to this ValidatorResources object. It will be associated with the Locale of the FormSet.
Copyright (c) 2001-2004 Apache Software Foundation