|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #ifndef DOMXPathEvaluator_HEADER_GUARD_ |
|
18 #define DOMXPathEvaluator_HEADER_GUARD_ |
|
19 |
|
20 /* |
|
21 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
22 * contributor license agreements. See the NOTICE file distributed with |
|
23 * this work for additional information regarding copyright ownership. |
|
24 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
25 * (the "License"); you may not use this file except in compliance with |
|
26 * the License. You may obtain a copy of the License at |
|
27 * |
|
28 * http://www.apache.org/licenses/LICENSE-2.0 |
|
29 * |
|
30 * Unless required by applicable law or agreed to in writing, software |
|
31 * distributed under the License is distributed on an "AS IS" BASIS, |
|
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
33 * See the License for the specific language governing permissions and |
|
34 * limitations under the License. |
|
35 */ |
|
36 |
|
37 #include <xercesc/util/XercesDefs.hpp> |
|
38 |
|
39 XERCES_CPP_NAMESPACE_BEGIN |
|
40 |
|
41 class DOMXPathNSResolver; |
|
42 class DOMXPathExpression; |
|
43 class DOMNode; |
|
44 |
|
45 /** |
|
46 * The evaluation of XPath expressions is provided by <code>DOMXPathEvaluator</code>. |
|
47 * In a DOM implementation which supports the XPath 3.0 feature, the <code>DOMXPathEvaluator</code> |
|
48 * interface will be implemented on the same object which implements the Document interface permitting |
|
49 * it to be obtained by casting or by using the DOM Level 3 getInterface method. In this case the |
|
50 * implementation obtained from the Document supports the XPath DOM module and is compatible |
|
51 * with the XPath 1.0 specification. |
|
52 * Evaluation of expressions with specialized extension functions or variables may not |
|
53 * work in all implementations and is, therefore, not portable. XPathEvaluator implementations |
|
54 * may be available from other sources that could provide specific support for specialized extension |
|
55 * functions or variables as would be defined by other specifications. |
|
56 * @since DOM Level 3 |
|
57 */ |
|
58 class CDOM_EXPORT DOMXPathEvaluator |
|
59 { |
|
60 |
|
61 protected: |
|
62 // ----------------------------------------------------------------------- |
|
63 // Hidden constructors |
|
64 // ----------------------------------------------------------------------- |
|
65 /** @name Hidden constructors */ |
|
66 //@{ |
|
67 DOMXPathEvaluator() {}; |
|
68 //@} |
|
69 |
|
70 private: |
|
71 // ----------------------------------------------------------------------- |
|
72 // Unimplemented constructors and operators |
|
73 // ----------------------------------------------------------------------- |
|
74 /** @name Unimplemented constructors and operators */ |
|
75 //@{ |
|
76 DOMXPathEvaluator(const DOMXPathEvaluator &); |
|
77 DOMXPathEvaluator& operator = (const DOMXPathEvaluator&); |
|
78 //@} |
|
79 |
|
80 public: |
|
81 // ----------------------------------------------------------------------- |
|
82 // All constructors are hidden, just the destructor is available |
|
83 // ----------------------------------------------------------------------- |
|
84 /** @name Destructor */ |
|
85 //@{ |
|
86 /** |
|
87 * Destructor |
|
88 * |
|
89 */ |
|
90 virtual ~DOMXPathEvaluator() {}; |
|
91 //@} |
|
92 |
|
93 // ----------------------------------------------------------------------- |
|
94 // Virtual DOMDocument interface |
|
95 // ----------------------------------------------------------------------- |
|
96 /** @name Functions introduced in DOM Level 3 */ |
|
97 //@{ |
|
98 |
|
99 /** |
|
100 * Creates a parsed XPath expression with resolved namespaces. This is useful |
|
101 * when an expression will be reused in an application since it makes it |
|
102 * possible to compile the expression string into a more efficient internal |
|
103 * form and preresolve all namespace prefixes which occur within the expression. |
|
104 * @param expression of type XMLCh - The XPath expression string to be parsed. |
|
105 * @param resolver of type <code>XPathNSResolver</code> - The resolver permits |
|
106 * translation of all prefixes, including the xml namespace prefix, within the XPath expression |
|
107 * into appropriate namespace URIs. If this is specified as null, any namespace |
|
108 * prefix within the expression will result in <code>DOMException</code> being thrown with the |
|
109 * code NAMESPACE_ERR. |
|
110 * @return <code>XPathExpression</code> The compiled form of the XPath expression. |
|
111 * @exception <code>XPathException</code> |
|
112 * INVALID_EXPRESSION_ERR: Raised if the expression is not legal according to the |
|
113 * rules of the <code>DOMXPathEvaluator</code>. |
|
114 * @exception DOMException |
|
115 * NAMESPACE_ERR: Raised if the expression contains namespace prefixes which cannot |
|
116 * be resolved by the specified <code>XPathNSResolver</code>. |
|
117 * @since DOM Level 3 |
|
118 */ |
|
119 virtual const DOMXPathExpression* createExpression(const XMLCh *expression, const DOMXPathNSResolver *resolver) = 0; |
|
120 |
|
121 |
|
122 /** Adapts any DOM node to resolve namespaces so that an XPath expression can be |
|
123 * easily evaluated relative to the context of the node where it appeared within |
|
124 * the document. This adapter works like the DOM Level 3 method lookupNamespaceURI |
|
125 * on nodes in resolving the namespaceURI from a given prefix using the current |
|
126 * information available in the node's hierarchy at the time lookupNamespaceURI |
|
127 * is called. also correctly resolving the implicit xml prefix. |
|
128 * @param nodeResolver of type <code>DOMNode</code> The node to be used as a context |
|
129 * for namespace resolution. |
|
130 * @return <code>XPathNSResolver</code> <code>XPathNSResolver</code> which resolves namespaces |
|
131 * with respect to the definitions in scope for a specified node. |
|
132 */ |
|
133 virtual const DOMXPathNSResolver* createNSResolver(DOMNode *nodeResolver) = 0; |
|
134 |
|
135 |
|
136 /** |
|
137 * Evaluates an XPath expression string and returns a result of the specified |
|
138 * type if possible. |
|
139 * @param expression of type XMLCh The XPath expression string to be parsed |
|
140 * and evaluated. |
|
141 * @param contextNode of type <code>DOMNode</code> The context is context node |
|
142 * for the evaluation |
|
143 * of this XPath expression. If the <code>DOMXPathEvaluator</code> was obtained by |
|
144 * casting the <code>DOMDocument</code> then this must be owned by the same |
|
145 * document and must be a <code>DOMDocument</code>, <code>DOMElement</code>, |
|
146 * <code>DOMAttribute</code>, <code>DOMText</code>, <code>DOMCDATASection</code>, |
|
147 * <code>DOMComment</code>, <code>DOMProcessingInstruction</code>, or |
|
148 * <code>XPathNamespace</code> node. If the context node is a <code>DOMText</code> or |
|
149 * a <code>DOMCDATASection</code>, then the context is interpreted as the whole |
|
150 * logical text node as seen by XPath, unless the node is empty in which case it |
|
151 * may not serve as the XPath context. |
|
152 * @param resolver of type <code>XPathNSResolver</code> The resolver permits |
|
153 * translation of all prefixes, including the xml namespace prefix, within |
|
154 * the XPath expression into appropriate namespace URIs. If this is specified |
|
155 * as null, any namespace prefix within the expression will result in |
|
156 * <code>DOMException</code> being thrown with the code NAMESPACE_ERR. |
|
157 * @param type of type unsigned short - If a specific type is specified, then |
|
158 * the result will be returned as the corresponding type. |
|
159 * For XPath 1.0 results, this must be one of the codes of the <code>XPathResult</code> |
|
160 * interface. |
|
161 * @param result of type void* - The result specifies a specific result object |
|
162 * which may be reused and returned by this method. If this is specified as |
|
163 * null or the implementation does not reuse the specified result, a new result |
|
164 * object will be constructed and returned. |
|
165 * For XPath 1.0 results, this object will be of type <code>XPathResult</code>. |
|
166 * @return void* The result of the evaluation of the XPath expression. |
|
167 * For XPath 1.0 results, this object will be of type <code>XPathResult</code>. |
|
168 * @exception <code>XPathException</code> |
|
169 * INVALID_EXPRESSION_ERR: Raised if the expression is not legal |
|
170 * according to the rules of the <code>DOMXPathEvaluator</code> |
|
171 * TYPE_ERR: Raised if the result cannot be converted to return the specified type. |
|
172 * @exception DOMException |
|
173 * NAMESPACE_ERR: Raised if the expression contains namespace prefixes |
|
174 * which cannot be resolved by the specified <code>XPathNSResolver</code>. |
|
175 * WRONG_DOCUMENT_ERR: The Node is from a document that is not supported |
|
176 * by this <code>DOMXPathEvaluator</code>. |
|
177 * NOT_SUPPORTED_ERR: The Node is not a type permitted as an XPath context |
|
178 * node or the request type is not permitted by this <code>DOMXPathEvaluator</code>. |
|
179 */ |
|
180 virtual void* evaluate(const XMLCh *expression, DOMNode *contextNode, const DOMXPathNSResolver *resolver, |
|
181 unsigned short type, void* result) = 0; |
|
182 |
|
183 //@} |
|
184 }; |
|
185 |
|
186 XERCES_CPP_NAMESPACE_END |
|
187 |
|
188 #endif |