vgritsenko    2002/07/29 18:32:59

  Modified:    src/java/org/apache/cocoon/components/language/markup/xsp/java
                        soap.xsl xscript-lib.xsl xscript.xsl
  Log:
  XScript now has better variable management: variables of request,
  session, global, and page scope are stored not in the XScriptManager,
  but as request, session, context attributes, or as XSP page field
  (respectively). Chances of memory leaks are highly reduced.
  
  Revision  Changes    Path
  1.3       +8 -30     
xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/soap.xsl
  
  Index: soap.xsl
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/soap.xsl,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- soap.xsl  13 Feb 2002 01:09:07 -0000      1.2
  +++ soap.xsl  30 Jul 2002 01:32:58 -0000      1.3
  @@ -104,24 +104,12 @@
         </xsl:call-template>
       </xsl:variable>
   
  -    <xsl:variable name="context">
  -      <xsl:call-template name="xscript-get-context">
  -        <xsl:with-param name="scope" select="@scope"/>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
       <xsl:variable name="creation-scope">
         <xsl:call-template name="xscript-get-scope-for-creation">
           <xsl:with-param name="scope" select="@scope"/>
         </xsl:call-template>
       </xsl:variable>
   
  -    <xsl:variable name="creation-context">
  -      <xsl:call-template name="xscript-get-context-for-creation">
  -        <xsl:with-param name="scope" select="@scope"/>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
       <xscript:variable name="soap:call">
         <xsl:choose>
           <xsl:when test="soap:env">
  @@ -136,27 +124,23 @@
         <xsl:call-template name="xscript-get">
           <xsl:with-param name="name" select="'soap:call'"/>
           <xsl:with-param name="scope" select="$scope"/>
  -        <xsl:with-param name="context" select="$context"/>
           <xsl:with-param name="as" select="'object'"/>
         </xsl:call-template>
       </xsl:variable>
       <xsp:logic>
  -      getLogger().debug("URL context is " + 
XSPRequestHelper.getRequestedURL(objectModel));
         getLogger().debug("XScriptObject for soap:call is\n" + <xsl:value-of 
select="$object"/>);
         try {
  -        xscriptManager.put("soap:call",
  +        xscriptManager.put(pageScope, objectModel, "soap:call",
             ((new SOAPHelper(manager,
                              XSPRequestHelper.getRequestedURL(objectModel),
                              <xsl:value-of select="$url"/>,
                              <xsl:value-of select="$method"/>,
                              <xsl:value-of select="$object"/>
                              )).invoke()),
  -          <xsl:value-of select="$creation-scope"/>,
  -          <xsl:value-of select="$creation-context"/>);
  +          <xsl:value-of select="$creation-scope"/>);
           getLogger().debug("SOAP result is\n" + <xsl:value-of select="$object"/>);
           <xscript:get name="soap:call"/>
  -      }
  -      catch (Exception ex) {
  +      } catch (Exception ex) {
           <soap-err:error 
xmlns:soap-err="http://apache.org/xsp/soap/3.0";><xsp:expr>ex</xsp:expr></soap-err:error>
           getLogger().error(ex.toString(), ex);
         }
  @@ -164,9 +148,7 @@
     </xsl:template>
   
     <xsl:template match="soap:env" name="soap-env">
  -    <SOAP-ENV:Envelope
  -      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
  -      >
  +    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";>
         <xsl:if test="soap:header">
             <xsl:apply-templates select="soap:header"/>
         </xsl:if>
  @@ -182,9 +164,7 @@
     </xsl:template>
   
     <xsl:template match="soap:header" name="soap-header">
  -      <SOAP-ENV:Header
  -        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
  -        >
  +      <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";>
           <xsl:apply-templates select="*[name() != 'soap:url'
                                          and name() != 'soap:method'
                                          and name() != 'soap:namespace']"/>
  @@ -200,9 +180,7 @@
             "<xsl:value-of select="@uri"/>");
         </xsl:for-each>
       </xsp:logic>
  -    <SOAP-ENV:Body
  -      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
  -      >
  +    <SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";>
         <xsl:apply-templates select="*[name() != 'soap:url'
                                        and name() != 'soap:method'
                                        and name() != 'soap:namespace']"/>
  
  
  
  1.6       +19 -79    
xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xscript-lib.xsl
  
  Index: xscript-lib.xsl
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xscript-lib.xsl,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- xscript-lib.xsl   14 Apr 2002 00:45:29 -0000      1.5
  +++ xscript-lib.xsl   30 Jul 2002 01:32:58 -0000      1.6
  @@ -74,14 +74,12 @@
       <xsl:param name="name"/>
       <xsl:param name="href"/>
       <xsl:param name="scope"/>
  -    <xsl:param name="context"/>
   
       <xsl:choose>
         <xsl:when test="$href">
           <xsl:call-template name="xscript-variable-from-url">
             <xsl:with-param name="name" select="$name"/>
             <xsl:with-param name="scope" select="$scope"/>
  -          <xsl:with-param name="context" select="$context"/>
             <xsl:with-param name="href" select="$href"/>
           </xsl:call-template>
         </xsl:when>
  @@ -89,7 +87,6 @@
           <xsl:call-template name="xscript-variable-inline">
             <xsl:with-param name="name" select="$name"/>
             <xsl:with-param name="scope" select="$scope"/>
  -          <xsl:with-param name="context" select="$context"/>
           </xsl:call-template>
         </xsl:otherwise>
       </xsl:choose>
  @@ -101,20 +98,11 @@
       <xsl:param name="name"/>
       <xsl:param name="as"/>
       <xsl:param name="scope"/>
  -    <xsl:param name="context"/>
   
       <xsl:variable name="object">
  -      <xsl:choose>
  -        <xsl:when test="contains($scope, 'ALL_SCOPES')">
  -          xscriptManager.getFirst("<xsl:value-of select="$name"/>",
  -                                  <xsl:value-of select="$context"/>)
  -        </xsl:when>
  -        <xsl:otherwise>
  -          xscriptManager.get("<xsl:value-of select="$name"/>",
  -                             <xsl:value-of select="$scope"/>,
  -                             <xsl:value-of select="$context"/>)
  -        </xsl:otherwise>
  -      </xsl:choose>
  +      xscriptManager.get(pageScope, objectModel, "<xsl:value-of select="$name"/>",
  +                         <xsl:value-of select="$scope"/>
  +      <xsl:text>)</xsl:text>
       </xsl:variable>
       <xsl:choose>
         <xsl:when test="$as = 'object'">
  @@ -139,39 +127,26 @@
       <!-- PUBLIC: undeclare an XScript variable -->
       <xsl:param name="name"/>
       <xsl:param name="scope"/>
  -    <xsl:param name="context"/>
       <xsp:logic>
  -      <xsl:choose>
  -        <xsl:when test="contains($scope, 'ALL_SCOPES')">
  -          xscriptManager.removeFirst("<xsl:value-of select="$name"/>",
  -                                     <xsl:value-of select="$context"/>);
  -        </xsl:when>
  -        <xsl:otherwise>
  -          xscriptManager.remove("<xsl:value-of select="$name"/>",
  -                                <xsl:value-of select="$scope"/>,
  -                                <xsl:value-of select="$context"/>);
  -        </xsl:otherwise>
  -      </xsl:choose>
  +      xscriptManager.remove(pageScope, objectModel, "<xsl:value-of 
select="$name"/>", <xsl:value-of select="$scope"/>);
       </xsp:logic>
     </xsl:template>
   
  +
     <xsl:template name="xscript-transform">
       <!-- PUBLIC: transform an XScriptObject pointed to by a variable
            using another XScriptObject, which is assumed to contain an
            XSLT stylesheet. -->
       <xsl:param name="name"/>
       <xsl:param name="scope"/>
  -    <xsl:param name="context">""</xsl:param>
       <xsl:param name="stylesheet"/>
       <xsl:param name="stylesheet-scope"/>
  -    <xsl:param name="stylesheet-context">""</xsl:param>
       <xsl:param name="parameters"/>
   
       <xsl:variable name="object">
         <xsl:call-template name="xscript-get">
           <xsl:with-param name="name" select="$name"/>
           <xsl:with-param name="scope" select="$scope"/>
  -        <xsl:with-param name="context" select="$context"/>
           <xsl:with-param name="as" select="'object'"/>
         </xsl:call-template>
       </xsl:variable>
  @@ -180,13 +155,12 @@
         <xsl:call-template name="xscript-get">
           <xsl:with-param name="name" select="$stylesheet"/>
           <xsl:with-param name="scope" select="$stylesheet-scope"/>
  -        <xsl:with-param name="context" select="$stylesheet-context"/>
           <xsl:with-param name="as" select="'object'"/>
         </xsl:call-template>
       </xsl:variable>
   
       <xsl:variable name="params">
  -      params<xsl:value-of select="count(ancestor-or-self::*)"/>
  +      <xsl:text>params</xsl:text><xsl:value-of select="count(ancestor-or-self::*)"/>
       </xsl:variable>
   
       <xsp:logic>
  @@ -216,14 +190,11 @@
       <!-- PUBLIC: create an XScript variable from an URL -->
       <xsl:param name="name"/>
       <xsl:param name="scope"/>
  -    <xsl:param name="context"/>
       <xsl:param name="href"/>
       <xsp:logic>
  -      xscriptManager.put("<xsl:value-of select="$name"/>",
  -                         new XScriptObjectFromURL(xscriptManager,
  -                                                  "<xsl:value-of select="$href"/>"),
  -                         <xsl:value-of select="$scope"/>,
  -                         <xsl:value-of select="$context"/>);
  +      xscriptManager.put(pageScope, objectModel, "<xsl:value-of select="$name"/>",
  +                         new XScriptObjectFromURL(xscriptManager, "<xsl:value-of 
select="$href"/>"),
  +                         <xsl:value-of select="$scope"/>);
       </xsp:logic>
     </xsl:template>
   
  @@ -231,10 +202,9 @@
       <!-- PUBLIC: create an XScript variable from inline XML -->
       <xsl:param name="name"/>
       <xsl:param name="scope"/>
  -    <xsl:param name="context"/>
   
       <xsl:variable name="xml-inline">
  -      xmlInline<xsl:value-of select="count(ancestor-or-self::*)"/>
  +      <xsl:text>xmlInline</xsl:text><xsl:value-of 
select="count(ancestor-or-self::*)"/>
       </xsl:variable>
   
       <xsl:variable name="oldHandler">
  @@ -246,26 +216,26 @@
           XScriptObjectInlineXML <xsl:value-of select="$xml-inline"/>
             = new XScriptObjectInlineXML(xscriptManager);
           ContentHandler <xsl:value-of select="$oldHandler"/> = this.contentHandler;
  -        <xsl:value-of select="$xml-inline"/>.setNextContentHandler(<xsl:value-of 
select="$oldHandler"/>);
  +<!--        <xsl:value-of 
select="$xml-inline"/>.setNextContentHandler(<xsl:value-of select="$oldHandler"/>);-->
           this.contentHandler = <xsl:value-of 
select="$xml-inline"/>.getContentHandler();
           <xsl:apply-templates/>
           this.contentHandler = <xsl:value-of select="$oldHandler"/>;
  -        xscriptManager.put("<xsl:value-of select="$name"/>",
  +        xscriptManager.put(pageScope, objectModel, "<xsl:value-of select="$name"/>",
                              <xsl:value-of select="$xml-inline"/>,
  -                           <xsl:value-of select="$scope"/>,
  -                           <xsl:value-of select="$context"/>);
  +                           <xsl:value-of select="$scope"/>);
         }
       </xsp:logic>
  -
     </xsl:template>
   
  +
     <xsl:template name="xscript-get-scope">
       <!-- PUBLIC: obtain the Java expression for a given XScript
            variable scope. If no scope parameter is specified,
            ALL_SCOPES is assumed. -->
       <xsl:param name="scope" select="'all-scopes'"/>
       <xsl:choose>
  -      <xsl:when test="$scope = 
'global'">org.apache.cocoon.components.xscript.XScriptManager.GLOBAL_SCOPE</xsl:when>
  +      <xsl:when test="$scope = 'global' or $scope = 
'application'">org.apache.cocoon.components.xscript.XScriptManager.GLOBAL_SCOPE</xsl:when>
  +      <xsl:when test="$scope = 
'request'">org.apache.cocoon.components.xscript.XScriptManager.REQUEST_SCOPE</xsl:when>
         <xsl:when test="$scope = 
'page'">org.apache.cocoon.components.xscript.XScriptManager.PAGE_SCOPE</xsl:when>
         <xsl:when test="$scope = 
'session'">org.apache.cocoon.components.xscript.XScriptManager.SESSION_SCOPE</xsl:when>
         
<xsl:otherwise>org.apache.cocoon.components.xscript.XScriptManager.ALL_SCOPES</xsl:otherwise>
  @@ -281,39 +251,9 @@
       <xsl:param name="scope" select="'session'"/>
       <xsl:choose>
         <xsl:when test="$scope = 
'global'">org.apache.cocoon.components.xscript.XScriptManager.GLOBAL_SCOPE</xsl:when>
  +      <xsl:when test="$scope = 
'request'">org.apache.cocoon.components.xscript.XScriptManager.REQUEST_SCOPE</xsl:when>
         <xsl:when test="$scope = 
'page'">org.apache.cocoon.components.xscript.XScriptManager.PAGE_SCOPE</xsl:when>
         
<xsl:otherwise>org.apache.cocoon.components.xscript.XScriptManager.SESSION_SCOPE</xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template name="xscript-get-context">
  -    <!-- PUBLIC: obtain the Java expression for an XScript variable
  -         context. If the 'scope' parameter is not specified or when
  -         its value is 'all-scopes', an expression that contains both
  -         the session and the page scope is returned. This could be
  -         passed directly to the getFirst() method of XScriptManager.
  -         -->
  -    <xsl:param name="scope" select="'all-scopes'"/>
  -    <xsl:choose>
  -      <xsl:when test="$scope = 'global'">""</xsl:when>
  -      <!-- for the page scope use the context-path as context -->
  -      <xsl:when test="$scope = 'page'">(request.getContextPath())</xsl:when>
  -      <xsl:when test="$scope = 'session'">(request.getSession().getId())</xsl:when>
  -      <xsl:otherwise>(request.getSession().getId()), 
(request.getContextPath())</xsl:otherwise>
  -    </xsl:choose>
  -  </xsl:template>
  -
  -  <xsl:template name="xscript-get-context-for-creation">
  -    <!-- PUBLIC: obtain the Java expression for an XScript variable
  -         context. If the `scope' parameter is not specified, the
  -         default is SESSION_SCOPE.
  -         -->
  -    <xsl:param name="scope" select="'session'"/>
  -    <xsl:choose>
  -      <xsl:when test="$scope = 'global'">""</xsl:when>
  -      <!-- for the page scope use the context-path as context -->
  -      <xsl:when test="$scope = 'page'">(request.getContextPath())</xsl:when>
  -      <xsl:otherwise>(request.getSession().getId())</xsl:otherwise>
       </xsl:choose>
     </xsl:template>
   
  
  
  
  1.4       +14 -48    
xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xscript.xsl
  
  Index: xscript.xsl
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/xscript.xsl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- xscript.xsl       13 Feb 2002 01:09:08 -0000      1.3
  +++ xscript.xsl       30 Jul 2002 01:32:58 -0000      1.4
  @@ -78,6 +78,7 @@
         </xsp:structure>
   
         <xsp:logic>
  +        XScriptVariableScope pageScope = new XScriptVariableScope();
           XScriptManager xscriptManager;
   
           public void compose(ComponentManager manager) throws ComponentException {
  @@ -105,17 +106,11 @@
           <xsl:with-param name="scope" select="@scope"/>
         </xsl:call-template>
       </xsl:variable>
  -    <xsl:variable name="context">
  -      <xsl:call-template name="xscript-get-context-for-creation">
  -        <xsl:with-param name="scope" select="@scope"/>
  -      </xsl:call-template>
  -    </xsl:variable>
   
       <xsl:call-template name="xscript-variable">
         <xsl:with-param name="name" select="@name"/>
         <xsl:with-param name="href" select="@href"/>
         <xsl:with-param name="scope" select="$scope"/>
  -      <xsl:with-param name="context" select="$context"/>
       </xsl:call-template>
     </xsl:template>
   
  @@ -126,37 +121,26 @@
           <xsl:with-param name="scope" select="@scope"/>
         </xsl:call-template>
       </xsl:variable>
  -    <xsl:variable name="context">
  -      <xsl:call-template name="xscript-get-context">
  -        <xsl:with-param name="scope" select="@scope"/>
  -      </xsl:call-template>
  -    </xsl:variable>
  +
       <xsp:logic>
         <xsl:call-template name="xscript-get">
           <xsl:with-param name="name" select="@name"/>
           <xsl:with-param name="as" select="@as"/>
           <xsl:with-param name="scope" select="$scope"/>
  -        <xsl:with-param name="context" select="$context"/>
  -      </xsl:call-template>
  -      ;
  +      </xsl:call-template>;
       </xsp:logic>
     </xsl:template>
   
  +
     <xsl:template match="xscript:remove">
       <xsl:variable name="scope">
         <xsl:call-template name="xscript-get-scope">
           <xsl:with-param name="scope" select="@scope"/>
         </xsl:call-template>
       </xsl:variable>
  -    <xsl:variable name="context">
  -      <xsl:call-template name="xscript-get-context">
  -        <xsl:with-param name="scope" select="@scope"/>
  -      </xsl:call-template>
  -    </xsl:variable>
       <xsl:call-template name="xscript-remove">
         <xsl:with-param name="name" select="@name"/>
         <xsl:with-param name="scope" select="$scope"/>
  -      <xsl:with-param name="context" select="$context"/>
       </xsl:call-template>
     </xsl:template>
   
  @@ -168,23 +152,12 @@
           <xsl:with-param name="scope" select="@scope"/>
         </xsl:call-template>
       </xsl:variable>
  -    <xsl:variable name="context">
  -      <xsl:call-template name="xscript-get-context">
  -        <xsl:with-param name="scope" select="@scope"/>
  -      </xsl:call-template>
  -    </xsl:variable>
  -
       <xsl:variable name="stylesheet" select="@stylesheet"/>
       <xsl:variable name="stylesheet-scope">
         <xsl:call-template name="xscript-get-scope">
           <xsl:with-param name="stylesheet-scope" select="@stylesheet-scope"/>
         </xsl:call-template>
       </xsl:variable>
  -    <xsl:variable name="stylesheet-context">
  -      <xsl:call-template name="xscript-get-context">
  -        <xsl:with-param name="stylesheet-context" select="@stylesheet-context"/>
  -      </xsl:call-template>
  -    </xsl:variable>
   
       <xsl:variable name="parameters">
         <xsl:copy-of select="xscript:parameter"/>
  @@ -193,10 +166,8 @@
       <xsl:call-template name="xscript-transform">
         <xsl:with-param name="name" select="$name"/>
         <xsl:with-param name="scope" select="$scope"/>
  -      <xsl:with-param name="context" select="$context"/>
         <xsl:with-param name="stylesheet" select="$stylesheet"/>
         <xsl:with-param name="stylesheet-scope" select="$stylesheet-scope"/>
  -      <xsl:with-param name="stylesheet-context" select="$stylesheet-context"/>
         <xsl:with-param name="parameters" select="$parameters"/>
       </xsl:call-template>
     </xsl:template>
  @@ -205,7 +176,13 @@
     <xsl:template match="xscript:copy-of | xscript:value-of">
       <xsl:variable name="parameters">
         <xscript:parameter name="xpath">
  -        <xsl:value-of select="@select"/>
  +        <xsl:choose>
  +          <xsl:when test="string-length(@select) &gt; 0">
  +            <xsl:value-of select="@select"/>
  +          </xsl:when>
  +          <xsl:otherwise>/</xsl:otherwise>
  +        </xsl:choose>
  +
         </xscript:parameter>
       </xsl:variable>
       <xsl:call-template name="xscript-builtin">
  @@ -226,31 +203,20 @@
           <xsl:with-param name="scope" select="@scope"/>
         </xsl:call-template>
       </xsl:variable>
  -    <xsl:variable name="context">
  -      <xsl:call-template name="xscript-get-context">
  -        <xsl:with-param name="scope" select="@scope"/>
  -      </xsl:call-template>
  -    </xsl:variable>
   
       <xsl:call-template name="xscript-transform">
         <xsl:with-param name="parameters" select="$parameters"/>
         <xsl:with-param name="name" select="$name"/>
         <xsl:with-param name="scope" select="$scope"/>
  -      <xsl:with-param name="context" select="$context"/>
         <xsl:with-param name="stylesheet" select="$builtin"/>
         <xsl:with-param name="stylesheet-scope">
           <xsl:call-template name="xscript-get-scope">
             <xsl:with-param name="scope" select="'global'"/>
           </xsl:call-template>
         </xsl:with-param>
  -      <xsl:with-param name="stylesheet-context">
  -        <xsl:call-template name="xscript-get-context">
  -          <xsl:with-param name="scope" select="'global'"/>
  -        </xsl:call-template>
  -      </xsl:with-param>
       </xsl:call-template>
  -
     </xsl:template>
  +
   
     <xsl:template match="@*|*|text()|processing-instruction()">
       <!-- Catch all template. Just pass along unmodified everything we
  
  
  

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