org.apache.commons.validator

Class ValidatorResources

Implemented Interfaces:
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.

Nested Class Summary

Field Summary

protected static Locale
defaultLocale
The default locale on our server.
protected FastHashMap
hActions
FastHashMap of ValidatorActions with the name of the ValidatorAction as the key.
protected FastHashMap
hConstants
FastHashMap of global constant values with the name of the constant as the key.
protected FastHashMap
hFormSets
FastHashMap of FormSets stored under a Locale key.
protected static Log
log
Deprecated. Subclasses should use their own logging instance.
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.

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

void
addConstant(String name, String value)
Add a global constant to the resource.
void
addConstant(Constant c)
Deprecated. Use addConstant(String, String) instead.
void
addConstantParam(String name, String value)
Deprecated. Use addConstant(String, String) instead.
void
addFormSet(FormSet fs)
Add a FormSet to this ValidatorResources object.
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.
Form
get(Locale locale, Object formKey)
Deprecated. Use getForm() instead.
Form
get(String language, String country, String variant, Object formKey)
Deprecated. Use getForm() instead.
protected Field
getClosestLocaleField(FormSet fs, String formKey, String fieldKey)
Retrieves the closest matching Field based on FormSet's locale.
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.
ValidatorAction
getValidatorAction(String key)
Get a ValidatorAction based on it's name.
Map
getValidatorActions()
Get an unmodifiable Map of the ValidatorActions.
private void
internalProcessForms()
Process the Form objects.
void
process()
Process the ValidatorResources object.
void
processForms()
Deprecated. This is an internal method that client classes need not call directly.
void
put(FormSet fs)
Deprecated. Use addFormSet() instead.

Field Details

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 Details

ValidatorResources

public ValidatorResources()
Create an empty ValidatorResources object.


ValidatorResources

public ValidatorResources(InputStream in)
            throws IOException,
                   SAXException
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.

Since:
Validator 1.1


ValidatorResources

public ValidatorResources(InputStream[] streams)
            throws IOException,
                   SAXException
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.

Since:
Validator 1.1

Method Details

addConstant

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


addConstant

public void addConstant(Constant c)

Deprecated. Use addConstant(String, String) instead.

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