commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 15345] New: - Validator not formsets by locale
Date Fri, 13 Dec 2002 03:43:53 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15345>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15345

Validator not formsets by locale

           Summary: Validator not formsets by locale
           Product: Commons
           Version: Nightly Builds
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Validator
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: gary.frost@ssmb.com.au


org.apache.commons.validator.ValidatorResources:get(String, String, String, 
Object)

This method seems to be searching the hFormSet entries incorrectly for finding 
a form with the given key, using a formset with the given locale.

The method bails out straight away if it does not find a formset with the 
language + country + variant passed in, rather than trying
1) language + country + variant 
2) language + country
3) language
4) default locale


The following diffs seem to fix it up, but I could be misunderstanding the 
problem.


--- ValidatorResources.java	Wed Dec  4 02:27:36 2002
+++ /home/gf06866/projects/webATLAS/src/java/org/apache/commons/validator/Valida
torResources.java	Fri Dec 13 11:06:01 2002
@@ -244,63 +244,61 @@
     * </ol>
    */
     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 : "") + 
-            ((country != null && country.length() > 0) ? "_" + country : "") +

-            ((variant != null && variant.length() > 0) ? "_" + variant : "");
-      
-	Vector v = (Vector) hFormSets.get(key);
+	String localeKey = null;
 
-	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);
+	// Try language + country + variant
+	if (!GenericValidator.isBlankOrNull(language) &&
+		!GenericValidator.isBlankOrNull(country) &&
+		!GenericValidator.isBlankOrNull(variant)) {
+		localeKey = language + "_" + country + "_" + variant;
+		f = getForm(localeKey, formKey);
+		if (f != null) {
+			if (log.isDebugEnabled()) {
+				log.debug("Form with key " + formKey + " found 
in formset with locale " + localeKey);
 		}
+			return f;
 	    }
 	}
-	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);
+	// Try language + country
+	if (!GenericValidator.isBlankOrNull(language) &&
+		!GenericValidator.isBlankOrNull(country)) {
+		localeKey = language + "_" + country;
+		f = getForm(localeKey, formKey);
+		if (f != null) {
+			if (log.isDebugEnabled()) {
+				log.debug("Form with key " + formKey + " found 
in formset with locale " + localeKey);
 		}
+			return f;
 	    }
 	}
-	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);
+
+	// Try language only
+	if (!GenericValidator.isBlankOrNull(language)) {
+		localeKey = language;
+		f = getForm(localeKey, formKey);
+		if (f != null) {
+			if (log.isDebugEnabled()) {
+				log.debug("Form with key " + formKey + " found 
in formset with locale " + localeKey);
 		}
+			return f;
 	    }
 	}
-	key = defaultLocale.toString();
-	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);
+
+	// Try default locale
+	localeKey = defaultLocale.toString();
+	f = getForm(localeKey, formKey);
+	if (f != null) {
+		if (log.isDebugEnabled()) {
+			log.debug("Form with key " + formKey + " found in 
formset with locale " + localeKey);
 		}
+		return f;
 	    }
+
+	// No form found
+	if (log.isDebugEnabled()) {
+			log.debug("No Form with key " + formKey);
 	}
 	return null;	
     }
@@ -425,5 +423,30 @@
       
       return field;  	
    }
+
+  /**
+   * Find a <code>FormSet</code in the collection of stored formsets with the 
given
+   * locale key, if a <code>FormSet</code> it found search it for a 
<code>Form</code>
+   * with the given formKey
+   */
+  protected Form getForm(String localeKey, Object formKey) {
+	Object o = null;
+	Vector v = (Vector) hFormSets.get(localeKey);
+	FormSet fs = null;
+
+	if (v == null) return null;
+
+	Enumeration formsets = v.elements();
+	while (formsets.hasMoreElements()) {
+	    o = formsets.nextElement();
+	    if (o != null) {
+		    fs = (FormSet)o;
+		    if (fs.getForm(formKey) != null) {
+		        return fs.getForm(formKey);
+		    }
+	    }
+	}
+	return null;
+	}
 
 }

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message