You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by st...@locus.apache.org on 2000/08/21 19:36:58 UTC

cvs commit: xml-cocoon/src/org/apache/cocoon/matching WildcardURIMatcherFactory.java

stefano     00/08/21 10:36:58

  Modified:    src/org/apache/cocoon/matching Tag: xml-cocoon2
                        WildcardURIMatcherFactory.java
  Log:
  wildcard matching now works
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.9   +49 -36    xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java
  
  Index: WildcardURIMatcherFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/matching/Attic/WildcardURIMatcherFactory.java,v
  retrieving revision 1.1.2.8
  retrieving revision 1.1.2.9
  diff -u -r1.1.2.8 -r1.1.2.9
  --- WildcardURIMatcherFactory.java	2000/08/04 21:11:53	1.1.2.8
  +++ WildcardURIMatcherFactory.java	2000/08/21 17:36:55	1.1.2.9
  @@ -4,12 +4,10 @@
    * This software is published under the terms of the Apache Software License * 
    * version 1.1, a copy of which has been included  with this distribution in * 
    * the LICENSE file.                                                         * 
  - *****************************************************************************/ 
  + *****************************************************************************/
  + 
   package org.apache.cocoon.matching; 
   
  -import org.apache.cocoon.sitemap.patterns.PatternTranslator; 
  -import org.apache.cocoon.sitemap.patterns.PatternException; 
  -
   import org.apache.avalon.ConfigurationException;
   
   import org.w3c.dom.DocumentFragment;
  @@ -19,20 +17,21 @@
    * for request URIs
    * 
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a> 
  - * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/08/04 21:11:53 $ 
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a> 
  + * @version CVS $Revision: 1.1.2.9 $ $Date: 2000/08/21 17:36:55 $ 
    */ 
   
  -public class WildcardURIMatcherFactory /*extends PatternTranslator*/ implements MatcherFactory {
  +public class WildcardURIMatcherFactory implements MatcherFactory {
   
       /** The int representing '*' in the pattern <code>int []</code>. */
  -    protected static final int MATCH_FILE=-1;
  +    protected static final int MATCH_FILE = -1;
       /** The int representing '**' in the pattern <code>int []</code>. */
  -    protected static final int MATCH_PATH=-2;
  +    protected static final int MATCH_PATH = -2;
       /** The int value that terminates the pattern <code>int []</code>. */
  -    protected static final int MATCH_END=-3;
  +    protected static final int MATCH_END = -3;
   
       /** The <code>int []</code> identifying the pattern to match. */
  -    protected int[] sourcePattern=null;
  +    protected int[] sourcePattern = null;
   
       /**
        * Generates the matcher method level source code
  @@ -58,10 +57,10 @@
           try {
               this.setPattern (pattern);
      
  -            result.append ("/* pattern=\""+pattern+"\" */")
  -                  .append ("int expr[] = {");
  +            result.append ("// wildcard pattern = \"" + pattern + "\"\n\t")
  +                  .append ("static int[] ").append(prefix).append("_expr = {");
   
  -            int j = sourcePattern.length-1;
  +            int j = sourcePattern.length - 1;
               char c;
               for (int i = 0; i < j; i++) {
                   result.append (sourcePattern[i])
  @@ -69,7 +68,7 @@
               }
               return result.append (sourcePattern[j])
                            .append ("};").toString();
  -        } catch (PatternException pe) {
  +        } catch (NullPointerException pe) {
               throw new ConfigurationException (pe.getMessage(), null);
           }
       }
  @@ -78,9 +77,9 @@
        * Set the pattern for matching.
        */
       public void setPattern(String pattern)
  -    throws PatternException {
  -        if (pattern==null) throw new PatternException("Null pattern");
  -        this.sourcePattern=this.convertPattern(pattern);
  +    throws NullPointerException {
  +        if (pattern == null) throw new NullPointerException("Pattern cannot be null");
  +        this.sourcePattern = this.convertPattern(pattern);
       }
   
       /**
  @@ -118,37 +117,51 @@
        */
       protected int[] convertPattern(String data)
       throws NullPointerException {
  +        
           // Prepare the arrays
  -        int expr[]=new int[data.length()+1];
  -        char buff[]=data.toCharArray();
  +        int expr[] = new int[data.length() + 1];
  +        char buff[] = data.toCharArray();
  +        
           // Prepare variables for the translation loop
  -        int y=0;
  -        boolean slash=false;
  -        if(buff[0]=='\\') slash=true;
  -        else if(buff[0]=='*') expr[y++]=MATCH_FILE;
  -        else expr[y++]=buff[0];
  +        int y = 0;
  +        boolean slash = false;
  +        
  +        if (buff[0]=='\\') {
  +            slash = true;
  +        } else if (buff[0] == '*') {
  +            expr[y++] = MATCH_FILE;
  +        }  else {
  +            expr[y++] = buff[0];
  +        }
  +        
           // Main translation loop
  -        for (int x=1; x<buff.length; x++) {
  +        for (int x = 1; x < buff.length; x++) {
               // If the previous char was '\' simply copy this char.
               if (slash) {
  -                expr[y++]=buff[x];
  -                slash=false;
  +                expr[y++] = buff[x];
  +                slash = false;
               // If the previous char was not '\' we have to do a bunch of checks
               } else {
  -                int prev=(y-1);
  +                int prev = (y - 1);
                   // If this char is '\' declare that and continue
  -                if(buff[x]=='\\') {
  -                    slash=true;
  +                if (buff[x] == '\\') {
  +                    slash = true;
                   // If this char is '*' check the previous one
  -                } else if(buff[x]=='*') {
  +                } else if (buff[x] == '*') {
                       // If the previous character als was '*' match a path
  -                    if(expr[y-1]<=MATCH_FILE) expr[y-1]=MATCH_PATH;
  -                    else expr[y++]=MATCH_FILE;
  -                } else expr[y++]=buff[x];
  +                    if (expr[y-1] <= MATCH_FILE) {
  +                        expr[y-1] = MATCH_PATH;
  +                    } else {
  +                        expr[y++] = MATCH_FILE;
  +                    }
  +                } else {
  +                    expr[y++]=buff[x];
  +                }
               }
           }
  +        
           // Declare the end of the array and return it
  -        expr[y]=MATCH_END;
  -        return(expr);
  +        expr[y] = MATCH_END;
  +        return expr;
       }        
   }