Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache\@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* $Id$
*/
// This class doesn't support having any children, and implements the behavior
// of an empty NodeList as far getChildNodes is concerned.
// The ParentNode subclass overrides this behavior.
#include "DOMNodeImpl.hpp"
#include "DOMCasts.hpp"
#include "DOMDocumentImpl.hpp"
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLRegisterCleanup.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <stdio.h>
#include <assert.h>
const unsigned short DOMNodeImpl::READONLY = 0x1<<0;
const unsigned short DOMNodeImpl::SYNCDATA = 0x1<<1;
const unsigned short DOMNodeImpl::SYNCCHILDREN = 0x1<<2;
const unsigned short DOMNodeImpl::OWNED = 0x1<<3;
const unsigned short DOMNodeImpl::FIRSTCHILD = 0x1<<4;
const unsigned short DOMNodeImpl::SPECIFIED = 0x1<<5;
const unsigned short DOMNodeImpl::IGNORABLEWS = 0x1<<6;
const unsigned short DOMNodeImpl::SETVALUE = 0x1<<7;
const unsigned short DOMNodeImpl::ID_ATTR = 0x1<<8;
const unsigned short DOMNodeImpl::USERDATA = 0x1<<9;
const unsigned short DOMNodeImpl::LEAFNODETYPE = 0x1<<10;
const unsigned short DOMNodeImpl::CHILDNODE = 0x1<<11;
const unsigned short DOMNodeImpl::TOBERELEASED = 0x1<<12;
// -----------------------------------------------------------------------
// Reset the singleton gEmptyNodeList
// -----------------------------------------------------------------------
static DOMNodeListImpl *gEmptyNodeList; // make a singleton empty node list
static void reinitEmptyNodeList()
{
delete gEmptyNodeList;
gEmptyNodeList = 0;
}
// -----------------------------------------------------------------------
// DOMNodeImpl Functions
// -----------------------------------------------------------------------
DOMNodeImpl::DOMNodeImpl(DOMNode *ownerNode)
{
this->flags = 0;
// as long as we do not have any owner, fOwnerNode is our ownerDocument
fOwnerNode = ownerNode;
};
// This only makes a shallow copy, cloneChildren must also be called for a
// deep clone
DOMNodeImpl::DOMNodeImpl(const DOMNodeImpl &other)
{
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
this->flags = other.flags;
this->isReadOnly(false);
// Need to break the association w/ original parent
this->fOwnerNode = other.getOwnerDocument();
this->isOwned(false);
};
DOMNodeImpl::~DOMNodeImpl() {
};
DOMNode * DOMNodeImpl::appendChild(DOMNode *newChild)
{
// Only node types that don't allow children will use this default function.
// Others will go to DOMParentNode::appendChild.
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0);
return 0;
// return insertBefore(newChild, 0);
};
DOMNamedNodeMap * DOMNodeImpl::getAttributes() const {
return 0; // overridden in ElementImpl
};
DOMNodeList *DOMNodeImpl::getChildNodes() const {
static XMLRegisterCleanup emptyNodeListCleanup;
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
if (gEmptyNodeList == 0)
{
DOMNodeList *t = new DOMNodeListImpl(0);
if (XMLPlatformUtils::compareAndSwap((void **)&gEmptyNodeList, t, 0) != 0)
{
delete t;
}
else
{
emptyNodeListCleanup.registerCleanup(reinitEmptyNodeList);
}
}
return (DOMNodeList *)gEmptyNodeList;
};
DOMNode * DOMNodeImpl::getFirstChild() const {
return 0; // overridden in ParentNode
};
DOMNode * DOMNodeImpl::getLastChild() const
{
return 0; // overridden in ParentNode
};
DOMNode * DOMNodeImpl::getNextSibling() const {
return 0; // overridden in ChildNode
};
const XMLCh * DOMNodeImpl::getNodeValue() const {
return 0; // Overridden by anything that has a value
}
//
// Unlike the external getOwnerDocument, this one returns the owner document
// for document nodes as well as all of the other node types.
//
DOMDocument *DOMNodeImpl::getOwnerDocument() const
{
if (!this->isLeafNode())
{
DOMElementImpl *ep = (DOMElementImpl *)castToNode(this);
return ep->fParent.fOwnerDocument;
}
// Leaf node types - those that cannot have children, like Text.
if (isOwned()) {
return fOwnerNode->getOwnerDocument();
} else {
assert (fOwnerNode->getNodeType() == DOMNode::DOCUMENT_NODE);
return (DOMDocument *)fOwnerNode;
}
};
void DOMNodeImpl::setOwnerDocument(DOMDocument *doc) {
// if we have an owner we rely on it to have it right
// otherwise fOwnerNode is our ownerDocument
if (!isOwned()) {
// revisit. Problem with storage for doctype nodes that were created
// on the system heap in advance of having a document.
fOwnerNode = doc;
}
}
DOMNode * DOMNodeImpl::getParentNode() const
{
return 0; // overridden in ChildNode
};
DOMNode* DOMNodeImpl::getPreviousSibling() const
{
return 0; // overridden in ChildNode
};
bool DOMNodeImpl::hasChildNodes() const
{
return false;
};
DOMNode *DOMNodeImpl::insertBefore(DOMNode *newChild, DOMNode *refChild) {
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR, 0);
return 0;
};
DOMNode *DOMNodeImpl::removeChild(DOMNode *oldChild)
{
throw DOMException(DOMException::NOT_FOUND_ERR, 0);
return 0;
};
DOMNode *DOMNodeImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
{
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0);
return 0;
};
void DOMNodeImpl::setNodeValue(const XMLCh *val)
{
// Default behavior is to do nothing, overridden in some subclasses
};
void DOMNodeImpl::setReadOnly(bool readOnl, bool deep)
{
this->isReadOnly(readOnl);
if (deep) {
for (DOMNode *mykid = castToNode(this)->getFirstChild();
mykid != 0;
mykid = mykid->getNextSibling())
if(mykid->getNodeType() != DOMNode::ENTITY_REFERENCE_NODE)
castToNodeImpl(mykid)->setReadOnly(readOnl,true);
}
}
//Introduced in DOM Level 2
void DOMNodeImpl::normalize()
{
// does nothing by default, overridden by subclasses
};
bool DOMNodeImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
{
return DOMImplementation::getImplementation()->hasFeature(feature, version);
}
const XMLCh *DOMNodeImpl::getNamespaceURI() const
{
return 0;
}
const XMLCh *DOMNodeImpl::getPrefix() const
{
return 0;
}
const XMLCh *DOMNodeImpl::getLocalName() const
{
return 0;
}
void DOMNodeImpl::setPrefix(const XMLCh *fPrefix)
{
throw DOMException(DOMException::NAMESPACE_ERR, 0);
}
bool DOMNodeImpl::hasAttributes() const {
return 0; // overridden in ElementImpl
};
static const XMLCh s_xml[] = {chLatin_x, chLatin_m, chLatin_l, chNull};
static const XMLCh s_xmlURI[] = // "http://www.w3.org/XML/1998/namespace"
{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod,
chLatin_o, chLatin_r, chLatin_g, chForwardSlash, chLatin_X, chLatin_M, chLatin_L, chForwardSlash,
chDigit_1, chDigit_9, chDigit_9, chDigit_8, chForwardSlash,
chLatin_n, chLatin_a, chLatin_m, chLatin_e, chLatin_s, chLatin_p, chLatin_a, chLatin_c, chLatin_e,
chNull};
static const XMLCh s_xmlns[] = {chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull};
static const XMLCh s_xmlnsURI[] = // "http://www.w3.org/2000/xmlns/"
{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod,
chLatin_o, chLatin_r, chLatin_g, chForwardSlash,
chDigit_2, chDigit_0, chDigit_0, chDigit_0, chForwardSlash,
chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chForwardSlash, chNull};
const XMLCh *DOMNodeImpl::getXmlString() {return s_xml;};
const XMLCh *DOMNodeImpl::getXmlURIString() {return s_xmlURI;};
const XMLCh *DOMNodeImpl::getXmlnsString() {return s_xmlns;};
const XMLCh *DOMNodeImpl::getXmlnsURIString() {return s_xmlnsURI;};
//Return a URI mapped from the given prefix and namespaceURI as below
//---------------------------------------------------
// "xml" xmlURI xmlURI
// "xml" otherwise NAMESPACE_ERR
// "xmlns" xmlnsURI xmlnsURI (nType = ATTRIBUTE_NODE only)
// "xmlns" otherwise NAMESPACE_ERR (nType = ATTRIBUTE_NODE only)
// != null null or "" NAMESPACE_ERR
// else any namesapceURI
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
const XMLCh* DOMNodeImpl::mapPrefix(const XMLCh *prefix,
const XMLCh *namespaceURI, short nType)
{
static const XMLCh s_xml[] = {chLatin_x, chLatin_m, chLatin_l, chNull};
static const XMLCh s_xmlURI[] = // "http://www.w3.org/XML/1998/namespace"
{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod,
chLatin_o, chLatin_r, chLatin_g, chForwardSlash, chLatin_X, chLatin_M, chLatin_L, chForwardSlash,
chDigit_1, chDigit_9, chDigit_9, chDigit_8, chForwardSlash,
chLatin_n, chLatin_a, chLatin_m, chLatin_e, chLatin_s, chLatin_p, chLatin_a, chLatin_c, chLatin_e,
chNull};
static const XMLCh s_xmlns[] = {chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull};
static const XMLCh s_xmlnsURI[] = // "http://www.w3.org/2000/xmlns/"
{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod,
chLatin_o, chLatin_r, chLatin_g, chForwardSlash,
chDigit_2, chDigit_0, chDigit_0, chDigit_0, chForwardSlash,
chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chForwardSlash, chNull};
if (prefix == 0)
return namespaceURI;
if (XMLString::compareString(prefix, s_xml) == 0) {
if (XMLString::compareString(namespaceURI, s_xmlURI) == 0)
return s_xmlURI;
throw DOMException(DOMException::NAMESPACE_ERR, 0);
} else if (nType == DOMNode::ATTRIBUTE_NODE && XMLString::compareString(prefix, s_xmlns) == 0) {
if (XMLString::compareString(namespaceURI, s_xmlnsURI) == 0)
return s_xmlnsURI;
throw DOMException(DOMException::NAMESPACE_ERR, 0);
} else if (namespaceURI == 0 || *namespaceURI == 0) {
throw DOMException(DOMException::NAMESPACE_ERR, 0);
} else
return namespaceURI;
return namespaceURI;
}
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
//Introduced in DOM Level 3
void* DOMNodeImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{
if (!data && !hasUserData())
return 0;
hasUserData(true);
return ((DOMDocumentImpl*)getOwnerDocument())->setUserData(this, key, data, handler);
}
void* DOMNodeImpl::getUserData(const XMLCh* key) const
{
if (hasUserData())
return ((DOMDocumentImpl*)getOwnerDocument())->getUserData(this, key);
return 0;
}
void DOMNodeImpl::callUserDataHandlers(DOMUserDataHandler::DOMOperationType operation,
const DOMNode* src,
const DOMNode* dst) const
{
((DOMDocumentImpl*)getOwnerDocument())->callUserDataHandlers(this, operation, src, dst);
}
bool DOMNodeImpl::isSameNode(const DOMNode* other)
{
return (castToNode(this) == other);
}
bool DOMNodeImpl::isEqualNode(const DOMNode* arg)
{
if (isSameNode(arg)) {
return true;
}
DOMNode* thisNode = castToNode(this);
if (arg->getNodeType() != thisNode->getNodeType()) {
return false;
}
// in theory nodeName can't be null but better be careful
// who knows what other implementations may be doing?...
if (!thisNode->getNodeName()) {
if (arg->getNodeName()) {
return false;
}
}
else if (XMLString::compareString(thisNode->getNodeName(), arg->getNodeName())) {
return false;
}
if (!thisNode->getLocalName()) {
if (arg->getLocalName()) {
return false;
}
}
else if (XMLString::compareString(thisNode->getLocalName(),arg->getLocalName())) {
return false;
}
if (!thisNode->getNamespaceURI()) {
if (arg->getNamespaceURI()) {
return false;
}
}
else if (XMLString::compareString(thisNode->getNamespaceURI(), arg->getNamespaceURI())) {
return false;
}
if (!thisNode->getPrefix()) {
if (arg->getPrefix()) {
return false;
}
}
else if (XMLString::compareString(thisNode->getPrefix(), arg->getPrefix())) {
return false;
}
if (!thisNode->getNodeValue()) {
if (arg->getNodeValue()) {
return false;
}
}
else if (XMLString::compareString(thisNode->getNodeValue(), arg->getNodeValue())) {
return false;
}
// baseURI not suppported yet
/*
if (!thisNode->getBaseURI()) {
if (arg->getBaseURI()) {
return false;
}
}
else if (XMLString::compareString(thisNode->getBaseURI(), arg->getBaseURI())) {
return false;
}*/
return true;
}