Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2009-04-08 13:06:21 -0400
committerpelder2009-04-08 13:06:21 -0400
commit16c605b313afb00d2e295963acbdc9024519629d (patch)
tree5864a536bf98fffc4d24dc1ed22991c5da95716a
parenta886d25844621c46d3b0026e58383fa089578a9e (diff)
downloadorg.eclipse.jet-16c605b313afb00d2e295963acbdc9024519629d.tar.gz
org.eclipse.jet-16c605b313afb00d2e295963acbdc9024519629d.tar.xz
org.eclipse.jet-16c605b313afb00d2e295963acbdc9024519629d.zip
[271663] Make c:with tag ignore content if select expression returns no result
-rw-r--r--plugins/org.eclipse.jet/plugin.xml4
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WithTag.java34
2 files changed, 20 insertions, 18 deletions
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 0d01f26..53f2fda 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -553,7 +553,7 @@ If this tag is not directly contained by a 'choose' tag, then an error results.
</description>
</attribute>
</conditionalTag>
- <containerTag
+ <conditionalTag
class="org.eclipse.jet.internal.taglib.control.WithTag"
name="with"
processContents="standard"
@@ -583,7 +583,7 @@ Optionally, an XPath variable may be set by providing a &apos;var&apos; attribut
An optional XPath variable name that will contain the result of the XPath expression.
</description>
</attribute>
- </containerTag>
+ </conditionalTag>
<iteratingTag
class="org.eclipse.jet.internal.taglib.control.DeepIterateTag"
name="deepIterate"
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WithTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WithTag.java
index 4123ddc..b9596de 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WithTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WithTag.java
@@ -12,43 +12,45 @@
*
* </copyright>
*
- * $Id: WithTag.java,v 1.1 2009/03/09 15:29:32 pelder Exp $
+ * $Id: WithTag.java,v 1.2 2009/04/08 17:06:21 pelder Exp $
*/
package org.eclipse.jet.internal.taglib.control;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.XPathContextExtender;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.taglib.AbstractContainerTag;
+import org.eclipse.jet.taglib.AbstractConditionalTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
/**
* Implement the &lt;c:with&gt; tag.
*/
-public class WithTag extends AbstractContainerTag
+public class WithTag extends AbstractConditionalTag
{
- private boolean contextPushed = false;
private String varName = null;
private Object savedVarValue = null;
+ private Object contextObject;
+ public boolean doEvalCondition(TagInfo td, JET2Context context) throws JET2TagException
+ {
+ final String selectXPath = getAttribute("select"); //$NON-NLS-1$
+ varName = getAttribute("var"); //$NON-NLS-1$
+ final XPathContextExtender xpc = XPathContextExtender.getInstance(context);
+
+ contextObject = xpc.resolveSingle(selectXPath);
+
+ return contextObject != null;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.jet.taglib.ContainerTag#doBeforeBody(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
*/
public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
- final String selectXPath = getAttribute("select"); //$NON-NLS-1$
- varName = getAttribute("var"); //$NON-NLS-1$
final XPathContextExtender xpc = XPathContextExtender.getInstance(context);
-
- final Object contextObject = xpc.resolveSingle(selectXPath);
- if(contextObject == null) {
- throw new JET2TagException(JET2Messages.GetTag_NoResult);
- }
xpc.pushXPathContextObject(contextObject);
- contextPushed = true;
if(varName != null) {
savedVarValue = context.hasVariable(varName) ? context.getVariable(varName) : null;
@@ -62,9 +64,8 @@ public class WithTag extends AbstractContainerTag
public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
final XPathContextExtender xpc = XPathContextExtender.getInstance(context);
- if(contextPushed) {
- xpc.popXPathContextObject();
- }
+
+ xpc.popXPathContextObject();
if(varName != null) {
if(savedVarValue != null) {
context.setVariable(varName, savedVarValue);
@@ -74,4 +75,5 @@ public class WithTag extends AbstractContainerTag
}
}
+
}

Back to the top