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