You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2001/08/31 23:38:37 UTC
cvs commit: xml-xalan/c/src/XPath XPathEvaluator.cpp XPathEvaluator.hpp
dbertoni 01/08/31 14:38:37
Modified: c/src/XPath XPathEvaluator.cpp XPathEvaluator.hpp
Log:
New features.
Revision Changes Path
1.4 +167 -5 xml-xalan/c/src/XPath/XPathEvaluator.cpp
Index: XPathEvaluator.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathEvaluator.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XPathEvaluator.cpp 2001/06/14 19:12:14 1.3
+++ XPathEvaluator.cpp 2001/08/31 21:38:36 1.4
@@ -93,6 +93,7 @@
XPathEvaluator::XPathEvaluator() :
m_xobjectFactory(new XObjectFactoryDefault),
+ m_xpathFactory(new XPathFactoryDefault),
m_executionContext(new XPathExecutionContextDefault)
{
@@ -155,6 +156,48 @@
+XalanNode*
+XPathEvaluator::selectSingleNode(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const XalanElement* namespaceNode)
+{
+ const XObjectPtr theResult(
+ evaluate(
+ domSupport,
+ contextNode,
+ xpath,
+ namespaceNode));
+
+ const NodeRefListBase& theNodeList = theResult->nodeset();
+
+ return theNodeList.getLength() == 0 ? 0 : theNodeList.item(0);
+}
+
+
+
+XalanNode*
+XPathEvaluator::selectSingleNode(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const PrefixResolver& prefixResolver)
+{
+ const XObjectPtr theResult(
+ evaluate(
+ domSupport,
+ contextNode,
+ xpath,
+ prefixResolver));
+
+ const NodeRefListBase& theNodeList = theResult->nodeset();
+
+ return theNodeList.getLength() == 0 ? 0 : theNodeList.item(0);
+}
+
+
+
NodeRefList
XPathEvaluator::selectNodeList(
DOMSupport& domSupport,
@@ -193,6 +236,44 @@
+NodeRefList
+XPathEvaluator::selectNodeList(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const XalanElement* namespaceNode)
+{
+ const XObjectPtr theResult(
+ evaluate(
+ domSupport,
+ contextNode,
+ xpath,
+ namespaceNode));
+
+ return NodeRefList(theResult->nodeset());
+}
+
+
+
+NodeRefList
+XPathEvaluator::selectNodeList(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const PrefixResolver& prefixResolver)
+{
+ const XObjectPtr theResult(
+ evaluate(
+ domSupport,
+ contextNode,
+ xpath,
+ prefixResolver));
+
+ return NodeRefList(theResult->nodeset());
+}
+
+
+
XObjectPtr
XPathEvaluator::evaluate(
DOMSupport& domSupport,
@@ -216,6 +297,25 @@
XPathEvaluator::evaluate(
DOMSupport& domSupport,
XalanNode* contextNode,
+ const XPath& xpath,
+ const XalanElement* namespaceNode)
+{
+ XPathEnvSupportDefault theEnvSupportDefault;
+
+ return evaluate(
+ domSupport,
+ contextNode,
+ xpath,
+ ElementPrefixResolverProxy(namespaceNode, theEnvSupportDefault, domSupport),
+ theEnvSupportDefault);
+}
+
+
+
+XObjectPtr
+XPathEvaluator::evaluate(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
const XalanDOMChar* xpathString,
const PrefixResolver& prefixResolver)
{
@@ -235,17 +335,62 @@
XPathEvaluator::evaluate(
DOMSupport& domSupport,
XalanNode* contextNode,
+ const XPath& xpath,
+ const PrefixResolver& prefixResolver)
+{
+ XPathEnvSupportDefault theEnvSupportDefault;
+
+ return evaluate(
+ domSupport,
+ contextNode,
+ xpath,
+ prefixResolver,
+ theEnvSupportDefault);
+}
+
+
+
+XPath*
+XPathEvaluator::createXPath(
const XalanDOMChar* xpathString,
+ const PrefixResolver& prefixResolver)
+{
+ XPath* const theXPath = m_xpathFactory->create();
+ assert(theXPath != 0);
+
+ XPathProcessorImpl theProcessor;
+
+ theProcessor.initXPath(
+ *theXPath,
+ XalanDOMString(xpathString),
+ prefixResolver);
+
+ return theXPath;
+}
+
+
+
+bool
+XPathEvaluator::destroyXPath(XPath* theXPath)
+{
+ assert(theXPath != 0);
+
+ return m_xpathFactory->returnObject(theXPath);
+}
+
+
+
+XObjectPtr
+XPathEvaluator::evaluate(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XalanDOMChar* xpathString,
const PrefixResolver& prefixResolver,
XPathEnvSupport& envSupport)
{
assert(contextNode != 0);
assert(xpathString != 0);
- // Reset these, in case we've been here before...
- m_executionContext->reset();
- m_xobjectFactory->reset();
-
// Create an XPath, and an XPathProcessorImpl to process
// the XPath.
XPath theXPath;
@@ -257,6 +402,23 @@
XalanDOMString(xpathString),
prefixResolver);
+ return evaluate(domSupport, contextNode, theXPath, prefixResolver, envSupport);
+}
+
+
+
+XObjectPtr
+XPathEvaluator::evaluate(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const PrefixResolver& prefixResolver,
+ XPathEnvSupport& envSupport)
+{
+ // Reset these, in case we've been here before...
+ m_executionContext->reset();
+ m_xobjectFactory->reset();
+
// Set up the connections between the execution context and
// the provided support objects...
m_executionContext->setXPathEnvSupport(&envSupport);
@@ -267,7 +429,7 @@
// OK, evaluate the expression...
const XObjectPtr theResult(
- theXPath.execute(
+ xpath.execute(
contextNode,
prefixResolver,
*m_executionContext.get()));
1.3 +190 -10 xml-xalan/c/src/XPath/XPathEvaluator.hpp
Index: XPathEvaluator.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathEvaluator.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XPathEvaluator.hpp 2001/07/10 05:15:50 1.2
+++ XPathEvaluator.hpp 2001/08/31 21:38:36 1.3
@@ -65,6 +65,7 @@
#if defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION)
#include <XPath/XObjectFactory.hpp>
+#include <XPath/XPathFactory.hpp>
#include <XPath/XPathExecutionContextDefault.hpp>
#endif
@@ -80,6 +81,7 @@
#if !defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION)
class XObjectFactory;
+class XPathFactory;
class XPathExecutionContextDefault;
#endif
@@ -91,6 +93,7 @@
class XalanNode;
class XalanElement;
class XObjectPtr;
+class XPath;
class XPathEnvSupport;
@@ -151,6 +154,42 @@
const PrefixResolver& prefixResolver);
/**
+ * Evaluate the supplied XPath, within the given context. If
+ * the expression doesn't select a node, 0 is returned. If it selects
+ * more than one node, only the first is returned.
+ *
+ * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
+ * @param contextNode The source tree context node
+ * @param xpath A reference to a compiled XPath expression.
+ * @param namespaceNode A node to use for namespace prefix resolution.
+ * @return A pointer to the node selected by the expression, if any.
+ */
+ XalanNode*
+ selectSingleNode(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const XalanElement* namespaceNode = 0);
+
+ /**
+ * Evaluate the supplied XPath, within the given context. If
+ * the expression doesn't select a node, 0 is returned. If it selects
+ * more than one node, only the first is returned.
+ *
+ * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
+ * @param contextNode The source tree context node
+ * @param xpath A reference to a compiled XPath expression.
+ * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
+ * @return A pointer to the node selected by the expression, if any.
+ */
+ XalanNode*
+ selectSingleNode(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const PrefixResolver& prefixResolver);
+
+ /**
* Evaluate the supplied XPath expression, within the given context. If
* the expression doesn't select a node, an empty list is returned.
*
@@ -185,14 +224,49 @@
const PrefixResolver& prefixResolver);
/**
+ * Evaluate the supplied XPath, within the given context. If
+ * the expression doesn't select a node, an empty list is returned.
+ *
+ * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
+ * @param contextNode The source tree context node
+ * @param xpath A reference to a compiled XPath expression.
+ * @param namespaceNode A node to use for namespace prefix resolution.
+ * @return A list of selected nodes.
+ */
+ NodeRefList
+ selectNodeList(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const XalanElement* namespaceNode = 0);
+
+ /**
+ * Evaluate the supplied XPath, within the given context. If
+ * the expression doesn't select a node, an empty list is returned.
+ *
+ * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
+ * @param contextNode The source tree context node
+ * @param xpath A reference to a compiled XPath expression.
+ * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
+ * @return A list of selected nodes.
+ */
+ NodeRefList
+ selectNodeList(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const PrefixResolver& prefixResolver);
+
+ /**
* Evaluate the supplied XPath expression, within the given context. The
* result is returned as a generalized object. The object will be
* destroyed when the returned when the user's copy of the returned
- * XObjectPtr goes out of scope, or when the XPathEvaluator instance
- * is reset or goes out of scope. The user's XObjectPtr copy _must_ no
- * longer be in scope when the XPathEvaluator instance is reset or
- * out of scope.
+ * XObjectPtr goes out of scope, or when the XPathEvaluator goes out of scope
+ * or another expression is evaluated.
*
+ * The user's XObjectPtr copy _must_ no longer be in scope when the XPathEvaluator
+ * instance goes out of scope, or another expression is evaluated.
+ *
* @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
* @param contextNode The source tree context node
* @param xpathString The XPath expression to evaluate
@@ -210,10 +284,11 @@
* Evaluate the supplied XPath expression, within the given context. The
* result is returned as a generalized object. The object will be
* destroyed when the returned when the user's copy of the returned
- * XObjectPtr goes out of scope, or when the XalanXPathEvaluator instance
- * is reset or goes out of scope. The user's XObjectPtr copy _must_ no
- * longer be in scope when the XPathEvaluator instance is reset or
- * out of scope.
+ * XObjectPtr goes out of scope, or when the XPathEvaluator goes out of scope
+ * or another expression is evaluated.
+ *
+ * The user's XObjectPtr copy _must_ no longer be in scope when the XPathEvaluator
+ * instance goes out of scope, or another expression is evaluated.
*
* @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
* @param contextNode The source tree context node
@@ -228,6 +303,90 @@
const XalanDOMChar* xpathString,
const PrefixResolver& prefixResolver);
+ /**
+ * Evaluate the supplied XPath, within the given context. The
+ * result is returned as a generalized object. The object will be
+ * destroyed when the returned when the user's copy of the returned
+ * XObjectPtr goes out of scope, or when the XPathEvaluator goes out of scope
+ * or another expression is evaluated.
+ *
+ * The user's XObjectPtr copy _must_ no longer be in scope when the XPathEvaluator
+ * instance goes out of scope, or another expression is evaluated.
+ *
+ * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
+ * @param contextNode The source tree context node
+ * @param xpath A reference to a compiled XPath expression.
+ * @param namespaceNode A node to use for namespace prefix resolution.
+ * @return The result of evaluting the XPath expression.
+ */
+ XObjectPtr
+ evaluate(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const XalanElement* namespaceNode = 0);
+
+ /**
+ * Evaluate the supplied XPath, within the given context. The
+ * result is returned as a generalized object. The object will be
+ * destroyed when the returned when the user's copy of the returned
+ * XObjectPtr goes out of scope, or when the XPathEvaluator goes out of scope
+ * or another expression is evaluated.
+ *
+ * The user's XObjectPtr copy _must_ no longer be in scope when the XPathEvaluator
+ * instance goes out of scope, or another expression is evaluated.
+ *
+ * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
+ * @param contextNode The source tree context node
+ * @param xpath A reference to a compiled XPath expression.
+ * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
+ * @return The result of evaluting the XPath expression.
+ */
+ XObjectPtr
+ evaluate(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const PrefixResolver& prefixResolver);
+
+ /**
+ * Compile an XPath expression into an object which can be used multiple times.
+ * Call destroyXPath() when finished with the instance. Otherwise, the object
+ * will be destroyed when the XPathEvaluator instance goes out of scope.
+ *
+ * @param xpathString The XPath expression to evaluate
+ * @param namespaceNode A node to use for namespace prefix resolution.
+ * @return A pointer to an XPath instance.
+ */
+ XPath*
+ createXPath(
+ const XalanDOMChar* xpathString,
+ const XalanElement* namespaceNode = 0);
+
+ /**
+ * Compile an XPath expression into an object which can be used multiple times.
+ * Call destroyXPath() when finished with the instance. Otherwise, the object
+ * will be destroyed when the XPathEvaluator instance goes out of scope.
+ *
+ * @param xpathString The XPath expression to evaluate
+ * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
+ * @return A pointer to an XPath instance.
+ */
+ XPath*
+ createXPath(
+ const XalanDOMChar* xpathString,
+ const PrefixResolver& prefixResolver);
+
+ /**
+ * Destory a compiled XPath instance. The instance must have
+ * been created using createXPath().
+ *
+ * @param theXPath The XPath instance to destroy
+ * @return true if the instance was successfully destroyed
+ */
+ bool
+ destroyXPath(XPath* theXPath);
+
private:
/**
@@ -238,7 +397,7 @@
* @param contextNode The source tree context node
* @param xpathString The XPath expression to evaluate
* @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
- * @param doEvaluate The XPathEnvSupport instance to use.
+ * @param envSupport The XPathEnvSupport instance to use.
* @return The result of evaluting the XPath expression.
*/
XObjectPtr
@@ -247,10 +406,31 @@
XalanNode* contextNode,
const XalanDOMChar* xpathString,
const PrefixResolver& prefixResolver,
- XPathEnvSupport& doEvaluate);
+ XPathEnvSupport& envSupport);
+ /**
+ * A helper function to evaluate the supplied XPath expression, within
+ * the given context.
+ *
+ * @param domSupport An instance of the corresponding DOMSupport-derived for the DOM implementation being used.
+ * @param contextNode The source tree context node
+ * @param xpath The XPath to evaluate
+ * @param prefixResolver A prefix resolver instance to use for namespace prefix resolution.
+ * @param envSupport The XPathEnvSupport instance to use.
+ * @return The result of evaluting the XPath expression.
+ */
+ XObjectPtr
+ evaluate(
+ DOMSupport& domSupport,
+ XalanNode* contextNode,
+ const XPath& xpath,
+ const PrefixResolver& prefixResolver,
+ XPathEnvSupport& envSupport);
+
// Data members...
const XalanAutoPtr<XObjectFactory> m_xobjectFactory;
+
+ const XalanAutoPtr<XPathFactory> m_xpathFactory;
const XalanAutoPtr<XPathExecutionContextDefault> m_executionContext;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org