| Constructor: |
public ValidatorResources() {
super();
}
Create an empty ValidatorResources object. |
public ValidatorResources(InputStream in) throws IOException, SAXException {
this(new 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.
IOException - if an I/O error occurs processing the XML files
- since:
Validator - 1.1
|
public ValidatorResources(InputStream[] streams) throws IOException, SAXException {
super();
Digester digester = initDigester();
for (int i = 0; i < streams.length; i++) {
digester.push(this);
digester.parse(streams[i]);
}
this.process();
}
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.
IOException - if an I/O error occurs processing the XML files
- since:
Validator - 1.1
|
public ValidatorResources(String uri) throws IOException, SAXException {
this(new String[]{uri});
}
Create a ValidatorResources object from an uri Parameters:
uri - The location of a validation.xml configuration file.
Throws:
IOException -
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
|
public ValidatorResources(String[] uris) throws IOException, SAXException {
super();
Digester digester = initDigester();
for (int i = 0; i < uris.length; i++) {
digester.push(this);
digester.parse(uris[i]);
}
this.process();
}
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:
IOException -
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
|
public ValidatorResources(URL url) throws IOException, SAXException {
this(new URL[]{url});
}
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:
IOException -
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
|
public ValidatorResources(URL[] urls) throws IOException, SAXException {
super();
Digester digester = initDigester();
for (int i = 0; i < urls.length; i++) {
digester.push(this);
InputStream stream = null;
try {
stream = urls[i].openStream();
org.xml.sax.InputSource source =
new org.xml.sax.InputSource(urls[i].toExternalForm());
source.setByteStream(stream);
digester.parse(source);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
// ignore problem closing
}
}
}
}
this.process();
}
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:
IOException -
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 from org.apache.commons.validator.ValidatorResources Detail: |
public void addConstant(String name,
String value) {
if (getLog().isDebugEnabled()) {
getLog().debug("Adding Global Constant: " + name + "," + value);
}
this.hConstants.put(name, value);
}
Add a global constant to the resource. |
public void addFormSet(FormSet fs) {
String key = this.buildKey(fs);
if (key.length() == 0) {// there can only be one default formset
if (getLog().isWarnEnabled() && defaultFormSet != null) {
// warn the user he might not get the expected results
getLog().warn("Overriding default FormSet definition.");
}
defaultFormSet = fs;
} else {
FormSet formset = (FormSet) hFormSets.get(key);
if (formset == null) {// it hasn't been included yet
if (getLog().isDebugEnabled()) {
getLog().debug("Adding FormSet '" + fs.toString() + "'.");
}
} else if (getLog().isWarnEnabled()) {// warn the user he might not
// get the expected results
getLog()
.warn("Overriding FormSet definition. Duplicate for locale: "
+ key);
}
hFormSets.put(key, fs);
}
}
Add a FormSet to this ValidatorResources
object. It will be associated with the Locale of the
FormSet. |
public void addValidatorAction(ValidatorAction va) {
va.init();
this.hActions.put(va.getName(), va);
if (getLog().isDebugEnabled()) {
getLog().debug("Add ValidatorAction: " + va.getName() + "," + va.getClassname());
}
}
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. |
protected String buildKey(FormSet fs) {
return
this.buildLocale(fs.getLanguage(), fs.getCountry(), fs.getVariant());
}
Builds a key to store the FormSet under based on it's
language, country, and variant values. |
protected Map getActions() {
return hActions;
}
Returns a Map of String ValidatorAction names to their ValidatorAction. |
protected Map getConstants() {
return hConstants;
}
Returns a Map of String constant names to their String values. |
public Form getForm(Locale locale,
String formKey) {
return this.getForm(locale.getLanguage(), locale.getCountry(), locale
.getVariant(), 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:
- language + country + variant
- language + country
- language
- default locale
|
public Form getForm(String language,
String country,
String variant,
String formKey) {
Form form = null;
// Try language/country/variant
String key = this.buildLocale(language, country, variant);
if (key.length() > 0) {
FormSet formSet = (FormSet)hFormSets.get(key);
if (formSet != null) {
form = formSet.getForm(formKey);
}
}
String localeKey = key;
// Try language/country
if (form == null) {
key = buildLocale(language, country, null);
if (key.length() > 0) {
FormSet formSet = (FormSet)hFormSets.get(key);
if (formSet != null) {
form = formSet.getForm(formKey);
}
}
}
// Try language
if (form == null) {
key = buildLocale(language, null, null);
if (key.length() > 0) {
FormSet formSet = (FormSet)hFormSets.get(key);
if (formSet != null) {
form = formSet.getForm(formKey);
}
}
}
// Try default formset
if (form == null) {
form = defaultFormSet.getForm(formKey);
key = "default";
}
if (form == null) {
if (getLog().isWarnEnabled()) {
getLog().warn("Form '" + formKey + "' not found for locale '" +
localeKey + "'");
}
} else {
if (getLog().isDebugEnabled()) {
getLog().debug("Form '" + formKey + "' found in formset '" +
key + "' for locale '" + localeKey + "'");
}
}
return form;
}
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:
- language + country + variant
- language + country
- language
- default locale
|
FormSet getFormSet(String language,
String country,
String variant) {
String key = buildLocale(language, country, variant);
if (key.length() == 0) {
return defaultFormSet;
}
return (FormSet)hFormSets.get(key);
}
Gets a FormSet based on the language, country
and variant.
|
protected Map getFormSets() {
return hFormSets;
}
Returns a Map of String locale keys to Lists of their FormSets. |
public ValidatorAction getValidatorAction(String key) {
return (ValidatorAction) hActions.get(key);
}
Get a ValidatorAction based on it's name. |
public Map getValidatorActions() {
return Collections.unmodifiableMap(hActions);
}
Get an unmodifiable Map of the ValidatorActions. |
public void process() {
hFormSets.setFast(true);
hConstants.setFast(true);
hActions.setFast(true);
this.processForms();
}
Process the ValidatorResources object. Currently sets the
FastHashMap 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. |