ovidiu      02/02/15 17:41:33

  Added:       src/scratchpad/schecoon/src/org/apache/cocoon/markup/xsp
                        jpath.xsl
  Log:
  Simple stylesheet for extracting data out of Java objects passed from
  the flow control layer. This should be only logicsheet needed when
  developing Web applications using Schecoon: the flow control layer
  invokes the business logic layer, and passes objects from it to the
  content generation layer. The content generation (XSP) uses this
  logicsheet to extract data from the objects passed to it.
  
  Revision  Changes    Path
  1.1                  
xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/markup/xsp/jpath.xsl
  
  Index: jpath.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <xsl:stylesheet
    version="1.0"
    xmlns:xsp="http://apache.org/xsp";
    xmlns:jpath="http://apache.org/xsp/jpath/1.0";
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
    <xsl:template match="xsp:page">
      <xsp:page>
        <xsl:apply-templates select="@*"/>
        <xsp:structure>
          <xsp:include>java.util.List</xsp:include>
          <xsp:include>java.util.Iterator</xsp:include>
          <xsp:include>org.apache.cocoon.environment.Environment</xsp:include>
          <xsp:include>org.apache.commons.jpath.JPath</xsp:include>
          <xsp:include>org.apache.commons.jpath.JPathContext</xsp:include>
          <xsp:include>sisc.data.Value</xsp:include>
          <xsp:include>sisc.modules.J2S</xsp:include>
        </xsp:structure>
  
        <xsp:logic>
        </xsp:logic>
  
        <xsp:init-page>
          Value sbean = (Value)((Environment)resolver).getAttribute("bean-dict");
          Object bean = sbean.javaValue();
          System.out.println ("bean class = " + bean.getClass() + ", bean = " + bean);
  
          JPathContext jpathContext = JPathContext.newContext(bean);
          System.out.println ("bean value = " + jpathContext.getValue("."));
        </xsp:init-page>
  
        <xsl:apply-templates/>
      </xsp:page>
    </xsl:template>
  
    <xsl:template match="jpath:if">
      <xsl:choose>
        <xsl:when test="@test">
          <xsp:logic>
            if (jpathContext.getValue("<xsl:value-of select="@test"/>") != null) {
              <xsl:apply-templates/>
            }
          </xsp:logic>
        </xsl:when>
        <xsl:otherwise>
          <xsl:message terminate="yes">
            <xsl:text>Required 'test' attribute in &lt;jpath:if&gt; is 
missing!</xsl:text>
          </xsl:message>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template match="jpath:for-each">
      <xsl:variable name="old-context">
        oldJPathContext<xsl:value-of select="count(ancestor-or-self::*)"/>
      </xsl:variable>
  
      <xsl:choose>
        <xsl:when test="@select">
          <xsp:logic>
            {
              List selection = jpathContext.eval("<xsl:value-of select="@select"/>");
              if (selection != null) {
                Iterator iter = selection.iterator();
                JPathContext <xsl:value-of select="$old-context"/> = jpathContext;
                while (iter.hasNext()) {
                  Object current = iter.next();
                  jpathContext = JPathContext.newContext(current);
          </xsp:logic>
  
          <xsl:apply-templates/>
  
          <xsp:logic>
                }
                jpathContext = <xsl:value-of select="$old-context"/>;
              }
            }
          </xsp:logic>
        </xsl:when>
        <xsl:otherwise>
          <xsl:message terminate="yes">
            <xsl:text>Required 'select' attribute in &lt;jpath:for-each&gt; is 
missing!</xsl:text>
          </xsl:message>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template match="jpath:value-of">
      <xsl:choose>
        <xsl:when test="@select">
          jpathContext.getValue("<xsl:value-of select="@select"/>")
        </xsl:when>
        <xsl:otherwise>
          <xsl:message terminate="yes">
            <xsl:text>Required 'select' attribute in &lt;jpath:value-of&gt; is 
missing!</xsl:text>
          </xsl:message>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template match="@*|*|text()|processing-instruction()">
      <!-- Catch all template. Just pass along unmodified everything we
           don't handle. -->
      <xsl:copy>
        <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
      </xsl:copy>
    </xsl:template>
  
  
  </xsl:stylesheet>
  
  
  
  

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