org.apache.commons.validator
Class ValidatorResources

java.lang.Object
  extended byorg.apache.commons.validator.ValidatorResources
All Implemented Interfaces:
java.io.Serializable

public class ValidatorResources
extends java.lang.Object
implements java.io.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.

See Also:
Serialized Form

Field Summary
protected static java.util.Locale defaultLocale
          The default locale on our server.
protected  org.apache.commons.collections.FastHashMap hActions
          FastHashMap of ValidatorActions with the name of the ValidatorAction as the key.
protected  org.apache.commons.collections.FastHashMap hConstants
          FastHashMap of global constant values with the name of the constant as the key.
protected  org.apache.commons.collections.FastHashMap hFormSets
          FastHashMap of FormSets stored under a Locale key.
protected static org.apache.commons.logging.Log log
          Deprecated. Subclasses should use their own logging instance.
private static 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.
 
Constructor Summary
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.
 
Method Summary
 void addConstant(Constant c)
          Deprecated. Use addConstant(String, String) instead.
 void addConstant(java.lang.String name, java.lang.String value)
          Add a global constant to the resource.
 void addConstantParam(java.lang.String name, java.lang.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  java.lang.String buildKey(FormSet fs)
          Builds a key to store the FormSet under based on it's language, country, and variant values.
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.
 Form get(java.util.Locale locale, java.lang.Object formKey)
          Deprecated. Use getForm() instead.
 Form get(java.lang.String language, java.lang.String country, java.lang.String variant, java.lang.Object formKey)
          Deprecated. Use getForm() instead.
protected  Field getClosestLocaleField(FormSet fs, java.lang.String formKey, java.lang.String fieldKey)
          Retrieves the closest matching Field based on FormSet's locale.
 Form getForm(java.util.Locale locale, java.lang.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(java.lang.String language, java.lang.String country, java.lang.String variant, java.lang.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(java.lang.String key)
          Get a ValidatorAction based on it's name.
 java.util.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

protected static org.apache.commons.logging.Log log
Deprecated. Subclasses should use their own logging instance.

Logger.


hFormSets

protected org.apache.commons.collections.FastHashMap hFormSets
FastHashMap of FormSets stored under a Locale key.


hConstants

protected org.apache.commons.collections.FastHashMap hConstants
FastHashMap of global constant values with the name of the constant as the key.


hActions

protected org.apache.commons.collections.FastHashMap hActions
FastHashMap of ValidatorActions with the name of the ValidatorAction as the key.


defaultLocale

protected static java.util.Locale defaultLocale
The default locale on our server.

Constructor Detail

ValidatorResources

public ValidatorResources()
Create an empty ValidatorResources object.


ValidatorResources

public ValidatorResources(java.io.InputStream in)
                   throws java.io.IOException,
                          org.xml.sax.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.
Throws:
java.io.IOException
org.xml.sax.SAXException - if the validation XML files are not valid or well formed.
Since:
Validator 1.1

ValidatorResources

public ValidatorResources(java.io.InputStream[] streams)
                   throws java.io.IOException,
                          org.xml.sax.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.
Throws:
java.io.IOException
org.xml.sax.SAXException - if the validation XML files are not valid or well formed.
Since:
Validator 1.1
Method Detail

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.


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

addConstant

public void addConstant(Constant c)
Deprecated. Use addConstant(String, String) instead.

Add a global constant to the resource.


addConstantParam

public void addConstantParam(java.lang.String name,
                             java.lang.String value)
Deprecated. Use addConstant(String, String) instead.

Add a global constant to the resource.


addConstant

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


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.


getValidatorAction

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


getValidatorActions

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


buildKey

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


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.


get

public Form get(java.util.Locale locale,
                java.lang.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


getForm

public Form getForm(java.util.Locale locale,
                    java.lang.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

get

public Form get(java.lang.String language,
                java.lang.String country,
                java.lang.String variant,
                java.lang.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


getForm

public Form getForm(java.lang.String language,
                    java.lang.String country,
                    java.lang.String variant,
                    java.lang.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

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.


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".


getClosestLocaleField

protected Field getClosestLocaleField(FormSet fs,
                                      java.lang.String formKey,
                                      java.lang.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.



Copyright (c) 2001-2004 Apache Software Foundation