1 | #ifndef DOMNodeFilter_HEADER_GUARD_ |
---|
2 | #define DOMNodeFilter_HEADER_GUARD_ |
---|
3 | |
---|
4 | /* |
---|
5 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
6 | * contributor license agreements. See the NOTICE file distributed with |
---|
7 | * this work for additional information regarding copyright ownership. |
---|
8 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
9 | * (the "License"); you may not use this file except in compliance with |
---|
10 | * the License. You may obtain a copy of the License at |
---|
11 | * |
---|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
13 | * |
---|
14 | * Unless required by applicable law or agreed to in writing, software |
---|
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
17 | * See the License for the specific language governing permissions and |
---|
18 | * limitations under the License. |
---|
19 | */ |
---|
20 | |
---|
21 | /* |
---|
22 | * $Id: DOMNodeFilter.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
23 | */ |
---|
24 | |
---|
25 | #include <xercesc/dom/DOMNode.hpp> |
---|
26 | |
---|
27 | XERCES_CPP_NAMESPACE_BEGIN |
---|
28 | |
---|
29 | |
---|
30 | /** |
---|
31 | * Filters are objects that know how to "filter out" nodes. If a |
---|
32 | * <code>DOMNodeIterator</code> or <code>DOMTreeWalker</code> is given a |
---|
33 | * <code>DOMNodeFilter</code>, it applies the filter before it returns the next |
---|
34 | * node. If the filter says to accept the node, the traversal logic returns |
---|
35 | * it; otherwise, traversal looks for the next node and pretends that the |
---|
36 | * node that was rejected was not there. |
---|
37 | * <p>The DOM does not provide any filters. <code>DOMNodeFilter</code> is just an |
---|
38 | * interface that users can implement to provide their own filters. |
---|
39 | * <p><code>DOMNodeFilters</code> do not need to know how to traverse from node |
---|
40 | * to node, nor do they need to know anything about the data structure that |
---|
41 | * is being traversed. This makes it very easy to write filters, since the |
---|
42 | * only thing they have to know how to do is evaluate a single node. One |
---|
43 | * filter may be used with a number of different kinds of traversals, |
---|
44 | * encouraging code reuse. |
---|
45 | * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>Document Object Model (DOM) Level 2 Traversal and Range Specification</a>. |
---|
46 | * @since DOM Level 2 |
---|
47 | */ |
---|
48 | |
---|
49 | class CDOM_EXPORT DOMNodeFilter |
---|
50 | { |
---|
51 | protected: |
---|
52 | // ----------------------------------------------------------------------- |
---|
53 | // Hidden constructors |
---|
54 | // ----------------------------------------------------------------------- |
---|
55 | /** @name Hidden constructors */ |
---|
56 | //@{ |
---|
57 | DOMNodeFilter() {}; |
---|
58 | //@} |
---|
59 | |
---|
60 | private: |
---|
61 | // ----------------------------------------------------------------------- |
---|
62 | // Unimplemented constructors and operators |
---|
63 | // ----------------------------------------------------------------------- |
---|
64 | /** @name Unimplemented constructors and operators */ |
---|
65 | //@{ |
---|
66 | DOMNodeFilter(const DOMNodeFilter &); |
---|
67 | DOMNodeFilter & operator = (const DOMNodeFilter &); |
---|
68 | //@} |
---|
69 | |
---|
70 | public: |
---|
71 | // ----------------------------------------------------------------------- |
---|
72 | // All constructors are hidden, just the destructor is available |
---|
73 | // ----------------------------------------------------------------------- |
---|
74 | /** @name Destructor */ |
---|
75 | //@{ |
---|
76 | /** |
---|
77 | * Destructor |
---|
78 | * |
---|
79 | */ |
---|
80 | virtual ~DOMNodeFilter() {}; |
---|
81 | //@} |
---|
82 | |
---|
83 | // ----------------------------------------------------------------------- |
---|
84 | // Class Types |
---|
85 | // ----------------------------------------------------------------------- |
---|
86 | /** @name Public Contants */ |
---|
87 | //@{ |
---|
88 | /** |
---|
89 | * Constants returned by acceptNode. |
---|
90 | * |
---|
91 | * <p><code>FILTER_ACCEPT:</code> |
---|
92 | * Accept the node. Navigation methods defined for |
---|
93 | * <code>DOMNodeIterator</code> or <code>DOMTreeWalker</code> will return this |
---|
94 | * node.</p> |
---|
95 | * |
---|
96 | * <p><code>FILTER_REJECT:</code> |
---|
97 | * Reject the node. Navigation methods defined for |
---|
98 | * <code>DOMNodeIterator</code> or <code>DOMTreeWalker</code> will not return |
---|
99 | * this node. For <code>DOMTreeWalker</code>, the children of this node |
---|
100 | * will also be rejected. <code>DOMNodeIterators</code> treat this as a |
---|
101 | * synonym for <code>FILTER_SKIP.</code></p> |
---|
102 | * |
---|
103 | * <p><code>FILTER_SKIP:</code> |
---|
104 | * Skip this single node. Navigation methods defined for |
---|
105 | * <code>DOMNodeIterator</code> or <code>DOMTreeWalker</code> will not return |
---|
106 | * this node. For both <code>DOMNodeIterator</code> and |
---|
107 | * <code>DOMTreeWalker</code>, the children of this node will still be |
---|
108 | * considered.</p> |
---|
109 | * |
---|
110 | * @since DOM Level 2 |
---|
111 | */ |
---|
112 | enum FilterAction {FILTER_ACCEPT = 1, |
---|
113 | FILTER_REJECT = 2, |
---|
114 | FILTER_SKIP = 3}; |
---|
115 | |
---|
116 | /** |
---|
117 | * Constants for whatToShow |
---|
118 | * |
---|
119 | * <p><code>SHOW_ALL:</code> |
---|
120 | * Show all <code>DOMNode(s)</code>.</p> |
---|
121 | * |
---|
122 | * <p><code>SHOW_ELEMENT:</code> |
---|
123 | * Show <code>DOMElement</code> nodes.</p> |
---|
124 | * |
---|
125 | * <p><code>SHOW_ATTRIBUTE:</code> |
---|
126 | * Show <code>DOMAttr</code> nodes. This is meaningful only when creating an |
---|
127 | * <code>DOMNodeIterator</code> or <code>DOMTreeWalker</code> with an |
---|
128 | * attribute node as its <code>root</code>; in this case, it means that |
---|
129 | * the attribute node will appear in the first position of the iteration |
---|
130 | * or traversal. Since attributes are never children of other nodes, |
---|
131 | * they do not appear when traversing over the document tree.</p> |
---|
132 | * |
---|
133 | * <p><code>SHOW_TEXT:</code> |
---|
134 | * Show <code>DOMText</code> nodes.</p> |
---|
135 | * |
---|
136 | * <p><code>SHOW_CDATA_SECTION:</code> |
---|
137 | * Show <code>DOMCDATASection</code> nodes.</p> |
---|
138 | * |
---|
139 | * <p><code>SHOW_ENTITY_REFERENCE:</code> |
---|
140 | * Show <code>DOMEntityReference</code> nodes.</p> |
---|
141 | * |
---|
142 | * <p><code>SHOW_ENTITY:</code> |
---|
143 | * Show <code>DOMEntity</code> nodes. This is meaningful only when creating |
---|
144 | * an <code>DOMNodeIterator</code> or <code>DOMTreeWalker</code> with an |
---|
145 | * <code>DOMEntity</code> node as its <code>root</code>; in this case, it |
---|
146 | * means that the <code>DOMEntity</code> node will appear in the first |
---|
147 | * position of the traversal. Since entities are not part of the |
---|
148 | * document tree, they do not appear when traversing over the document |
---|
149 | * tree.</p> |
---|
150 | * |
---|
151 | * <p><code>SHOW_PROCESSING_INSTRUCTION:</code> |
---|
152 | * Show <code>DOMProcessingInstruction</code> nodes.</p> |
---|
153 | * |
---|
154 | * <p><code>SHOW_COMMENT:</code> |
---|
155 | * Show <code>DOMComment</code> nodes.</p> |
---|
156 | * |
---|
157 | * <p><code>SHOW_DOCUMENT:</code> |
---|
158 | * Show <code>DOMDocument</code> nodes.</p> |
---|
159 | * |
---|
160 | * <p><code>SHOW_DOCUMENT_TYPE:</code> |
---|
161 | * Show <code>DOMDocumentType</code> nodes.</p> |
---|
162 | * |
---|
163 | * <p><code>SHOW_DOCUMENT_FRAGMENT:</code> |
---|
164 | * Show <code>DOMDocumentFragment</code> nodes.</p> |
---|
165 | * |
---|
166 | * <p><code>SHOW_NOTATION:</code> |
---|
167 | * Show <code>DOMNotation</code> nodes. This is meaningful only when creating |
---|
168 | * an <code>DOMNodeIterator</code> or <code>DOMTreeWalker</code> with a |
---|
169 | * <code>DOMNotation</code> node as its <code>root</code>; in this case, it |
---|
170 | * means that the <code>DOMNotation</code> node will appear in the first |
---|
171 | * position of the traversal. Since notations are not part of the |
---|
172 | * document tree, they do not appear when traversing over the document |
---|
173 | * tree.</p> |
---|
174 | * |
---|
175 | * @since DOM Level 2 |
---|
176 | */ |
---|
177 | enum ShowType { |
---|
178 | SHOW_ALL = 0x0000FFFF, |
---|
179 | SHOW_ELEMENT = 0x00000001, |
---|
180 | SHOW_ATTRIBUTE = 0x00000002, |
---|
181 | SHOW_TEXT = 0x00000004, |
---|
182 | SHOW_CDATA_SECTION = 0x00000008, |
---|
183 | SHOW_ENTITY_REFERENCE = 0x00000010, |
---|
184 | SHOW_ENTITY = 0x00000020, |
---|
185 | SHOW_PROCESSING_INSTRUCTION = 0x00000040, |
---|
186 | SHOW_COMMENT = 0x00000080, |
---|
187 | SHOW_DOCUMENT = 0x00000100, |
---|
188 | SHOW_DOCUMENT_TYPE = 0x00000200, |
---|
189 | SHOW_DOCUMENT_FRAGMENT = 0x00000400, |
---|
190 | SHOW_NOTATION = 0x00000800 |
---|
191 | }; |
---|
192 | //@} |
---|
193 | |
---|
194 | // ----------------------------------------------------------------------- |
---|
195 | // Virtual DOMNodeFilter interface |
---|
196 | // ----------------------------------------------------------------------- |
---|
197 | /** @name Functions introduced in DOM Level 2 */ |
---|
198 | //@{ |
---|
199 | /** |
---|
200 | * Test whether a specified node is visible in the logical view of a |
---|
201 | * <code>DOMTreeWalker</code> or <code>DOMNodeIterator</code>. This function |
---|
202 | * will be called by the implementation of <code>DOMTreeWalker</code> and |
---|
203 | * <code>DOMNodeIterator</code>; it is not normally called directly from |
---|
204 | * user code. (Though you could do so if you wanted to use the same |
---|
205 | * filter to guide your own application logic.) |
---|
206 | * @param node The node to check to see if it passes the filter or not. |
---|
207 | * @return A constant to determine whether the node is accepted, |
---|
208 | * rejected, or skipped, as defined above. |
---|
209 | * @since DOM Level 2 |
---|
210 | */ |
---|
211 | virtual short acceptNode (const DOMNode* node) const =0; |
---|
212 | //@} |
---|
213 | |
---|
214 | }; |
---|
215 | |
---|
216 | XERCES_CPP_NAMESPACE_END |
---|
217 | |
---|
218 | #endif |
---|