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 678381 2008-07-21 10:15:01Z borisk $ |
---|
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 | : fNode(ownerDoc), fCharacterData(ownerDoc, dat), fBaseURI(0) |
---|
37 | { |
---|
38 | fNode.setIsLeafNode(true); |
---|
39 | this->fTarget = ((DOMDocumentImpl *)ownerDoc)->cloneString(targt); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | DOMProcessingInstructionImpl::DOMProcessingInstructionImpl( |
---|
44 | const DOMProcessingInstructionImpl &other, |
---|
45 | bool /*deep*/) |
---|
46 | : DOMProcessingInstruction(other), |
---|
47 | fNode(other.fNode), |
---|
48 | fChild(other.fChild), |
---|
49 | fCharacterData(other.fCharacterData), |
---|
50 | fTarget(other.fTarget), |
---|
51 | fBaseURI(other.fBaseURI) |
---|
52 | { |
---|
53 | fNode.setIsLeafNode(true); |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | DOMProcessingInstructionImpl::~DOMProcessingInstructionImpl() |
---|
58 | { |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | DOMNode *DOMProcessingInstructionImpl::cloneNode(bool deep) const |
---|
63 | { |
---|
64 | DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT) DOMProcessingInstructionImpl(*this, deep); |
---|
65 | fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode); |
---|
66 | return newNode; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | const XMLCh * DOMProcessingInstructionImpl::getNodeName() const |
---|
71 | { |
---|
72 | return fTarget; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | DOMNode::NodeType DOMProcessingInstructionImpl::getNodeType() const { |
---|
77 | return DOMNode::PROCESSING_INSTRUCTION_NODE; |
---|
78 | } |
---|
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 | { |
---|
93 | return fTarget; |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | void DOMProcessingInstructionImpl::release() |
---|
98 | { |
---|
99 | if (fNode.isOwned() && !fNode.isToBeReleased()) |
---|
100 | throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager); |
---|
101 | |
---|
102 | DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument(); |
---|
103 | if (doc) { |
---|
104 | fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0); |
---|
105 | fCharacterData.releaseBuffer(); |
---|
106 | doc->release(this, DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT); |
---|
107 | } |
---|
108 | else { |
---|
109 | // shouldn't reach here |
---|
110 | throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | void DOMProcessingInstructionImpl::setBaseURI(const XMLCh* baseURI) { |
---|
115 | this->fBaseURI = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(baseURI); |
---|
116 | } |
---|
117 | |
---|
118 | const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const |
---|
119 | { |
---|
120 | return fBaseURI? fBaseURI : fNode.fOwnerNode->getBaseURI(); |
---|
121 | } |
---|
122 | |
---|
123 | // Non standard extension for the range to work |
---|
124 | DOMProcessingInstruction *DOMProcessingInstructionImpl::splitText(XMLSize_t offset) |
---|
125 | { |
---|
126 | if (fNode.isReadOnly()) |
---|
127 | { |
---|
128 | throw DOMException( |
---|
129 | DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager); |
---|
130 | } |
---|
131 | XMLSize_t len = fCharacterData.fDataBuf->getLen(); |
---|
132 | if (offset > len) |
---|
133 | throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager); |
---|
134 | |
---|
135 | DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument(); |
---|
136 | DOMProcessingInstruction *newText = |
---|
137 | doc->createProcessingInstruction( |
---|
138 | fTarget, this->substringData(offset, len - offset)); |
---|
139 | |
---|
140 | DOMNode *parent = getParentNode(); |
---|
141 | if (parent != 0) |
---|
142 | parent->insertBefore(newText, getNextSibling()); |
---|
143 | |
---|
144 | fCharacterData.fDataBuf->chop(offset); |
---|
145 | |
---|
146 | if (doc != 0) { |
---|
147 | Ranges* ranges = doc->getRanges(); |
---|
148 | if (ranges != 0) { |
---|
149 | XMLSize_t sz = ranges->size(); |
---|
150 | if (sz != 0) { |
---|
151 | for (XMLSize_t i =0; i<sz; i++) { |
---|
152 | ranges->elementAt(i)->updateSplitInfo( this, newText, offset); |
---|
153 | } |
---|
154 | } |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | return newText; |
---|
159 | } |
---|
160 | |
---|
161 | // |
---|
162 | // Delegation stubs for inherited functions |
---|
163 | // |
---|
164 | DOMNode* DOMProcessingInstructionImpl::appendChild(DOMNode *newChild) {return fNode.appendChild (newChild); } |
---|
165 | DOMNamedNodeMap* DOMProcessingInstructionImpl::getAttributes() const {return fNode.getAttributes (); } |
---|
166 | DOMNodeList* DOMProcessingInstructionImpl::getChildNodes() const {return fNode.getChildNodes (); } |
---|
167 | DOMNode* DOMProcessingInstructionImpl::getFirstChild() const {return fNode.getFirstChild (); } |
---|
168 | DOMNode* DOMProcessingInstructionImpl::getLastChild() const {return fNode.getLastChild (); } |
---|
169 | const XMLCh* DOMProcessingInstructionImpl::getLocalName() const {return fNode.getLocalName (); } |
---|
170 | const XMLCh* DOMProcessingInstructionImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); } |
---|
171 | DOMNode* DOMProcessingInstructionImpl::getNextSibling() const {return fChild.getNextSibling (); } |
---|
172 | const XMLCh* DOMProcessingInstructionImpl::getNodeValue() const {return fCharacterData.getNodeValue (); } |
---|
173 | DOMDocument* DOMProcessingInstructionImpl::getOwnerDocument() const {return fNode.getOwnerDocument (); } |
---|
174 | const XMLCh* DOMProcessingInstructionImpl::getPrefix() const {return fNode.getPrefix (); } |
---|
175 | DOMNode* DOMProcessingInstructionImpl::getParentNode() const {return fChild.getParentNode (this); } |
---|
176 | DOMNode* DOMProcessingInstructionImpl::getPreviousSibling() const {return fChild.getPreviousSibling (this); } |
---|
177 | bool DOMProcessingInstructionImpl::hasChildNodes() const {return fNode.hasChildNodes (); } |
---|
178 | DOMNode* DOMProcessingInstructionImpl::insertBefore(DOMNode *newChild, DOMNode *refChild) |
---|
179 | {return fNode.insertBefore (newChild, refChild); } |
---|
180 | void DOMProcessingInstructionImpl::normalize() {fNode.normalize (); } |
---|
181 | DOMNode* DOMProcessingInstructionImpl::removeChild(DOMNode *oldChild) {return fNode.removeChild (oldChild); } |
---|
182 | DOMNode* DOMProcessingInstructionImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild) |
---|
183 | {return fNode.replaceChild (newChild, oldChild); } |
---|
184 | bool DOMProcessingInstructionImpl::isSupported(const XMLCh *feature, const XMLCh *version) const |
---|
185 | {return fNode.isSupported (feature, version); } |
---|
186 | void DOMProcessingInstructionImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); } |
---|
187 | bool DOMProcessingInstructionImpl::hasAttributes() const {return fNode.hasAttributes(); } |
---|
188 | bool DOMProcessingInstructionImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); } |
---|
189 | bool DOMProcessingInstructionImpl::isEqualNode(const DOMNode* arg) const {return fNode.isEqualNode(arg); } |
---|
190 | void* DOMProcessingInstructionImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler) |
---|
191 | {return fNode.setUserData(key, data, handler); } |
---|
192 | void* DOMProcessingInstructionImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); } |
---|
193 | short DOMProcessingInstructionImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); } |
---|
194 | const XMLCh* DOMProcessingInstructionImpl::getTextContent() const {return fNode.getTextContent(); } |
---|
195 | void DOMProcessingInstructionImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); } |
---|
196 | const XMLCh* DOMProcessingInstructionImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); } |
---|
197 | bool DOMProcessingInstructionImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); } |
---|
198 | const XMLCh* DOMProcessingInstructionImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); } |
---|
199 | void* DOMProcessingInstructionImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); } |
---|
200 | |
---|
201 | // |
---|
202 | // Delegation of CharacerData functions. |
---|
203 | // |
---|
204 | |
---|
205 | |
---|
206 | const XMLCh* DOMProcessingInstructionImpl::getData() const {return fCharacterData.getData();} |
---|
207 | void DOMProcessingInstructionImpl::deleteData(XMLSize_t offset, XMLSize_t count) |
---|
208 | {fCharacterData.deleteData(this, offset, count);} |
---|
209 | const XMLCh* DOMProcessingInstructionImpl::substringData(XMLSize_t offset, XMLSize_t count) const |
---|
210 | {return fCharacterData.substringData(this, offset, count);} |
---|
211 | void DOMProcessingInstructionImpl::setData(const XMLCh *data) {fCharacterData.setData(this, data);} |
---|
212 | void DOMProcessingInstructionImpl::setNodeValue(const XMLCh *nodeValue) {fCharacterData.setNodeValue (this, nodeValue); } |
---|
213 | |
---|
214 | |
---|
215 | XERCES_CPP_NAMESPACE_END |
---|