You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dg...@apache.org on 2003/05/21 04:53:41 UTC
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResources.java Validator.java
dgraham 2003/05/20 19:53:41
Modified: validator/src/test/org/apache/commons/validator
ValidatorTest.java
validator/src/share/org/apache/commons/validator
ValidatorResources.java Validator.java
Log:
Cleaned up ValidatorResources method names and deprecated the old
versions.
Revision Changes Path
1.10 +6 -6 jakarta-commons/validator/src/test/org/apache/commons/validator/ValidatorTest.java
Index: ValidatorTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/ValidatorTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ValidatorTest.java 2 May 2003 23:39:30 -0000 1.9
+++ ValidatorTest.java 21 May 2003 02:53:40 -0000 1.10
@@ -140,7 +140,7 @@
fs.addForm(form);
resources.addValidatorAction(va);
- resources.put(fs);
+ resources.addFormSet(fs);
resources.process();
TestBean bean = new TestBean();
@@ -209,7 +209,7 @@
fs.addForm(form);
resources.addValidatorAction(va);
- resources.put(fs);
+ resources.addFormSet(fs);
resources.process();
List l = new ArrayList();
1.15 +83 -32 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ValidatorResources.java 18 May 2003 21:29:36 -0000 1.14
+++ ValidatorResources.java 21 May 2003 02:53:41 -0000 1.15
@@ -77,7 +77,7 @@
* <p>General purpose class for storing <code>FormSet</code> objects based
* on their associated <code>Locale</code>.</p>
*
- * <p><strong>IMPLEMENTATION NOTE</strong> - Classes that extend this class
+ * <p><strong>Note</strong> - Classes that extend this class
* must be Serializable so that instances may be used in distributable
* application server environments.</p>
*
@@ -119,23 +119,35 @@
* Add a <code>FormSet</code> to this <code>ValidatorResources</code>
* object. It will be associated with the <code>Locale</code> of the
* <code>FormSet</code>.
+ * @deprecated Use addFormSet() instead.
*/
public void put(FormSet fs) {
- if (fs != null) {
- String key = buildKey(fs);
- List formsets = (List) hFormSets.get(key);
+ this.addFormSet(fs);
+ }
+
+ /**
+ * Add a <code>FormSet</code> to this <code>ValidatorResources</code>
+ * object. It will be associated with the <code>Locale</code> of the
+ * <code>FormSet</code>.
+ */
+ public void addFormSet(FormSet fs) {
+ if (fs == null) {
+ return;
+ }
+
+ String key = buildKey(fs);
+ List formsets = (List) hFormSets.get(key);
- if (formsets == null) {
- formsets = new ArrayList();
- hFormSets.put(key, formsets);
- }
+ if (formsets == null) {
+ formsets = new ArrayList();
+ hFormSets.put(key, formsets);
+ }
- if (!formsets.contains(fs)) {
- if (log.isDebugEnabled()) {
- log.debug("Adding FormSet '" + fs.toString() + "'.");
- }
- formsets.add(fs);
+ if (!formsets.contains(fs)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Adding FormSet '" + fs.toString() + "'.");
}
+ formsets.add(fs);
}
}
@@ -248,9 +260,25 @@
* <li>language</li>
* <li>default locale</li>
* </ol>
- */
+ * @deprecated Use getForm() instead.
+ */
public Form get(Locale locale, Object formKey) {
- return get(
+ return this.getForm(locale, formKey);
+ }
+
+ /**
+ * <p>Gets a <code>Form</code> based on the name of the form and the <code>Locale</code> that
+ * most closely matches the <code>Locale</code> passed in. The order of <code>Locale</code>
+ * matching is:</p>
+ * <ol>
+ * <li>language + country + variant</li>
+ * <li>language + country</li>
+ * <li>language</li>
+ * <li>default locale</li>
+ * </ol>
+ */
+ public Form getForm(Locale locale, Object formKey) {
+ return this.getForm(
locale.getLanguage(),
locale.getCountry(),
locale.getVariant(),
@@ -258,15 +286,16 @@
}
/**
- * <p>Gets a <code>Form</code> based on the name of the form and the <code>Locale</code> that
- * most closely matches the <code>Locale</code> passed in. The order of <code>Locale</code>
- * matching is:</p>
+ * <p>Gets a <code>Form</code> based on the name of the form and the
+ * <code>Locale</code> that most closely matches the <code>Locale</code>
+ * passed in. The order of <code>Locale</code> matching is:</p>
* <ol>
* <li>language + country + variant</li>
* <li>language + country</li>
* <li>language</li>
* <li>default locale</li>
* </ol>
+ * @deprecated Use getForm() instead.
*/
public Form get(
String language,
@@ -274,22 +303,42 @@
String variant,
Object formKey) {
+ return this.getForm(language, country, variant, formKey);
+ }
+
+ /**
+ * <p>Gets a <code>Form</code> based on the name of the form and the
+ * <code>Locale</code> that most closely matches the <code>Locale</code>
+ * passed in. The order of <code>Locale</code> matching is:</p>
+ * <ol>
+ * <li>language + country + variant</li>
+ * <li>language + country</li>
+ * <li>language</li>
+ * <li>default locale</li>
+ * </ol>
+ */
+ public Form getForm(
+ String language,
+ String country,
+ 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 : "");
+ key = (language != null && language.length() > 0) ? language : "";
+ key += (country != null && country.length() > 0) ? "_" + country : "";
+ key += (variant != null && variant.length() > 0) ? "_" + variant : "";
List v = (List) hFormSets.get(key);
if (v == null) {
- key = ((language != null && language.length() > 0) ? language : "");
- key += ((country != null && country.length() > 0) ? "_" + country : "");
+ key = (language != null && language.length() > 0) ? language : "";
+ key += (country != null && country.length() > 0) ? "_" + country : "";
v = (List) hFormSets.get(key);
}
if (v == null) {
- key = ((language != null && language.length() > 0) ? language : "");
+ key = (language != null && language.length() > 0) ? language : "";
v = (List) hFormSets.get(key);
}
@@ -362,18 +411,19 @@
// If they don't exist in the current locale's form, then clone them.
Form defaultForm = get(defaultLocale, formKey);
- for (Iterator defaultFields = defaultForm.getFields().iterator();
- defaultFields.hasNext();
- ) {
+ Iterator defaultFields = defaultForm.getFields().iterator();
+ while (defaultFields.hasNext()) {
Field defaultField = (Field) defaultFields.next();
String fieldKey = defaultField.getKey();
if (form.getFieldMap().containsKey(fieldKey)) {
newForm.addField(
(Field) form.getFieldMap().get(fieldKey));
+
} else {
Field field =
getClosestLocaleField(fs, formKey, fieldKey);
+
newForm.addField((Field) field.clone());
}
}
@@ -382,6 +432,7 @@
}
}
}
+
// Process Fully Constructed FormSets
for (Iterator i = hFormSets.values().iterator(); i.hasNext();) {
List formsets = (List) i.next();
@@ -401,7 +452,7 @@
* on <code>FormSet</code>'s locale. This is used when
* constructing a clone, field by field, of partial
* <code>FormSet</code>.
- */
+ */
protected Field getClosestLocaleField(
FormSet fs,
String formKey,
1.20 +5 -5 jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java
Index: Validator.java
===================================================================
RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Validator.java 20 May 2003 01:52:27 -0000 1.19
+++ Validator.java 21 May 2003 02:53:41 -0000 1.20
@@ -608,7 +608,7 @@
throw new ValidatorException("Resources not defined for Validator");
}
- Form form = resources.get(locale, formName);
+ Form form = resources.getForm(locale, formName);
if (form != null) {
Iterator forms = form.getFields().iterator();
while (forms.hasNext()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org