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 Changes Path 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 -0000 1.19 +++ ValidatorResources.java 28 May 2003 04:14:32 -0000 1.20 @@ -209,11 +209,7 @@ * <code>FormSet</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); + } /** - * <p>Add a <code>ValidatorAction</code> to the resource. It also creates an instance - * of the class based on the <code>ValidatorAction</code>s classname and retrieves - * the <code>Method</code> instance and sets them in the <code>ValidatorAction</code>.</p> + * Add a <code>ValidatorAction</code> to the resource. It also creates an + * instance of the class based on the <code>ValidatorAction</code>s + * classname and retrieves the <code>Method</code> instance and sets them + * in the <code>ValidatorAction</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 <code>FormSet</code> under based on it's language, country, - * and variant values. + * Builds a key to store the <code>FormSet</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 && variant.length() > 0) ? "_" + variant : ""); - - if (key.length() == 0) { - key = defaultLocale.toString(); - } - return key; } @@ -388,11 +390,7 @@ String variant, Object formKey) { - String key = null; - - key = (language != null && language.length() > 0) ? language : ""; - key += (country != null && country.length() > 0) ? "_" + country : ""; - key += (variant != null && variant.length() > 0) ? "_" + variant : ""; + String key = this.buildLocale(language, country, variant); List v = (List) hFormSets.get(key); @@ -544,41 +542,29 @@ && !GenericValidator.isBlankOrNull(country) && !GenericValidator.isBlankOrNull(variant)) { - Form form = get(language, country, variant, formKey); - - if (form.getFieldMap().containsKey(fieldKey)) { - field = (Field) form.getFieldMap().get(fieldKey); - } + Form form = this.getForm(language, country, variant, formKey); + field = (Field) form.getFieldMap().get(fieldKey); } if (field == null) { if (!GenericValidator.isBlankOrNull(language) && !GenericValidator.isBlankOrNull(country)) { - Form form = get(language, country, null, formKey); - - if (form.getFieldMap().containsKey(fieldKey)) { - field = (Field) form.getFieldMap().get(fieldKey); - } + Form form = this.getForm(language, country, null, formKey); + field = (Field) form.getFieldMap().get(fieldKey); } } if (field == null) { if (!GenericValidator.isBlankOrNull(language)) { - Form form = get(language, null, null, formKey); - - if (form.getFieldMap().containsKey(fieldKey)) { - field = (Field) form.getFieldMap().get(fieldKey); - } + Form form = this.getForm(language, null, null, formKey); + field = (Field) form.getFieldMap().get(fieldKey); } } if (field == null) { - Form form = get(defaultLocale, formKey); - - if (form.getFieldMap().containsKey(fieldKey)) { - field = (Field) form.getFieldMap().get(fieldKey); - } + Form form = this.getForm(defaultLocale, formKey); + field = (Field) form.getFieldMap().get(fieldKey); } return field; 1.4 +4 -4 jakarta-commons/validator/src/share/org/apache/commons/validator/digester-rules.xml Index: digester-rules.xml =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/digester-rules.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- digester-rules.xml 25 May 2003 18:00:23 -0000 1.3 +++ digester-rules.xml 28 May 2003 04:14:32 -0000 1.4 @@ -16,7 +16,7 @@ <pattern value="form-validation/global"> <pattern value="constant"> - <call-method-rule methodname="addConstantParam" paramcount="2" /> + <call-method-rule methodname="addConstant" paramcount="2" /> <call-param-rule pattern="constant-name" paramnumber="0" /> <call-param-rule pattern="constant-value" paramnumber="1" /> </pattern> @@ -37,7 +37,7 @@ <set-next-rule methodname="addFormSet" paramtype="org.apache.commons.validator.FormSet" /> <pattern value="constant"> - <call-method-rule methodname="addConstantParam" paramcount="2" /> + <call-method-rule methodname="addConstant" paramcount="2" /> <call-param-rule pattern="constant-name" paramnumber="0" /> <call-param-rule pattern="constant-value" paramnumber="1" /> </pattern> @@ -53,7 +53,7 @@ <set-next-rule methodname="addField" paramtype="org.apache.commons.validator.Field" /> <pattern value="var"> - <call-method-rule methodname="addVarParam" paramcount="3" /> + <call-method-rule methodname="addVar" paramcount="3" /> <call-param-rule pattern="var-name" paramnumber="0" /> <call-param-rule pattern="var-value" paramnumber="1" /> <call-param-rule pattern="var-jstype" paramnumber="2" /> 1.14 +14 -11 jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java Index: Field.java =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- Field.java 25 May 2003 18:00:23 -0000 1.13 +++ Field.java 28 May 2003 04:14:32 -0000 1.14 @@ -456,20 +456,23 @@ * Add a <code>Var</code> to the <code>Field</code>. */ public void addVar(Var v) { - if (v != null - && v.getName() != null - && v.getName().length() > 0 - && v.getValue() != null) { - - hVars.put(v.getName(), v); - } + this.hVars.put(v.getName(), v); } /** * Add a <code>Var</code>, based on the values passed in, to the * <code>Field</code>. + * @deprecated Use addVar(String, String, String) instead. */ public void addVarParam(String name, String value, String jsType) { + this.addVar(new Var(name, value, jsType)); + } + + /** + * Add a <code>Var</code>, based on the values passed in, to the + * <code>Field</code>. + */ + public void addVar(String name, String value, String jsType) { this.addVar(new Var(name, value, jsType)); } 1.6 +9 -14 jakarta-commons/validator/src/share/org/apache/commons/validator/Form.java Index: Form.java =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Form.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Form.java 22 May 2003 03:28:05 -0000 1.5 +++ Form.java 28 May 2003 04:14:32 -0000 1.6 @@ -59,7 +59,6 @@ * */ - package org.apache.commons.validator; import java.io.Serializable; @@ -68,8 +67,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.apache.commons.collections.FastHashMap; +import org.apache.commons.collections.FastHashMap; /** * <p> @@ -99,7 +98,7 @@ /** * Map of <code>Field</code>s keyed on their property value. - */ + */ protected FastHashMap hFields = new FastHashMap(); /** @@ -120,11 +119,8 @@ * Add a <code>Field</code> to the <code>Form</code>. */ public void addField(Field f) { - if (f != null && f.getProperty() != null && f.getProperty().length() > 0) { - lFields.add(f); - - hFields.put(f.getKey(), f); - } + this.lFields.add(f); + this.hFields.put(f.getKey(), f); } /** @@ -136,8 +132,7 @@ } /** - * A <code>Map</code> of <code>Field</code>s is returned as an - * unmodifiable <code>List</code>. + * The <code>Field</code>s are returned as an unmodifiable <code>Map</code>. */ public Map getFieldMap() { return Collections.unmodifiableMap(hFields); 1.6 +5 -4 jakarta-commons/validator/src/share/org/apache/commons/validator/Constant.java Index: Constant.java =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Constant.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Constant.java 22 May 2003 03:28:05 -0000 1.5 +++ Constant.java 28 May 2003 04:14:32 -0000 1.6 @@ -77,6 +77,7 @@ * * @author David Winterfeldt * @version $Revision$ $Date$ + * @deprecated This class is no longer needed. */ public class Constant implements Serializable { 1.9 +14 -4 jakarta-commons/validator/src/share/org/apache/commons/validator/FormSet.java Index: FormSet.java =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/FormSet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- FormSet.java 22 May 2003 03:28:05 -0000 1.8 +++ FormSet.java 28 May 2003 04:14:32 -0000 1.9 @@ -166,6 +166,7 @@ /** * Add a <code>Constant</code> (locale level). + * @deprecated Use addConstant(String, String) instead. */ public void addConstant(Constant c) { if (c.getName() != null && c.getName().length() > 0 && @@ -177,6 +178,7 @@ /** * Add a <code>Constant</code> to the locale level. + * @deprecated Use addConstant(String, String) instead. */ public void addConstantParam(String name, String value) { if (name != null && name.length() > 0 && @@ -184,6 +186,14 @@ constants.put(name, value); } + } + + /** + * Add a <code>Constant</code> to the locale level. + * @deprecated Use addConstant(String, String) instead. + */ + public void addConstant(String name, String value) { + this.constants.put(name, value); } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]