cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java
rleland 2004/04/12 22:50:11 Modified:validator/src/share/org/apache/commons/validator Tag: VALIDATOR_1_1_2_BRANCH ValidatorResources.java Log: register 1.1.3 DTD Revision ChangesPath No revision No revision 1.30.2.1 +6 -4 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.30 retrieving revision 1.30.2.1 diff -u -r1.30 -r1.30.2.1 --- ValidatorResources.java 21 Feb 2004 17:10:29 - 1.30 +++ ValidatorResources.java 13 Apr 2004 05:50:11 - 1.30.2.1 @@ -64,7 +64,9 @@ -//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0.1//EN, /org/apache/commons/validator/resources/validator_1_0_1.dtd, -//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN, -/org/apache/commons/validator/resources/validator_1_1.dtd +/org/apache/commons/validator/resources/validator_1_1.dtd, +-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN, +/org/apache/commons/validator/resources/validator_1_1_3.dtd }; /** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java
dgraham 2003/06/04 18:17:43 Modified:validator/src/share/org/apache/commons/validator ValidatorResources.java Log: Fixed NPE in deprecated get() methods for PR# 20432. Revision ChangesPath 1.23 +9 -7 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- ValidatorResources.java 29 May 2003 03:34:35 - 1.22 +++ ValidatorResources.java 5 Jun 2003 01:17:43 - 1.23 @@ -330,7 +330,8 @@ * @deprecated Use getForm() instead. */ public Form get(Locale locale, Object formKey) { -return this.getForm(locale, formKey.toString()); +String key = (formKey == null) ? null : formKey.toString(); +return this.getForm(locale, key); } /** @@ -369,8 +370,9 @@ String country, String variant, Object formKey) { - -return this.getForm(language, country, variant, formKey.toString()); + + String key = (formKey == null) ? null : formKey.toString(); + return this.getForm(language, country, variant, key); } /** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java
dgraham 2003/05/28 20:03:02 Modified:validator/src/share/org/apache/commons/validator ValidatorResources.java Log: Changed getForm(Locale, Object) to getForm(Locale, String). Revision ChangesPath 1.21 +16 -15 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- ValidatorResources.java 28 May 2003 04:14:32 - 1.20 +++ ValidatorResources.java 29 May 2003 03:03:02 - 1.21 @@ -330,13 +330,13 @@ * @deprecated Use getForm() instead. */ public Form get(Locale locale, Object formKey) { -return this.getForm(locale, formKey); +return this.getForm(locale, formKey.toString()); } /** - * pGets a codeForm/code based on the name of the form and the codeLocale/code that - * most closely matches the codeLocale/code passed in. The order of codeLocale/code - * matching is:/p + * pGets a codeForm/code based on the name of the form and the + * codeLocale/code that most closely matches the codeLocale/code + * passed in. The order of codeLocale/code matching is:/p * ol *lilanguage + country + variant/li *lilanguage + country/li @@ -344,7 +344,7 @@ *lidefault locale/li * /ol */ -public Form getForm(Locale locale, Object formKey) { +public Form getForm(Locale locale, String formKey) { return this.getForm( locale.getLanguage(), locale.getCountry(), @@ -370,7 +370,7 @@ String variant, Object formKey) { -return this.getForm(language, country, variant, formKey); +return this.getForm(language, country, variant, formKey.toString()); } /** @@ -388,7 +388,7 @@ String language, String country, String variant, -Object formKey) { +String formKey) { String key = this.buildLocale(language, country, variant); @@ -427,10 +427,11 @@ } /** - * pProcess the codeValidatorResources/code object. /p - * - * pCurrently sets the codeFastHashMap/codes to the 'fast' - * mode and call the processes all other resources./p + * Process the codeValidatorResources/code object. Currently sets the + * codeFastHashMap/codes to the 'fast' mode and call the processes all + * other resources. strongNote/strong: The framework calls this automatically + * when ValidatorResources is created from an XML file. If you create an instance + * of this class by hand you strongmust/strong call this method when finished. */ public void process() { hFormSets.setFast(true); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java digester-rules.xml Field.java Form.java Constant.java FormSet.java
dgraham 2003/05/27 21:14:33 Modified:validator/src/share/org/apache/commons/validator ValidatorResources.java digester-rules.xml Field.java Form.java Constant.java FormSet.java Log: Deprecated Constant class as it is never really used. Deprecated various methods like addConstantParam and addVarParam to shortened versions like addConstant. Removed unneeded null checking and checking for properties being set that are guaranteed by the DTD to be set. Revision ChangesPath 1.20 +52 -66 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ValidatorResources.java 24 May 2003 19:24:58 - 1.19 +++ ValidatorResources.java 28 May 2003 04:14:32 - 1.20 @@ -209,11 +209,7 @@ * codeFormSet/code. */ public void addFormSet(FormSet fs) { -if (fs == null) { -return; -} - -String key = buildKey(fs); +String key = this.buildKey(fs); List formsets = (List) hFormSets.get(key); if (formsets == null) { @@ -231,6 +227,7 @@ /** * Add a global constant to the resource. + * @deprecated Use addConstant(String, String) instead. */ public void addConstant(Constant c) { this.addConstantParam(c.getName(), c.getValue()); @@ -238,6 +235,7 @@ /** * Add a global constant to the resource. + * @deprecated Use addConstant(String, String) instead. */ public void addConstantParam(String name, String value) { if (name != null @@ -252,32 +250,31 @@ this.hConstants.put(name, value); } } + +/** + * Add a global constant to the resource. + */ +public void addConstant(String name, String value) { +if (log.isDebugEnabled()) { +log.debug(Adding Global Constant: + name + , + value); +} + +this.hConstants.put(name, value); +} /** - * pAdd a codeValidatorAction/code to the resource. It also creates an instance - * of the class based on the codeValidatorAction/codes classname and retrieves - * the codeMethod/code instance and sets them in the codeValidatorAction/code./p + * Add a codeValidatorAction/code to the resource. It also creates an + * instance of the class based on the codeValidatorAction/codes + * classname and retrieves the codeMethod/code instance and sets them + * in the codeValidatorAction/code. */ public void addValidatorAction(ValidatorAction va) { -if (va != null - va.getName() != null - va.getName().length() 0 - va.getClassname() != null - va.getClassname().length() 0 - va.getMethod() != null - va.getMethod().length() 0) { - -va.init(); - -hActions.put(va.getName(), va); - -if (log.isDebugEnabled()) { -log.debug( -Add ValidatorAction: -+ va.getName() -+ , -+ va.getClassname()); -} +va.init(); + +this.hActions.put(va.getName(), va); + +if (log.isDebugEnabled()) { +log.debug(Add ValidatorAction: + va.getName() + , + va.getClassname()); } } @@ -296,22 +293,27 @@ } /** - * Builds a key to store the codeFormSet/code under based on it's language, country, - * and variant values. + * Builds a key to store the codeFormSet/code under based on it's + * language, country, and variant values. */ protected String buildKey(FormSet fs) { -String lang = fs.getLanguage(); -String country = fs.getCountry(); -String variant = fs.getVariant(); +String locale = +this.buildLocale(fs.getLanguage(), fs.getCountry(), fs.getVariant()); +if (locale.length() == 0) { +locale = defaultLocale.toString(); +} + +return locale; +} + +/** + * Assembles a Locale code from the given parts. + */ +private String buildLocale(String lang, String country, String variant) { String key = ((lang != null lang.length() 0) ? lang : ); key += ((country != null country.length() 0) ? _ + country : ); key += ((variant != null
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java
dgraham 2003/03/19 17:11:18 Modified:validator/src/share/org/apache/commons/validator ValidatorResources.java Log: Formatting changes only. Revision ChangesPath 1.11 +373 -331 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ValidatorResources.java 20 Jan 2003 06:15:06 - 1.10 +++ ValidatorResources.java 20 Mar 2003 01:11:18 - 1.11 @@ -7,7 +7,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999-2002 The Apache Software Foundation. All rights + * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -59,21 +59,20 @@ * */ - package org.apache.commons.validator; import java.io.Serializable; import java.util.Collections; -import java.util.Iterator; import java.util.Enumeration; -import java.util.Vector; +import java.util.Iterator; import java.util.Locale; import java.util.Map; -import org.apache.commons.collections.FastHashMap; +import java.util.Vector; + +import org.apache.commons.collections.FastHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - /** * pGeneral purpose class for storing codeFormSet/code objects based * on their associated codeLocale/code./p @@ -87,334 +86,377 @@ */ public class ValidatorResources implements Serializable { - /** -* Logger - */ - protected static Log log = LogFactory.getLog(ValidatorResources.class); - - /** -* codeFastHashMap/code of codeFormSet/codes stored under -* a codeLocale/code key. - */ - protected FastHashMap hFormSets = new FastHashMap(); - - /** -* codeFastHashMap/code of global constant values with -* the name of the constant as the key. - */ - protected FastHashMap hConstants = new FastHashMap(); - - /** -* codeFastHashMap/code of codeValidatorAction/codes with -* the name of the codeValidatorAction/code as the key. - */ - protected FastHashMap hActions = new FastHashMap(); - - /** -* The default locale on our server. - */ - protected static Locale defaultLocale = Locale.getDefault(); - - /** -* Add a codeFormSet/code to this codeValidatorResources/code -* object. It will be associated with the codeLocale/code of the -* codeFormSet/code. - */ - public void put(FormSet fs) { - if (fs != null) { - String key = buildKey(fs); - if (hFormSets.get(key) == null) { - hFormSets.put(key, new Vector()); - } - Vector formsets = (Vector) hFormSets.get(key); - if (!formsets.contains(fs)) { - formsets.add(fs); - } - - if (log.isDebugEnabled()) { - log.debug(Adding FormSet ' + fs.toString() + '.); -} - } - } - - /** -* Add a global constant to the resource. - */ - public void addConstant(Constant c) { - if (c != null - c.getName() != null c.getName().length() 0 - c.getValue() != null c.getValue().length() 0) { - hConstants.put(c.getName(), c.getValue()); - } - - if (log.isDebugEnabled()) { - log.debug(Add Global Constant: + c.getName() + , + c.getValue()); - } - } - - /** -* Add a global constant to the resource. - */ - public void addConstantParam(String name, String value) { - if (name != null name.length() 0 - value != null value.length() 0) { - hConstants.put(name, value); - } - - if (log.isDebugEnabled()) { - log.debug(Add Global Constant: + name + , + value); - } - } - - /** -* pAdd a codeValidatorAction/code to the resource. It also creates an instance -* of the class based on the codeValidatorAction/codes classname and retrieves -* the codeMethod/code instance and sets them in the codeValidatorAction/code./p - */ - public void addValidatorAction(ValidatorAction va) { - if (va != null - va.getName() != null va.getName().length() 0 - va.getClassname() != null va.getClassname().length() 0 - va.getMethod() != null va.getMethod().length() 0) { - - va.process(hConstants); - - hActions.put(va.getName(), va); - - if (log.isDebugEnabled()) { -
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java
dgraham 2003/03/19 18:09:12 Modified:validator/src/share/org/apache/commons/validator ValidatorResources.java Log: Removed unused variables and replaced legacy collections classes (Enumeration, Vector) with appropriate newer counterparts (Iterator, ArrayList). Revision ChangesPath 1.12 +62 -69 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ValidatorResources.java 20 Mar 2003 01:11:18 - 1.11 +++ ValidatorResources.java 20 Mar 2003 02:09:12 - 1.12 @@ -62,12 +62,12 @@ package org.apache.commons.validator; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collections; -import java.util.Enumeration; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Vector; import org.apache.commons.collections.FastHashMap; import org.apache.commons.logging.Log; @@ -82,50 +82,51 @@ * application server environments./p * * @author David Winterfeldt + * @author David Graham * @version $Revision$ $Date$ -*/ + */ public class ValidatorResources implements Serializable { /** * Logger. -*/ + */ protected static Log log = LogFactory.getLog(ValidatorResources.class); /** * codeFastHashMap/code of codeFormSet/codes stored under * a codeLocale/code key. -*/ + */ protected FastHashMap hFormSets = new FastHashMap(); /** * codeFastHashMap/code of global constant values with * the name of the constant as the key. -*/ + */ protected FastHashMap hConstants = new FastHashMap(); /** * codeFastHashMap/code of codeValidatorAction/codes with * the name of the codeValidatorAction/code as the key. -*/ + */ protected FastHashMap hActions = new FastHashMap(); /** * The default locale on our server. -*/ + */ protected static Locale defaultLocale = Locale.getDefault(); /** * Add a codeFormSet/code to this codeValidatorResources/code * object. It will be associated with the codeLocale/code of the * codeFormSet/code. -*/ + */ public void put(FormSet fs) { if (fs != null) { String key = buildKey(fs); if (hFormSets.get(key) == null) { -hFormSets.put(key, new Vector()); +hFormSets.put(key, new ArrayList()); } -Vector formsets = (Vector) hFormSets.get(key); +List formsets = (List) hFormSets.get(key); if (!formsets.contains(fs)) { formsets.add(fs); } @@ -138,14 +139,14 @@ /** * Add a global constant to the resource. -*/ + */ public void addConstant(Constant c) { if (c != null c.getName() != null c.getName().length() 0 c.getValue() != null c.getValue().length() 0) { - + hConstants.put(c.getName(), c.getValue()); } @@ -156,12 +157,13 @@ /** * Add a global constant to the resource. -*/ + */ public void addConstantParam(String name, String value) { if (name != null name.length() 0 value != null value.length() 0) { + hConstants.put(name, value); } @@ -174,7 +176,7 @@ * pAdd a codeValidatorAction/code to the resource. It also creates an instance * of the class based on the codeValidatorAction/codes classname and retrieves * the codeMethod/code instance and sets them in the codeValidatorAction/code./p -*/ + */ public void addValidatorAction(ValidatorAction va) { if (va != null va.getName() != null @@ -200,14 +202,14 @@ /** * Get a codeValidatorAction/code based on it's name. -*/ + */ public ValidatorAction getValidatorAction(String key) { return (ValidatorAction) hActions.get(key); } /** * Get an unmodifiable codeMap/code of the codeValidatorAction/codes. -*/ + */ public Map getValidatorActions() { return Collections.unmodifiableMap(hActions); } @@ -215,18 +217,15 @@ /** * Builds a key to store the codeFormSet/code under based on it's language, country,
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java
turner 2002/12/04 13:24:01 Modified:validator/src/share/org/apache/commons/validator ValidatorResources.java Log: Fixed bug 14384, refactored code a bit to remove lots of redundent stuff. Thanks to Björn-H. Moritz for suggesting the fix. Revision ChangesPath 1.8 +20 -39 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ValidatorResources.java 16 Oct 2002 18:48:08 - 1.7 +++ ValidatorResources.java 4 Dec 2002 21:24:01 - 1.8 @@ -255,44 +255,25 @@ Vector v = (Vector) hFormSets.get(key); - if (v == null) return f; - - Enumeration formsets = v.elements(); - while (formsets.hasMoreElements()) { - o = formsets.nextElement(); - if (o != null) { - fs = (FormSet)o; - if ((fs != null) (fs.getForm(formKey) != null)) { - return fs.getForm(formKey); - } - } + if (v == null) { + key = ((language != null language.length() 0) ? language : ) + + ((country != null country.length() 0) ? _ + country : ); + v = (Vector) hFormSets.get(key); } - key = ((language != null language.length() 0) ? language : ) + - ((country != null country.length() 0) ? _ + country : ); - - formsets = v.elements(); - while (formsets.hasMoreElements()) { - o = formsets.nextElement(); - if (o != null) { - fs = (FormSet)o; - if ((fs != null) (fs.getForm(formKey) != null)) { - return fs.getForm(formKey); - } - } + + if (v == null) { + key = ((language != null language.length() 0) ? language : ); + v = (Vector) hFormSets.get(key); } - key = ((language != null language.length() 0) ? language : ); - formsets = v.elements(); - while (formsets.hasMoreElements()) { - o = formsets.nextElement(); - if (o != null) { - fs = (FormSet)o; - if ((fs != null) (fs.getForm(formKey) != null)) { - return fs.getForm(formKey); - } - } + + if (v == null) { + key = defaultLocale.toString(); + v = (Vector) hFormSets.get(key); } - key = defaultLocale.toString(); - formsets = v.elements(); + + if (v == null) return null; + + Enumeration formsets = v.elements(); while (formsets.hasMoreElements()) { o = formsets.nextElement(); if (o != null) { -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java
turner 2002/10/16 11:48:08 Modified:validator/src/share/org/apache/commons/validator ValidatorResources.java Log: Changed ValidatorResources to store FormSets as a vector attached to the Locale key rather than as a single element. The way it was, it was causing only the formset of the last XML file for a given Locale to have it's FormSets saved. Potentially very destabilizing change, but it passes the unit tests afterward, so I think it's OK, since the changes are all internal to ValidatorResources (i.e., it's all private access stuff, and the API is still the same.) Only screw case I can think of is that if resource initialization is called multiple times on the same Resource (and I couldn't think of a plausible case of this happening), the FormSets are going to pile up on the Vector used to store it. Fixed bug 10584 Revision ChangesPath 1.7 +122 -102 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ValidatorResources.java 30 Mar 2002 04:33:17 - 1.6 +++ ValidatorResources.java 16 Oct 2002 18:48:08 - 1.7 @@ -65,6 +65,8 @@ import java.io.Serializable; import java.util.Collections; import java.util.Iterator; +import java.util.Enumeration; +import java.util.Vector; import java.util.Locale; import java.util.Map; import org.apache.commons.collections.FastHashMap; @@ -120,7 +122,14 @@ */ public void put(FormSet fs) { if (fs != null) { -hFormSets.put(buildKey(fs), fs); + String key = buildKey(fs); + if (hFormSets.get(key) == null) { + hFormSets.put(key, new Vector()); + } + Vector formsets = (Vector) hFormSets.get(key); + if (!formsets.contains(fs)) { + formsets.add(fs); + } if (log.isInfoEnabled()) { log.info(Adding FormSet ' + fs.toString() + '.); @@ -234,61 +243,67 @@ *lidefault locale/li * /ol */ - public Form get(String language, String country, String variant, Object formKey) { - FormSet fs = null; - Form f = null; - String key = null; - Object o = null; +public Form get(String language, String country, String variant, Object formKey) { + FormSet fs = null; + Form f = null; + String key = null; + Object o = null; - key = ((language != null language.length() 0) ? language : ) + + key = ((language != null language.length() 0) ? language : ) + ((country != null country.length() 0) ? _ + country : ) + ((variant != null variant.length() 0) ? _ + variant : ); - o = hFormSets.get(key); - if (o != null) { - fs = (FormSet)o; - if (fs != null) -f = fs.getForm(formKey); - } + Vector v = (Vector) hFormSets.get(key); - if (f == null) { - key = ((language != null language.length() 0) ? language : ) + - ((country != null country.length() 0) ? _ + country : ); - - o = hFormSets.get(key); - if (o != null) { -fs = (FormSet)o; -if (fs != null) - f = fs.getForm(formKey); - } - - } + if (v == null) return f; - if (f == null) { - key = ((language != null language.length() 0) ? language : ); + Enumeration formsets = v.elements(); + while (formsets.hasMoreElements()) { + o = formsets.nextElement(); + if (o != null) { + fs = (FormSet)o; + if ((fs != null) (fs.getForm(formKey) != null)) { + return fs.getForm(formKey); + } + } + } + key = ((language != null language.length() 0) ? language : ) + + ((country != null country.length() 0) ? _ + country : ); - o = hFormSets.get(key); - if (o != null) { -fs = (FormSet)o; -if (fs != null) - f = fs.getForm(formKey); - } - } - - if (f == null) { - key = defaultLocale.toString(); - - o = hFormSets.get(key); - if (o != null) { -fs = (FormSet)o; -if (fs != null) - f = fs.getForm(formKey); - } - } - - - return f; - } + formsets = v.elements(); + while (formsets.hasMoreElements()) { + o = formsets.nextElement(); +