summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-04-27 12:00:32 (EDT)
committerpelder2006-04-27 12:00:32 (EDT)
commit7490691accbe94285768b8bf095c9da4d72376c5 (patch)
treeafceec0ab8897349f80a3019da545bae60e30a7d
parent2048c4e26f5047a8bf794fd26288117c2ba32512 (diff)
downloadorg.eclipse.jet-7490691accbe94285768b8bf095c9da4d72376c5.zip
org.eclipse.jet-7490691accbe94285768b8bf095c9da4d72376c5.tar.gz
org.eclipse.jet-7490691accbe94285768b8bf095c9da4d72376c5.tar.bz2
[138934] Move c:get logic into XPathContextExtender.resolveAsString(), and have resolveDynamic check for null results from resolveAsString().
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/XPathContextExtender.java28
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/GetTag.java17
2 files changed, 23 insertions, 22 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 6f067a6..3d94d1c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/XPathContextExtender.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/XPathContextExtender.java
@@ -32,12 +32,14 @@ import org.eclipse.jet.internal.xpath.functions.StringFunction;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.xpath.DefaultXPathFunctionResolver;
import org.eclipse.jet.xpath.IAnnotationManager;
+import org.eclipse.jet.xpath.NodeSet;
import org.eclipse.jet.xpath.XPath;
import org.eclipse.jet.xpath.XPathException;
import org.eclipse.jet.xpath.XPathExpression;
import org.eclipse.jet.xpath.XPathFactory;
import org.eclipse.jet.xpath.XPathFunctionMetaData;
import org.eclipse.jet.xpath.XPathRuntimeException;
+import org.eclipse.jet.xpath.XPathUtil;
import org.eclipse.jet.xpath.XPathVariableResolver;
import org.eclipse.jet.xpath.inspector.AddElementException;
import org.eclipse.jet.xpath.inspector.CopyElementException;
@@ -127,17 +129,31 @@ public final class XPathContextExtender extends AbstractContextExtender implemen
}
}
+ /**
+ * Resolve the given XPath expression as a string value. Note that if the XPath expression
+ * returns an empty Node set, this method returns <code>null</code>
+ * @param xpathContextObject the xpath context
+ * @param selectXPath the XPath expression
+ * @return the string value of the XPath expression, or <code>null</code> if the expression resulted in an empty node set.
+ * @throws JET2TagException if an error occurs during expression evaluation
+ */
public String resolveAsString(Object xpathContextObject, String selectXPath) throws JET2TagException
{
- try
+ Object resultObject = resolveAsObject(currentXPathContextObject(), selectXPath);
+
+ String result = null;
+ if(resultObject instanceof NodeSet)
{
- XPathExpression expr = compileXPath(selectXPath);
- return expr.evaluateAsString(xpathContextObject);
- }
- catch (XPathException e)
+ if(((NodeSet)resultObject).size() > 0)
+ {
+ result = XPathUtil.xpathString(resultObject);
+ }
+ }
+ else if(resultObject != null)
{
- throw new JET2TagException(e);
+ result = XPathUtil.xpathString(resultObject);
}
+ return result;
}
public Object resolveSingle(Object xpathContextObject, String selectXPath) throws JET2TagException
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 a2ad577..c676f09 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,8 +25,6 @@ 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;
/**
@@ -53,20 +51,7 @@ public class GetTag extends AbstractEmptyTag
String defaultValue = getAttribute("default"); //$NON-NLS-1$
XPathContextExtender xpathContext = XPathContextExtender.getInstance(context);
- Object resultObject = xpathContext.resolveAsObject(xpathContext.currentXPathContextObject(), selectXPath);
-
- String result = null;
- if(resultObject instanceof NodeSet)
- {
- if(((NodeSet)resultObject).size() > 0)
- {
- result = XPathUtil.xpathString(resultObject);
- }
- }
- else if(resultObject != null)
- {
- result = XPathUtil.xpathString(resultObject);
- }
+ String result = xpathContext.resolveAsString(xpathContext.currentXPathContextObject(), selectXPath);
if (result == null && defaultValue != null)
{
result = defaultValue;