cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ovi...@apache.org
Subject cvs commit: xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/markup/xsp jpath.xsl
Date Wed, 08 May 2002 18:16:07 GMT
ovidiu      02/05/08 11:16:07

  Modified:    src/scratchpad/schecoon/src/org/apache/cocoon/markup/xsp
                        jpath.xsl
  Log:
  Updated to work with the 1.0b1 version of JXPath. Make use of
  CompiledExpressions to speed up the processing.
  
  Revision  Changes    Path
  1.8       +57 -10    xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/markup/xsp/jpath.xsl
  
  Index: jpath.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/markup/xsp/jpath.xsl,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- jpath.xsl	25 Mar 2002 07:39:34 -0000	1.7
  +++ jpath.xsl	8 May 2002 18:16:07 -0000	1.8
  @@ -20,8 +20,9 @@
           <xsp:include>java.util.Iterator</xsp:include>
           <xsp:include>org.apache.cocoon.environment.Environment</xsp:include>
           <xsp:include>org.apache.cocoon.components.flow.WebContinuation</xsp:include>
  -        <xsp:include>org.apache.commons.jpath.JPath</xsp:include>
  -        <xsp:include>org.apache.commons.jpath.JPathContext</xsp:include>
  +        <xsp:include>org.apache.commons.jxpath.JXPath</xsp:include>
  +        <xsp:include>org.apache.commons.jxpath.JXPathContext</xsp:include>
  +        <xsp:include>org.apache.commons.jxpath.CompiledExpression</xsp:include>
         </xsp:structure>
   
         <xsp:logic>
  @@ -31,18 +32,55 @@
           Object bean = ((Environment)resolver).getAttribute("bean-dict");
           WebContinuation kont
             = (WebContinuation)((Environment)resolver).getAttribute("kont");
  -        JPathContext jpathContext = JPathContext.newContext(bean);
  +        JXPathContext jxpathContext = JXPathContext.newContext(bean);
  +        // Generate the compiled representation of the JXPath
  +        // expressions used by this page.
  +        <xsl:apply-templates mode="compile"/>
         </xsp:init-page>
   
         <xsl:apply-templates/>
       </xsp:page>
     </xsl:template>
   
  +  <xsl:template match="jpath:if | jpath:when" mode="compile">
  +    <xsl:variable name="var-name">
  +      <xsl:call-template name="get-var-name">
  +        <xsl:with-param name="expr" select="@test"/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +    CompiledExpression <xsl:value-of select="$var-name"/>
  +      = jxpathContext.compile("<xsl:value-of select="@test"/>");
  +    <xsl:apply-templates select="jpath:*" mode="compile"/>
  +  </xsl:template>
  +
  +  <xsl:template match="jpath:for-each | jpath:value-of" mode="compile">
  +    <xsl:variable name="var-name">
  +      <xsl:call-template name="get-var-name">
  +        <xsl:with-param name="expr" select="@select"/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +    CompiledExpression <xsl:value-of select="$var-name"/>
  +      = jxpathContext.compile("<xsl:value-of select="@select"/>");
  +    <xsl:apply-templates select="jpath:*" mode="compile"/>
  +  </xsl:template>
  +
  +  <xsl:template match="*|@*|text()|processing-instruction()" mode="compile">
  +    <xsl:apply-templates mode="compile"/>
  +  </xsl:template>
  +
  +  <xsl:template name="get-var-name">
  +    <xsl:param name="expr"/>
  +    jxpath_<xsl:value-of select="translate($expr, '&#x20;&#x9;&#xA;&#xD;~`!@%^*()-+=[]{}\|,./?&gt;&lt;',
'')"/>
  +  </xsl:template>
  +
     <xsl:template match="jpath:if">
       <xsl:choose>
         <xsl:when test="@test">
           <xsp:logic>
  -          if (jpathContext.getValue("<xsl:value-of select="@test"/>") != null) {
  +          if (<xsl:call-template name="get-var-name">
  +                <xsl:with-param name="expr" select="@test"/>
  +              </xsl:call-template>
  +              .getValue(jxpathContext) != null) {
               <xsl:apply-templates/>
             }
           </xsp:logic>
  @@ -67,7 +105,10 @@
   
     <xsl:template match="jpath:when">
       <xsp:logic>
  -      else if (jpathContext.getValue("<xsl:value-of select="@test"/>") != null) {
  +      else if (<xsl:call-template name="get-var-name">
  +                <xsl:with-param name="expr" select="@test"/>
  +              </xsl:call-template>
  +              .getValue(jxpathContext) != null) {
           <xsl:apply-templates/>
         }
       </xsp:logic>
  @@ -91,20 +132,23 @@
         <xsl:when test="@select">
           <xsp:logic>
             {
  -            List selection = jpathContext.eval("<xsl:value-of select="@select"/>");
  +            List selection = <xsl:call-template name="get-var-name">
  +                               <xsl:with-param name="expr" select="@test"/>
  +                             </xsl:call-template>
  +                             .eval(jxpathContext);
               if (selection != null) {
                 Iterator iter = selection.iterator();
  -              JPathContext <xsl:value-of select="$old-context"/> = jpathContext;
  +              JPathContext <xsl:value-of select="$old-context"/> = jxpathContext;
                 while (iter.hasNext()) {
                   Object current = iter.next();
  -                jpathContext = JPathContext.newContext(current);
  +                jxpathContext = JPathContext.newContext(current);
           </xsp:logic>
   
           <xsl:apply-templates/>
   
           <xsp:logic>
                 }
  -              jpathContext = <xsl:value-of select="$old-context"/>;
  +              jxpathContext = <xsl:value-of select="$old-context"/>;
               }
             }
           </xsp:logic>
  @@ -121,7 +165,10 @@
       <xsp:expr>
         <xsl:choose>
           <xsl:when test="@select">
  -          jpathContext.getValue("<xsl:value-of select="@select"/>")
  +          <xsl:call-template name="get-var-name">
  +            <xsl:with-param name="expr" select="@select"/>
  +          </xsl:call-template>
  +          .getValue(jxpathContext)
           </xsl:when>
           <xsl:otherwise>
             <xsl:message terminate="yes">
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message