1 | #ifndef DocumentImpl_HEADER_GUARD_
|
---|
2 | #define DocumentImpl_HEADER_GUARD_
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * The Apache Software License, Version 1.1
|
---|
6 | *
|
---|
7 | * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
|
---|
8 | * reserved.
|
---|
9 | *
|
---|
10 | * Redistribution and use in source and binary forms, with or without
|
---|
11 | * modification, are permitted provided that the following conditions
|
---|
12 | * are met:
|
---|
13 | *
|
---|
14 | * 1. Redistributions of source code must retain the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer.
|
---|
16 | *
|
---|
17 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
18 | * notice, this list of conditions and the following disclaimer in
|
---|
19 | * the documentation and/or other materials provided with the
|
---|
20 | * distribution.
|
---|
21 | *
|
---|
22 | * 3. The end-user documentation included with the redistribution,
|
---|
23 | * if any, must include the following acknowledgment:
|
---|
24 | * "This product includes software developed by the
|
---|
25 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
26 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
27 | * if and wherever such third-party acknowledgments normally appear.
|
---|
28 | *
|
---|
29 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
30 | * not be used to endorse or promote products derived from this
|
---|
31 | * software without prior written permission. For written
|
---|
32 | * permission, please contact apache\@apache.org.
|
---|
33 | *
|
---|
34 | * 5. Products derived from this software may not be called "Apache",
|
---|
35 | * nor may "Apache" appear in their name, without prior written
|
---|
36 | * permission of the Apache Software Foundation.
|
---|
37 | *
|
---|
38 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
39 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
40 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
41 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
42 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
44 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
45 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
46 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
47 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
48 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
49 | * SUCH DAMAGE.
|
---|
50 | * ====================================================================
|
---|
51 | *
|
---|
52 | * This software consists of voluntary contributions made by many
|
---|
53 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
54 | * originally based on software copyright (c) 1999, International
|
---|
55 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
56 | * on the Apache Software Foundation, please see
|
---|
57 | * <http://www.apache.org/>.
|
---|
58 | */
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * $Id: DocumentImpl.hpp,v 1.7 2003/05/22 02:26:50 knoaman Exp $
|
---|
62 | */
|
---|
63 |
|
---|
64 | //
|
---|
65 | // This file is part of the internal implementation of the C++ XML DOM.
|
---|
66 | // It should NOT be included or used directly by application programs.
|
---|
67 | //
|
---|
68 | // Applications should include the file <xercesc/dom/deprecated/DOM.hpp> for the entire
|
---|
69 | // DOM API, or DOM_*.hpp for individual DOM classes, where the class
|
---|
70 | // name is substituded for the *.
|
---|
71 | //
|
---|
72 |
|
---|
73 | #include <xercesc/util/XercesDefs.hpp>
|
---|
74 | #include "ParentNode.hpp"
|
---|
75 | #include "DOM_Node.hpp"
|
---|
76 | #include "DOM_Element.hpp"
|
---|
77 | #include "xercesc/util/RefVectorOf.hpp"
|
---|
78 | #include "xercesc/util/RefHashTableOf.hpp"
|
---|
79 | #include "XMLDeclImpl.hpp"
|
---|
80 |
|
---|
81 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
82 |
|
---|
83 |
|
---|
84 | class DocumentTypeImpl;
|
---|
85 | class ElementImpl;
|
---|
86 | class AttrImpl;
|
---|
87 | class CDATASectionImpl;
|
---|
88 | class CommentImpl;
|
---|
89 | class DeepNodeListImpl;
|
---|
90 | class DocumentFragmentImpl;
|
---|
91 | class DocumentTypeImpl;
|
---|
92 | class DStringPool;
|
---|
93 | class EntityImpl;
|
---|
94 | class EntityReferenceImpl;
|
---|
95 | class NotationImpl;
|
---|
96 | class ProcessingInstructionImpl;
|
---|
97 | class TextImpl;
|
---|
98 | class NodeIteratorImpl;
|
---|
99 | class TreeWalkerImpl;
|
---|
100 | class DOM_NodeFilter;
|
---|
101 | class NodeFilterImpl;
|
---|
102 | class DOM_DOMImplementation;
|
---|
103 | class DOMString;
|
---|
104 | class NodeIDMap;
|
---|
105 | class RangeImpl;
|
---|
106 |
|
---|
107 | typedef RefVectorOf<NodeIteratorImpl> NodeIterators;
|
---|
108 | typedef RefVectorOf<TreeWalkerImpl> TreeWalkers;
|
---|
109 | typedef RefVectorOf<RangeImpl> RangeImpls;
|
---|
110 |
|
---|
111 |
|
---|
112 | class CDOM_EXPORT DocumentImpl: public ParentNode {
|
---|
113 | private:
|
---|
114 | // -----------------------------------------------------------------------
|
---|
115 | // Private data types
|
---|
116 | // -----------------------------------------------------------------------
|
---|
117 |
|
---|
118 | void setDocumentType(DocumentTypeImpl *doctype);
|
---|
119 |
|
---|
120 | DocumentTypeImpl *docType;
|
---|
121 | ElementImpl *docElement;
|
---|
122 | DStringPool *namePool;
|
---|
123 | NodeIDMap *fNodeIDMap; // for use by GetElementsById().
|
---|
124 |
|
---|
125 | NodeIterators *iterators;
|
---|
126 | TreeWalkers *treeWalkers;
|
---|
127 | RefHashTableOf<void> *userData;
|
---|
128 | RangeImpls *ranges;
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Number of alterations made to this document since its creation.
|
---|
132 | * Serves as a "dirty bit" so that live objects such as NodeList can
|
---|
133 | * recognize when an alteration has been made and discard its cached
|
---|
134 | * state information.
|
---|
135 | * <p>
|
---|
136 | * Any method that alters the tree structure MUST cause or be
|
---|
137 | * accompanied by a call to changed(), to inform it that any outstanding
|
---|
138 | * NodeLists may have to be updated.
|
---|
139 | * <p>
|
---|
140 | * (Required because NodeList is simultaneously "live" and integer-
|
---|
141 | * indexed -- a bad decision in the DOM's design.)
|
---|
142 | * <p>
|
---|
143 | * Note that changes which do not affect the tree's structure -- changing
|
---|
144 | * the node's name, for example -- do _not_ have to call changed().
|
---|
145 | * <p>
|
---|
146 | * Alternative implementation would be to use a cryptographic
|
---|
147 | * Digest value rather than a count. This would have the advantage that
|
---|
148 | * "harmless" changes (those producing equal() trees) would not force
|
---|
149 | * NodeList to resynchronize. Disadvantage is that it's slightly more prone
|
---|
150 | * to "false negatives", though that's the difference between "wildly
|
---|
151 | * unlikely" and "absurdly unlikely". IF we start maintaining digests,
|
---|
152 | * we should consider taking advantage of them.
|
---|
153 | *
|
---|
154 | * Note: This used to be done a node basis, so that we knew what
|
---|
155 | * subtree changed. But since only DeepNodeList really use this today,
|
---|
156 | * the gain appears to be really small compared to the cost of having
|
---|
157 | * an int on every (parent) node plus having to walk up the tree all the
|
---|
158 | * way to the root to mark the branch as changed everytime a node is
|
---|
159 | * changed.
|
---|
160 | * So we now have a single counter global to the document. It means that
|
---|
161 | * some objects may flush their cache more often than necessary, but this
|
---|
162 | * makes nodes smaller and only the document needs to be marked as changed.
|
---|
163 | */
|
---|
164 | int fChanges;
|
---|
165 |
|
---|
166 | /** Bypass error checking. */
|
---|
167 | bool errorChecking;
|
---|
168 |
|
---|
169 | MemoryManager *fMemoryManager;
|
---|
170 |
|
---|
171 | friend class NodeIteratorImpl;
|
---|
172 | friend class TreeWalkerImpl;
|
---|
173 | friend class RangeImpl;
|
---|
174 | friend class DOMParser;
|
---|
175 |
|
---|
176 | public:
|
---|
177 | DocumentImpl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
178 | DocumentImpl(const DOMString &namespaceURI, //DOM Level 2
|
---|
179 | const DOMString &qualifiedName,
|
---|
180 | DocumentTypeImpl *doctype,
|
---|
181 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
182 | virtual ~DocumentImpl();
|
---|
183 | virtual bool isDocumentImpl(); // RTTI replacement function
|
---|
184 |
|
---|
185 | virtual NodeImpl *cloneNode(bool deep);
|
---|
186 | virtual DOMString getNodeName();
|
---|
187 | virtual short getNodeType();
|
---|
188 | virtual DocumentImpl * getOwnerDocument();
|
---|
189 | virtual AttrImpl *createAttribute(const DOMString &name);
|
---|
190 | virtual CDATASectionImpl *createCDATASection(const DOMString &data);
|
---|
191 | virtual CommentImpl *createComment(const DOMString &data);
|
---|
192 | virtual DocumentFragmentImpl *createDocumentFragment();
|
---|
193 | virtual DocumentTypeImpl *createDocumentType(const DOMString &name);
|
---|
194 | virtual DocumentTypeImpl *createDocumentType(const DOMString &qName,
|
---|
195 | const DOMString &publicId,
|
---|
196 | const DOMString &systemId);
|
---|
197 | virtual ElementImpl *createElement(const DOMString & tagName);
|
---|
198 | virtual ElementImpl *createElement(const XMLCh *tagName);
|
---|
199 | virtual EntityImpl *createEntity(const DOMString & name);
|
---|
200 | virtual EntityReferenceImpl *createEntityReference(const DOMString & name);
|
---|
201 | virtual NotationImpl *createNotation(const DOMString & name);
|
---|
202 | virtual ProcessingInstructionImpl *createProcessingInstruction(const DOMString & target, const DOMString & data);
|
---|
203 | virtual TextImpl *createTextNode(const DOMString & data);
|
---|
204 | virtual DocumentTypeImpl *getDoctype();
|
---|
205 | virtual ElementImpl *getDocumentElement();
|
---|
206 | virtual DeepNodeListImpl *getElementsByTagName(const DOMString & tagname);
|
---|
207 | virtual NodeImpl *insertBefore(NodeImpl *newChild, NodeImpl *refChild);
|
---|
208 | bool isXMLName(const DOMString & s);
|
---|
209 | virtual void referenced();
|
---|
210 | virtual NodeImpl *removeChild(NodeImpl *oldChild);
|
---|
211 | virtual void unreferenced();
|
---|
212 | static NodeIteratorImpl* createNodeIterator(DOM_Node root, unsigned long whatToShow, DOM_NodeFilter* filter, bool entityReferenceExpansion,
|
---|
213 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
214 | static TreeWalkerImpl* createTreeWalker(DOM_Node root, unsigned long whatToShow, DOM_NodeFilter* filter, bool entityReferenceExpansion,
|
---|
215 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
216 | virtual XMLDeclImpl* createXMLDecl(const DOMString& version, const DOMString& encoding, const DOMString& standalone);
|
---|
217 | virtual void* getUserData();
|
---|
218 | virtual void setUserData(void* value);
|
---|
219 | virtual RangeImpl* createRange();
|
---|
220 | virtual RangeImpls* getRanges(); //non-standard api
|
---|
221 | virtual void removeRange(RangeImpl* range); //non-standard api
|
---|
222 |
|
---|
223 |
|
---|
224 | // helper functions to prevent storing userdata pointers on every node.
|
---|
225 | virtual void setUserData(NodeImpl* n, void* data);
|
---|
226 | virtual void* getUserData(NodeImpl* n);
|
---|
227 |
|
---|
228 | //Introduced in DOM Level 2
|
---|
229 | virtual NodeImpl *importNode(NodeImpl *source, bool deep);
|
---|
230 | virtual ElementImpl *createElementNS(const DOMString &namespaceURI,
|
---|
231 | const DOMString &qualifiedName);
|
---|
232 | virtual AttrImpl *createAttributeNS(const DOMString &namespaceURI,
|
---|
233 | const DOMString &qualifiedName);
|
---|
234 | virtual DeepNodeListImpl *getElementsByTagNameNS(const DOMString &namespaceURI,
|
---|
235 | const DOMString &localName);
|
---|
236 | virtual ElementImpl *getElementById(const DOMString &elementId);
|
---|
237 |
|
---|
238 | //Return the index > 0 of ':' in the given qualified name qName="prefix:localName".
|
---|
239 | //Return 0 if there is no ':', or -1 if qName is malformed such as ":abcd".
|
---|
240 | static int indexofQualifiedName(const DOMString & qName);
|
---|
241 | static bool isKidOK(NodeImpl *parent, NodeImpl *child);
|
---|
242 |
|
---|
243 | inline NodeIDMap * getNodeIDMap() {return fNodeIDMap;};
|
---|
244 |
|
---|
245 | virtual void changed();
|
---|
246 | virtual int changes();
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Sets whether the DOM implementation performs error checking
|
---|
250 | * upon operations. Turning off error checking only affects
|
---|
251 | * the following DOM checks:
|
---|
252 | * <ul>
|
---|
253 | * <li>Checking strings to make sure that all characters are
|
---|
254 | * legal XML characters
|
---|
255 | * <li>Hierarchy checking such as allowed children, checks for
|
---|
256 | * cycles, etc.
|
---|
257 | * </ul>
|
---|
258 | * <p>
|
---|
259 | * Turning off error checking does <em>not</em> turn off the
|
---|
260 | * following checks:
|
---|
261 | * <ul>
|
---|
262 | * <li>Read only checks
|
---|
263 | * <li>Checks related to DOM events
|
---|
264 | * </ul>
|
---|
265 | */
|
---|
266 | inline void setErrorChecking(bool check) {
|
---|
267 | errorChecking = check;
|
---|
268 | }
|
---|
269 |
|
---|
270 | /**
|
---|
271 | * Returns true if the DOM implementation performs error checking.
|
---|
272 | */
|
---|
273 | inline bool getErrorChecking() {
|
---|
274 | return errorChecking;
|
---|
275 | }
|
---|
276 |
|
---|
277 | inline MemoryManager* getMemoryManager() const {
|
---|
278 | return fMemoryManager;
|
---|
279 | }
|
---|
280 |
|
---|
281 | // -----------------------------------------------------------------------
|
---|
282 | // Notification that lazy data has been deleted
|
---|
283 | // -----------------------------------------------------------------------
|
---|
284 | static void reinitDocumentImpl();
|
---|
285 |
|
---|
286 | };
|
---|
287 |
|
---|
288 | XERCES_CPP_NAMESPACE_END
|
---|
289 |
|
---|
290 | #endif
|
---|