2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
19
* $Id: DOMNodeImpl.cpp 673428 2008-07-02 16:00:35Z amassari $
22
// This class doesn't support having any children, and implements the behavior
23
// of an empty NodeList as far getChildNodes is concerned.
24
// The ParentNode subclass overrides this behavior.
27
#include "DOMCasts.hpp"
29
#include "DOMDocumentTypeImpl.hpp"
30
#include "DOMElementImpl.hpp"
31
#include "DOMAttrImpl.hpp"
33
#include <xercesc/dom/DOMImplementation.hpp>
34
#include <xercesc/dom/DOMException.hpp>
36
#include <xercesc/util/XMLUniDefs.hpp>
37
#include <xercesc/util/PlatformUtils.hpp>
38
#include <xercesc/util/XMLInitializer.hpp>
42
XERCES_CPP_NAMESPACE_BEGIN
44
//Though DOMNodeImpl does not derivate from DOMNode, it shares
45
//the same GetDOMNodeMemoryManager
47
const unsigned short DOMNodeImpl::READONLY = 0x1<<0;
48
const unsigned short DOMNodeImpl::SYNCDATA = 0x1<<1;
49
const unsigned short DOMNodeImpl::SYNCCHILDREN = 0x1<<2;
50
const unsigned short DOMNodeImpl::OWNED = 0x1<<3;
51
const unsigned short DOMNodeImpl::FIRSTCHILD = 0x1<<4;
52
const unsigned short DOMNodeImpl::SPECIFIED = 0x1<<5;
53
const unsigned short DOMNodeImpl::IGNORABLEWS = 0x1<<6;
54
const unsigned short DOMNodeImpl::SETVALUE = 0x1<<7;
55
const unsigned short DOMNodeImpl::ID_ATTR = 0x1<<8;
56
const unsigned short DOMNodeImpl::USERDATA = 0x1<<9;
57
const unsigned short DOMNodeImpl::LEAFNODETYPE = 0x1<<10;
58
const unsigned short DOMNodeImpl::CHILDNODE = 0x1<<11;
59
const unsigned short DOMNodeImpl::TOBERELEASED = 0x1<<12;
63
static DOMNodeListImpl *gEmptyNodeList = 0; // Singleton empty node list.
65
void XMLInitializer::initializeDOMNodeListImpl()
67
gEmptyNodeList = new DOMNodeListImpl(0);
70
void XMLInitializer::terminateDOMNodeListImpl()
72
delete gEmptyNodeList;
76
// -----------------------------------------------------------------------
77
// DOMNodeImpl Functions
78
// -----------------------------------------------------------------------
79
DOMNodeImpl::DOMNodeImpl(DOMNode *ownerNode)
80
: fOwnerNode(ownerNode)
83
// as long as we do not have any owner, fOwnerNode is our ownerDocument
86
// This only makes a shallow copy, cloneChildren must also be called for a
88
DOMNodeImpl::DOMNodeImpl(const DOMNodeImpl &other)
90
this->flags = other.flags;
91
this->isReadOnly(false);
93
// Need to break the association w/ original parent
94
this->fOwnerNode = other.getOwnerDocument();
100
DOMNodeImpl::~DOMNodeImpl() {
104
DOMNode * DOMNodeImpl::appendChild(DOMNode *)
106
// Only node types that don't allow children will use this default function.
107
// Others will go to DOMParentNode::appendChild.
108
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0, GetDOMNodeMemoryManager);
110
// return insertBefore(newChild, 0);
114
DOMNamedNodeMap * DOMNodeImpl::getAttributes() const {
115
return 0; // overridden in ElementImpl
119
DOMNodeList *DOMNodeImpl::getChildNodes() const {
120
return gEmptyNodeList;
125
DOMNode * DOMNodeImpl::getFirstChild() const {
126
return 0; // overridden in ParentNode
130
DOMNode * DOMNodeImpl::getLastChild() const
132
return 0; // overridden in ParentNode
136
DOMNode * DOMNodeImpl::getNextSibling() const {
137
return 0; // overridden in ChildNode
141
const XMLCh * DOMNodeImpl::getNodeValue() const {
142
return 0; // Overridden by anything that has a value
147
// Unlike the external getOwnerDocument, this one returns the owner document
148
// for document nodes as well as all of the other node types.
150
DOMDocument *DOMNodeImpl::getOwnerDocument() const
152
if (!this->isLeafNode())
154
DOMElementImpl *ep = (DOMElementImpl *)castToNode(this);
155
return ep->fParent.fOwnerDocument;
158
// Leaf node types - those that cannot have children, like Text.
161
DOMDocument* ownerDoc = fOwnerNode->getOwnerDocument();
165
assert (fOwnerNode->getNodeType() == DOMNode::DOCUMENT_NODE);
166
return (DOMDocument *)fOwnerNode;
172
assert (fOwnerNode->getNodeType() == DOMNode::DOCUMENT_NODE);
173
return (DOMDocument *)fOwnerNode;
178
void DOMNodeImpl::setOwnerDocument(DOMDocument *doc) {
179
// if we have an owner we rely on it to have it right
180
// otherwise fOwnerNode is our ownerDocument
182
// revisit. Problem with storage for doctype nodes that were created
183
// on the system heap in advance of having a document.
188
DOMNode * DOMNodeImpl::getParentNode() const
190
return 0; // overridden in ChildNode
194
DOMNode* DOMNodeImpl::getPreviousSibling() const
196
return 0; // overridden in ChildNode
199
bool DOMNodeImpl::hasChildNodes() const
206
DOMNode *DOMNodeImpl::insertBefore(DOMNode *, DOMNode *) {
207
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR, 0, GetDOMNodeMemoryManager);
212
DOMNode *DOMNodeImpl::removeChild(DOMNode *)
214
throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNodeMemoryManager);
219
DOMNode *DOMNodeImpl::replaceChild(DOMNode *, DOMNode *)
221
throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0, GetDOMNodeMemoryManager);
227
void DOMNodeImpl::setNodeValue(const XMLCh *)
229
// Default behavior is to do nothing, overridden in some subclasses
234
void DOMNodeImpl::setReadOnly(bool readOnl, bool deep)
236
this->isReadOnly(readOnl);
239
for (DOMNode *mykid = castToNode(this)->getFirstChild();
241
mykid = mykid->getNextSibling()) {
243
short kidNodeType = mykid->getNodeType();
245
switch (kidNodeType) {
246
case DOMNode::ENTITY_REFERENCE_NODE:
248
case DOMNode::ELEMENT_NODE:
249
((DOMElementImpl*) mykid)->setReadOnly(readOnl, true);
251
case DOMNode::DOCUMENT_TYPE_NODE:
252
((DOMDocumentTypeImpl*) mykid)->setReadOnly(readOnl, true);
255
castToNodeImpl(mykid)->setReadOnly(readOnl, true);
263
//Introduced in DOM Level 2
265
void DOMNodeImpl::normalize()
267
// does nothing by default, overridden by subclasses
271
bool DOMNodeImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
273
return DOMImplementation::getImplementation()->hasFeature(feature, version);
276
const XMLCh *DOMNodeImpl::getNamespaceURI() const
281
const XMLCh *DOMNodeImpl::getPrefix() const
286
const XMLCh *DOMNodeImpl::getLocalName() const
292
void DOMNodeImpl::setPrefix(const XMLCh *)
294
throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
298
bool DOMNodeImpl::hasAttributes() const {
299
return 0; // overridden in ElementImpl
306
const XMLCh *DOMNodeImpl::getXmlString() {return XMLUni::fgXMLString;}
307
const XMLCh *DOMNodeImpl::getXmlURIString() {return XMLUni::fgXMLURIName;}
308
const XMLCh *DOMNodeImpl::getXmlnsString() {return XMLUni::fgXMLNSString;}
309
const XMLCh *DOMNodeImpl::getXmlnsURIString() {return XMLUni::fgXMLNSURIName;}
311
//Return a URI mapped from the given prefix and namespaceURI as below
312
// prefix namespaceURI output
313
//---------------------------------------------------
314
// "xml" xmlURI xmlURI
315
// "xml" otherwise NAMESPACE_ERR
316
// "xmlns" xmlnsURI xmlnsURI (nType = ATTRIBUTE_NODE only)
317
// "xmlns" otherwise NAMESPACE_ERR (nType = ATTRIBUTE_NODE only)
318
// != null null or "" NAMESPACE_ERR
319
// else any namesapceURI
320
const XMLCh* DOMNodeImpl::mapPrefix(const XMLCh *prefix,
321
const XMLCh *namespaceURI, short nType)
326
if (XMLString::equals(prefix, XMLUni::fgXMLString)) {
327
if (XMLString::equals(namespaceURI, XMLUni::fgXMLURIName))
328
return XMLUni::fgXMLURIName;
329
throw DOMException(DOMException::NAMESPACE_ERR, 0);
330
} else if (nType == DOMNode::ATTRIBUTE_NODE && XMLString::equals(prefix, XMLUni::fgXMLNSString)) {
331
if (XMLString::equals(namespaceURI, XMLUni::fgXMLNSURIName))
332
return XMLUni::fgXMLNSURIName;
333
throw DOMException(DOMException::NAMESPACE_ERR, 0);
334
} else if (namespaceURI == 0 || *namespaceURI == 0)
335
throw DOMException(DOMException::NAMESPACE_ERR, 0);
339
//Introduced in DOM Level 3
340
void* DOMNodeImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
342
if (!data && !hasUserData())
346
return ((DOMDocumentImpl*)getOwnerDocument())->setUserData(this, key, data, handler);
349
void* DOMNodeImpl::getUserData(const XMLCh* key) const
352
return ((DOMDocumentImpl*)getOwnerDocument())->getUserData(this, key);
356
void DOMNodeImpl::callUserDataHandlers(DOMUserDataHandler::DOMOperationType operation,
360
DOMDocumentImpl* doc=(DOMDocumentImpl*)getOwnerDocument();
362
doc->callUserDataHandlers(this, operation, src, dst);
365
bool DOMNodeImpl::isSameNode(const DOMNode* other) const
367
return (castToNode(this) == other);
370
bool DOMNodeImpl::isEqualNode(const DOMNode* arg) const
375
if (isSameNode(arg)) {
379
DOMNode* thisNode = castToNode(this);
381
if (arg->getNodeType() != thisNode->getNodeType()) {
385
// the compareString will check null string as well
386
if (!XMLString::equals(thisNode->getNodeName(), arg->getNodeName())) {
390
if (!XMLString::equals(thisNode->getLocalName(),arg->getLocalName())) {
394
if (!XMLString::equals(thisNode->getNamespaceURI(), arg->getNamespaceURI())) {
398
if (!XMLString::equals(thisNode->getPrefix(), arg->getPrefix())) {
402
if (!XMLString::equals(thisNode->getNodeValue(), arg->getNodeValue())) {
409
const XMLCh* DOMNodeImpl::lookupPrefix(const XMLCh* namespaceURI) const {
410
// REVISIT: When Namespaces 1.1 comes out this may not be true
411
// Prefix can't be bound to null namespace
412
if (namespaceURI == 0) {
416
DOMNode *thisNode = castToNode(this);
418
short type = thisNode->getNodeType();
421
case DOMNode::ELEMENT_NODE: {
422
return lookupPrefix(namespaceURI, (DOMElement*)thisNode);
424
case DOMNode::DOCUMENT_NODE:{
425
return ((DOMDocument*)thisNode)->getDocumentElement()->lookupPrefix(namespaceURI);
428
case DOMNode::ENTITY_NODE :
429
case DOMNode::NOTATION_NODE:
430
case DOMNode::DOCUMENT_FRAGMENT_NODE:
431
case DOMNode::DOCUMENT_TYPE_NODE:
434
case DOMNode::ATTRIBUTE_NODE:{
435
if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) {
436
return fOwnerNode->lookupPrefix(namespaceURI);
441
DOMNode *ancestor = getElementAncestor(thisNode);
443
return ancestor->lookupPrefix(namespaceURI);
451
DOMNode* DOMNodeImpl::getElementAncestor (const DOMNode* currentNode) const {
452
DOMNode* parent = currentNode->getParentNode();
454
short type = parent->getNodeType();
455
if (type == DOMNode::ELEMENT_NODE) {
458
parent=parent->getParentNode();
464
const XMLCh* DOMNodeImpl::lookupPrefix(const XMLCh* const namespaceURI, DOMElement *originalElement) const {
465
DOMNode *thisNode = castToNode(this);
467
const XMLCh* ns = thisNode->getNamespaceURI();
468
// REVISIT: if no prefix is available is it null or empty string, or
470
const XMLCh* prefix = thisNode->getPrefix();
472
if (ns != 0 && XMLString::equals(ns,namespaceURI) && prefix != 0) {
473
const XMLCh* foundNamespace = originalElement->lookupNamespaceURI(prefix);
474
if (foundNamespace != 0 && XMLString::equals(foundNamespace, namespaceURI)) {
478
if (thisNode->hasAttributes()) {
479
DOMNamedNodeMap *nodeMap = thisNode->getAttributes();
482
XMLSize_t length = nodeMap->getLength();
484
for (XMLSize_t i = 0;i < length;i++) {
485
DOMNode *attr = nodeMap->item(i);
486
const XMLCh* attrPrefix = attr->getPrefix();
487
const XMLCh* value = attr->getNodeValue();
489
ns = attr->getNamespaceURI();
491
if (ns != 0 && XMLString::equals(ns, XMLUni::fgXMLNSURIName)) {
493
if ((attrPrefix != 0 && XMLString::equals(attrPrefix, XMLUni::fgXMLNSString)) &&
494
XMLString::equals(value, namespaceURI)) {
495
const XMLCh* localname= attr->getLocalName();
496
const XMLCh* foundNamespace = originalElement->lookupNamespaceURI(localname);
497
if (foundNamespace != 0 && XMLString::equals(foundNamespace, namespaceURI)) {
505
DOMNode *ancestor = getElementAncestor(thisNode);
507
return castToNodeImpl(ancestor)->lookupPrefix(namespaceURI, originalElement);
512
const XMLCh* DOMNodeImpl::lookupNamespaceURI(const XMLCh* specifiedPrefix) const {
513
DOMNode *thisNode = castToNode(this);
515
short type = thisNode->getNodeType();
517
case DOMNode::ELEMENT_NODE : {
518
const XMLCh* ns = thisNode->getNamespaceURI();
519
const XMLCh* prefix = thisNode->getPrefix();
521
// REVISIT: is it possible that prefix is empty string?
522
if (specifiedPrefix == 0 && prefix == specifiedPrefix) {
523
// looking for default namespace
525
} else if (prefix != 0 && XMLString::equals(prefix, specifiedPrefix)) {
526
// non default namespace
530
if (thisNode->hasAttributes()) {
531
DOMNamedNodeMap *nodeMap = thisNode->getAttributes();
533
XMLSize_t length = nodeMap->getLength();
534
for (XMLSize_t i = 0;i < length;i++) {
535
DOMNode *attr = nodeMap->item(i);
536
const XMLCh *attrPrefix = attr->getPrefix();
537
const XMLCh *value = attr->getNodeValue();
538
ns = attr->getNamespaceURI();
540
if (ns != 0 && XMLString::equals(ns, XMLUni::fgXMLNSURIName)) {
541
// at this point we are dealing with DOM Level 2 nodes only
542
if (specifiedPrefix == 0 &&
543
XMLString::equals(attr->getNodeName(), XMLUni::fgXMLNSString)) {
546
} else if (attrPrefix != 0 &&
547
XMLString::equals(attrPrefix, XMLUni::fgXMLNSString) &&
548
XMLString::equals(attr->getLocalName(), specifiedPrefix)) {
549
// non default namespace
556
DOMNode *ancestor = getElementAncestor(thisNode);
558
return ancestor->lookupNamespaceURI(specifiedPrefix);
562
case DOMNode::DOCUMENT_NODE : {
563
return((DOMDocument*)thisNode)->getDocumentElement()->lookupNamespaceURI(specifiedPrefix);
565
case DOMNode::ENTITY_NODE :
566
case DOMNode::NOTATION_NODE:
567
case DOMNode::DOCUMENT_FRAGMENT_NODE:
568
case DOMNode::DOCUMENT_TYPE_NODE:
571
case DOMNode::ATTRIBUTE_NODE:{
572
if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) {
573
return fOwnerNode->lookupNamespaceURI(specifiedPrefix);
578
DOMNode *ancestor = getElementAncestor(castToNode(this));
580
return ancestor->lookupNamespaceURI(specifiedPrefix);
588
const XMLCh* DOMNodeImpl::getBaseURI() const{
589
DOMNode *thisNode = castToNode(this);
590
DOMNode* parent = thisNode->getParentNode();
592
return parent->getBaseURI();
597
const DOMNode* DOMNodeImpl::getTreeParentNode(const DOMNode* node) const {
598
const DOMNode* parent=node->getParentNode();
601
short nodeType=node->getNodeType();
604
case DOMNode::ATTRIBUTE_NODE: return ((const DOMAttr*)node)->getOwnerElement();
605
case DOMNode::NOTATION_NODE:
606
case DOMNode::ENTITY_NODE: return node->getOwnerDocument()->getDoctype();
611
short DOMNodeImpl::compareDocumentPosition(const DOMNode* other) const {
612
DOMNode* thisNode = castToNode(this);
614
// If the two nodes being compared are the same node, then no flags are set on the return.
615
if (thisNode == other)
618
//if this is a custom node, we don't really know what to do, just return
619
//user should provide its own compareDocumentPosition logic, and shouldn't reach here
620
if(thisNode->getNodeType() > 12) {
624
//if it is a custom node we must ask it for the order
625
if(other->getNodeType() > 12) {
626
return reverseTreeOrderBitPattern(other->compareDocumentPosition(thisNode));
629
// Otherwise, the order of two nodes is determined by looking for common containers --
630
// containers which contain both. A node directly contains any child nodes.
631
// A node also directly contains any other nodes attached to it such as attributes
632
// contained in an element or entities and notations contained in a document type.
633
// Nodes contained in contained nodes are also contained, but less-directly as
634
// the number of intervening containers increases.
636
// If one of the nodes being compared contains the other node, then the container precedes
637
// the contained node, and reversely the contained node follows the container. For example,
638
// when comparing an element against its own attribute or child, the element node precedes
639
// its attribute node and its child node, which both follow it.
641
const DOMNode* tmpNode;
642
const DOMNode* myRoot = castToNode(this);
644
while((tmpNode=getTreeParentNode(myRoot))!=0)
648
return DOMNode::DOCUMENT_POSITION_CONTAINS | DOMNode::DOCUMENT_POSITION_PRECEDING;
652
const DOMNode* hisRoot = other;
654
while((tmpNode=getTreeParentNode(hisRoot))!=0)
657
if(hisRoot==thisNode)
658
return DOMNode::DOCUMENT_POSITION_CONTAINED_BY | DOMNode::DOCUMENT_POSITION_FOLLOWING;
662
// If there is no common container node, then the order is based upon order between the
663
// root container of each node that is in no container. In this case, the result is
664
// disconnected and implementation-specific. This result is stable as long as these
665
// outer-most containing nodes remain in memory and are not inserted into some other
666
// containing node. This would be the case when the nodes belong to different documents
667
// or fragments, and cloning the document or inserting a fragment might change the order.
670
return DOMNode::DOCUMENT_POSITION_DISCONNECTED | DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC |
671
(myRoot<hisRoot?DOMNode::DOCUMENT_POSITION_PRECEDING:DOMNode::DOCUMENT_POSITION_FOLLOWING);
673
// If neither of the previous cases apply, then there exists a most-direct container common
674
// to both nodes being compared. In this case, the order is determined based upon the two
675
// determining nodes directly contained in this most-direct common container that either
676
// are or contain the corresponding nodes being compared.
678
// if the two depths are different, go to the same one
679
myRoot = castToNode(this);
681
if (myDepth > hisDepth) {
682
for (int i= 0 ; i < myDepth - hisDepth; i++)
683
myRoot = getTreeParentNode(myRoot);
686
for (int i = 0; i < hisDepth - myDepth; i++)
687
hisRoot = getTreeParentNode(hisRoot);
690
// We now have nodes at the same depth in the tree. Find a common ancestor.
691
const DOMNode *myNodeP=myRoot;
692
const DOMNode *hisNodeP=hisRoot;
693
while(myRoot!=hisRoot)
697
myRoot = getTreeParentNode(myRoot);
698
hisRoot = getTreeParentNode(hisRoot);
701
short myNodeType=myNodeP->getNodeType();
702
short hisNodeType=hisNodeP->getNodeType();
703
bool bMyNodeIsChild=(myNodeType!=DOMNode::ATTRIBUTE_NODE && myNodeType!=DOMNode::ENTITY_NODE && myNodeType!=DOMNode::NOTATION_NODE);
704
bool bHisNodeIsChild=(hisNodeType!=DOMNode::ATTRIBUTE_NODE && hisNodeType!=DOMNode::ENTITY_NODE && hisNodeType!=DOMNode::NOTATION_NODE);
706
// If these two determining nodes are both child nodes, then the natural DOM order of these
707
// determining nodes within the containing node is returned as the order of the corresponding nodes.
708
// This would be the case, for example, when comparing two child elements of the same element.
709
if(bMyNodeIsChild && bHisNodeIsChild)
713
myNodeP = myNodeP->getNextSibling();
714
if(myNodeP == hisNodeP)
715
return DOMNode::DOCUMENT_POSITION_FOLLOWING;
717
return DOMNode::DOCUMENT_POSITION_PRECEDING;
720
// If one of the two determining nodes is a child node and the other is not, then the corresponding
721
// node of the child node follows the corresponding node of the non-child node. This would be the case,
722
// for example, when comparing an attribute of an element with a child element of the same element.
723
else if(!bMyNodeIsChild && bHisNodeIsChild)
724
return DOMNode::DOCUMENT_POSITION_FOLLOWING;
725
else if(bMyNodeIsChild && !bHisNodeIsChild)
726
return DOMNode::DOCUMENT_POSITION_PRECEDING;
730
// If neither of the two determining node is a child node and one determining node has a greater value
731
// of nodeType than the other, then the corresponding node precedes the other. This would be the case,
732
// for example, when comparing an entity of a document type against a notation of the same document type.
733
if(myNodeType!=hisNodeType)
734
return (myNodeType<hisNodeType)?DOMNode::DOCUMENT_POSITION_FOLLOWING:DOMNode::DOCUMENT_POSITION_PRECEDING;
736
// If neither of the two determining node is a child node and nodeType is the same for both determining
737
// nodes, then an implementation-dependent order between the determining nodes is returned. This order
738
// is stable as long as no nodes of the same nodeType are inserted into or removed from the direct container.
739
// This would be the case, for example, when comparing two attributes of the same element, and inserting
740
// or removing additional attributes might change the order between existing attributes.
741
return DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | ((myNodeP<hisNodeP)?DOMNode::DOCUMENT_POSITION_FOLLOWING:DOMNode::DOCUMENT_POSITION_PRECEDING);
743
// REVISIT: shouldn't get here. Should probably throw an
748
short DOMNodeImpl::reverseTreeOrderBitPattern(short pattern) const {
750
if(pattern & DOMNode::DOCUMENT_POSITION_PRECEDING) {
751
pattern &= !DOMNode::DOCUMENT_POSITION_PRECEDING;
752
pattern |= DOMNode::DOCUMENT_POSITION_FOLLOWING;
754
else if(pattern & DOMNode::DOCUMENT_POSITION_FOLLOWING) {
755
pattern &= !DOMNode::DOCUMENT_POSITION_FOLLOWING;
756
pattern |= DOMNode::DOCUMENT_POSITION_PRECEDING;
759
if(pattern & DOMNode::DOCUMENT_POSITION_CONTAINED_BY) {
760
pattern &= !DOMNode::DOCUMENT_POSITION_CONTAINED_BY;
761
pattern |= DOMNode::DOCUMENT_POSITION_CONTAINS;
763
else if(pattern & DOMNode::DOCUMENT_POSITION_CONTAINS) {
764
pattern &= !DOMNode::DOCUMENT_POSITION_CONTAINS;
765
pattern |= DOMNode::DOCUMENT_POSITION_CONTAINED_BY;
773
* Excerpt from http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#Node3-textContent
775
* textContent of type DOMString, introduced in DOM Level 3
777
* This attribute returns the text content of this node and its descendants. When it is defined
778
* to be null, setting it has no effect.
780
* When set, any possible children this node may have are removed and replaced by a single Text node
781
* containing the string this attribute is set to.
783
* On getting, no serialization is performed, the returned string does not contain any markup.
784
* No whitespace normalization is performed, the returned string does not contain the element content
785
* whitespaces Fundamental Interfaces.
787
* Similarly, on setting, no parsing is performed either, the input string is taken as pure textual content.
789
* The string returned is made of the text content of this node depending on its type,
793
* ==================== ========================================================================
794
* ELEMENT_NODE concatenation of the textContent attribute value of every child node,
795
* ENTITY_NODE excluding COMMENT_NODE and PROCESSING_INSTRUCTION_NODE nodes.
796
* ENTITY_REFERENCE_NODE This is the empty string if the node has no children.
797
* DOCUMENT_FRAGMENT_NODE
798
* --------------------------------------------------------------------------------------------------
803
* PROCESSING_INSTRUCTION_NODE nodeValue
804
* --------------------------------------------------------------------------------------------------
806
* DOCUMENT_TYPE_NODE,
811
const XMLCh* DOMNodeImpl::getTextContent() const
813
XMLSize_t nBufferLength = 0;
815
getTextContent(NULL, nBufferLength);
816
XMLCh* pzBuffer = (XMLCh*)((DOMDocumentImpl*)getOwnerDocument())->allocate((nBufferLength+1) * sizeof(XMLCh));
817
getTextContent(pzBuffer, nBufferLength);
818
pzBuffer[nBufferLength] = 0;
824
const XMLCh* DOMNodeImpl::getTextContent(XMLCh* pzBuffer, XMLSize_t& rnBufferLength) const
826
XMLSize_t nRemainingBuffer = rnBufferLength;
832
DOMNode *thisNode = castToNode(this);
834
switch (thisNode->getNodeType())
836
case DOMNode::ELEMENT_NODE:
837
case DOMNode::ENTITY_NODE:
838
case DOMNode::ENTITY_REFERENCE_NODE:
839
case DOMNode::DOCUMENT_FRAGMENT_NODE:
841
DOMNode* current = thisNode->getFirstChild();
843
while (current != NULL)
845
if (current->getNodeType() != DOMNode::COMMENT_NODE &&
846
current->getNodeType() != DOMNode::PROCESSING_INSTRUCTION_NODE)
851
XMLSize_t nContentLength = nRemainingBuffer;
852
castToNodeImpl(current)->getTextContent(pzBuffer + rnBufferLength, nContentLength);
853
rnBufferLength += nContentLength;
854
nRemainingBuffer -= nContentLength;
858
XMLSize_t nContentLength = 0;
859
castToNodeImpl(current)->getTextContent(NULL, nContentLength);
860
rnBufferLength += nContentLength;
864
current = current->getNextSibling();
871
case DOMNode::ATTRIBUTE_NODE:
872
case DOMNode::TEXT_NODE:
873
case DOMNode::CDATA_SECTION_NODE:
874
case DOMNode::COMMENT_NODE:
875
case DOMNode::PROCESSING_INSTRUCTION_NODE:
877
const XMLCh* pzValue = thisNode->getNodeValue();
878
XMLSize_t nStrLen = XMLString::stringLen(pzValue);
882
XMLSize_t nContentLength = (nRemainingBuffer >= nStrLen) ? nStrLen : nRemainingBuffer;
883
XMLString::copyNString(pzBuffer + rnBufferLength, pzValue, nContentLength);
884
rnBufferLength += nContentLength;
885
nRemainingBuffer -= nContentLength;
889
rnBufferLength += nStrLen;
910
void DOMNodeImpl::setTextContent(const XMLCh* textContent){
911
DOMNode *thisNode = castToNode(this);
912
switch (thisNode->getNodeType())
914
case DOMNode::ELEMENT_NODE:
915
case DOMNode::ENTITY_NODE:
916
case DOMNode::ENTITY_REFERENCE_NODE:
917
case DOMNode::DOCUMENT_FRAGMENT_NODE:
920
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
923
DOMNode* current = thisNode->getFirstChild();
924
while (current != NULL)
926
thisNode->removeChild(current);
927
current = thisNode->getFirstChild();
929
if (textContent != NULL)
931
// Add textnode containing data
932
current = ((DOMDocumentImpl*)thisNode->getOwnerDocument())->createTextNode(textContent);
933
thisNode->appendChild(current);
938
case DOMNode::ATTRIBUTE_NODE:
939
case DOMNode::TEXT_NODE:
940
case DOMNode::CDATA_SECTION_NODE:
941
case DOMNode::COMMENT_NODE:
942
case DOMNode::PROCESSING_INSTRUCTION_NODE:
944
throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
946
thisNode->setNodeValue(textContent);
949
case DOMNode::DOCUMENT_NODE:
950
case DOMNode::DOCUMENT_TYPE_NODE:
951
case DOMNode::NOTATION_NODE:
955
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
960
bool DOMNodeImpl::isDefaultNamespace(const XMLCh* namespaceURI) const{
961
DOMNode *thisNode = castToNode(this);
962
short type = thisNode->getNodeType();
964
case DOMNode::ELEMENT_NODE: {
965
const XMLCh *prefix = thisNode->getPrefix();
967
// REVISIT: is it possible that prefix is empty string?
968
if (prefix == 0 || !*prefix) {
969
return XMLString::equals(namespaceURI, thisNode->getNamespaceURI());
972
if (thisNode->hasAttributes()) {
973
DOMElement *elem = (DOMElement *)thisNode;
974
DOMNode *attr = elem->getAttributeNodeNS(XMLUni::fgXMLNSURIName, XMLUni::fgXMLNSString);
976
const XMLCh *value = attr->getNodeValue();
977
return XMLString::equals(namespaceURI, value);
980
DOMNode *ancestor = getElementAncestor(thisNode);
982
return ancestor->isDefaultNamespace(namespaceURI);
987
case DOMNode::DOCUMENT_NODE:{
988
return ((DOMDocument*)thisNode)->getDocumentElement()->isDefaultNamespace(namespaceURI);
991
case DOMNode::ENTITY_NODE :
992
case DOMNode::NOTATION_NODE:
993
case DOMNode::DOCUMENT_FRAGMENT_NODE:
994
case DOMNode::DOCUMENT_TYPE_NODE:
997
case DOMNode::ATTRIBUTE_NODE:{
998
if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) {
999
return fOwnerNode->isDefaultNamespace(namespaceURI);
1005
DOMNode *ancestor = getElementAncestor(thisNode);
1006
if (ancestor != 0) {
1007
return ancestor->isDefaultNamespace(namespaceURI);
1015
void* DOMNodeImpl::getFeature(const XMLCh*, const XMLCh*) const {
1020
// non-standard extension
1021
void DOMNodeImpl::release()
1023
// shouldn't reach here
1024
throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
1027
XERCES_CPP_NAMESPACE_END