craigmcc    01/03/13 11:39:50

  Modified:    src/share/org/apache/struts/digester Digester.java
  Log:
  When digesting recursive structures, allow the developer to distinguish
  rules for the root node of the structure from nested nodes, by
  deterministically matching the longest "*/xxx" pattern that is specified.
  For example, if you are processing a structure:
  
        <tree>
                <node> <!-- #1 -->
                        <node> <! -- #2 -->
                                <node> <!-- #3 -->
                                </node>
                                <node> <!-- #4 -->
                                </node>
                        </node>
                        <node> <!-- #5 -->
                        </node>
                </node>
        </tree>
  
  you can distinguish between the root node (#1) and all the rest like this:
  
        digester.addRule("*/tree/node", ... rule for root node ...);
        digester.addRule("*/node", ... rule for non-root node ...);
  
  PR:  Bugzilla #950, 951
  Submitted by: Pierre Metras <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.16      +12 -7     
jakarta-struts/src/share/org/apache/struts/digester/Digester.java
  
  Index: Digester.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Digester.java     2001/02/13 23:53:36     1.15
  +++ Digester.java     2001/03/13 19:39:48     1.16
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v 1.15 
2001/02/13 23:53:36 craigmcc Exp $
  - * $Revision: 1.15 $
  - * $Date: 2001/02/13 23:53:36 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/digester/Digester.java,v 1.16 
2001/03/13 19:39:48 craigmcc Exp $
  + * $Revision: 1.16 $
  + * $Date: 2001/03/13 19:39:48 $
    *
    * ====================================================================
    * 
  @@ -102,7 +102,7 @@
    * even from the same thread.</p>
    *
    * @author Craig McClanahan
  - * @version $Revision: 1.15 $ $Date: 2001/02/13 23:53:36 $
  + * @version $Revision: 1.16 $ $Date: 2001/03/13 19:39:48 $
    */
   
   public final class Digester extends HandlerBase {
  @@ -1081,7 +1081,8 @@
        * The selected rules are those that match exactly, or those rules
        * that specify a suffix match and the tail of the rule matches the
        * current match position.  Exact matches have precedence over
  -     * suffix matches.
  +     * suffix matches, then (among suffix matches) the longest match
  +     * is preferred.
        *
        * @param match The current match position
        */
  @@ -1089,13 +1090,17 @@
   
           List rulesList = (List) this.rules.get(match);
        if (rulesList == null) {
  +            // Find the longest key, ie more discriminant
  +            String longKey = "";
            Iterator keys = this.rules.keySet().iterator();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                if (key.startsWith("*/")) {
                    if (match.endsWith(key.substring(1))) {
  -                     rulesList = (List) this.rules.get(key);
  -                     break;
  +                        if (key.length() > longKey.length()) {
  +                            rulesList = (List) this.rules.get(key);
  +                            longKey = key;
  +                        }
                    }
                }
            }
  
  
  

Reply via email to