dgraham     2004/01/10 13:29:12

  Modified:    src/share/org/apache/struts/util WildcardHelper.java
               src/share/org/apache/struts/config ActionConfigMatcher.java
  Log:
  Changed WildcardHelper methods from statics to instance methods to
  allow subclasses to override and customize behavior.  Changed 
  WildcardHelper.match() to accept a generic Map parameter rather than
  HashMap.
  
  Revision  Changes    Path
  1.4       +19 -16    
jakarta-struts/src/share/org/apache/struts/util/WildcardHelper.java
  
  Index: WildcardHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/WildcardHelper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WildcardHelper.java       10 Jan 2004 21:20:48 -0000      1.3
  +++ WildcardHelper.java       10 Jan 2004 21:29:12 -0000      1.4
  @@ -61,25 +61,29 @@
    
   package org.apache.struts.util;
   
  -import java.util.HashMap;
  +import java.util.Map;
   
   /**
    * This class is an utility class that perform wilcard-patterns matching and
    * isolation taken from Apache Cocoon.
    *
  - *         (Apache Software Foundation)
  + * @since Struts 1.2
    * @version CVS $Id$
    */
   public class WildcardHelper {
   
       /** The int representing '*' in the pattern <code>int []</code>. */
       protected static final int MATCH_FILE = -1;
  +    
       /** The int representing '**' in the pattern <code>int []</code>. */
       protected static final int MATCH_PATH = -2;
  +    
       /** The int representing begin in the pattern <code>int []</code>. */
       protected static final int MATCH_BEGIN = -4;
  +    
       /** The int representing end in pattern <code>int []</code>. */
       protected static final int MATCH_THEEND = -5;
  +    
       /** The int value that terminates the pattern <code>int []</code>. */
       protected static final int MATCH_END = -3;
   
  @@ -117,8 +121,7 @@
        *         value (don't consider the array length).
        * @exception NullPointerException If data is null.
        */
  -    public static int[] compilePattern(String data)
  -    throws NullPointerException {
  +    public int[] compilePattern(String data) {
   
           // Prepare the arrays
           int expr[] = new int[data.length() + 2];
  @@ -182,8 +185,7 @@
        * @return True if a match
        * @throws NullPointerException If any parameters are null
        */
  -    public static boolean match (HashMap map, String data,
  -            int[] expr) throws NullPointerException {
  +    public boolean match(Map map, String data, int[] expr) {
           if (map == null) {
               throw new NullPointerException ("No map provided");
           }    
  @@ -315,7 +317,7 @@
           }
       }
   
  -    /**
  +     /**
         * Get the offset of a part of an int array within a char array.
         * <br>
         * This method return the index in d of the first occurrence after dpos of
  @@ -330,8 +332,9 @@
         * @return The offset in d of the part of r matched in d or -1 if that was
         *         not found.
         */
  -    protected static int indexOfArray (int r[], int rpos, int rend,
  +    protected int indexOfArray (int r[], int rpos, int rend,
               char d[], int dpos) {
  +                
           // Check if pos and len are legal
           if (rend < rpos) {
               throw new IllegalArgumentException ("rend < rpos");
  @@ -372,7 +375,7 @@
           return (-1);
       }
   
  -    /**
  +     /**
         * Get the offset of a last occurance of an int array within a char array.
         * <br>
         * This method return the index in d of the last occurrence after dpos of
  @@ -387,7 +390,7 @@
         * @return The offset in d of the last part of r matched in d or -1 if 
         *         that was not found.
         */
  -    protected static int lastIndexOfArray (int r[], int rpos, int rend,
  +    protected int lastIndexOfArray (int r[], int rpos, int rend,
               char d[], int dpos) {
           // Check if pos and len are legal
           if (rend < rpos) {
  @@ -432,7 +435,7 @@
           return (-1);
       }
   
  -    /**
  +     /**
         * Matches elements of array r from rpos to rend with array d, starting 
         * from dpos.
         * <br>
  @@ -446,7 +449,7 @@
         * @param dpos The starting offset in d for the matching.
         * @return true if array d starts from portion of array r.
         */
  -    protected static boolean matchArray (int r[], int rpos, int rend,
  +    protected boolean matchArray (int r[], int rpos, int rend,
               char d[], int dpos) {
           if (d.length - dpos < rend - rpos) {
               return (false);
  
  
  
  1.7       +17 -12    
jakarta-struts/src/share/org/apache/struts/config/ActionConfigMatcher.java
  
  Index: ActionConfigMatcher.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ActionConfigMatcher.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ActionConfigMatcher.java  10 Jan 2004 21:03:33 -0000      1.6
  +++ ActionConfigMatcher.java  10 Jan 2004 21:29:12 -0000      1.7
  @@ -77,10 +77,11 @@
   import org.apache.struts.util.WildcardHelper;
   
   /**
  - *  Matches paths against pre-compiled wildcard expressions pulled from 
  - *  action configs. It uses the wildcard matcher from the Apache
  - *  Cocoon project.
  + * Matches paths against pre-compiled wildcard expressions pulled from 
  + * action configs. It uses the wildcard matcher from the Apache
  + * Cocoon project.
    *
  + * @since Struts 1.2
    */
   public class ActionConfigMatcher implements Serializable {
   
  @@ -89,6 +90,11 @@
        */
       private static final Log log =
           LogFactory.getLog(ActionConfigMatcher.class);
  +        
  +    /**
  +     * Handles all wildcard pattern matching.
  +     */
  +    private static final WildcardHelper wildcard = new WildcardHelper();
       
       /**  
        * The compiled paths and their associated ActionConfig's 
  @@ -117,18 +123,17 @@
                   if (log.isDebugEnabled()) {
                       log.debug("Compiling action config path '" + path + "'");
                   }    
  -                pattern = WildcardHelper.compilePattern(path);
  +                pattern = wildcard.compilePattern(path);
                   compiledPaths.add(new Mapping(pattern, configs[x]));
               }    
           }
       }
   
       /**
  -     *  Matches the path against the compiled wildcard patterns.
  +     * Matches the path against the compiled wildcard patterns.
        *
  -     * @param  path             The portion of the request URI for selecting a
  -     *      config
  -     * @return                  The action config if matched, else null
  +     * @param path The portion of the request URI for selecting a config.
  +     * @return The action config if matched, else null
        */
       public ActionConfig match(String path) {
   
  @@ -145,7 +150,7 @@
               HashMap vars = new HashMap();
               for (Iterator i = compiledPaths.iterator(); i.hasNext();) {
                   m = (Mapping) i.next();
  -                if (WildcardHelper.match(vars, path, m.getPattern())) {
  +                if (wildcard.match(vars, path, m.getPattern())) {
                       config = convertActionConfig(
                               path,
                               (ActionConfig) m.getActionConfig(),
  
  
  

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

Reply via email to