/src/xerces-c/src/xercesc/dom/impl/DOMProcessingInstructionImpl.cpp
Line | Count | Source |
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: DOMProcessingInstructionImpl.cpp 1800911 2017-07-05 18:52:15Z scantor $ |
20 | | */ |
21 | | |
22 | | #include "DOMProcessingInstructionImpl.hpp" |
23 | | #include "DOMDocumentImpl.hpp" |
24 | | #include "DOMNodeImpl.hpp" |
25 | | #include "DOMStringPool.hpp" |
26 | | #include "DOMRangeImpl.hpp" |
27 | | |
28 | | #include <xercesc/dom/DOMException.hpp> |
29 | | #include <xercesc/dom/DOMNode.hpp> |
30 | | |
31 | | XERCES_CPP_NAMESPACE_BEGIN |
32 | | |
33 | | DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(DOMDocument *ownerDoc, |
34 | | const XMLCh *targt, |
35 | | const XMLCh *dat) |
36 | 0 | : fNode(this, ownerDoc), fCharacterData(ownerDoc, dat), fBaseURI(0) |
37 | 0 | { |
38 | 0 | fNode.setIsLeafNode(true); |
39 | 0 | this->fTarget = ((DOMDocumentImpl *)ownerDoc)->cloneString(targt); |
40 | 0 | } |
41 | | |
42 | | |
43 | | DOMProcessingInstructionImpl::DOMProcessingInstructionImpl( |
44 | | const DOMProcessingInstructionImpl &other, |
45 | | bool /*deep*/) |
46 | 0 | : DOMProcessingInstruction(other), |
47 | 0 | fNode(this, other.fNode), |
48 | 0 | fChild(other.fChild), |
49 | 0 | fCharacterData(other.fCharacterData), |
50 | 0 | fTarget(other.fTarget), |
51 | 0 | fBaseURI(other.fBaseURI) |
52 | 0 | { |
53 | 0 | fNode.setIsLeafNode(true); |
54 | 0 | } |
55 | | |
56 | | |
57 | | DOMProcessingInstructionImpl::~DOMProcessingInstructionImpl() |
58 | 0 | { |
59 | 0 | } |
60 | | |
61 | | |
62 | | DOMNode *DOMProcessingInstructionImpl::cloneNode(bool deep) const |
63 | 0 | { |
64 | 0 | DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT) DOMProcessingInstructionImpl(*this, deep); |
65 | 0 | fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode); |
66 | 0 | return newNode; |
67 | 0 | } |
68 | | |
69 | | |
70 | | const XMLCh * DOMProcessingInstructionImpl::getNodeName() const |
71 | 0 | { |
72 | 0 | return fTarget; |
73 | 0 | } |
74 | | |
75 | | |
76 | 0 | DOMNode::NodeType DOMProcessingInstructionImpl::getNodeType() const { |
77 | 0 | return DOMNode::PROCESSING_INSTRUCTION_NODE; |
78 | 0 | } |
79 | | |
80 | | |
81 | | /** A PI's "target" states what processor channel the PI's data |
82 | | should be directed to. It is defined differently in HTML and XML. |
83 | | |
84 | | In XML, a PI's "target" is the first (whitespace-delimited) token |
85 | | following the "<?" token that begins the PI. |
86 | | |
87 | | In HTML, target is always 0. |
88 | | |
89 | | Note that getNodeName is aliased to getTarget. |
90 | | */ |
91 | | const XMLCh * DOMProcessingInstructionImpl::getTarget() const |
92 | 0 | { |
93 | 0 | return fTarget; |
94 | 0 | } |
95 | | |
96 | | |
97 | | void DOMProcessingInstructionImpl::release() |
98 | 0 | { |
99 | 0 | if (fNode.isOwned() && !fNode.isToBeReleased()) |
100 | 0 | throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager); |
101 | | |
102 | 0 | DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument(); |
103 | 0 | if (doc) { |
104 | 0 | fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0); |
105 | 0 | fCharacterData.releaseBuffer(); |
106 | 0 | doc->release(this, DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT); |
107 | 0 | } |
108 | 0 | else { |
109 | | // shouldn't reach here |
110 | 0 | throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager); |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | 0 | void DOMProcessingInstructionImpl::setBaseURI(const XMLCh* baseURI) { |
115 | 0 | this->fBaseURI = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(baseURI); |
116 | 0 | } |
117 | | |
118 | | const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const |
119 | 0 | { |
120 | 0 | return fBaseURI? fBaseURI : fNode.fOwnerNode->getBaseURI(); |
121 | 0 | } |
122 | | |
123 | | // Non standard extension for the range to work |
124 | | DOMProcessingInstruction *DOMProcessingInstructionImpl::splitText(XMLSize_t offset) |
125 | 0 | { |
126 | 0 | if (fNode.isReadOnly()) |
127 | 0 | { |
128 | 0 | throw DOMException( |
129 | 0 | DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager); |
130 | 0 | } |
131 | 0 | XMLSize_t len = fCharacterData.fDataBuf->getLen(); |
132 | 0 | if (offset > len) |
133 | 0 | throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager); |
134 | | |
135 | 0 | DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument(); |
136 | 0 | DOMProcessingInstruction *newText = |
137 | 0 | doc->createProcessingInstruction( |
138 | 0 | fTarget, this->substringData(offset, len - offset)); |
139 | |
|
140 | 0 | DOMNode *parent = getParentNode(); |
141 | 0 | if (parent != 0) |
142 | 0 | parent->insertBefore(newText, getNextSibling()); |
143 | |
|
144 | 0 | fCharacterData.fDataBuf->chop(offset); |
145 | |
|
146 | 0 | if (doc != 0) { |
147 | 0 | Ranges* ranges = doc->getRanges(); |
148 | 0 | if (ranges != 0) { |
149 | 0 | XMLSize_t sz = ranges->size(); |
150 | 0 | if (sz != 0) { |
151 | 0 | for (XMLSize_t i =0; i<sz; i++) { |
152 | 0 | ranges->elementAt(i)->updateSplitInfo( this, newText, offset); |
153 | 0 | } |
154 | 0 | } |
155 | 0 | } |
156 | 0 | } |
157 | |
|
158 | 0 | return newText; |
159 | 0 | } |
160 | | |
161 | | // |
162 | | // Delegation stubs for inherited functions |
163 | | // |
164 | 0 | DOMNode* DOMProcessingInstructionImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); } |
165 | 0 | DOMNamedNodeMap* DOMProcessingInstructionImpl::getAttributes() const {return fNode.getAttributes (); } |
166 | 0 | DOMNodeList* DOMProcessingInstructionImpl::getChildNodes() const {return fNode.getChildNodes (); } |
167 | 0 | DOMNode* DOMProcessingInstructionImpl::getFirstChild() const {return fNode.getFirstChild (); } |
168 | 0 | DOMNode* DOMProcessingInstructionImpl::getLastChild() const {return fNode.getLastChild (); } |
169 | 0 | const XMLCh* DOMProcessingInstructionImpl::getLocalName() const {return fNode.getLocalName (); } |
170 | 0 | const XMLCh* DOMProcessingInstructionImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); } |
171 | 0 | DOMNode* DOMProcessingInstructionImpl::getNextSibling() const {return fChild.getNextSibling (); } |
172 | 0 | const XMLCh* DOMProcessingInstructionImpl::getNodeValue() const {return fCharacterData.getNodeValue (); } |
173 | 0 | DOMDocument* DOMProcessingInstructionImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); } |
174 | 0 | const XMLCh* DOMProcessingInstructionImpl::getPrefix() const {return fNode.getPrefix (); } |
175 | 0 | DOMNode* DOMProcessingInstructionImpl::getParentNode() const {return fChild.getParentNode (this); } |
176 | 0 | DOMNode* DOMProcessingInstructionImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); } |
177 | 0 | bool DOMProcessingInstructionImpl::hasChildNodes() const {return fNode.hasChildNodes (); } |
178 | | DOMNode* DOMProcessingInstructionImpl::insertBefore(DOMNode *newChild, DOMNode *refChild) |
179 | 0 | {return fNode.insertBefore (newChild, refChild); } |
180 | 0 | void DOMProcessingInstructionImpl::normalize() {fNode.normalize (); } |
181 | 0 | DOMNode* DOMProcessingInstructionImpl::removeChild(DOMNode *oldChild) {return fNode.removeChild (oldChild); } |
182 | | DOMNode* DOMProcessingInstructionImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild) |
183 | 0 | {return fNode.replaceChild (newChild, oldChild); } |
184 | | bool DOMProcessingInstructionImpl::isSupported(const XMLCh *feature, const XMLCh *version) const |
185 | 0 | {return fNode.isSupported (feature, version); } |
186 | 0 | void DOMProcessingInstructionImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); } |
187 | 0 | bool DOMProcessingInstructionImpl::hasAttributes() const {return fNode.hasAttributes(); } |
188 | 0 | bool DOMProcessingInstructionImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); } |
189 | 0 | bool DOMProcessingInstructionImpl::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); } |
190 | | void* DOMProcessingInstructionImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler) |
191 | 0 | {return fNode.setUserData(key, data, handler); } |
192 | 0 | void* DOMProcessingInstructionImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); } |
193 | 0 | short DOMProcessingInstructionImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); } |
194 | 0 | const XMLCh* DOMProcessingInstructionImpl::getTextContent() const {return fNode.getTextContent(); } |
195 | 0 | void DOMProcessingInstructionImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); } |
196 | 0 | const XMLCh* DOMProcessingInstructionImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); } |
197 | 0 | bool DOMProcessingInstructionImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); } |
198 | 0 | const XMLCh* DOMProcessingInstructionImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); } |
199 | 0 | void* DOMProcessingInstructionImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); } |
200 | | |
201 | | // Macro-in implementation accessors. |
202 | | DOMNODEIMPL_IMPL(DOMProcessingInstructionImpl); |
203 | | DOMCHILDIMPL_IMPL(DOMProcessingInstructionImpl); |
204 | | |
205 | | // |
206 | | // Delegation of CharacerData functions. |
207 | | // |
208 | | |
209 | | |
210 | 0 | const XMLCh* DOMProcessingInstructionImpl::getData() const {return fCharacterData.getData();} |
211 | | void DOMProcessingInstructionImpl::deleteData(XMLSize_t offset, XMLSize_t count) |
212 | 0 | {fCharacterData.deleteData(this, offset, count);} |
213 | | const XMLCh* DOMProcessingInstructionImpl::substringData(XMLSize_t offset, XMLSize_t count) const |
214 | 0 | {return fCharacterData.substringData(this, offset, count);} |
215 | 0 | void DOMProcessingInstructionImpl::setData(const XMLCh *data) {fCharacterData.setData(this, data);} |
216 | 0 | void DOMProcessingInstructionImpl::setNodeValue(const XMLCh *nodeValue) {fCharacterData.setNodeValue (this, nodeValue); } |
217 | | |
218 | | |
219 | | XERCES_CPP_NAMESPACE_END |