Uploaded image for project: 'Commons Validator'
  1. Commons Validator
  2. VALIDATOR-22

Validator incorrectly searching formsets by locale

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • Nightly Builds
    • None
    • None
    • None
    • Operating System: other
      Platform: All

    • 15345

    Description

      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)
        Unknown macro: {+ 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)
        Unknown macro: {+ 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)
        Unknown macro: {+ 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;
      + }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            gary.frost@ssmb.com.au Gary Frost
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: