haul        01/07/11 02:50:03

  Modified:    webapp   sitemap.xmap
               webapp/docs/samples samples.xml
               src/org/apache/cocoon Constants.java
  Added:       webapp/stylesheets simple-page2html.xsl
               webapp/docs/samples/session-state start.xsp state01.xsp
                        state11.xsp state12.xsp state21.xsp state22.xsp
               webapp/docs/samples/referer/b a.xml b.xml
               webapp/docs/samples/referer/a a.xml b.xml
               src/org/apache/cocoon/selection HeaderSelectorFactory.java
                        RequestSelectorFactory.java
                        SessionStateSelectorFactory.java
               src/org/apache/cocoon/matching
                        WildcardHeaderMatcherFactory.java
                        WildcardParameterValueMatcherFactory.java
                        WildcardSessionStateMatcherFactory.java
               src/org/apache/cocoon/acting SessionIsValidAction.java
                        SessionStateAction.java
  Log:
  Provide matchers, selectors & actions to modify or select pipelines
  in sitemape according to previous application state.
  
  State is represented either as session attribute, request parameter, or
  request header attribute.
  
  Examples that illustrate usage.
  
  Revision  Changes    Path
  1.25      +72 -0     xml-cocoon2/webapp/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/sitemap.xmap,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- sitemap.xmap      2001/07/10 16:00:43     1.24
  +++ sitemap.xmap      2001/07/11 09:49:47     1.25
  @@ -92,6 +92,14 @@
     <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="request" 
src="org.apache.cocoon.matching.RequestParamMatcher"/>
  +   <map:matcher name="sessionstate" 
src="org.apache.cocoon.matching.WildcardSessionStateMatcherFactory"/>
  +   <map:matcher name="next-page" 
src="org.apache.cocoon.matching.WildcardParameterValueMatcherFactory">
  +      <map:parameter name="parameter-name" value="next-state"/>
  +   </map:matcher>
  +   <map:matcher name="referer-match" 
src="org.apache.cocoon.matching.WildcardHeaderMatcherFactory">
  +      <map:parameter name="parameter-name" value="referer"/>
  +   </map:matcher>
     </map:matchers>
   
     <map:actions>
  @@ -102,6 +110,8 @@
      <map:action name="locale" src="org.apache.cocoon.acting.LocaleAction"/>
      <map:action name="request" src="org.apache.cocoon.acting.RequestParamAction"/>
      <map:action name="form-validator" 
src="org.apache.cocoon.acting.FormValidatorAction"/>
  +   <map:action name="session-state" 
src="org.apache.cocoon.acting.SessionStateAction"/>
  +   <map:action name="session-isvalid" 
src="org.apache.cocoon.acting.SessionIsValidAction"/>
     </map:actions>
   
    </map:components>
  @@ -139,6 +149,28 @@
        </map:transform>
        <map:serialize/>
     </map:resource>
  +
  +  <map:resource name="dynamic-page1">
  +     <map:act type="session-state">
  +        <map:parameter name="new-state" value="{../next-state}"/>
  +        <map:redirect-to resource="dynamic-page" 
target="{../target}/state{../../../state}{../../next-state}"/>
  +     </map:act>
  +  </map:resource>
  +
  +  <map:resource name="dynamic-page2">
  +     <map:act type="session-state">
  +        <map:parameter name="new-state" value="1"/>
  +        <map:redirect-to resource="dynamic-page" target="{../target}1"/>
  +     </map:act>
  +  </map:resource>
  +
  +  <map:resource name="simple-page">
  +     <map:generate type="file" src="{target}.xml"/>
  +     <map:transform src="stylesheets/simple-page2html.xsl">
  +        <map:parameter name="view-source" value="{target}.xml"/>
  +     </map:transform>
  +     <map:serialize/>
  +  </map:resource>
    </map:resources>
   
   <!-- ========================== Action sets ================================ -->
  @@ -460,6 +492,46 @@
        <map:serialize/>
      </map:match>
   
  +  <!-- ========================== session state ================================= 
-->
  +
  +  <map:match pattern="session-state/example">
  +      <map:act type="session-isvalid">
  +
  +         <map:match type="sessionstate" pattern="1">
  +         <map:match type="next-page" pattern="1">
  +                <map:redirect-to resource="dynamic-page1" 
target="docs/samples/session-state"/>
  +         </map:match>
  +         <map:match type="next-page" pattern="2">
  +                <map:redirect-to resource="dynamic-page1" 
target="docs/samples/session-state"/>
  +         </map:match>
  +       </map:match>
  +
  +         <map:match type="sessionstate" pattern="2">
  +         <map:match type="next-page" pattern="1">
  +                <map:redirect-to resource="dynamic-page1" 
target="docs/samples/session-state"/>
  +         </map:match>
  +         <map:match type="next-page" pattern="2">
  +                <map:redirect-to resource="dynamic-page1" 
target="docs/samples/session-state"/>
  +         </map:match>
  +       </map:match>
  +
  +          <map:redirect-to resource="dynamic-page2" 
target="docs/samples/session-state/state0"/>
  +      </map:act>
  +      <map:redirect-to resource="dynamic-page" 
target="docs/samples/session-state/start"/>
  +  </map:match>
  +
  +   <!-- ========================== referer ================================= -->
  +
  +  <map:match pattern="referer/*">
  +     <map:match type="referer-match" 
pattern="http://localhost:8080/cocoon/referer/a";>
  +        <map:redirect-to resource="simple-page" 
target="docs/samples/referer/a/{../1}"/>
  +     </map:match>
  +     <map:match type="referer-match" 
pattern="http://localhost:8080/cocoon/referer/b";>
  +        <map:redirect-to resource="simple-page" 
target="docs/samples/referer/b/{../1}"/>
  +     </map:match>
  +
  +     <map:redirect-to resource="simple-page" target="docs/samples/referer/a/a"/>
  +  </map:match>
   
      <!-- ========================== Stream ================================= -->
      <map:match pattern="request1">
  
  
  
  1.1                  xml-cocoon2/webapp/stylesheets/simple-page2html.xsl
  
  Index: simple-page2html.xsl
  ===================================================================
  <?xml version="1.0"?>
  
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
    <xsl:param name="view-source"/>
  
    <xsl:template match="page">
     <html>
      <head>
       <title>
        <xsl:value-of select="title"/>
       </title>
      </head>
      <body bgcolor="#ffffff" alink="red" link="blue" vlink="blue">
       <xsl:apply-templates/>
      </body>
     </html>
    </xsl:template>
  
    <xsl:template match="title">
     <h2 style="color: navy; text-align: center">
        <xsl:if test="not($view-source)">
           <xsl:apply-templates/>
        </xsl:if>     
        <xsl:if test="$view-source">
        <A>
           <xsl:attribute name="HREF">../view-source?filename=/<xsl:value-of 
select="$view-source"/></xsl:attribute>
                 <xsl:attribute name="TARGET">_blank</xsl:attribute>
           <xsl:apply-templates/>
        </A>
        </xsl:if>     
     </h2>
    </xsl:template>
  
    <xsl:template match="para">
      <p align="center">
        <i><xsl:apply-templates/></i>
      </p>
    </xsl:template>
  
    <!--
    
    <xsl:template match="form">
      <form method="POST" action="{@target}">
        <xsl:apply-templates/>
      </form>
    </xsl:template>
  
  
    <xsl:template match="input">
      <center>
        <xsl:value-of select="@title"/>
        <input type="{@type}" name="{@name}" value="{.}"/>
      </center><br/>
    </xsl:template>
  
  -->
  
    <xsl:template match="linkbar">
      <!--
      <center>
        [
        <a href="login"> login </a>
        |
        <a href="protected"> protected </a>
        |
        <a href="do-logout"> logout </a>
        ]
      </center>
      -->
    </xsl:template>
    
    <xsl:template match="@*|node()" priority="-1">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.7       +11 -0     xml-cocoon2/webapp/docs/samples/samples.xml
  
  Index: samples.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/docs/samples/samples.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- samples.xml       2001/07/10 16:00:50     1.6
  +++ samples.xml       2001/07/11 09:49:51     1.7
  @@ -153,6 +153,17 @@
       </sample>
     </group>
   
  +  <group name="Stateful Applications">
  +   <sample name="Session State" href="session-state/example">
  +    Here the application state is stored in a session attribute.
  +   </sample>
  +   <sample name="Sessionless State" href="referer/a">
  +    Whereas this example uses the request header referer
  +    attribute. The complete URL must be known to the sitemap, so this
  +    works only if you access Cocoon on http://localhost:8080/cocoon
  +   </sample>
  +  </group>
  +
     <group name="System Pages">
      <sample name="Status Page" href="status">
       Cocoon status page.
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/session-state/start.xsp
  
  Index: start.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?><!-- -*- sgml -*- -->
  <xsp:page
     language="java"
     xmlns:xsp="http://apache.org/xsp";
     xmlns:xsp-request="http://apache.org/xsp/request/2.0";
     xmlns:session="http://apache.org/xsp/session/2.0";
  >
     <page>
        <title>Start page.</title>
        <content>
        <para>
        This could be a login page. <a href="example">continue</a>
        </para>
        <xsp:logic>
        String sessionID = <session:get-id/>;
        </xsp:logic>
        
        </content>
     </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/session-state/state01.xsp
  
  Index: state01.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?><!-- -*- sgml -*- -->
  <xsp:page
     language="java"
     xmlns:xsp="http://apache.org/xsp";
     xmlns:xsp-request="http://apache.org/xsp/request/2.0";
     xmlns:session="http://apache.org/xsp/session/2.0";
  >
     <page>
        <title>state 0-1</title>
        <content>
  
           <form action="example" method="get">
             <select size="1" name="next-state">
             <option value="1">1</option>
             <option value="2">2</option>
             </select>
             <input type="submit" name="go" value="go"/>
         </form>
        </content>
     </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/session-state/state11.xsp
  
  Index: state11.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?><!-- -*- sgml -*- -->
  <xsp:page
     language="java"
     xmlns:xsp="http://apache.org/xsp";
     xmlns:xsp-request="http://apache.org/xsp/request/2.0";
     xmlns:session="http://apache.org/xsp/session/2.0";
  >
     <page>
        <title>state 1-1</title>
        <content>
  
           <form action="example" method="get">
             <select size="1" name="next-state">
             <option value="1">1</option>
             <option value="2">2</option>
             </select>
             <input type="submit" name="go" value="go"/>
         </form>
        </content>
     </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/session-state/state12.xsp
  
  Index: state12.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?><!-- -*- sgml -*- -->
  <xsp:page
     language="java"
     xmlns:xsp="http://apache.org/xsp";
     xmlns:xsp-request="http://apache.org/xsp/request/2.0";
     xmlns:session="http://apache.org/xsp/session/2.0";
  >
     <page>
        <title>state 1-2</title>
        <content>
  
           <form action="example" method="get">
             <select size="1" name="next-state">
             <option value="1">1</option>
             <option value="2">2</option>
             </select>
             <input type="submit" name="go" value="go"/>
         </form>
        </content>
     </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/session-state/state21.xsp
  
  Index: state21.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?><!-- -*- sgml -*- -->
  <xsp:page
     language="java"
     xmlns:xsp="http://apache.org/xsp";
     xmlns:xsp-request="http://apache.org/xsp/request/2.0";
     xmlns:session="http://apache.org/xsp/session/2.0";
  >
     <page>
        <title>state 2-1</title>
        <content>
  
           <form action="example" method="get">
             <select size="1" name="next-state">
             <option value="1">1</option>
             <option value="2">2</option>
             </select>
             <input type="submit" name="go" value="go"/>
         </form>
        </content>
     </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/session-state/state22.xsp
  
  Index: state22.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?><!-- -*- sgml -*- -->
  <xsp:page
     language="java"
     xmlns:xsp="http://apache.org/xsp";
     xmlns:xsp-request="http://apache.org/xsp/request/2.0";
     xmlns:session="http://apache.org/xsp/session/2.0";
  >
     <page>
        <title>state 2-2</title>
        <content>
  
           <form action="example" method="get">
             <select size="1" name="next-state">
             <option value="1">1</option>
             <option value="2">2</option>
             </select>
             <input type="submit" name="go" value="go"/>
         </form>
        </content>
     </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/referer/b/a.xml
  
  Index: a.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <page>
   <title>previous state <b>b</b> - current state <b>a</b></title>
   <content>
   <a href="a">a</a>
   <a href="b">b</a>
   </content>
  </page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/referer/b/b.xml
  
  Index: b.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <page>
   <title>previous state <b>b</b> - current state <b>b</b></title>
   <content>
   <a href="a">a</a>
   <a href="b">b</a>
   </content>
  </page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/referer/a/a.xml
  
  Index: a.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <page>
   <title>previous state <b>a</b> - current state <b>a</b></title>
   <content>
   <a href="a">a</a>
   <a href="b">b</a>
   </content>
  </page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/referer/a/b.xml
  
  Index: b.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <page>
   <title>previous state <b>a</b> - current state <b>b</b></title>
   <content>
   <a href="a">a</a>
   <a href="b">b</a>
   </content>
  </page>
  
  
  
  1.8       +3 -1      xml-cocoon2/src/org/apache/cocoon/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Constants.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Constants.java    2001/07/11 08:47:41     1.7
  +++ Constants.java    2001/07/11 09:49:57     1.8
  @@ -10,7 +10,7 @@
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.7 $ $Date: 2001/07/11 08:47:41 $
  + * @version CVS $Revision: 1.8 $ $Date: 2001/07/11 09:49:57 $
    */
   
   public interface Constants {
  @@ -72,5 +72,7 @@
       String CONTEXT_LOG_DIR         = "log-directory";
   
       boolean DESCRIPTOR_RELOADABLE_DEFAULT = true;
  +
  +    String SESSION_STATE_ATTRIBUTE = "org.apache.cocoon.SessionState";
   
   }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/selection/HeaderSelectorFactory.java
  
  Index: HeaderSelectorFactory.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.selection;
  
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.CodeFactory;
  import org.apache.xerces.dom.TreeWalkerImpl;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.traversal.NodeFilter;
  import org.w3c.dom.traversal.TreeWalker;
  
  /**
   * This class generates source code to implement a selector that
   * matches a string against a configurable request header, e.g. "referer".
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>parameter-name</code></td><td>Name of the request header to
   * match against</td></tr>
   * </table>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christian Haul</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/11 09:49:59 $
   */
  public class HeaderSelectorFactory extends ParameterSelectorFactory {
  
      public String generateMethodSource (NodeList conf)
      throws ConfigurationException {
        String parameterName = null;
          Node node = null;
          Node attrNode = null;
          NamedNodeMap attributes = null;
  
          int count = conf.getLength();
          for(int k = 0; k < count;k++) {
              node = conf.item(k);
            if (node.getNodeName() != null && 
                node.getNodeName().equals("map:parameter")) 
                {
                    attributes = node.getAttributes();
                    if (attributes != null) {
                        attrNode = attributes.getNamedItem("name");
                        if (attrNode != null && 
                            attrNode.getNodeValue().equals("parameter-name"))
                            {
                                attrNode = attributes.getNamedItem("value");
                                if (attrNode != null ) 
                                    parameterName=attrNode.getNodeValue();
                            }
                    }
                }
          }
  
          StringBuffer sb = new StringBuffer();
        sb.append("String compareToString = null;")
          .append("if (param == null) {")
            .append("  compareToString = (String) 
XSPRequestHelper.getHeader(objectModel, \""+parameterName+"\");")
            .append("} else { ")
            .append("  compareToString = (String) 
XSPRequestHelper.getHeader(objectModel, 
param.getParameter(\"state-key\",\""+parameterName+"\"));")
          .append("}")
          .append("return compareToString != null && compareToString.equals 
(pattern);");
          return sb.toString();
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/selection/RequestSelectorFactory.java
  
  Index: RequestSelectorFactory.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.selection;
  
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.CodeFactory;
  import org.apache.xerces.dom.TreeWalkerImpl;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.traversal.NodeFilter;
  import org.w3c.dom.traversal.TreeWalker;
  
  /**
   * This class generates source code to implement a selector that
   * matches a string against a configurable request parameter's value.
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>parameter-name</code></td><td>Name of the request
   * parameter whose value to match against</td></tr>
   * </table>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christian Haul</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/11 09:49:59 $
   */
  public class RequestSelectorFactory extends ParameterSelectorFactory {
  
      public String generateMethodSource (NodeList conf)
      throws ConfigurationException {
        String parameterName = null;
          Node node = null;
          Node attrNode = null;
          NamedNodeMap attributes = null;
  
          int count = conf.getLength();
          for(int k = 0; k < count;k++) {
              node = conf.item(k);
            if (node.getNodeName() != null && 
                node.getNodeName().equals("map:parameter")) 
                {
                    attributes = node.getAttributes();
                    if (attributes != null) {
                        attrNode = attributes.getNamedItem("name");
                        if (attrNode != null && 
                            attrNode.getNodeValue().equals("parameter-name"))
                            {
                                attrNode = attributes.getNamedItem("value");
                                if (attrNode != null ) 
                                    parameterName=attrNode.getNodeValue();
                            }
                    }
                }
          }
  
          StringBuffer sb = new StringBuffer();
        sb.append("String compareToString = null;")
          .append("if (param == null) {")
            .append("  compareToString = (String) 
XSPRequestHelper.getParameter(objectModel, \""+parameterName+"\",null);")
            .append("} else { ")
            .append("  compareToString = (String) 
XSPRequestHelper.getParameter(objectModel, 
param.getParameter(\"state-key\",\""+parameterName+"\"),null);")
          .append("}")
          .append("return compareToString != null && compareToString.equals 
(pattern);");
          return sb.toString();
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/selection/SessionStateSelectorFactory.java
  
  Index: SessionStateSelectorFactory.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.selection;
  
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.CodeFactory;
  import org.apache.cocoon.Constants;
  import org.apache.xerces.dom.TreeWalkerImpl;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.traversal.NodeFilter;
  import org.w3c.dom.traversal.TreeWalker;
  
  /**
   * This class generates source code to implement a selector that
   * matches a string against a configurable session state.
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>state-key</code></td><td>String identifying the session attribute 
that 
   * stores the current session state</td></tr>
   * </table>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christian Haul</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/11 09:49:59 $
   */
  public class SessionStateSelectorFactory extends ParameterSelectorFactory {
  
      public String generateMethodSource (NodeList conf)
      throws ConfigurationException {
        String statekey=Constants.SESSION_STATE_ATTRIBUTE;
          Node node = null;
          Node attrNode = null;
          NamedNodeMap attributes = null;
  
          int count = conf.getLength();
          for(int k = 0; k < count;k++) {
              node = conf.item(k);
            if (node.getNodeName() != null && 
                node.getNodeName().equals("map:parameter")) 
                {
                    attributes = node.getAttributes();
                    if (attributes != null) {
                        attrNode = attributes.getNamedItem("name");
                        if (attrNode != null && 
                            attrNode.getNodeValue().equals("state-key"))
                            {
                                attrNode = attributes.getNamedItem("value");
                                if (attrNode != null ) 
                                    statekey=attrNode.getNodeValue();
                            }
                    }
                }
          }
  
          StringBuffer sb = new StringBuffer();
        sb.append("String compareToString = null;")
          .append("if (param == null) {")
            .append("  compareToString = (String) 
XSPRequestHelper.getSessionAttribute(objectModel, \""+statekey+"\");")
            .append("} else { ")
            .append("  compareToString = (String) 
XSPRequestHelper.getSessionAttribute(objectModel, ")
          .append("param.getParameter(\"state-key\",\""+statekey+"\"));")
          .append("}")
          .append("return compareToString != null && compareToString.equals 
(pattern);");
          return sb.toString();
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/WildcardHeaderMatcherFactory.java
  
  Index: WildcardHeaderMatcherFactory.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.cocoon.CodeFactory;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  
  /**
   * This class generates source code which represents a specific pattern matcher
   * for values of request headers, e.g. "referer"
   *
   * <p><b>Global and local configuration</b></p>
   * <table border="1">
   * <tr><td><code>parameter-name</code></td><td>Name of the request header to
   * match against</td></tr>
   * </table>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christian Haul</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/11 09:50:01 $
   */
  
  public class WildcardHeaderMatcherFactory extends WildcardURIMatcherFactory {
  
      /**
       * Generates the matcher method level source code
       */
      public String generateMethodSource (NodeList conf)
      throws ConfigurationException {
        String parameterName = null;
          Node node = null;
          Node attrNode = null;
          NamedNodeMap attributes = null;
  
          int count = conf.getLength();
          for(int k = 0; k < count;k++) {
              node = conf.item(k);
            if (node.getNodeName() != null && 
                node.getNodeName().equals("map:parameter")) 
                {
                    attributes = node.getAttributes();
                    if (attributes != null) {
                        attrNode = attributes.getNamedItem("name");
                        if (attrNode != null && 
                            attrNode.getNodeValue().equals("parameter-name"))
                            {
                                attrNode = attributes.getNamedItem("value");
                                if (attrNode != null ) 
                                    parameterName=attrNode.getNodeValue();
                            }
                    }
                }
          }
        return "HashMap map = new HashMap(1);" +
            "String theParameter = null;" +
            "if (parameters == null) {"+
            "  theParameter = XSPRequestHelper.getHeader(objectModel, 
\""+parameterName+"\");" +
            " } else { " +
            "  theParameter = XSPRequestHelper.getHeader(objectModel, 
parameters.getParameter(\"parameter-name\", \""+parameterName+"\"));" +
            " }; " +
            "if (theParameter != null && 
org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (map, theParameter, 
pattern)) {" +
            "map.put(\""+parameterName+"\", theParameter);"+
            "return map;" +
            "} else {" +
            "return null;}";
      }
  
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/WildcardParameterValueMatcherFactory.java
  
  Index: WildcardParameterValueMatcherFactory.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.cocoon.CodeFactory;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  
  /**
   * This class generates source code which represents a specific pattern matcher
   * for request parameters.
   *
   * <p> In contrast to the {@link RequestParamMatcher} this matcher
   * factory generates matchers that match the <b>value</b> of a request
   * parameter.</p>
   *
   * <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>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/11 09:50:01 $ */
  
  public class WildcardParameterValueMatcherFactory extends WildcardURIMatcherFactory {
  
      /**
       * Generates the matcher method level source code
       */
      public String generateMethodSource (NodeList conf)
      throws ConfigurationException {
        String parameterName = null;
          Node node = null;
          Node attrNode = null;
          NamedNodeMap attributes = null;
  
          int count = conf.getLength();
          for(int k = 0; k < count;k++) {
              node = conf.item(k);
            if (node.getNodeName() != null && 
                node.getNodeName().equals("map:parameter")) 
                {
                    attributes = node.getAttributes();
                    if (attributes != null) {
                        attrNode = attributes.getNamedItem("name");
                        if (attrNode != null && 
                            attrNode.getNodeValue().equals("parameter-name"))
                            {
                                attrNode = attributes.getNamedItem("value");
                                if (attrNode != null ) 
                                    parameterName=attrNode.getNodeValue();
                            }
                    }
                }
          }
        return "HashMap map = new HashMap(1);" +
            "String theParameter = null; " +
            "if (parameters == null) {"+
            "  theParameter = XSPRequestHelper.getParameter(objectModel, 
\""+parameterName+"\",null);" +
            " } else { " +
            "  theParameter = XSPRequestHelper.getParameter(objectModel, 
parameters.getParameter(\"parameter-name\",\""+parameterName+"\"),null);" +
            " }; " +
            "if (theParameter != null && 
org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (map, theParameter, 
pattern)) {" +
            "map.put(\""+parameterName+"\", theParameter);"+
            "return map;" +
            "} else {" +
            "return null;}";
      }
  
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/matching/WildcardSessionStateMatcherFactory.java
  
  Index: WildcardSessionStateMatcherFactory.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.cocoon.CodeFactory;
  import org.apache.cocoon.Constants;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  
  /**
   * This class generates source code which represents a specific pattern matcher
   * for session states
   *
   * <p><b>Global and local configuration</b></p>
   * <tableborder="1">
   * <tr><td><code>state-key</code></td><td>String identifying the session attribute 
that 
   * stores the current session state</td></tr>
   * </table>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christian Haul</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/11 09:50:01 $
   */
  
  public class WildcardSessionStateMatcherFactory extends WildcardURIMatcherFactory {
  
      /**
       * Generates the matcher method level source code
       */
      public String generateMethodSource (NodeList conf)
      throws ConfigurationException {
        String statekey=Constants.SESSION_STATE_ATTRIBUTE;
          Node node = null;
          Node attrNode = null;
          NamedNodeMap attributes = null;
  
          int count = conf.getLength();
          for(int k = 0; k < count;k++) {
              node = conf.item(k);
            if (node.getNodeName() != null && 
                node.getNodeName().equals("map:parameter")) 
                {
                    attributes = node.getAttributes();
                    if (attributes != null) {
                        attrNode = attributes.getNamedItem("name");
                        if (attrNode != null && 
                            attrNode.getNodeValue().equals("state-key"))
                            {
                                attrNode = attributes.getNamedItem("value");
                                if (attrNode != null ) 
                                    statekey=attrNode.getNodeValue();
                            }
                    }
                }
          }
        return "HashMap map = new HashMap(1);" +
            "String currentState = null; " +
            "if (parameters == null) {"+
            "  currentState = (String) 
XSPRequestHelper.getSessionAttribute(objectModel, \""+statekey+"\"); " +
            " } else { " +
            "  currentState = (String) 
XSPRequestHelper.getSessionAttribute(objectModel, 
parameters.getParameter(\"state-key\",\""+statekey+"\"));" +
            " }; " +
            "if (currentState != null && 
org.apache.cocoon.matching.helpers.WildcardURIMatcher.match (map, currentState, 
pattern)) {" +
            "map.put(\"state\", currentState);"+
            "return map;" +
            "} else {" +
            "return null;}";
      }
  
  }
  
  
  
  1.1                  
xml-cocoon2/src/org/apache/cocoon/acting/SessionIsValidAction.java
  
  Index: SessionIsValidAction.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.acting;
  
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Map;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.acting.ValidatorActionHelper;
  import org.apache.cocoon.Constants;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.Session;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.util.Tokenizer;
  import org.apache.log.Logger;
  
  
  /**
   * This action just checks if a session exists and whether the current
   * seesion is still valid.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christian Haul</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/11 09:50:02 $
   */
  
  public class SessionIsValidAction extends AbstractValidatorAction
  {
      /**
       * Main invocation routine.
       */
      public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, 
String src,
              Parameters parameters) throws Exception {
          Request req = (Request)
              objectModel.get (Constants.REQUEST_OBJECT);
  
          if (req == null) {
              getLogger ().debug ("SESSIONVALIDATOR: no request object");
              return null;
          }
  
          /* check session validity */
          Session session = req.getSession (false);
          if (session == null) {
              getLogger ().debug ("SESSIONVALIDATOR: no session object");
              return null;
          }
        if (!req.isRequestedSessionIdValid()) {
              getLogger ().debug ("SESSIONVALIDATOR: requested session id is invalid");
              return null;
          }
            
        return new HashMap();
  
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/acting/SessionStateAction.java
  
  Index: SessionStateAction.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.acting;
  
  import java.util.Map;
  import java.util.HashMap;
  
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.Constants;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.Session;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.SourceResolver;
  
  /**
   * Store the session's current state in a session attribute.
   *
   * <p> To keep track of the state of a user's session, a string is
   * stored in a session attribute in order to allow to chose between
   * different pipelines in the sitemap accordingly.</p>
   *
   * <p> For added flexibility it is possible to use sub states as
   * well. For this declare your own name for the session state
   * attribute and give the number of sublevels plus the level to
   * modify. (This is <b>one</b> based!) Sub states below the current
   * one are removed from the session so that the default sub state will
   * be reentered when the user returns. If you don't like this
   * behaviour and prefer independent sub states, use this action
   * several times with different attribute names rather than sub
   * levels. </p>
   *
   * <p><b>Global and local paramters:</b></p> 
   *
   * <table border="1"> 
   *   <tr>
   *     <td><code>state-key-prefix</code></td>
   *     <td>String that identifies the attribute that stores the session state in the
   *             session object. When sublevels are used, this is a prefix ie. the
   *             number of the level is appended to the prefix. Example prefix is
   *             "<code>__sessionState</code>", sub-levels is 2, attributes
   *             "<code>__sessionState1</code>", "<code>__sessionState2</code>", and
   *             "<code>__sessionState3</code>" will be used to store the
   *             information.
   *     </td>
   *   </tr> 
   *   <tr>
   *     <td><code>new-state</code></td>
   *     <td>String that identifies the current state</td>
   *   </tr>
   *   <tr>
   *     <td><code>sub-levels</code></td>
   *     <td>Number of sub levels to  use</td>
   *   </tr> 
   *   <tr>
   *     <td><code>state-level</code></td>
   *     <td>Sub level to modify, this is <b>one</b> based</td>
   *   </tr> 
   * </table>
   *
   * @see org.apache.cocoon.matching.WildcardSessionStateMatcherFactory
   * @see org.apache.cocoon.selection.SessionStateSelectorFactory
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christian Haul</a>
   * @version CVS $Id: SessionStateAction.java,v 1.1 2001/07/11 09:50:03 haul Exp $ */
  public class SessionStateAction extends ComposerAction {
  
      private static String componentName = "REZEPTE SessionStateAction";
      protected String statekey = Constants.SESSION_STATE_ATTRIBUTE;
      protected String newstate = null;
      protected int sublevels = 0;
      protected int mylevel = 0;
  
      /**
       * read settings from global section and store them for
       * easier access to instance variables.
       */
  
      public void configure(Configuration conf) throws ConfigurationException 
      {
        super.configure(conf);
  
        if (settings.containsKey("state-key-prefix"))
            statekey = (String) settings.get("state-key-prefix");
        if (settings.containsKey("new-state"))
            newstate = (String) settings.get("new-state");
        if (settings.containsKey("sub-levels"))
            sublevels = Integer.parseInt((String) settings.get("sub-levels"));
        if (settings.containsKey("state-level"))
            mylevel = Integer.parseInt((String) settings.get("state-level"));
      }
  
  
      public Map        act (Redirector redirector, 
                     SourceResolver resolver, 
                     Map objectModel, 
                     String src, 
                     Parameters par) throws Exception 
      {
          Request request = (Request) objectModel.get(Constants.REQUEST_OBJECT);
  
        // read local settings
        newstate = par.getParameter("new-state", newstate);
        statekey = par.getParameter("state-key", statekey);
        sublevels = par.getParameterAsInteger("sublevels", sublevels);
        mylevel = par.getParameterAsInteger("state-level", mylevel);
  
        if (newstate == null ) {
            getLogger().error(componentName + ": new-state is null");
            return null;
        }
  
  
          if (request != null) {
             Session session = request.getSession (false);
            
              if (session != null && request.isRequestedSessionIdValid()) {
                String oldstate = null;
                if (sublevels == 0) {
                    oldstate = (String) session.getAttribute(statekey);
                    session.setAttribute(statekey, newstate);
                    getLogger().debug(componentName+" : "+statekey+"="+newstate);
  
                } else { // sublevels != 0
                    oldstate = (String) session.getAttribute( statekey + 
Integer.toString(mylevel) );
                    for (int i=mylevel+1; i<=sublevels; i++) {
                        session.removeAttribute( statekey+Integer.toString(i) );
                        getLogger().debug(componentName+" : remove 
"+statekey+Integer.toString(i));
                    }
                    session.setAttribute( statekey + Integer.toString(mylevel), 
newstate);
                    getLogger().debug(componentName+" : 
"+statekey+Integer.toString(mylevel)+"="+newstate);
                }
                getLogger().debug(componentName + " transition " + oldstate + " -> " + 
newstate);
                
                HashMap map = new HashMap(1);
                map.put("newstate", newstate);
                return map;
                
            } else {
                  getLogger().warn(componentName + ": A session object was not present 
or no longer valid");
                return null;
              }
          } else {
            getLogger().warn(componentName + ": No request object");
            return null;
        }
        
      }
  }
  
  
  
  
  
  

----------------------------------------------------------------------
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