summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-03-21 10:33:45 (EST)
committer pelder2006-03-21 10:33:45 (EST)
commitbea4ac33c408a1f30ea2246abbe5ab34181a2596 (patch)
treed9f67103e3c668dd2cadb695fe42fe701c44770b
parentbac10b26cfdd6ae8dbbf520cf0b3ed391b4d0331 (diff)
downloadorg.eclipse.jet-bea4ac33c408a1f30ea2246abbe5ab34181a2596.zip
org.eclipse.jet-bea4ac33c408a1f30ea2246abbe5ab34181a2596.tar.gz
org.eclipse.jet-bea4ac33c408a1f30ea2246abbe5ab34181a2596.tar.bz2
[132691] Control tag clean-up.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/XPathContextExtender.java10
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AbstractChooseAlternative.java74
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddElementTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddTextElementTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/ChooseTag.java34
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/CopyElementTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/GetTag.java22
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IfTag.java40
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IterateTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OtherwiseTag.java18
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/RemoveElementTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetTag.java36
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetVariableTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitorTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WhenTag.java54
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java6
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java2
18 files changed, 244 insertions, 68 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/XPathContextExtender.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/XPathContextExtender.java
index ed77b55..6f067a6 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/XPathContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/XPathContextExtender.java
@@ -71,12 +71,22 @@ public final class XPathContextExtender extends AbstractContextExtender implemen
/**
* @param context
+ * @deprecated Use {@link #getInstance(JET2Context)}. This method will be made private in the near future.
*/
public XPathContextExtender(JET2Context context)
{
super(context);
}
+ /**
+ * Factory method for XPathContextExtenders
+ * @param context the JET2Context that is extended
+ * @return an XPathContextExtender
+ */
+ public static XPathContextExtender getInstance(JET2Context context)
+ {
+ return new XPathContextExtender(context);
+ }
/* (non-Javadoc)
* @see org.eclipse.jet.AbstractContextExtender#createExtendedData(org.eclipse.jet.JET2Context)
*/
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AbstractChooseAlternative.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AbstractChooseAlternative.java
new file mode 100644
index 0000000..4492fe9
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AbstractChooseAlternative.java
@@ -0,0 +1,74 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.taglib.control;
+
+import java.text.MessageFormat;
+
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.taglib.AbstractConditionalTag;
+import org.eclipse.jet.taglib.CustomTag;
+import org.eclipse.jet.taglib.JET2TagException;
+
+/**
+ * Abstract class than handles common behaviors between 'when' and 'otherwise' tag implementations
+ */
+public abstract class AbstractChooseAlternative extends AbstractConditionalTag
+{
+
+ /**
+ *
+ */
+ public AbstractChooseAlternative()
+ {
+ super();
+ }
+
+ /**
+ * Write the body content to the parent Choose tag selectionWriter.
+ */
+ public void setBodyContent(JET2Writer bodyContent)
+ {
+ CustomTag parentTag = getParent();
+
+ if (parentTag instanceof ChooseTag)
+ {
+ ChooseTag chooseTag = (ChooseTag)parentTag;
+ chooseTag.writeSelection(bodyContent);
+ }
+ }
+
+ /**
+ * Return the parent ChooseTag, or throw an exception
+ * @return the parent ChooseTag
+ * @throws JET2TagException if there is no parent choose tag.
+ */
+ protected final ChooseTag getChooseTag() throws JET2TagException
+ {
+ CustomTag parentTag = getParent();
+
+ if (parentTag instanceof ChooseTag)
+ {
+ return (ChooseTag)parentTag;
+ }
+ else
+ {
+ throw new JET2TagException(MessageFormat.format(JET2Messages.AnyTag_IllegalParent, new Object []{ "choose" })); //$NON-NLS-1$
+ }
+
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddElementTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddElementTag.java
index be76bb0..f1e7e31 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddElementTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddElementTag.java
@@ -53,7 +53,7 @@ public class AddElementTag extends AbstractEmptyTag
String var = getAttribute("var"); //$NON-NLS-1$
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
Object parent = xpathExtender.resolveSingle(xpathExtender.currentXPathContextObject(), select);
if (parent == null)
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddTextElementTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddTextElementTag.java
index f5e9b98..e03b5a2 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddTextElementTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/AddTextElementTag.java
@@ -54,7 +54,7 @@ public class AddTextElementTag extends AbstractFunctionTag
String var = getAttribute("var"); //$NON-NLS-1$
boolean asCData = Boolean.valueOf(getAttribute("cdata")).booleanValue(); //$NON-NLS-1$
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
final Object parentElement = xpathExtender.resolveSingle(xpathExtender.currentXPathContextObject(), select);
if (parentElement == null)
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/ChooseTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/ChooseTag.java
index 7217846..1f81147 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/ChooseTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/ChooseTag.java
@@ -18,8 +18,10 @@
package org.eclipse.jet.internal.taglib.control;
+import org.eclipse.jet.BodyContentWriter;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.XPathContextExtender;
import org.eclipse.jet.taglib.AbstractContainerTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
@@ -33,6 +35,8 @@ public class ChooseTag extends AbstractContainerTag
{
private boolean satisfied;
+ private JET2Writer selectionWriter;
+ private Object selectObject = null;
/**
*
@@ -47,8 +51,14 @@ public class ChooseTag extends AbstractContainerTag
*/
public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
+ String select = getAttribute("select"); //$NON-NLS-1$
+ if(select != null) {
+ final XPathContextExtender xce = XPathContextExtender.getInstance(context);
+ selectObject = xce.resolveAsObject(xce.currentXPathContextObject(), select);
+ }
+
satisfied = false;
-
+ this.selectionWriter = new BodyContentWriter();
}
/* (non-Javadoc)
@@ -56,8 +66,7 @@ public class ChooseTag extends AbstractContainerTag
*/
public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
- // TODO Auto-generated method stub
-
+ // nothing to do
}
/**
@@ -78,4 +87,23 @@ public class ChooseTag extends AbstractContainerTag
this.satisfied = satisfied;
}
+ public void setBodyContent(JET2Writer bodyContent)
+ {
+ // ignore the direct body content of the tag, and instead, write what is in the selectionWriter,
+ // which has been written to by one of the child 'when' or 'otherwise' tags.
+ getOut().write(selectionWriter);
+ }
+
+ public void writeSelection(JET2Writer bodyContent)
+ {
+ selectionWriter.write(bodyContent);
+ }
+
+ /**
+ * @return Returns the selectObject.
+ */
+ protected final Object getSelectObject()
+ {
+ return selectObject;
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/CopyElementTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/CopyElementTag.java
index 77ed35d..efbafa9 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/CopyElementTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/CopyElementTag.java
@@ -55,7 +55,7 @@ public class CopyElementTag extends AbstractEmptyTag
String recursiveString = getAttribute("recursive"); //$NON-NLS-1$
boolean recursive = recursiveString == null ? true : Boolean.valueOf(recursiveString).booleanValue();
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
Object srcElement = xpathExtender.resolveSingle(xpathExtender.currentXPathContextObject(), select);
Object tgtParent = xpathExtender.resolveSingle(xpathExtender.currentXPathContextObject(), toSelect);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/GetTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/GetTag.java
index 02669df..a2ad577 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/GetTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/GetTag.java
@@ -25,6 +25,8 @@ import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.xpath.NodeSet;
+import org.eclipse.jet.xpath.XPathUtil;
/**
@@ -50,19 +52,27 @@ public class GetTag extends AbstractEmptyTag
String selectXPath = getAttribute("select"); //$NON-NLS-1$
String defaultValue = getAttribute("default"); //$NON-NLS-1$
- XPathContextExtender xpathContext = new XPathContextExtender(context);
+ XPathContextExtender xpathContext = XPathContextExtender.getInstance(context);
Object resultObject = xpathContext.resolveAsObject(xpathContext.currentXPathContextObject(), selectXPath);
- String result;
- if (resultObject != null)
+ String result = null;
+ if(resultObject instanceof NodeSet)
{
- result = xpathContext.resolveAsString(resultObject, "."); //$NON-NLS-1$
+ if(((NodeSet)resultObject).size() > 0)
+ {
+ result = XPathUtil.xpathString(resultObject);
+ }
+ }
+ else if(resultObject != null)
+ {
+ result = XPathUtil.xpathString(resultObject);
}
- else if (defaultValue != null)
+ if (result == null && defaultValue != null)
{
result = defaultValue;
}
- else
+
+ if(result == null)
{
throw new JET2TagException(JET2Messages.GetTag_NoResult);
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IfTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IfTag.java
index 84a4d76..76fba9c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IfTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IfTag.java
@@ -19,10 +19,12 @@ 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.taglib.AbstractConditionalTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.xpath.XPathUtil;
/**
@@ -32,6 +34,10 @@ import org.eclipse.jet.taglib.TagInfo;
public class IfTag extends AbstractConditionalTag
{
+ private String var = null;
+ private boolean varAlreadySet = false;
+ private Object savedValue;
+
/**
*
*/
@@ -47,11 +53,39 @@ public class IfTag extends AbstractConditionalTag
{
String testXPath = getAttribute("test"); //$NON-NLS-1$
-
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
- boolean processContents = xpathExtender.resolveTest(xpathExtender.currentXPathContextObject(), testXPath);
+ var = getAttribute("var"); //$NON-NLS-1$
+
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
+
+ // get the result of the xpath expression prior to casting to boolean, in case we define a 'var'.
+ Object rawObject = xpathExtender.resolveAsObject(xpathExtender.currentXPathContextObject(), testXPath);
+
+ boolean processContents = XPathUtil.xpathBoolean(rawObject);
+ if(processContents && var != null)
+ {
+ varAlreadySet = context.hasVariable(var);
+ if(varAlreadySet)
+ {
+ savedValue = context.getVariable(var);
+ }
+ context.setVariable(var, rawObject);
+ }
return processContents;
}
+ public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ {
+ if(var != null)
+ {
+ if(varAlreadySet)
+ {
+ context.setVariable(var, savedValue);
+ }
+ else
+ {
+ context.removeVariable(var);
+ }
+ }
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IterateTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IterateTag.java
index 8a00000..950eecc 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IterateTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IterateTag.java
@@ -99,7 +99,7 @@ public class IterateTag extends AbstractIteratingTag
setDelimiter(getAttribute("delimiter")); //$NON-NLS-1$
- XPathContextExtender xpathContext = new XPathContextExtender(context);
+ XPathContextExtender xpathContext = XPathContextExtender.getInstance(context);
if (context.hasVariable(varName))
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OtherwiseTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OtherwiseTag.java
index 9c2a012..9358012 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OtherwiseTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OtherwiseTag.java
@@ -19,8 +19,6 @@ package org.eclipse.jet.internal.taglib.control;
import org.eclipse.jet.JET2Context;
-import org.eclipse.jet.taglib.AbstractConditionalTag;
-import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
@@ -29,7 +27,7 @@ import org.eclipse.jet.taglib.TagInfo;
* Implement the JET2 standard tag 'otherwise', which is a child tag of 'choose'
*
*/
-public class OtherwiseTag extends AbstractConditionalTag
+public class OtherwiseTag extends AbstractChooseAlternative
{
/**
@@ -47,17 +45,13 @@ public class OtherwiseTag extends AbstractConditionalTag
{
boolean processContents = false;
- CustomTag parentTag = getParent();
-
- if (parentTag instanceof ChooseTag)
+ ChooseTag chooseTag = getChooseTag();
+ if (!chooseTag.isSatisfied())
{
- ChooseTag chooseTag = (ChooseTag)parentTag;
- if (!chooseTag.isSatisfied())
- {
- processContents = true;
- chooseTag.setSatisfied(true);
- }
+ processContents = true;
+ chooseTag.setSatisfied(true);
}
+
return processContents;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/RemoveElementTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/RemoveElementTag.java
index 10c4965..12fc7cf 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/RemoveElementTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/RemoveElementTag.java
@@ -49,7 +49,7 @@ public class RemoveElementTag extends AbstractEmptyTag
final String select = getAttribute("select"); //$NON-NLS-1$
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
final Object element = xpathExtender.resolveSingle(xpathExtender.currentXPathContextObject(), select);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetTag.java
index 09a13f5..d40e883 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetTag.java
@@ -1,11 +1,11 @@
/**
* <copyright>
*
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
+ * are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
@@ -14,27 +14,28 @@
*
* $Id$
*/
-
package org.eclipse.jet.internal.taglib.control;
import java.text.MessageFormat;
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.AbstractFunctionTag;
+import org.eclipse.jet.taglib.AbstractContainerTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
/**
* Implement the standard JET2 Control tag 'set'.
- *
*/
-public class SetTag extends AbstractFunctionTag
+public class SetTag extends AbstractContainerTag
{
+ private String tagContent = ""; //$NON-NLS-1$
+
/**
*
*/
@@ -44,28 +45,37 @@ public class SetTag extends AbstractFunctionTag
}
/* (non-Javadoc)
- * @see org.eclipse.jet.taglib.FunctionTag#doFunction(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, java.lang.String)
+ * @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
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.ContainerTag#doAfterBody(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
*/
- public String doFunction(TagInfo td, JET2Context context, String bodyContent) throws JET2TagException
+ public void doAfterBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
String selectXPath = getAttribute("select"); //$NON-NLS-1$
String name = getAttribute("name"); //$NON-NLS-1$
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
Object element = xpathExtender.resolveSingle(xpathExtender.currentXPathContextObject(), selectXPath);
if (element == null)
{
throw new JET2TagException(JET2Messages.XPath_NoElementSelected);
}
- final boolean isSet = xpathExtender.setAttribute(element, name, bodyContent);
+ final boolean isSet = xpathExtender.setAttribute(element, name, tagContent);
if (!isSet)
{
String msg = JET2Messages.SetTag_CoundNotSet;
throw new JET2TagException(MessageFormat.format(msg, new Object []{ msg }));
}
-
- return ""; //$NON-NLS-1$
}
+ public void setBodyContent(JET2Writer bodyContent)
+ {
+ tagContent = bodyContent.toString();
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetVariableTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetVariableTag.java
index 1f1c658..64d3453 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetVariableTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/SetVariableTag.java
@@ -48,7 +48,7 @@ public class SetVariableTag extends AbstractEmptyTag
String select = getAttribute("select"); //$NON-NLS-1$
String var = getAttribute("var"); //$NON-NLS-1$
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
Object value = xpathExtender.resolveAsObject(xpathExtender.currentXPathContextObject(), select);
context.setVariable(var, value);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitTag.java
index 9644c5a..5bd54c0 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitTag.java
@@ -59,7 +59,7 @@ public class VisitTag extends AbstractConditionalTag
String testXPath = getAttribute("test"); //$NON-NLS-1$
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
return xpathExtender.resolveTest(next, testXPath);
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitorTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitorTag.java
index 51b3379..676e8e1 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitorTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/VisitorTag.java
@@ -81,7 +81,7 @@ public class VisitorTag extends AbstractIteratingTag
String xpathSelect = getAttribute("select"); //$NON-NLS-1$
varName = getAttribute("var"); //$NON-NLS-1$
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
Object root = xpathExtender.resolveSingle(xpathExtender.currentXPathContextObject(), xpathSelect);
// hack alert...
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WhenTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WhenTag.java
index fa4887e..2e9824f 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WhenTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/WhenTag.java
@@ -18,13 +18,8 @@
package org.eclipse.jet.internal.taglib.control;
-import java.text.MessageFormat;
-
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.XPathContextExtender;
-import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.taglib.AbstractConditionalTag;
-import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
@@ -34,10 +29,16 @@ import org.eclipse.jet.taglib.TagInfo;
* @see org.eclipse.jet.internal.taglib.control.ChooseTag
*
*/
-public class WhenTag extends AbstractConditionalTag
+public class WhenTag extends AbstractChooseAlternative
{
/**
+ * A variable name that hopefully nobody will every use.
+ * We use it to handle the chase where the choose tag had a select expression.
+ */
+ private static final String CHOOSE_SELECT_OBJECT_TMP_VAR = "_org.eclipse.jet.tags.choose"; //$NON-NLS-1$
+
+ /**
*
*/
public WhenTag()
@@ -50,31 +51,40 @@ public class WhenTag extends AbstractConditionalTag
*/
public boolean doEvalCondition(TagInfo td, JET2Context context) throws JET2TagException
{
+ String testXPath = getAttribute("test"); //$NON-NLS-1$
boolean processContents = false;
- CustomTag parentTag = getParent();
-
- if (parentTag instanceof ChooseTag)
+ ChooseTag chooseTag = getChooseTag();
+ if (!chooseTag.isSatisfied())
{
- ChooseTag chooseTag = (ChooseTag)parentTag;
- if (!chooseTag.isSatisfied())
+ XPathContextExtender xpathExtender = XPathContextExtender.getInstance(context);
+ final Object chooseSelectObject = chooseTag.getSelectObject();
+ if (chooseSelectObject != null)
{
- XPathContextExtender xpathExtender = new XPathContextExtender(context);
- String testXPath = getAttribute("test"); //$NON-NLS-1$
- boolean testIsTrue = xpathExtender.resolveTest(xpathExtender.currentXPathContextObject(), testXPath);
- if (testIsTrue)
+ // handle the case where choose had a select attribute by converting the test XPATH expression
+ // into a comparison with the result of the choose select expression.
+ try
+ {
+ context.setVariable(CHOOSE_SELECT_OBJECT_TMP_VAR, chooseSelectObject);
+ testXPath = "$" + CHOOSE_SELECT_OBJECT_TMP_VAR + " = (" + testXPath + ")"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ processContents = xpathExtender.resolveTest(xpathExtender.currentXPathContextObject(), testXPath);
+ }
+ finally
{
- processContents = true;
- chooseTag.setSatisfied(true);
+ // make sure we undefine the variable
+ context.removeVariable(CHOOSE_SELECT_OBJECT_TMP_VAR);
}
}
- }
- else
- {
- throw new JET2TagException(MessageFormat.format(JET2Messages.AnyTag_IllegalParent, new Object []{ "choose" })); //$NON-NLS-1$
+ else
+ {
+ processContents = xpathExtender.resolveTest(xpathExtender.currentXPathContextObject(), testXPath);
+ }
+ if (processContents)
+ {
+ chooseTag.setSatisfied(true);
+ }
}
return processContents;
}
-
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
index 2883cd8..6f60af4 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
@@ -21,6 +21,7 @@ import org.eclipse.jet.compiler.JET2Expression;
import org.eclipse.jet.compiler.JET2Scriptlet;
import org.eclipse.jet.compiler.TextElement;
import org.eclipse.jet.compiler.XMLBodyElement;
+import org.eclipse.jet.compiler.XMLBodyElementEnd;
import org.eclipse.jet.compiler.XMLEmptyElement;
import org.eclipse.jet.internal.compiler.templates.JET2JavaGenerator;
import org.eclipse.jet.tests.FileUtils;
@@ -181,6 +182,11 @@ public class TestJET2Parser extends TestCase {
buffer.append("</comment>").append(NL);
}
+ public void visit(XMLBodyElementEnd xmlBodyElementEnd) {
+ // do nothing
+
+ }
+
}
private FileInputStream getFileContentsAsStream(String urlString) throws IOException, MalformedURLException, FileNotFoundException {
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java
index 48f10ec..7186820 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/taglib/control/LoadTagTests.java
@@ -42,7 +42,7 @@ public class LoadTagTests extends TestCase {
tag.doAction(td, context, out);
assertEquals("", out.getDocument().get());
- final Object loadedDocument = new XPathContextExtender(context).resolveVariable("root");
+ final Object loadedDocument = XPathContextExtender.getInstance(context).resolveVariable("root");
assertNotNull("loaded document", loadedDocument);
}