1 /*
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
18 /*
19 * $Id: DOMCommentImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
20 */
21
22 #include "DOMCommentImpl.hpp"
23 #include "DOMCharacterDataImpl.hpp"
24 #include "DOMStringPool.hpp"
25 #include "DOMCasts.hpp"
26 #include "DOMDocumentImpl.hpp"
27 #include "DOMRangeImpl.hpp"
28 #include <xercesc/dom/DOMNode.hpp>
29 #include <xercesc/dom/DOMException.hpp>
30 #include <xercesc/util/XMLUniDefs.hpp>
31
32 XERCES_CPP_NAMESPACE_BEGIN
33
DOMCommentImpl(DOMDocument * ownerDoc,const XMLCh * dat)34 DOMCommentImpl::DOMCommentImpl(DOMDocument *ownerDoc, const XMLCh *dat)
35 : fNode(ownerDoc), fCharacterData(ownerDoc, dat)
36 {
37 fNode.setIsLeafNode(true);
38 }
39
40
DOMCommentImpl(const DOMCommentImpl & other,bool)41 DOMCommentImpl::DOMCommentImpl(const DOMCommentImpl &other, bool)
42
43 : fNode(other.fNode),
44 fChild(other.fChild),
45 fCharacterData(other.fCharacterData)
46 {
47 fNode.setIsLeafNode(true);
48 }
49
50
~DOMCommentImpl()51 DOMCommentImpl::~DOMCommentImpl() {
52 }
53
54
55
cloneNode(bool deep) const56 DOMNode * DOMCommentImpl::cloneNode(bool deep) const
57 {
58 DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::COMMENT_OBJECT) DOMCommentImpl(*this, deep);
59 fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
60 return newNode;
61 }
62
63
getNodeName() const64 const XMLCh * DOMCommentImpl::getNodeName() const {
65 static const XMLCh gComment[] =
66 {chPound, chLatin_c, chLatin_o, chLatin_m, chLatin_m, chLatin_e,chLatin_n, chLatin_t, 0};
67 return gComment;
68 }
69
getNodeType() const70 DOMNode::NodeType DOMCommentImpl::getNodeType() const {
71 return DOMNode::COMMENT_NODE;
72 }
73
release()74 void DOMCommentImpl::release()
75 {
76 if (fNode.isOwned() && !fNode.isToBeReleased())
77 throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
78
79 DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
80 if (doc) {
81 fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
82 fCharacterData.releaseBuffer();
83 doc->release(this, DOMMemoryManager::COMMENT_OBJECT);
84 }
85 else {
86 // shouldn't reach here
87 throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
88 }
89 }
90
91
92 // Non standard extension for the range to work
splitText(XMLSize_t offset)93 DOMComment *DOMCommentImpl::splitText(XMLSize_t offset)
94 {
95 if (fNode.isReadOnly())
96 {
97 throw DOMException(
98 DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
99 }
100 XMLSize_t len = fCharacterData.fDataBuf->getLen();
101 if (offset > len)
102 throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager);
103
104 DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument();
105 DOMComment *newText =
106 doc->createComment(this->substringData(offset, len - offset));
107
108 DOMNode *parent = getParentNode();
109 if (parent != 0)
110 parent->insertBefore(newText, getNextSibling());
111
112 fCharacterData.fDataBuf->chop(offset);
113
114 if (doc != 0) {
115 Ranges* ranges = doc->getRanges();
116 if (ranges != 0) {
117 XMLSize_t sz = ranges->size();
118 if (sz != 0) {
119 for (XMLSize_t i =0; i<sz; i++) {
120 ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
121 }
122 }
123 }
124 }
125
126 return newText;
127 }
128
129
appendChild(DOMNode * newChild)130 DOMNode* DOMCommentImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); }
getAttributes() const131 DOMNamedNodeMap* DOMCommentImpl::getAttributes() const {return fNode.getAttributes (); }
getChildNodes() const132 DOMNodeList* DOMCommentImpl::getChildNodes() const {return fNode.getChildNodes (); }
getFirstChild() const133 DOMNode* DOMCommentImpl::getFirstChild() const {return fNode.getFirstChild (); }
getLastChild() const134 DOMNode* DOMCommentImpl::getLastChild() const {return fNode.getLastChild (); }
getLocalName() const135 const XMLCh* DOMCommentImpl::getLocalName() const {return fNode.getLocalName (); }
getNamespaceURI() const136 const XMLCh* DOMCommentImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
getNextSibling() const137 DOMNode* DOMCommentImpl::getNextSibling() const {return fChild.getNextSibling (); }
getNodeValue() const138 const XMLCh* DOMCommentImpl::getNodeValue() const {return fCharacterData.getNodeValue (); }
getOwnerDocument() const139 DOMDocument* DOMCommentImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); }
getPrefix() const140 const XMLCh* DOMCommentImpl::getPrefix() const {return fNode.getPrefix (); }
getParentNode() const141 DOMNode* DOMCommentImpl::getParentNode() const {return fChild.getParentNode (this); }
getPreviousSibling() const142 DOMNode* DOMCommentImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); }
hasChildNodes() const143 bool DOMCommentImpl::hasChildNodes() const {return fNode.hasChildNodes (); }
insertBefore(DOMNode * newChild,DOMNode * refChild)144 DOMNode* DOMCommentImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
145 {return fNode.insertBefore (newChild, refChild); }
normalize()146 void DOMCommentImpl::normalize() {fNode.normalize (); }
removeChild(DOMNode * oldChild)147 DOMNode* DOMCommentImpl::removeChild(DOMNode *oldChild) {return fNode.removeChild (oldChild); }
replaceChild(DOMNode * newChild,DOMNode * oldChild)148 DOMNode* DOMCommentImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
149 {return fNode.replaceChild (newChild, oldChild); }
isSupported(const XMLCh * feature,const XMLCh * version) const150 bool DOMCommentImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
151 {return fNode.isSupported (feature, version); }
setPrefix(const XMLCh * prefix)152 void DOMCommentImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
hasAttributes() const153 bool DOMCommentImpl::hasAttributes() const {return fNode.hasAttributes(); }
isSameNode(const DOMNode * other) const154 bool DOMCommentImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
isEqualNode(const DOMNode * arg) const155 bool DOMCommentImpl::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); }
setUserData(const XMLCh * key,void * data,DOMUserDataHandler * handler)156 void* DOMCommentImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
157 {return fNode.setUserData(key, data, handler); }
getUserData(const XMLCh * key) const158 void* DOMCommentImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
getBaseURI() const159 const XMLCh* DOMCommentImpl::getBaseURI() const {return fNode.getBaseURI(); }
compareDocumentPosition(const DOMNode * other) const160 short DOMCommentImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
getTextContent() const161 const XMLCh* DOMCommentImpl::getTextContent() const {return fNode.getTextContent(); }
setTextContent(const XMLCh * textContent)162 void DOMCommentImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
lookupPrefix(const XMLCh * namespaceURI) const163 const XMLCh* DOMCommentImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
isDefaultNamespace(const XMLCh * namespaceURI) const164 bool DOMCommentImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
lookupNamespaceURI(const XMLCh * prefix) const165 const XMLCh* DOMCommentImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
getFeature(const XMLCh * feature,const XMLCh * version) const166 void* DOMCommentImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
167
168
169
170 //
171 // Delegation of CharacerData functions.
172 //
173
174
getData() const175 const XMLCh* DOMCommentImpl::getData() const {return fCharacterData.getData();}
getLength() const176 XMLSize_t DOMCommentImpl::getLength() const {return fCharacterData.getLength();}
substringData(XMLSize_t offset,XMLSize_t count) const177 const XMLCh* DOMCommentImpl::substringData(XMLSize_t offset, XMLSize_t count) const
178 {return fCharacterData.substringData(this, offset, count);}
appendData(const XMLCh * arg)179 void DOMCommentImpl::appendData(const XMLCh *arg) {fCharacterData.appendData(this, arg);}
insertData(XMLSize_t offset,const XMLCh * arg)180 void DOMCommentImpl::insertData(XMLSize_t offset, const XMLCh *arg)
181 {fCharacterData.insertData(this, offset, arg);}
deleteData(XMLSize_t offset,XMLSize_t count)182 void DOMCommentImpl::deleteData(XMLSize_t offset, XMLSize_t count)
183 {fCharacterData.deleteData(this, offset, count);}
replaceData(XMLSize_t offset,XMLSize_t count,const XMLCh * arg)184 void DOMCommentImpl::replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh *arg)
185 {fCharacterData.replaceData(this, offset, count, arg);}
setData(const XMLCh * data)186 void DOMCommentImpl::setData(const XMLCh *data) {fCharacterData.setData(this, data);}
setNodeValue(const XMLCh * nodeValue)187 void DOMCommentImpl::setNodeValue(const XMLCh *nodeValue) {fCharacterData.setNodeValue (this, nodeValue); }
188
189 XERCES_CPP_NAMESPACE_END
190