sylvain     01/10/19 08:28:46

  Modified:    .        changes.xml
               documentation sitemap.xmap
               src/org/apache/cocoon CodeFactory.java
               src/org/apache/cocoon/components/language/markup/sitemap/java
                        sitemap.xsl
               src/org/apache/cocoon/matching BrowserMatcherFactory.java
                        RegexpTargetHostMatcherFactory.java
                        RegexpURIMatcherFactory.java
                        WildcardHeaderMatcherFactory.java
                        WildcardParameterValueMatcherFactory.java
                        WildcardSessionAttributeMatcherFactory.java
                        WildcardURIMatcherFactory.java
               src/org/apache/cocoon/matching/helpers
                        WildcardURIMatcher.java
               src/org/apache/cocoon/sitemap PatternException.java
                        XSLTFactoryLoader.java
               webapp   sitemap.xmap
               webapp/i18n sitemap.xmap
               webapp/protected sitemap.xmap
               webapp/sitebuilder sitemap.xmap
               webapp/sub sitemap.xmap
               webapp.site sitemap.xmap
               webapp.tutorial sitemap.xmap
  Added:       src/org/apache/cocoon/matching AbstractRegexpMatcher.java
                        AbstractWildcardMatcher.java PreparedMatcher.java
                        RegexpTargetHostMatcher.java RegexpURIMatcher.java
                        WildcardHeaderMatcher.java
                        WildcardParameterValueMatcher.java
                        WildcardSessionAttributeMatcher.java
                        WildcardURIMatcher.java
               src/org/apache/cocoon/matching/helpers WildcardHelper.java
  Log:
  New PreparedMatcher interface, port of factory-based matcher and deprecation 
of CodeFactory.
  
  Revision  Changes    Path
  1.42      +9 -4      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- changes.xml       2001/10/17 10:06:24     1.41
  +++ changes.xml       2001/10/19 15:28:44     1.42
  @@ -1,10 +1,10 @@
   <?xml version="1.0"?>
   
  -<!DOCTYPE changes SYSTEM "./xdocs/dtd/changes-v10.dtd">
  +<!DOCTYPE changes SYSTEM "./documentation/xdocs/dtd/changes-v10.dtd">
   
   <!--
     History of Cocoon changes
  -  $Id: changes.xml,v 1.41 2001/10/17 10:06:24 sylvain Exp $
  +  $Id: changes.xml,v 1.42 2001/10/19 15:28:44 sylvain Exp $
   -->
   
   <changes title="History of Changes">
  @@ -26,6 +26,11 @@
    </devs>
   
    <release version="2.1-dev" date="@date@">
  +  <action dev="SW" type="add">
  +    New PreparedMatcher interface as a replacement for CodeFactory. All 
factory-based matchers have
  +    been rewritten using this new interface. CodeFactory shouldn't be used 
anymore in preparation of
  +    the tree traversal implementation of the sitemap.
  +  </action>
     <action dev="SW" type="fix">
       Reduce exception nesting in case of sitemap setup errors, and display 
all nested exceptions
       in the error page (avoids searching the logs for the failure cause).
  @@ -53,11 +58,11 @@
       Added RTF serialization of XSL-FO documents (requires jfor).
       Patch submitted by Bertrand Delacretaz [EMAIL PROTECTED]
       Applied patch for the SQLTransformer to output namespaces for the
  -    generated elements. Patch submitted by Per-Olof Nor�n [EMAIL PROTECTED]
  +    generated elements. Patch submitted by Per-Olof [EMAIL PROTECTED]
     </action>
     <action dev="CZ" type="update">
       Applied patch for the SQLTransformer to output namespaces for the
  -    generated elements. Patch submitted by Per-Olof Nor�n [EMAIL PROTECTED]
  +    generated elements. Patch submitted by Per-Olof [EMAIL PROTECTED]
     </action>
     <action dev="CZ" type="fix">
      Throw exception for internal requests instead of using the error handler 
and
  
  
  
  1.23      +1 -1      xml-cocoon2/documentation/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/documentation/sitemap.xmap,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- sitemap.xmap      2001/10/18 15:48:07     1.22
  +++ sitemap.xmap      2001/10/19 15:28:44     1.23
  @@ -34,7 +34,7 @@
     </map:serializers>
   
     <map:matchers default="wildcard">
  -   <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
  +   <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcher"/>
     </map:matchers>
    </map:components>
   
  
  
  
  1.5       +3 -1      xml-cocoon2/src/org/apache/cocoon/CodeFactory.java
  
  Index: CodeFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/CodeFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CodeFactory.java  2001/10/11 07:28:15     1.4
  +++ CodeFactory.java  2001/10/19 15:28:45     1.5
  @@ -21,7 +21,9 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2001/10/11 07:28:15 $
  + * @version CVS $Revision: 1.5 $ $Date: 2001/10/19 15:28:45 $
  + * @deprecated Shouldn't be used anymore to allow an intrepreded 
implementation
  + *             of the sitemap.
    */
   
   public interface CodeFactory {
  
  
  
  1.44      +92 -6     
xml-cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java/sitemap.xsl
  
  Index: sitemap.xsl
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java/sitemap.xsl,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- sitemap.xsl       2001/10/17 10:06:24     1.43
  +++ sitemap.xsl       2001/10/19 15:28:45     1.44
  @@ -107,6 +107,7 @@
       import org.apache.cocoon.environment.Environment;
       import org.apache.cocoon.environment.Redirector;
       import org.apache.cocoon.matching.Matcher;
  +    import org.apache.cocoon.matching.PreparedMatcher;
       import org.apache.cocoon.selection.Selector;
       import org.apache.cocoon.sitemap.AbstractSitemap;
       import org.apache.cocoon.components.pipeline.StreamPipeline;
  @@ -124,7 +125,7 @@
        *
        * @author &lt;a href="mailto:[EMAIL PROTECTED]"&gt;Giacomo 
Pati&lt;/a&gt;
        * @author &lt;a href="mailto:[EMAIL PROTECTED]"&gt;Berin 
Loritsch&lt;/a&gt;
  -     * @version CVS $Id: sitemap.xsl,v 1.43 2001/10/17 10:06:24 sylvain Exp $
  +     * @version CVS $Id: sitemap.xsl,v 1.44 2001/10/19 15:28:45 sylvain Exp $
        */
       public class <xsl:value-of select="@file-name"/> extends AbstractSitemap 
{
         static final String LOCATION = "<xsl:value-of 
select="translate(@file-path, '/', '.')"/>.<xsl:value-of select="@file-name"/>";
  @@ -137,7 +138,7 @@
         private Parameters emptyParam = new Parameters();
   
   
  -      <!-- Generate matchers which implements CodeFactory -->
  +      <!-- Generate matchers which implements CodeFactory or PreparedMatcher 
-->
         <xsl:for-each 
select="/map:sitemap/map:components/map:matchers/map:matcher">
           <xsl:call-template name="line-number"/>
           <xsl:variable name="src">
  @@ -164,6 +165,25 @@
               <xsl:value-of 
select="XSLTFactoryLoader:getClassSource($factory-loader,string($src),string($matcher-name),string(@pattern),$config)"/>
             </xsl:for-each>
           </xsl:if>
  +
  +        <xsl:if test="XSLTFactoryLoader:isPreparedMatcher($factory-loader, 
string($src))">
  +          <xsl:variable name="name" select="@name"/>
  +          <!--xsl:variable name="type" select="translate(@name, '- ', 
'__')"/-->
  +          <xsl:variable name="default" select="@name = ../@default"/>
  +
  +          <!-- process all map:match elements with a type attribute refering 
to the current matcher factory iteration -->
  +          <xsl:for-each 
select="/map:sitemap/map:pipelines/map:pipeline/descendant-or-self::map:[EMAIL 
PROTECTED] or (not(@type) and $default)]">
  +            <xsl:call-template name="line-number"/>
  +            <xsl:variable name="matcher-name">
  +              <xsl:call-template name="generate-name">
  +                <xsl:with-param name="prefix">matcher_</xsl:with-param>
  +                <xsl:with-param name="suffix"><xsl:value-of 
select="$name"/>_<xsl:value-of select="generate-id(.)"/></xsl:with-param>
  +              </xsl:call-template>
  +            </xsl:variable>
  +            // The prepared pattern for "<xsl:value-of select="@pattern"/>"
  +            private Object <xsl:value-of select="$matcher-name"/>_expr;
  +          </xsl:for-each>
  +        </xsl:if>
         </xsl:for-each>
   
   
  @@ -210,6 +230,18 @@
         }
   
         /**
  +       * Method that handles prepared matchers.
  +       */
  +      private Map preparedMatches(String hint, Object preparedPattern, List 
listOfMaps, Parameters params, Map objectModel) throws Exception {
  +        PreparedMatcher matcher = 
(PreparedMatcher)this.matchers.select(hint);
  +        try {
  +          return matcher.match(preparedPattern, objectModel, params);
  +        } finally {
  +          this.matchers.release(matcher);
  +        }
  +      }
  +
  +      /**
          * Method that handles non-factory matchers.
          */
         private Map matches(String hint, String patternValue, List listOfMaps, 
Parameters params, Map objectModel) throws Exception {
  @@ -253,6 +285,7 @@
             this.readers.initialize();
             this.actions.initialize();
             this.matchers.initialize();
  +          this.prepareMatchers();
             this.selectors.initialize();
   
             this.manager.initialize();
  @@ -338,6 +371,42 @@
           }
         }
   
  +      /** Prepare patterns of PreparedMatchers. */
  +      public void prepareMatchers() throws Exception {
  +
  +        <!-- Prepare patterns for PreparedMatchers -->
  +        PreparedMatcher matcher = null;
  +      <xsl:for-each 
select="/map:sitemap/map:components/map:matchers/map:matcher">
  +        <xsl:call-template name="line-number"/>
  +        <xsl:variable name="src">
  +          <xsl:value-of select="@src"/>
  +        </xsl:variable>
  +
  +        <xsl:if test="XSLTFactoryLoader:isPreparedMatcher($factory-loader, 
string($src))">
  +          <xsl:variable name="name" select="@name"/>
  +          <!--xsl:variable name="type" select="translate(@name, '- ', 
'__')"/-->
  +          <xsl:variable name="default" select="@name = ../@default"/>
  +
  +          // Prepare patterns for matcher '<xsl:value-of select="@name"/>'
  +          matcher = (PreparedMatcher)this.matchers.select("<xsl:value-of 
select="@name"/>");
  +
  +          <!-- process all map:match elements with a type attribute refering 
to the current matcher factory iteration -->
  +          <xsl:for-each 
select="/map:sitemap/map:pipelines/map:pipeline/descendant-or-self::map:[EMAIL 
PROTECTED] or (not(@type) and $default)]">
  +            <xsl:call-template name="line-number"/>
  +            <xsl:variable name="matcher-name">
  +              <xsl:call-template name="generate-name">
  +                <xsl:with-param name="prefix">matcher_</xsl:with-param>
  +                <xsl:with-param name="suffix"><xsl:value-of 
select="$name"/>_<xsl:value-of select="generate-id(.)"/></xsl:with-param>
  +              </xsl:call-template>
  +            </xsl:variable>
  +            // Prepare the pattern for "<xsl:value-of select="@pattern"/>"
  +            this.<xsl:value-of select="$matcher-name"/>_expr = 
matcher.preparePattern("<xsl:value-of 
select="XSLTFactoryLoader:escape($factory-loader, @pattern)"/>");
  +          </xsl:for-each>
  +          this.matchers.release(matcher);
  +        </xsl:if>
  +      </xsl:for-each>
  +      }
  +
         <!-- generate methods for every map:resource element -->
         <xsl:for-each select="/map:sitemap/map:resources/map:resource">
           <xsl:call-template name="line-number"/>
  @@ -642,6 +711,11 @@
         <xsl:value-of select="XSLTFactoryLoader:isFactory($factory-loader, 
string(/map:sitemap/map:components/map:matchers/map:[EMAIL PROTECTED]/@src))"/>
       </xsl:variable>
   
  +    <!-- check if this matcher is a prepared matcher ? -->
  +    <xsl:variable name="is-prepared">
  +      <xsl:value-of 
select="XSLTFactoryLoader:isPreparedMatcher($factory-loader, 
string(/map:sitemap/map:components/map:matchers/map:[EMAIL PROTECTED]/@src))"/>
  +    </xsl:variable>
  +
       <!-- break on error when old parameter syntax exists -->
       <xsl:if test="parameter">
         <xsl:call-template name="error">
  @@ -678,8 +752,11 @@
           <xsl:when test="string($is-factory)='true'">
             <xsl:value-of select="translate($matcher-type, '- ', 
'__')"/>Match(<xsl:value-of select="$matcher-name2"/>_expr, objectModel, 
<xsl:value-of select="$component-param"/>)
           </xsl:when>
  +        <xsl:when test="string($is-prepared)='true'">
  +          preparedMatches("<xsl:value-of select="$matcher-type"/>", 
<xsl:value-of select="$matcher-name2"/>_expr, listOfMaps, <xsl:value-of 
select="$component-param"/>, objectModel)
  +        </xsl:when>
           <xsl:otherwise>
  -          matches("<xsl:value-of select="$matcher-type"/>", "<xsl:value-of 
select="$pattern-value"/>", listOfMaps, <xsl:value-of 
select="$component-param"/>, objectModel)
  +          matches("<xsl:value-of select="$matcher-type"/>", "<xsl:value-of 
select="XSLTFactoryLoader:escape($factory-loader, $pattern-value)"/>", 
listOfMaps, <xsl:value-of select="$component-param"/>, objectModel)
           </xsl:otherwise>
         </xsl:choose>
       </xsl:variable>
  @@ -687,7 +764,7 @@
       <!-- this is the actual code produced -->
       // handling "<xsl:value-of select="@pattern"/>"
           if ((map = <xsl:value-of select="$matcher-name"/>) != null) {
  -          getLogger().debug("Matched <xsl:value-of 
select="$matcher-type"/><xsl:text> </xsl:text><xsl:value-of 
select="$matcher-name2"/><xsl:text> </xsl:text>pattern:<xsl:value-of 
select="@pattern"/>");
  +          getLogger().debug("Matched <xsl:value-of 
select="$matcher-type"/><xsl:text> </xsl:text><xsl:value-of 
select="$matcher-name2"/><xsl:text> </xsl:text>pattern:<xsl:value-of 
select="XSLTFactoryLoader:escape($factory-loader, @pattern)"/>");
             listOfMaps.add (map);
             <xsl:apply-templates/>
             listOfMaps.remove (listOfMaps.size()-1);
  @@ -728,6 +805,10 @@
         <xsl:value-of select="XSLTFactoryLoader:isFactory($factory-loader, 
string(/map:sitemap/map:components/map:matchers/map:[EMAIL PROTECTED]/@src))"/>
       </xsl:variable>
   
  +    <xsl:variable name="is-prepared">
  +      <xsl:value-of 
select="XSLTFactoryLoader:isPreparedMatcher($factory-loader, 
string(/map:sitemap/map:components/map:matchers/map:[EMAIL PROTECTED]/@src))"/>
  +    </xsl:variable>
  +
       <!-- break on error when old parameter syntax exists -->
       <xsl:if test="parameter">
         <xsl:call-template name="error">
  @@ -764,8 +845,13 @@
           <xsl:when test="string($is-factory)='true'">
             <xsl:value-of select="translate($matcher-type, '- ', 
'__')"/>Match(<xsl:value-of select="$matcher-name2"/>_expr, objectModel, 
<xsl:value-of select="$component-param"/>)
           </xsl:when>
  +
  +        <xsl:when test="string($is-prepared)='true'">
  +          <xsl:text>preparedMatches("</xsl:text><xsl:value-of 
select="$matcher-type"/>", <xsl:value-of select="$matcher-name2"/>_expr, 
listOfMaps, <xsl:value-of select="$component-param"/><xsl:text>, 
objectModel)</xsl:text>
  +        </xsl:when>
  +
           <xsl:otherwise>
  -          <xsl:text>((Matcher)this.matchers.select(</xsl:text>"<xsl:value-of 
select="$matcher-type"/>")).match(substitute(listOfMaps,"<xsl:value-of 
select="$pattern-value"/>"), objectModel, <xsl:value-of 
select="$component-param"/><xsl:text>)</xsl:text>
  +          <xsl:text>matches("</xsl:text><xsl:value-of 
select="$matcher-type"/>", "<xsl:value-of 
select="XSLTFactoryLoader:escape($factory-loader, $pattern-value)"/>", 
listOfMaps, <xsl:value-of select="$component-param"/><xsl:text>, 
objectModel)</xsl:text>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:variable>
  @@ -785,7 +871,7 @@
           String cocoon_action = environment.getAction();
   
           if ((map = <xsl:value-of select="$matcher-name"/>) != null) {
  -          getLogger().debug("Matched <xsl:value-of select="$matcher-type"/> 
<xsl:value-of select="$matcher-name2"/><xsl:text> 
</xsl:text>pattern:<xsl:value-of select="@pattern"/>");
  +          getLogger().debug("Matched <xsl:value-of select="$matcher-type"/> 
<xsl:value-of select="$matcher-name2"/><xsl:text> 
</xsl:text>pattern:<xsl:value-of 
select="XSLTFactoryLoader:escape($factory-loader, @pattern)"/>");
             listOfMaps.add (map);
             <xsl:apply-templates/>
             listOfMaps.remove (listOfMaps.size()-1);
  
  
  
  1.7       +2 -1      
xml-cocoon2/src/org/apache/cocoon/matching/BrowserMatcherFactory.java
  
  Index: BrowserMatcherFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/matching/BrowserMatcherFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BrowserMatcherFactory.java        2001/10/11 07:28:22     1.6
  +++ BrowserMatcherFactory.java        2001/10/19 15:28:45     1.7
  @@ -19,7 +19,8 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version CVS $Revision: 1.6 $ $Date: 2001/10/11 07:28:22 $
  + * @version CVS $Revision: 1.7 $ $Date: 2001/10/19 15:28:45 $
  + * @deprecated code factories are replaced by PreparedMatcher
    */
   
   public class BrowserMatcherFactory implements CodeFactory {
  
  
  
  1.5       +2 -1      
xml-cocoon2/src/org/apache/cocoon/matching/RegexpTargetHostMatcherFactory.java
  
  Index: RegexpTargetHostMatcherFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/matching/RegexpTargetHostMatcherFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RegexpTargetHostMatcherFactory.java       2001/10/11 07:28:22     1.4
  +++ RegexpTargetHostMatcherFactory.java       2001/10/19 15:28:45     1.5
  @@ -23,7 +23,8 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Paul Russell</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2001/10/11 07:28:22 $
  + * @version CVS $Revision: 1.5 $ $Date: 2001/10/19 15:28:45 $
  + * @deprecated code factories are replaced by PreparedMatcher
    */
   
   public class RegexpTargetHostMatcherFactory extends AbstractLoggable 
implements CodeFactory {
  
  
  
  1.5       +2 -1      
xml-cocoon2/src/org/apache/cocoon/matching/RegexpURIMatcherFactory.java
  
  Index: RegexpURIMatcherFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/matching/RegexpURIMatcherFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RegexpURIMatcherFactory.java      2001/10/11 07:28:22     1.4
  +++ RegexpURIMatcherFactory.java      2001/10/19 15:28:45     1.5
  @@ -21,7 +21,8 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2001/10/11 07:28:22 $
  + * @version CVS $Revision: 1.5 $ $Date: 2001/10/19 15:28:45 $
  + * @deprecated code factories are replaced by PreparedMatcher
    */
   
   public class RegexpURIMatcherFactory extends AbstractLoggable implements 
CodeFactory {
  
  
  
  1.8       +2 -1      
xml-cocoon2/src/org/apache/cocoon/matching/WildcardHeaderMatcherFactory.java
  
  Index: WildcardHeaderMatcherFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/matching/WildcardHeaderMatcherFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WildcardHeaderMatcherFactory.java 2001/10/11 07:28:22     1.7
  +++ WildcardHeaderMatcherFactory.java 2001/10/19 15:28:45     1.8
  @@ -22,7 +22,8 @@
    * </table>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
  - * @version CVS $Revision: 1.7 $ $Date: 2001/10/11 07:28:22 $
  + * @version CVS $Revision: 1.8 $ $Date: 2001/10/19 15:28:45 $
  + * @deprecated code factories are replaced by PreparedMatcher
    */
   
   public class WildcardHeaderMatcherFactory extends WildcardURIMatcherFactory {
  
  
  
  1.8       +2 -1      
xml-cocoon2/src/org/apache/cocoon/matching/WildcardParameterValueMatcherFactory.java
  
  Index: WildcardParameterValueMatcherFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/matching/WildcardParameterValueMatcherFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WildcardParameterValueMatcherFactory.java 2001/10/11 07:28:22     1.7
  +++ WildcardParameterValueMatcherFactory.java 2001/10/19 15:28:45     1.8
  @@ -26,7 +26,8 @@
    * </table>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
  - * @version CVS $Revision: 1.7 $ $Date: 2001/10/11 07:28:22 $ */
  + * @deprecated code factories are replaced by PreparedMatcher
  + * @version CVS $Revision: 1.8 $ $Date: 2001/10/19 15:28:45 $ */
   
   public class WildcardParameterValueMatcherFactory extends 
WildcardURIMatcherFactory {
   
  
  
  
  1.5       +2 -1      
xml-cocoon2/src/org/apache/cocoon/matching/WildcardSessionAttributeMatcherFactory.java
  
  Index: WildcardSessionAttributeMatcherFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/matching/WildcardSessionAttributeMatcherFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WildcardSessionAttributeMatcherFactory.java       2001/10/11 07:28:22     
1.4
  +++ WildcardSessionAttributeMatcherFactory.java       2001/10/19 15:28:45     
1.5
  @@ -21,7 +21,8 @@
    * </table>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2001/10/11 07:28:22 $
  + * @version CVS $Revision: 1.5 $ $Date: 2001/10/19 15:28:45 $
  + * @deprecated code factories are replaced by PreparedMatcher
    */
   
   public class WildcardSessionAttributeMatcherFactory extends 
WildcardURIMatcherFactory {
  
  
  
  1.5       +2 -1      
xml-cocoon2/src/org/apache/cocoon/matching/WildcardURIMatcherFactory.java
  
  Index: WildcardURIMatcherFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/matching/WildcardURIMatcherFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WildcardURIMatcherFactory.java    2001/10/11 07:28:22     1.4
  +++ WildcardURIMatcherFactory.java    2001/10/19 15:28:45     1.5
  @@ -19,7 +19,8 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2001/10/11 07:28:22 $
  + * @version CVS $Revision: 1.5 $ $Date: 2001/10/19 15:28:45 $
  + * @deprecated code factories are replaced by PreparedMatcher
    */
   
   public class WildcardURIMatcherFactory extends AbstractLoggable implements 
CodeFactory {
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/AbstractRegexpMatcher.java
  
  Index: AbstractRegexpMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.regexp.RE;
  import org.apache.regexp.RECompiler;
  import org.apache.regexp.REProgram;
  import org.apache.regexp.RESyntaxException;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * Base class for all matchers using a regular expression pattern.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @authos <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  
  public abstract class AbstractRegexpMatcher extends AbstractLoggable 
implements PreparedMatcher, ThreadSafe {
  
      /**
       * Compile the pattern in a <code>org.apache.regexp.REProgram</code>.
       */
      public Object preparePattern(String pattern) throws PatternException {
          try {
              RECompiler compiler = new RECompiler();
              REProgram program = compiler.compile(pattern);
              return program;
              
          } catch (RESyntaxException rse) {
              getLogger().debug("Failed to compile the pattern '" + pattern + 
"'", rse);
              throw new PatternException(rse.getMessage(), rse);
          }
      }
      
      /**
       * Match the prepared pattern against the value returned by [EMAIL 
PROTECTED] #getMatchString()}.
       */
      public Map match(Object preparedPattern, Map objectModel, Parameters 
parameters) {
          
          RE re = new RE((REProgram)preparedPattern);
          String match = getMatchString(objectModel, parameters);
          
          if (match == null)
              return null;
          
          if(re.match(match)) {
              /* Handle parenthesised subexpressions. XXX: could be faster if 
we count
               * parens *outside* the generated code.
               * Note: *ONE* based, not zero.
               */
              int parenCount = re.getParenCount();
              Map map = new HashMap();
              for (int paren = 1; paren <= parenCount; paren++) {
                  map.put(Integer.toString(paren), re.getParen(paren));
              }
  
              return map;
          }
          
          return null;
      }
      
      /**
       * Get the string to test against the regular expression. To be defined
       * by concrete subclasses.
       */
      protected abstract String getMatchString(Map objectModel, Parameters 
parameters);
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/AbstractWildcardMatcher.java
  
  Index: AbstractWildcardMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.matching.helpers.WildcardHelper;
  
  import java.util.HashMap;
  import java.util.Map;
  
  
  /**
   * Base class for wildcard matchers
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  
  public abstract class AbstractWildcardMatcher extends AbstractLoggable 
implements PreparedMatcher, ThreadSafe {
  
      /**
       * Compile the pattern in an <code>int[]</code>.
       */
      public Object preparePattern(String pattern) {
          return WildcardHelper.compilePattern(pattern);
      }
      
      /**
       * Match the prepared pattern against the result of [EMAIL PROTECTED] 
#getMatchString()}.
       */
      public Map match(Object preparedPattern, Map objectModel, Parameters 
parameters) {
          
          String match = getMatchString(objectModel, parameters);
          
          if (match == null) {
              return null;
          }
          
          HashMap map = new HashMap();
          
          if (WildcardHelper.match(map, match, (int[])preparedPattern)) {
              return map;
          } else {
              return null;
          }
      }
      
      /**
       * Get the string to test against the wildcard expression. To be defined
       * by concrete subclasses.
       */
      protected abstract String getMatchString(Map objectModel, Parameters 
parameters);
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/PreparedMatcher.java
  
  Index: PreparedMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.component.Component;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.sitemap.PatternException;
  
  import java.util.Map;
  
  /**
   * A matcher that can prepare patterns during sitemap setup for faster match 
at request time.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  public interface PreparedMatcher extends Component {
  
      /**
       * Prepares a pattern in a form that allows faster match. For example, a 
regular
       * expression matcher can precompile the expression and return the 
corresponding
       * object. This method is called once for each pattern used with a 
particular matcher
       * class. The returned value is then passed back as the 
<code>preparedPattern</code>
       * parameter of [EMAIL PROTECTED] #match()}.
       *
       * @param pattern The pattern to prepare. Depending on the implementation 
the pattern
       *                can contain wildcards or regular expressions.
       * @return an optimized representation of the pattern.
       * @throws a <code>PatternException</code> if the pattern couldn't be 
prepared.
       */
      Object preparePattern(String pattern) throws PatternException;
  
      /**
       * Matches the prepared pattern against some values in the object model 
(most often the
       * <code>Request</code) and returns a <code>Map</code> object with 
replacements
       * for wildcards contained in the pattern.
       *
       * @param preparedPattern The preparedPattern to match against, as 
returned by [EMAIL PROTECTED] #preparePattern()}.
       * @param objectModel     The <code>Map</code> with objects of the 
calling environment
       *                        which can be used to select values this 
matchers matches against.
       * @return                a <code>Map</code> object with replacements for 
wildcards/regular-expressions
       *                        contained in the pattern. If the return value 
is null there was no match.
       */
      Map match(Object preparedPattern, Map objectModel, Parameters parameters);
  }
  
  
  
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/RegexpTargetHostMatcher.java
  
  Index: RegexpTargetHostMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import java.util.Map;
  
  
  /**
   * Matches the target host ("Host" request header) against a regular 
expression.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Paul Russell</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  
  public class RegexpTargetHostMatcher extends AbstractRegexpMatcher {
  
      protected String getMatchString(Map objectModel, Parameters parameters) {
          return ObjectModelHelper.getRequest(objectModel).getHeader("Host");
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/RegexpURIMatcher.java
  
  Index: RegexpURIMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.sitemap.PatternException;
  
  import org.apache.regexp.RE;
  import org.apache.regexp.RECompiler;
  import org.apache.regexp.REProgram;
  import org.apache.regexp.RESyntaxException;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * Matches the request URIs against a regular expression pattern.
   *
   * @authos <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  
  public class RegexpURIMatcher extends AbstractRegexpMatcher {
  
      /**
       * Return the request URI.
       */
      protected String getMatchString(Map objectModel, Parameters parameters) {
          String uri = 
ObjectModelHelper.getRequest(objectModel).getSitemapURI();
          
          if (uri.startsWith("/")) {
              uri = uri.substring(1);
          }
          
          return uri;
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/WildcardHeaderMatcher.java
  
  Index: WildcardHeaderMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  
  import java.util.Map;
  
  /**
   * Matches a request header (e.g. "referer") against a wildcard expression.
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>header-name</code></td><td>Name of the request header to
   * match against</td></tr>
   * </table>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  
  public class WildcardHeaderMatcher extends AbstractWildcardMatcher implements 
Configurable {
  
      private String defaultParam;
  
      public void configure(Configuration config) throws ConfigurationException 
{
          // Check old name
          this.defaultParam = config.getChild("parameter-name").getValue(null);
          if (defaultParam != null) {
              getLogger().warn("'parameter-name' is deprecated. Please use 
'header-name'");
          }
          // Load with new one
          this.defaultParam = 
config.getChild("header-name").getValue(this.defaultParam);
      }
  
      protected String getMatchString(Map objectModel, Parameters parameters) {
          
          // Check old name
          String paramName = parameters.getParameter("parameter-name", null);
          if (paramName != null) {
              getLogger().warn("'parameter-name' is deprecated. Please use 
'header-name'");
          } else {
              paramName = this.defaultParam;
          }
          
          // Load with new one.
          paramName = parameters.getParameter("header-name", paramName);
          
          if (paramName == null) {
              getLogger().warn("No header name given. FAILING");
              return null;
          }
          
          String result = 
ObjectModelHelper.getRequest(objectModel).getHeader(paramName);
          if (result == null) {
              getLogger().debug("Header '" + paramName + "' not set.");
          }
          
          return result;
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/WildcardParameterValueMatcher.java
  
  Index: WildcardParameterValueMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  
  import java.util.Map;
  
  /**
   * Matches a request parameter against a wildcard expression.
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>parameter-name</code></td><td>Name of the request parameter 
to
   * match against</td></tr>
   * </table>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  
  public class WildcardParameterValueMatcher extends AbstractWildcardMatcher 
implements Configurable {
  
      private String defaultParam;
  
      public void configure(Configuration config) throws ConfigurationException 
{
          this.defaultParam = config.getChild("parameter-name").getValue(null);
      }
  
      protected String getMatchString(Map objectModel, Parameters parameters) {
          
          String paramName = parameters.getParameter("parameter-name", 
this.defaultParam);
          if (paramName == null) {
              getLogger().warn("No header name given. FAILING");
              return null;
          }
          
          String result = 
ObjectModelHelper.getRequest(objectModel).getParameter(paramName);
          if (result == null) {
              getLogger().debug("Header '" + paramName + "' not set.");
          }
          
          return result;
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/WildcardSessionAttributeMatcher.java
  
  Index: WildcardSessionAttributeMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  
  import java.util.Map;
  
  /**
   * Matches a session attribute against a wildcard expression.
   *
   * <p><b>Global and local configuration</b></p>
   * <tableborder="1">
   * <tr><td><code>attribute-name</code></td><td>String identifying the session 
attribute</td></tr>
   * </table>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  
  public class WildcardSessionAttributeMatcher extends 
WildcardURIMatcherFactory {
  
      private String defaultParam;
  
      public void configure(Configuration config) throws ConfigurationException 
{
          this.defaultParam = config.getChild("attribute-name").getValue(null);
      }
  
      protected String getMatchString(Map objectModel, Parameters parameters) {
          
          String paramName = parameters.getParameter("attribute-name", 
this.defaultParam);
          if (paramName == null) {
              getLogger().warn("No attribute name given. FAILING");
              return null;
          }
          
          String result = 
(String)ObjectModelHelper.getRequest(objectModel).getSession().getAttribute(paramName);
          if (result == null) {
              getLogger().debug("Session attribute '" + paramName + "' not 
set.");
          }
          
          return result;
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/WildcardURIMatcher.java
  
  Index: WildcardURIMatcher.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import org.apache.cocoon.environment.ObjectModelHelper;
  
  import java.util.HashMap;
  import java.util.Map;
  
  
  /**
   * Match the request URI against a regular expression.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  
  public class WildcardURIMatcher extends AbstractWildcardMatcher {
  
      /**
       * Return the request URI.
       */
      protected String getMatchString(Map objectModel, Parameters parameters) {
          String uri = 
ObjectModelHelper.getRequest(objectModel).getSitemapURI();
          
          if (uri.startsWith("/")) {
              uri = uri.substring(1);
          }
          
          return uri;
      }
  }
  
  
  
  1.2       +2 -1      
xml-cocoon2/src/org/apache/cocoon/matching/helpers/WildcardURIMatcher.java
  
  Index: WildcardURIMatcher.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/matching/helpers/WildcardURIMatcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WildcardURIMatcher.java   2001/05/09 20:49:40     1.1
  +++ WildcardURIMatcher.java   2001/10/19 15:28:45     1.2
  @@ -17,7 +17,8 @@
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/05/09 20:49:40 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/10/19 15:28:45 $
  + * @deprecated renamed to WildcardHelper
    */
   public class WildcardURIMatcher {
   
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/helpers/WildcardHelper.java
  
  Index: WildcardHelper.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * 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.helpers;
  
  import java.util.HashMap;
  
  /**
   * This class is an utility class that perform wilcard-patterns matching and
   * isolation.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
   *         (Apache Software Foundation, Exoffice Technologies)
   * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/10/19 15:28:45 $
   */
  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;
  
  
      /**
       * Translate the given <code>String</code> into a <code>int []</code>
       * representing the pattern matchable by this class.
       * <br>
       * This function translates a <code>String</code> into an int array
       * converting the special '*' and '\' characters.
       * <br>
       * Here is how the conversion algorithm works:
       * <ul>
       *   <li>The '*' character is converted to MATCH_FILE, meaning that zero
       *        or more characters (excluding the path separator '/') are to
       *        be matched.</li>
       *   <li>The '**' sequence is converted to MATCH_PATH, meaning that zero
       *       or more characters (including the path separator '/') are to
       *        be matched.</li>
       *   <li>The '\' character is used as an escape sequence ('\*' is
       *       translated in '*', not in MATCH_FILE). If an exact '\' character
       *       is to be matched the source string must contain a '\\'.
       *       sequence.</li>
       * </ul>
       * When more than two '*' characters, not separated by another character,
       * are found their value is considered as '**' (MATCH_PATH).
       * <br>
       * The array is always terminated by a special value (MATCH_END).
       * <br>
       * All MATCH* values are less than zero, while normal characters are equal
       * or greater.
       *
       * @parameter data The string to translate.
       * @return The encoded string as an int array, terminated by the MATCH_END
       *         value (don't consider the array length).
       * @exception NullPointerException If data is null.
       */
      public static int[] compilePattern(String data)
      throws NullPointerException {
  
          // Prepare the arrays
          int expr[] = new int[data.length() + 2];
          char buff[] = data.toCharArray();
  
          // Prepare variables for the translation loop
          int y = 0;
          boolean slash = false;
  
          // Must start from beginning
          expr[y++] = MATCH_BEGIN;
  
          if (buff.length > 0) {
              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++) {
                  // If the previous char was '\' simply copy this char.
                  if (slash) {
                      expr[y++] = buff[x];
                      slash = false;
                  // If the previous char was not '\' we have to do a bunch of 
checks
                  } else {
                      // If this char is '\' declare that and continue
                      if (buff[x] == '\\') {
                          slash = true;
                      // If this char is '*' check the previous one
                      } 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];
                      }
                  }
              }
          }
  
          // Must match end at the end
          expr[y] = MATCH_THEEND;
          return expr;
      }
      
      /**
       * match a pattern agains a string and isolates wildcard replacement into 
a
       * <code>Stack</code>.
       */
      public static boolean match (HashMap map, String data,
              int[] expr) throws NullPointerException {
          if (map == null)
              throw new NullPointerException ("No map provided");
          if (data == null)
              throw new NullPointerException ("No data provided");
          if (expr == null)
              throw new NullPointerException ("No pattern expression provided");
  
  
          char buff[] = data.toCharArray();
          // Allocate the result buffer
          char rslt[] = new char[expr.length + buff.length];
  
  
          // The previous and current position of the expression character
          // (MATCH_*)
          int charpos = 0;
  
          // The position in the expression, input, translation and result 
arrays
          int exprpos = 0;
          int buffpos = 0;
          int rsltpos = 0;
          int offset = -1;
  
          // The matching count
          int mcount = 0;
  
          // First check for MATCH_BEGIN
          boolean matchBegin = false;
          if (expr[charpos] == MATCH_BEGIN) {
              matchBegin = true;
              exprpos = ++charpos;
          }
  
          // Search the fist expression character (except MATCH_BEGIN - already 
skipped)
          while (expr[charpos] >= 0)
              charpos++;
  
          // The expression charater (MATCH_*)
          int exprchr = expr[charpos];
  
          while (true) {
              // Check if the data in the expression array before the current
              // expression character matches the data in the input buffer
              if (matchBegin) {
                  if (!matchArray(expr, exprpos, charpos, buff, buffpos))
                      return (false);
                  matchBegin = false;
              } else {
                  offset = indexOfArray (expr, exprpos, charpos, buff,
                          buffpos);
                  if (offset < 0)
                      return (false);
              }
  
              // Check for MATCH_BEGIN
              if (matchBegin) {
                  if (offset != 0)
                      return (false);
                  matchBegin = false;
              }
  
              // Advance buffpos
              buffpos += (charpos - exprpos);
  
              // Check for END's
              if (exprchr == MATCH_END) {
                  if (rsltpos > 0)
                      map.put(Integer.toString(++mcount),new String(rslt, 0, 
rsltpos));
                  // Don't care about rest of input buffer
                  return (true);
              } else if (exprchr == MATCH_THEEND) {
                  if (rsltpos > 0)
                      map.put (Integer.toString(++mcount),new String(rslt, 0, 
rsltpos));
                  // Check that we reach buffer's end
                  return (buffpos == buff.length);
              }
  
              // Search the next expression character
              exprpos = ++charpos;
              while (expr[charpos] >= 0)
                  charpos++;
              int prevchr = exprchr;
              exprchr = expr[charpos];
  
              // We have here prevchr == * or **.
              offset = (prevchr == MATCH_FILE) ?
                      indexOfArray (expr, exprpos, charpos, buff, buffpos) :
                      lastIndexOfArray (expr, exprpos, charpos, buff,
                      buffpos);
  
              if (offset < 0)
                  return (false);
  
              // Copy the data from the source buffer into the result buffer
              // to substitute the expression character
              if (prevchr == MATCH_PATH) {
                  while (buffpos < offset)
                      rslt[rsltpos++] = buff[buffpos++];
              } else {
                  // Matching file, don't copy '/'
                  while (buffpos < offset) {
                      if (buff[buffpos] == '/')
                          return (false);
                      rslt[rsltpos++] = buff[buffpos++];
                  }
              }
  
              map.put(Integer.toString(++mcount),new String (rslt, 0, rsltpos));
              rsltpos = 0;
          }
      }
  
      /**
        * 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
        * that part of array specified by r, starting at rpos and terminating at
        * rend.
        *
        * @param r The array containing the data that need to be matched in d.
        * @param rpos The index of the first character in r to look for.
        * @param rend The index of the last character in r to look for plus 1.
        * @param d The array of char that should contain a part of r.
        * @param dpos The starting offset in d for the matching.
        * @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,
              char d[], int dpos) {
          // Check if pos and len are legal
          if (rend < rpos)
              throw new IllegalArgumentException ("rend < rpos");
          // If we need to match a zero length string return current dpos
          if (rend == rpos)
              return (d.length); //?? dpos?
          // If we need to match a 1 char length string do it simply
          if ((rend - rpos) == 1) {
              // Search for the specified character
              for (int x = dpos; x < d.length; x++)
                  if (r[rpos] == d[x])
                      return (x);
          }
          // Main string matching loop. It gets executed if the characters to
          // match are less then the characters left in the d buffer
          while ((dpos + rend - rpos) <= d.length) {
              // Set current startpoint in d
              int y = dpos;
              // Check every character in d for equity. If the string is matched
              // return dpos
              for (int x = rpos; x <= rend; x++) {
                  if (x == rend)
                      return (dpos);
                  if (r[x] != d[y++])
                      break;
              }
              // Increase dpos to search for the same string at next offset
              dpos++;
          }
          // The remaining chars in d buffer were not enough or the string
          // wasn't matched
          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
        * that part of array specified by r, starting at rpos and terminating at
        * rend.
        *
        * @param r The array containing the data that need to be matched in d.
        * @param rpos The index of the first character in r to look for.
        * @param rend The index of the last character in r to look for plus 1.
        * @param d The array of char that should contain a part of r.
        * @param dpos The starting offset in d for the matching.
        * @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,
              char d[], int dpos) {
          // Check if pos and len are legal
          if (rend < rpos)
              throw new IllegalArgumentException ("rend < rpos");
          // If we need to match a zero length string return current dpos
          if (rend == rpos)
              return (d.length); //?? dpos?
  
          // If we need to match a 1 char length string do it simply
          if ((rend - rpos) == 1) {
              // Search for the specified character
              for (int x = d.length - 1; x > dpos; x--)
                  if (r[rpos] == d[x])
                      return (x);
          }
  
          // Main string matching loop. It gets executed if the characters to
          // match are less then the characters left in the d buffer
          int l = d.length - (rend - rpos);
          while (l >= dpos) {
              // Set current startpoint in d
              int y = l;
              // Check every character in d for equity. If the string is matched
              // return dpos
              for (int x = rpos; x <= rend; x++) {
                  if (x == rend)
                      return (l);
                  if (r[x] != d[y++])
                      break;
              }
              // Decrease l to search for the same string at next offset
              l--;
          }
          // The remaining chars in d buffer were not enough or the string
          // wasn't matched
          return (-1);
      }
  
      /**
        * Matches elements of array r from rpos to rend with array d, starting 
from dpos.
        * <br>
        * This method return true if elements of array r from rpos to rend
        * equals elements of array d starting from dpos to dpos+(rend-rpos).
        *
        * @param r The array containing the data that need to be matched in d.
        * @param rpos The index of the first character in r to look for.
        * @param d The array of char that should start from a part of r.
        * @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,
              char d[], int dpos) {
          if (d.length - dpos < rend - rpos)
              return (false);
          for (int i = rpos; i < rend; i++)
              if (r[i] != d[dpos++])
                  return (false);
          return (true);
      }
  }
  
  
  
  1.3       +24 -3     
xml-cocoon2/src/org/apache/cocoon/sitemap/PatternException.java
  
  Index: PatternException.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/PatternException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PatternException.java     2001/06/08 20:28:26     1.2
  +++ PatternException.java     2001/10/19 15:28:45     1.3
  @@ -8,6 +8,8 @@
   
   package org.apache.cocoon.sitemap;
   
  +import org.apache.avalon.framework.CascadingException;
  +
   /**
    * This exception is thrown by a <code>URIMatcher</code> or by a
    * <code>URITranslator</code> when there's something wrong with the matching 
or
  @@ -15,13 +17,32 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.2 $ $Date: 2001/06/08 20:28:26 $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
  + * @version CVS $Revision: 1.3 $ $Date: 2001/10/19 15:28:45 $
    */
  -public class PatternException extends Exception {
  +public class PatternException extends CascadingException {
  +
       /**
        * Construct a new <code>PatternException</code> instance.
        */
       public PatternException(String message) {
  -        super(message);
  +        super(message, null);
  +    }
  +
  +    /**
  +     * Creates a new <code>PatternException</code> instance.
  +     *
  +     * @param ex an <code>Exception</code> value
  +     */
  +    public PatternException(Exception ex) {
  +        super(ex.getMessage(), ex);
  +    }
  + 
  +    /**
  +     * Construct a new <code>PatternException</code> that references
  +     * a parent Exception.
  +     */
  +    public PatternException(String message, Throwable t) {
  +        super(message, t);
       }
   }
  
  
  
  1.8       +34 -1     
xml-cocoon2/src/org/apache/cocoon/sitemap/XSLTFactoryLoader.java
  
  Index: XSLTFactoryLoader.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/XSLTFactoryLoader.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XSLTFactoryLoader.java    2001/10/11 07:28:23     1.7
  +++ XSLTFactoryLoader.java    2001/10/19 15:28:45     1.8
  @@ -10,6 +10,7 @@
   
   import org.apache.avalon.framework.logger.Loggable;
   import org.apache.cocoon.CodeFactory;
  +import org.apache.cocoon.matching.PreparedMatcher;
   import org.apache.cocoon.util.ClassUtils;
   import org.apache.log.Logger;
   import org.w3c.dom.NodeList;
  @@ -26,7 +27,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version CVS $Revision: 1.7 $ $Date: 2001/10/11 07:28:23 $
  + * @version CVS $Revision: 1.8 $ $Date: 2001/10/19 15:28:45 $
    */
   public class XSLTFactoryLoader {
       protected static Logger log;
  @@ -114,5 +115,37 @@
               log.debug("Exception in XSLTFactoryLoader.isFactory checking for 
" + className, e);
           }
           return result;
  +    }
  +    
  +    public boolean isPreparedMatcher(String className) {
  +        boolean result = false;
  +        try {
  +            result = ClassUtils.implementsInterface(className, 
PreparedMatcher.class.getName());
  +        } catch (ClassNotFoundException e) {
  +            log.debug("ClassNotFoundException in 
XSLTFactoryLoader.isPreparedMatcher checking for " + className, e);
  +        } catch (Exception e) {
  +            log.debug("Exception in XSLTFactoryLoader.isPreparedMatcher 
checking for " + className, e);
  +        }
  +        return result;
  +    }
  +    
  +    /**
  +     * Escapes '"' and '\' characters in a String so that it can be inserted 
in java source
  +     */
  +    public String escape(String string) {
  +        if (string.indexOf('\\') == -1 && string.indexOf('"') == -1) {
  +            // Nothing to escape
  +            return string;
  +        }
  +        
  +        StringBuffer buf = new StringBuffer();
  +        for (int i = 0; i < string.length(); i++) {
  +            char ch = string.charAt(i);
  +            if (ch == '\\' || ch == '"') {
  +                buf.append('\\');
  +            }
  +            buf.append(ch);
  +        }
  +        return buf.toString();
       }
   }
  
  
  
  1.57      +8 -7      xml-cocoon2/webapp/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/sitemap.xmap,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- sitemap.xmap      2001/10/18 19:52:58     1.56
  +++ sitemap.xmap      2001/10/19 15:28:46     1.57
  @@ -97,17 +97,17 @@
     </map:selectors>
   
     <map:matchers default="wildcard">
  -   <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
  -   <map:matcher name="regexp" 
src="org.apache.cocoon.matching.RegexpURIMatcherFactory"/>
  +   <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcher"/>
  +   <map:matcher name="regexp" 
src="org.apache.cocoon.matching.RegexpURIMatcher"/>
      <map:matcher name="request" 
src="org.apache.cocoon.matching.RequestParamMatcher"/>
  -   <map:matcher name="sessionstate" 
src="org.apache.cocoon.matching.WildcardSessionAttributeMatcherFactory">
  +   <map:matcher name="sessionstate" 
src="org.apache.cocoon.matching.WildcardSessionAttributeMatcher">
         <attribute-name>org.apache.cocoon.SessionState</attribute-name>
      </map:matcher>
  -   <map:matcher name="next-page" 
src="org.apache.cocoon.matching.WildcardParameterValueMatcherFactory">
  +   <map:matcher name="next-page" 
src="org.apache.cocoon.matching.WildcardParameterValueMatcher">
         <parameter-name>next-state</parameter-name>
      </map:matcher>
  -   <map:matcher name="referer-match" 
src="org.apache.cocoon.matching.WildcardHeaderMatcherFactory">
  -      <parameter-name>referer</parameter-name>
  +   <map:matcher name="referer-match" 
src="org.apache.cocoon.matching.WildcardHeaderMatcher">
  +      <header-name>referer</header-name>
      </map:matcher>
     </map:matchers>
   
  @@ -199,7 +199,8 @@
   
     <!-- Utility for viewing source xml or html-->
     <map:pipeline>
  -   <map:match pattern="**.source">
  +   <!-- sample use of regexp equivalent to "**.source" using wildcard -->
  +   <map:match pattern="(.*)\.source" type="regexp">
       <map:generate src="cocoon:/{1}" />
       <map:transform src="stylesheets/simple-xml2html.xsl"/>
       <map:serialize/>
  
  
  
  1.8       +1 -1      xml-cocoon2/webapp/i18n/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/i18n/sitemap.xmap,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- sitemap.xmap      2001/07/19 11:22:21     1.7
  +++ sitemap.xmap      2001/10/19 15:28:46     1.8
  @@ -8,7 +8,7 @@
                <map:serializers default="html"/>
                <map:selectors default="browser"/>
                <map:matchers default="wildcard">
  -                     <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
  +       <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcher"/>
                </map:matchers>
   
        </map:components>
  
  
  
  1.6       +1 -2      xml-cocoon2/webapp/protected/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/protected/sitemap.xmap,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- sitemap.xmap      2001/06/21 19:29:02     1.5
  +++ sitemap.xmap      2001/10/19 15:28:46     1.6
  @@ -17,8 +17,7 @@
       <map:selectors default="browser"/>
   
       <map:matchers default="wildcard">
  -      <map:matcher name="wildcard"
  -        src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
  +       <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcher"/>
       </map:matchers>
   
       <map:actions>
  
  
  
  1.2       +2 -2      xml-cocoon2/webapp/sitebuilder/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/sitebuilder/sitemap.xmap,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sitemap.xmap      2001/08/21 12:43:37     1.1
  +++ sitemap.xmap      2001/10/19 15:28:46     1.2
  @@ -21,8 +21,8 @@
     <map:selectors id="11" default="browser"/>
   
     <map:matchers id="12" default="wildcard">
  -    <map:matcher id="13" name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
  -    <map:matcher id="14" name="regexp" 
src="org.apache.cocoon.matching.RegexpURIMatcherFactory"/>
  +    <map:matcher id="13" name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcher"/>
  +    <map:matcher id="14" name="regexp" 
src="org.apache.cocoon.matching.RegexpURIMatcher"/>
     </map:matchers>
   
     <map:actions id="15" >
  
  
  
  1.5       +1 -1      xml-cocoon2/webapp/sub/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/sub/sitemap.xmap,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sitemap.xmap      2001/08/24 01:20:10     1.4
  +++ sitemap.xmap      2001/10/19 15:28:46     1.5
  @@ -17,7 +17,7 @@
     <map:selectors default="browser"/>
   
     <map:matchers default="wildcard">
  -   <map:matcher name="wildcard"        
src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
  +     <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcher"/>
     </map:matchers>
   
    </map:components>
  
  
  
  1.8       +1 -1      xml-cocoon2/webapp.site/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp.site/sitemap.xmap,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- sitemap.xmap      2001/10/05 07:15:20     1.7
  +++ sitemap.xmap      2001/10/19 15:28:46     1.8
  @@ -32,7 +32,7 @@
     </map:serializers>
   
     <map:matchers default="wildcard">
  -   <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
  +   <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcher"/>
     </map:matchers>
    </map:components>
   
  
  
  
  1.3       +2 -2      xml-cocoon2/webapp.tutorial/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp.tutorial/sitemap.xmap,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- sitemap.xmap      2001/09/19 15:09:28     1.2
  +++ sitemap.xmap      2001/10/19 15:28:46     1.3
  @@ -60,8 +60,8 @@
     </map:selectors>
   
     <map:matchers default="wildcard">
  -   <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcherFactory"/>
  -   <map:matcher name="regexp" 
src="org.apache.cocoon.matching.RegexpURIMatcherFactory"/>
  +   <map:matcher name="wildcard" 
src="org.apache.cocoon.matching.WildcardURIMatcher"/>
  +   <map:matcher name="regexp" 
src="org.apache.cocoon.matching.RegexpURIMatcher"/>
      <map:matcher name="request" 
src="org.apache.cocoon.matching.RequestParamMatcher"/>
     </map:matchers>
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to