Author: niallp
Date: Wed Sep 14 17:40:52 2005
New Revision: 287172

URL: http://svn.apache.org/viewcvs?rev=287172&view=rev
Log:
Add digester rule so that arg0-arg3 elements are not ignored when using DTD 
version prior to 1.2.0. This change is in a private method and makes Validator 
1.2.0 backward compatible with version 1.1.3 of the DTD.

Modified:
    
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java

Modified: 
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java?rev=287172&r1=287171&r2=287172&view=diff
==============================================================================
--- 
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java
 (original)
+++ 
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java
 Wed Sep 14 17:40:52 2005
@@ -32,10 +32,12 @@
 
 import org.apache.commons.collections.FastHashMap;
 import org.apache.commons.digester.Digester;
+import org.apache.commons.digester.Rule;
 import org.apache.commons.digester.xmlrules.DigesterLoader;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.SAXException;
+import org.xml.sax.Attributes;
 
 /**
  * <p>
@@ -200,6 +202,9 @@
         digester.setValidating(true);
         digester.setUseContextClassLoader(true);
 
+        // Add rules for arg0-arg3 elements
+        addOldArgRules(digester);
+
         // register DTDs
         for (int i = 0; i < registrations.length; i += 2) {
             URL url = this.getClass().getResource(registrations[i + 1]);
@@ -208,6 +213,45 @@
             }
         }
         return digester;
+    }
+
+    private static final String argsPattern 
+               = "form-validation/formset/form/field/arg";
+
+    /**
+     * Create a <code>Rule</code> to handle <code>arg0-arg3</code>
+     * elements. This will allow validation.xml files that use the
+     * versions of the DTD prior to Validator 1.2.0 to continue
+     * working.
+     */
+    private void addOldArgRules(Digester digester) {
+
+        // Create a new rule to process args elements
+        Rule rule = new Rule() {
+            public void begin(String namespace, String name, 
+                               Attributes attributes) throws Exception {
+                // Create the Arg
+                Arg arg = new Arg();
+                arg.setKey(attributes.getValue("key"));
+                arg.setName(attributes.getValue("name"));
+                try {
+                    arg.setPosition(Integer.parseInt(name.substring(3)));
+                } catch (Exception ex) {
+                    log.error("Error parsing Arg position: " 
+                               + name + " " + arg + " " + ex);
+                }
+
+                // Add the arg to the parent field
+                ((Field)digester.peek(0)).addArg(arg);
+            }
+        };
+
+        // Add the rule for each of the arg elements
+        digester.addRule(argsPattern + "0", rule);
+        digester.addRule(argsPattern + "1", rule);
+        digester.addRule(argsPattern + "2", rule);
+        digester.addRule(argsPattern + "3", rule);
+
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to