Author: antonio Date: Mon Oct 25 14:57:51 2004 New Revision: 55535 Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/jpath.xsl cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/userdocs/flow/jpath.xml cocoon/branches/BRANCH_2_1_X/status.xml Log: Fix bug #31564- [XSP] - JXPath logicsheet: Allow use relative contexts in <jxpath:for-each>. Add a new tag <jpath:set-lenient lenient='true|false'>
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/jpath.xsl ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/jpath.xsl (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/java/jpath.xsl Mon Oct 25 14:57:51 2004 @@ -46,6 +46,7 @@ <xsp:include>org.apache.cocoon.components.flow.FlowHelper</xsp:include> <xsp:include>org.apache.commons.jxpath.JXPathContext</xsp:include> <xsp:include>org.apache.commons.jxpath.CompiledExpression</xsp:include> + <xsp:include>org.apache.commons.jxpath.Pointer</xsp:include> </xsp:structure> <xsp:logic> @@ -164,22 +165,25 @@ <xsl:when test="@select"> <xsp:logic> { - Iterator iter_<xsl:value-of select="generate-id(.)"/> - = <xsl:call-template name="get-var-name"> - <xsl:with-param name="expr" select="@select"/> - </xsl:call-template> - .iterate(jxpathContext); JXPathContext <xsl:value-of select="$old-context"/> = jxpathContext; - while (iter_<xsl:value-of select="generate-id(.)"/>.hasNext()) { - Object current_<xsl:value-of select="generate-id(.)"/> = iter_<xsl:value-of select="generate-id(.)"/>.next(); - jxpathContext = JXPathContext.newContext(current_<xsl:value-of select="generate-id(.)"/>); + try { + Iterator iter_<xsl:value-of select="generate-id(.)"/> + = <xsl:call-template name="get-var-name"> + <xsl:with-param name="expr" select="@select"/> + </xsl:call-template> + .iteratePointers(jxpathContext); + while (iter_<xsl:value-of select="generate-id(.)"/>.hasNext()) { + jxpathContext = <xsl:value-of select="$old-context"/> + .getRelativeContext((Pointer)iter_<xsl:value-of select="generate-id(.)"/>.next()); </xsp:logic> <xsl:apply-templates/> <xsp:logic> + } + } finally { + jxpathContext = <xsl:value-of select="$old-context"/>; } - jxpathContext = <xsl:value-of select="$old-context"/>; } </xsp:logic> </xsl:when> @@ -223,6 +227,29 @@ </xsp:expr> </xsl:template> + <xsl:template match="jpath:set-lenient"> + <xsl:choose> + <xsl:when test="*"> + <xsp:logic> + { + boolean __jxpathLenient = jxpathContext.isLenient(); + try { + jxpathContext.setLenient(<xsl:value-of select="@lenient"/>); + </xsp:logic> + <xsl:apply-templates/> + <xsp:logic> + } finally { + jxpathContext.setLenient(__jxpathLenient); + } + } + </xsp:logic> + </xsl:when> + <xsl:otherwise> + <xsp:logic>jxpathContext.setLenient(<xsl:value-of select="@lenient"/>);</xsp:logic> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template match="@*|*|text()|processing-instruction()"> <!-- Catch all template. Just pass along unmodified everything we don't handle. --> @@ -230,6 +257,5 @@ <xsl:apply-templates select="@*|*|text()|processing-instruction()"/> </xsl:copy> </xsl:template> - </xsl:stylesheet> Modified: cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/userdocs/flow/jpath.xml ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/userdocs/flow/jpath.xml (original) +++ cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/userdocs/flow/jpath.xml Mon Oct 25 14:57:51 2004 @@ -34,6 +34,7 @@ alternate bean properties. It is based on <link href="http://jakarta.apache.org/commons/jxpath">Apache JXPath</link>. </p> + <p>Samples of this Logic Sheet are avaliable in the XSP implementation of the petstore block</p> </s1> <s1 title ="Tags"> <p>The JPath tags are defined in the namespace</p> @@ -119,6 +120,27 @@ <source> <xsp:attribute name="action"><xsp:expr><jpath:continuation/>+".form"</xsp:expr></xsp:attribute> </source> + </s2> + <s2 title="set-lenient"> + <note>Since Cocoon 2.1.6</note> + <p> + The <code>set-lenient</code> tag switch the lenient setting of jxpath. + By default it is set to false. If set to true, xpaths that don't point to an + object or a set of them will return null (Instead of that annoying exception). + Saves all the checking if you can accept nulls and are sure there are no typos. + </p> + <p> + If the tag contains child elements it will scope the setting for the enclosed + elements, otherwise it is a global setting. You can't nest <jpath:set-lenient> + tags. + </p> + <source> + <jpath:set-lenient lenient="true|false"> + </source> + <p>Example:</p> + <source> + <jpath:set-lenient lenient="true"> + </source> </s2> </s1> </body> Modified: cocoon/branches/BRANCH_2_1_X/status.xml ============================================================================== --- cocoon/branches/BRANCH_2_1_X/status.xml (original) +++ cocoon/branches/BRANCH_2_1_X/status.xml Mon Oct 25 14:57:51 2004 @@ -205,6 +205,10 @@ <changes> <release version="@version@" date="@date@"> + <action dev="AG" type="fix" fixes-bug="31564" due-to="Gunnar Brand" due-to-email="[EMAIL PROTECTED]"> + XSP - JXPath logicsheet: Allow use relative contexts in <jxpath:for-each>. + Add a new tag <jpath:set-lenient lenient="true|false"> + </action> <action dev="AG" type="update"> Updated commons-httpclient to 2.0.2 </action>