giacomo     00/12/30 13:33:12

  Modified:    src/org/apache/cocoon/components/language/markup/sitemap/java
                        Tag: xml-cocoon2 sitemap.xsl
               src/org/apache/cocoon/environment Tag: xml-cocoon2
                        Environment.java AbstractEnvironment.java
               src/org/apache/cocoon/environment/http Tag: xml-cocoon2
                        HttpEnvironment.java
               src/org/apache/cocoon Tag: xml-cocoon2 Constants.java
  Log:
  First implementation of a rudimentary action framework.
  
  The new elements are:
  
  action-sets which holds the definitions of several actions-set.
  
  An action-set holds several actions which can optionally refer to an action 
suplied from the Environment. Details are explained in the 
xdocs/drafts/sitemap-working-draft.xmap file.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.73  +166 -10   
xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl
  
  Index: sitemap.xsl
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl,v
  retrieving revision 1.1.2.72
  retrieving revision 1.1.2.73
  diff -u -r1.1.2.72 -r1.1.2.73
  --- sitemap.xsl       2000/12/15 20:35:11     1.1.2.72
  +++ sitemap.xsl       2000/12/30 21:33:08     1.1.2.73
  @@ -78,7 +78,7 @@
        *
        * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo 
Pati</a>
        * @author <a href="mailto:[EMAIL PROTECTED]">Berin 
Loritsch</a>
  -     * @version CVS $Revision: 1.1.2.72 $ $Date: 2000/12/15 20:35:11 $
  +     * @version CVS $Revision: 1.1.2.73 $ $Date: 2000/12/30 21:33:08 $
        */
       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"/>";
  @@ -269,6 +269,41 @@
           }
         </xsl:for-each>
   
  +      <!-- generate methods for every map:action-set element -->
  +      <xsl:for-each select="/map:sitemap/map:action-sets/map:action-set">
  +        /**
  +         * This is the method to process the "<xsl:value-of 
select="@name"/>" action-set of the requested resource
  +         * @param cocoon_action A &lt;code&gt;String&lt;/code&gt; holding 
the requested action
  +         * @param listOfMaps A &lt;code&gt;List&lt;/code&gt; of Maps holding 
replacement values for src attributes
  +         * @param environment The &lt;code&gt;Environment&lt;/code&gt; 
requesting a resource
  +         * @param objectModel The &lt;code&gt;Map&lt;/code&gt; containing 
the environments model objects
  +         * @return Wether the request has been processed or not
  +         * @exception Exception If an error occurs during request evaluation 
and production
  +         */
  +        private Map action_set_<xsl:value-of select="translate(@name, '- ', 
'__')"/> (String cocoon_action, List listOfMaps, Environment environment, Map 
objectModel, String src, Parameters param)
  +        throws Exception {
  +          Map map;
  +          Map allMap = new HashMap();
  +          Parameters nparam;
  +          <xsl:for-each select="map:act">
  +            map = null;
  +            <xsl:choose>
  +              <xsl:when test="@action">
  +                if ("<xsl:value-of 
select="@action"/>".equals(cocoon_action)) {
  +                  <xsl:apply-templates select="." mode="set"/>
  +                  if (map != null) allMap.putAll (map);
  +                }
  +              </xsl:when>
  +              <xsl:otherwise>
  +                <xsl:apply-templates select="." mode="set"/>
  +                if (map != null) allMap.putAll (map);
  +              </xsl:otherwise>
  +            </xsl:choose>
  +          </xsl:for-each>
  +          return allMap;
  +        }
  +      </xsl:for-each>
  +
         /**
          * Process to producing the output to the specified 
&lt;code&gt;OutputStream&lt;/code&gt;.
          */
  @@ -286,6 +321,7 @@
           Parameters param;
           Map objectModel = environment.getObjectModel();
           String cocoon_view = environment.getView();
  +        String cocoon_action = environment.getAction();
   
           <!-- process the pipelines -->
           <!-- for each pipeline element generate a try/catch block -->
  @@ -398,7 +434,7 @@
         log.debug("Matched <xsl:value-of select="$matcher-name"/>");
         listOfMaps.add (map);
         <xsl:apply-templates/>
  -      listOfMaps.remove (map);
  +      listOfMaps.remove (listOfMaps.size()-1);
       }
     </xsl:template> <!-- match="map:match" -->
   
  @@ -484,14 +520,14 @@
       </xsl:for-each>
     </xsl:template> <!-- match="map:select" -->
   
  -  <!-- processing of an act element -->
  -  <xsl:template match="map:act">
  +  <!-- processing of an act element having a type attribute -->
  +  <xsl:template match="map:[EMAIL PROTECTED]">
   
       <!-- get the type of action used -->
       <xsl:variable name="action-type">
         <xsl:call-template name="get-parameter">
           <xsl:with-param name="parname">type</xsl:with-param>
  -        <xsl:with-param name="default"><xsl:value-of 
select="/map:sitemap/map:components/map:actions/@default"/></xsl:with-param>
  +        <xsl:with-param name="default" value=""/>
         </xsl:call-template>
       </xsl:variable>
   
  @@ -530,19 +566,139 @@
   
       <!-- generate the invocation of the act method of the action component 
-->
       <xsl:choose>
  -      <xsl:when test="./*">
  +      <xsl:when 
test="./*[namespace-uri()='http://apache.org/cocoon/sitemap/1.0']">
           if ((map = <xsl:value-of select="$action-name"/> (environment, 
objectModel, substitute(listOfMaps,<xsl:value-of select="$action-source"/>), 
<xsl:value-of select="$component-param"/>)) != null) {
  -         log.debug("Action <xsl:value-of 
select="translate($action-name,'&quot;',' ')"/>"); 
  +         log.debug("Action <xsl:value-of 
select="translate($action-name,'&quot;',' ')"/>");
             listOfMaps.add (map);
             <xsl:apply-templates/>
  -          listOfMaps.remove(map);
  +          listOfMaps.remove(listOfMaps.size()-1);
           }
         </xsl:when>
         <xsl:otherwise>
           map = <xsl:value-of select="$action-name"/> (environment, 
objectModel, substitute(listOfMaps,<xsl:value-of select="$action-source"/>), 
<xsl:value-of select="$component-param"/>);
         </xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template> <!-- match="map:[EMAIL PROTECTED]" -->
  +
  +  <!-- processing of an act element having a type attribute -->
  +  <xsl:template match="map:[EMAIL PROTECTED]" mode="set">
  +
  +    <!-- get the type of action used -->
  +    <xsl:variable name="action-type">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="parname">type</xsl:with-param>
  +        <xsl:with-param name="default" value=""/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <!-- get the source parameter for the Action -->
  +    <xsl:variable name="action-source">
  +      <xsl:call-template name="get-parameter-as-string">
  +        <xsl:with-param name="parname">src</xsl:with-param>
  +        <xsl:with-param name="default">src</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <!-- gets the string how the action is to be invoced in java code -->
  +    <xsl:variable name="action-name">
  +      
((Action)((ComponentHolder)super.sitemapComponentManager.lookup("action:<xsl:value-of
 select="$action-type"/>")).get()).act
  +    </xsl:variable>
  +
  +    <!-- test if we have to define parameters for this action -->
  +    <xsl:if test="count(parameter)>0">
  +      nparam = new Parameters ();
  +    </xsl:if>
  +
  +    <!-- generate the value used for the parameter argument in the 
invocation of the act method of this action -->
  +    <xsl:variable name="component-param">
  +      <xsl:choose>
  +        <xsl:when test="count(parameter)>0">
  +          nparam
  +        </xsl:when>
  +        <xsl:otherwise>
  +          param
  +        </xsl:otherwise>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <!-- collect the parameters -->
  +    <xsl:apply-templates select="parameter"/>
  +
  +    <!-- generate the invocation of the act method of the action component 
-->
  +    <xsl:choose>
  +      <xsl:when 
test="./*[namespace-uri()='http://apache.org/cocoon/sitemap/1.0']">
  +        if ((map = <xsl:value-of select="$action-name"/> (environment, 
objectModel, substitute(listOfMaps,<xsl:value-of select="$action-source"/>), 
<xsl:value-of select="$component-param"/>)) != null) {
  +         log.debug("Action <xsl:value-of 
select="translate($action-name,'&quot;',' ')"/>");
  +          listOfMaps.add (map);
  +          <xsl:apply-templates/>
  +          listOfMaps.remove(listOfMaps.size()-1);
  +        }
  +      </xsl:when>
  +      <xsl:otherwise>
  +        map = <xsl:value-of select="$action-name"/> (environment, 
objectModel, substitute(listOfMaps,<xsl:value-of select="$action-source"/>), 
<xsl:value-of select="$component-param"/>);
  +      </xsl:otherwise>
  +    </xsl:choose>
  +  </xsl:template> <!-- match="map:[EMAIL PROTECTED]" mode="set" -->
  +
  +  <!-- processing of an act element having a set attribute -->
  +  <xsl:template match="map:[EMAIL PROTECTED]">
  +
  +    <!-- get the type of action used -->
  +    <xsl:variable name="action-set">
  +      <xsl:call-template name="get-parameter">
  +        <xsl:with-param name="parname">set</xsl:with-param>
  +        <xsl:with-param name="default" value=""/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <!-- get the source parameter for the Action -->
  +    <xsl:variable name="action-source">
  +      <xsl:call-template name="get-parameter-as-string">
  +        <xsl:with-param name="parname">src</xsl:with-param>
  +        <xsl:with-param name="default">null</xsl:with-param>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <!-- gets the string how the action is to be invoced in java code -->
  +    <xsl:variable name="action-name">
  +      action_set_<xsl:value-of select="$action-set"/>
  +    </xsl:variable>
  +
  +    <!-- test if we have to define parameters for this action -->
  +    <xsl:if test="count(parameter)>0">
  +      param = new Parameters ();
  +    </xsl:if>
  +
  +    <!-- generate the value used for the parameter argument in the 
invocation of the act method of this action -->
  +    <xsl:variable name="component-param">
  +      <xsl:choose>
  +        <xsl:when test="count(parameter)>0">
  +          param
  +        </xsl:when>
  +        <xsl:otherwise>
  +          emptyParam
  +        </xsl:otherwise>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <!-- collect the parameters -->
  +    <xsl:apply-templates select="parameter"/>
  +
  +    <!-- generate the invocation of the act method of the action component 
-->
  +    <xsl:choose>
  +      <xsl:when 
test="./*[namespace-uri()='http://apache.org/cocoon/sitemap/1.0']">
  +        if ((map = <xsl:value-of select="$action-name"/> (cocoon_action, 
listOfMaps, environment, objectModel, substitute(listOfMaps,<xsl:value-of 
select="$action-source"/>), <xsl:value-of select="$component-param"/>)) != 
null) {
  +         log.debug("Action <xsl:value-of 
select="translate($action-name,'&quot;',' ')"/>");
  +          listOfMaps.add (map);
  +          <xsl:apply-templates/>
  +          listOfMaps.remove(listOfMaps.size()-1);
  +        }
  +      </xsl:when>
  +      <xsl:otherwise>
  +        map = <xsl:value-of select="$action-name"/> (cocoon_action, 
listOfMaps, environment, objectModel, substitute(listOfMaps,<xsl:value-of 
select="$action-source"/>), <xsl:value-of select="$component-param"/>);
  +      </xsl:otherwise>
       </xsl:choose>
  -  </xsl:template> <!-- match="map:act" -->
  +  </xsl:template> <!-- match="map:[EMAIL PROTECTED]" -->
   
     <!-- generate the code to invoke a generator -->
     <xsl:template match="map:generate">
  @@ -667,7 +823,7 @@
     </xsl:template> <!-- match="map:label" -->
   
     <!-- collect parameter definitions -->
  -  <xsl:template match="map:pipeline//parameter">
  +  <xsl:template match="map:pipeline//parameter | map:action-set//parameter">
       param.setParameter ("<xsl:value-of select="@name"/>", 
substitute(listOfMaps, "<xsl:value-of select="@value"/>"));
     </xsl:template>
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.13  +7 -2      
xml-cocoon/src/org/apache/cocoon/environment/Attic/Environment.java
  
  Index: Environment.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/environment/Attic/Environment.java,v
  retrieving revision 1.1.2.12
  retrieving revision 1.1.2.13
  diff -u -r1.1.2.12 -r1.1.2.13
  --- Environment.java  2000/12/11 16:06:47     1.1.2.12
  +++ Environment.java  2000/12/30 21:33:10     1.1.2.13
  @@ -20,7 +20,7 @@
    * Base interface for an environment abstraction
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.12 $ $Date: 2000/12/11 16:06:47 $
  + * @version CVS $Revision: 1.1.2.13 $ $Date: 2000/12/30 21:33:10 $
    */
   
   public interface Environment extends EntityResolver {
  @@ -28,12 +28,17 @@
       /**
        * Get the URI to process
        */
  -    String getUri();
  +    String getURI();
   
       /**
        * Get the view to process
        */
       String getView();
  +
  +    /**
  +     * Get the action to process
  +     */
  +    String getAction();
   
       /**
        * Change the context from uriprefix to context
  
  
  
  1.1.2.7   +33 -2     
xml-cocoon/src/org/apache/cocoon/environment/Attic/AbstractEnvironment.java
  
  Index: AbstractEnvironment.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/environment/Attic/AbstractEnvironment.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- AbstractEnvironment.java  2000/11/15 19:29:37     1.1.2.6
  +++ AbstractEnvironment.java  2000/12/30 21:33:10     1.1.2.7
  @@ -41,6 +41,9 @@
       /** The View requested */
       protected String view = null;
   
  +    /** The Action requested */
  +    protected String action = null;
  +
        /** The Context path */
       protected URL context = null;
   
  @@ -51,8 +54,16 @@
        * Constructs the abstract enviornment
        */
       public AbstractEnvironment(String uri, String view, String context)
  +    throws MalformedURLException {
  +        this(uri, view, new File(context), null);
  +    }
  +
  +    /**
  +     * Constructs the abstract enviornment
  +     */
  +    public AbstractEnvironment(String uri, String view, String context, 
String action)
       throws MalformedURLException {
  -        this(uri, view, new File(context));
  +        this(uri, view, new File(context), action);
       }
   
       /**
  @@ -60,9 +71,18 @@
        */
       public AbstractEnvironment(String uri, String view, File context)
       throws MalformedURLException {
  +        this(uri, view, context, null);
  +    }
  +
  +    /**
  +     * Constructs the abstract enviornment
  +     */
  +    public AbstractEnvironment(String uri, String view, File context, String 
action)
  +    throws MalformedURLException {
           this.uri = uri;
           this.view = view;
           this.context = context.toURL();
  +        this.action = action;
           this.objectModel = new HashMap();
       }
   
  @@ -71,7 +91,7 @@
       /**
        * Returns the uri in progress. The prefix is stripped off
        */
  -    public String getUri() {
  +    public String getURI() {
           return this.uri;
       }
   
  @@ -90,6 +110,10 @@
                   this.context = f.toURL();
               }
           } else {
  +            log.error("The current URI ("
  +                + uri + ") doesn't start with given prefix ("
  +                + prefix + ")"
  +            );
               throw new RuntimeException("The current URI ("
                   + uri + ") doesn't start with given prefix ("
                   + prefix + ")"
  @@ -109,6 +133,13 @@
        */
       public String getView() {
           return this.view;
  +    }
  +
  +    /**
  +     * Returns the request action
  +     */
  +    public String getAction() {
  +        return this.action;
       }
   
       // Response methods
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.18  +1 -1      
xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java
  
  Index: HttpEnvironment.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java,v
  retrieving revision 1.1.2.17
  retrieving revision 1.1.2.18
  diff -u -r1.1.2.17 -r1.1.2.18
  --- HttpEnvironment.java      2000/12/18 16:55:19     1.1.2.17
  +++ HttpEnvironment.java      2000/12/30 21:33:11     1.1.2.18
  @@ -49,7 +49,7 @@
                               HttpServletResponse response,
                               ServletContext servletContext)
       throws MalformedURLException, IOException {
  -        super(uri, request.getParameter(Cocoon.VIEW_PARAM), 
servletContext.getRealPath("/"));
  +        super(uri, request.getParameter(Cocoon.VIEW_PARAM), 
servletContext.getRealPath("/"), request.getParameter(Cocoon.ACTION_PARAM));
           this.request = new HttpRequest (request, this);
           this.servletRequest = request;
           this.response = new HttpResponse (response);
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.13  +2 -1      xml-cocoon/src/org/apache/cocoon/Attic/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Constants.java,v
  retrieving revision 1.1.2.12
  retrieving revision 1.1.2.13
  diff -u -r1.1.2.12 -r1.1.2.13
  --- Constants.java    2000/12/06 19:19:51     1.1.2.12
  +++ Constants.java    2000/12/30 21:33:12     1.1.2.13
  @@ -10,7 +10,7 @@
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.12 $ $Date: 2000/12/06 19:19:51 $
  + * @version CVS $Revision: 1.1.2.13 $ $Date: 2000/12/30 21:33:12 $
    */
   
   public interface Constants {
  @@ -24,6 +24,7 @@
       String RELOAD_PARAM   = "cocoon-reload";
       String SHOWTIME_PARAM = "cocoon-showtime";
       String VIEW_PARAM     = "cocoon-view";
  +    String ACTION_PARAM   = "cocoon-action";
   
       String TEMPDIR_PROPERTY    = "org.apache.cocoon.properties.tempdir";
       String DEFAULT_CONTEXT_DIR = "./webapp";
  
  
  

Reply via email to