GME  13
DOMProcessingInstructionImpl.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: DOMProcessingInstructionImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
00020  */
00021 
00022 #include "DOMProcessingInstructionImpl.hpp"
00023 #include "DOMDocumentImpl.hpp"
00024 #include "DOMNodeImpl.hpp"
00025 #include "DOMStringPool.hpp"
00026 #include "DOMRangeImpl.hpp"
00027 
00028 #include <xercesc/dom/DOMException.hpp>
00029 #include <xercesc/dom/DOMNode.hpp>
00030 
00031 XERCES_CPP_NAMESPACE_BEGIN
00032 
00033 DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(DOMDocument *ownerDoc,
00034                                                      const XMLCh *targt,
00035                                                      const XMLCh *dat)
00036     : fNode(ownerDoc), fCharacterData(ownerDoc, dat), fBaseURI(0)
00037 {
00038     fNode.setIsLeafNode(true);
00039     this->fTarget = ((DOMDocumentImpl *)ownerDoc)->cloneString(targt);
00040 }
00041 
00042 
00043 DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(
00044                                         const DOMProcessingInstructionImpl &other,
00045                                         bool /*deep*/)
00046     : DOMProcessingInstruction(other),
00047       fNode(other.fNode),
00048       fChild(other.fChild),
00049       fCharacterData(other.fCharacterData),
00050       fTarget(other.fTarget),
00051       fBaseURI(other.fBaseURI)
00052 {
00053     fNode.setIsLeafNode(true);
00054 }
00055 
00056 
00057 DOMProcessingInstructionImpl::~DOMProcessingInstructionImpl()
00058 {
00059 }
00060 
00061 
00062 DOMNode *DOMProcessingInstructionImpl::cloneNode(bool deep) const
00063 {
00064     DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT) DOMProcessingInstructionImpl(*this, deep);
00065     fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
00066     return newNode;
00067 }
00068 
00069 
00070 const XMLCh * DOMProcessingInstructionImpl::getNodeName() const
00071 {
00072     return fTarget;
00073 }
00074 
00075 
00076 DOMNode::NodeType DOMProcessingInstructionImpl::getNodeType() const {
00077     return DOMNode::PROCESSING_INSTRUCTION_NODE;
00078 }
00079 
00080 
00091 const XMLCh * DOMProcessingInstructionImpl::getTarget() const
00092 {
00093     return fTarget;
00094 }
00095 
00096 
00097 void DOMProcessingInstructionImpl::release()
00098 {
00099     if (fNode.isOwned() && !fNode.isToBeReleased())
00100         throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
00101 
00102     DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
00103     if (doc) {
00104         fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
00105         fCharacterData.releaseBuffer();
00106         doc->release(this, DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT);
00107     }
00108     else {
00109         // shouldn't reach here
00110         throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
00111     }
00112 }
00113 
00114 void DOMProcessingInstructionImpl::setBaseURI(const XMLCh* baseURI) {
00115     this->fBaseURI = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(baseURI);
00116 }
00117 
00118 const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const
00119 {
00120     return fBaseURI? fBaseURI : fNode.fOwnerNode->getBaseURI();
00121 }
00122 
00123 // Non standard extension for the range to work
00124 DOMProcessingInstruction *DOMProcessingInstructionImpl::splitText(XMLSize_t offset)
00125 {
00126     if (fNode.isReadOnly())
00127     {
00128         throw DOMException(
00129             DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
00130     }
00131     XMLSize_t len = fCharacterData.fDataBuf->getLen();
00132     if (offset > len)
00133         throw DOMException(DOMException::INDEX_SIZE_ERR, 0,  GetDOMNodeMemoryManager);
00134 
00135     DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument();
00136     DOMProcessingInstruction *newText =
00137       doc->createProcessingInstruction(
00138         fTarget, this->substringData(offset, len - offset));
00139 
00140     DOMNode *parent = getParentNode();
00141     if (parent != 0)
00142         parent->insertBefore(newText, getNextSibling());
00143 
00144     fCharacterData.fDataBuf->chop(offset);
00145 
00146     if (doc != 0) {
00147         Ranges* ranges = doc->getRanges();
00148         if (ranges != 0) {
00149             XMLSize_t sz = ranges->size();
00150             if (sz != 0) {
00151                 for (XMLSize_t i =0; i<sz; i++) {
00152                     ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
00153                 }
00154             }
00155         }
00156     }
00157 
00158     return newText;
00159 }
00160 
00161 //
00162 //    Delegation stubs for inherited functions
00163 //
00164            DOMNode*         DOMProcessingInstructionImpl::appendChild(DOMNode *newChild)          {return fNode.appendChild (newChild); }
00165            DOMNamedNodeMap* DOMProcessingInstructionImpl::getAttributes() const                   {return fNode.getAttributes (); }
00166            DOMNodeList*     DOMProcessingInstructionImpl::getChildNodes() const                   {return fNode.getChildNodes (); }
00167            DOMNode*         DOMProcessingInstructionImpl::getFirstChild() const                   {return fNode.getFirstChild (); }
00168            DOMNode*         DOMProcessingInstructionImpl::getLastChild() const                    {return fNode.getLastChild (); }
00169      const XMLCh*           DOMProcessingInstructionImpl::getLocalName() const                    {return fNode.getLocalName (); }
00170      const XMLCh*           DOMProcessingInstructionImpl::getNamespaceURI() const                 {return fNode.getNamespaceURI (); }
00171            DOMNode*         DOMProcessingInstructionImpl::getNextSibling() const                  {return fChild.getNextSibling (); }
00172      const XMLCh*           DOMProcessingInstructionImpl::getNodeValue() const                    {return fCharacterData.getNodeValue (); }
00173            DOMDocument*     DOMProcessingInstructionImpl::getOwnerDocument() const                {return fNode.getOwnerDocument (); }
00174      const XMLCh*           DOMProcessingInstructionImpl::getPrefix() const                       {return fNode.getPrefix (); }
00175            DOMNode*         DOMProcessingInstructionImpl::getParentNode() const                   {return fChild.getParentNode (this); }
00176            DOMNode*         DOMProcessingInstructionImpl::getPreviousSibling() const              {return fChild.getPreviousSibling (this); }
00177            bool             DOMProcessingInstructionImpl::hasChildNodes() const                   {return fNode.hasChildNodes (); }
00178            DOMNode*         DOMProcessingInstructionImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
00179                                                                                                   {return fNode.insertBefore (newChild, refChild); }
00180            void             DOMProcessingInstructionImpl::normalize()                             {fNode.normalize (); }
00181            DOMNode*         DOMProcessingInstructionImpl::removeChild(DOMNode *oldChild)          {return fNode.removeChild (oldChild); }
00182            DOMNode*         DOMProcessingInstructionImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
00183                                                                                                   {return fNode.replaceChild (newChild, oldChild); }
00184            bool             DOMProcessingInstructionImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
00185                                                                                                   {return fNode.isSupported (feature, version); }
00186            void             DOMProcessingInstructionImpl::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); }
00187            bool             DOMProcessingInstructionImpl::hasAttributes() const                   {return fNode.hasAttributes(); }
00188            bool             DOMProcessingInstructionImpl::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); }
00189            bool             DOMProcessingInstructionImpl::isEqualNode(const DOMNode* arg) const   {return fNode.isEqualNode(arg); }
00190            void*            DOMProcessingInstructionImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
00191                                                                                                   {return fNode.setUserData(key, data, handler); }
00192            void*            DOMProcessingInstructionImpl::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); }
00193            short            DOMProcessingInstructionImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
00194            const XMLCh*     DOMProcessingInstructionImpl::getTextContent() const                  {return fNode.getTextContent(); }
00195            void             DOMProcessingInstructionImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
00196            const XMLCh*     DOMProcessingInstructionImpl::lookupPrefix(const XMLCh* namespaceURI) const  {return fNode.lookupPrefix(namespaceURI); }
00197            bool             DOMProcessingInstructionImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
00198            const XMLCh*     DOMProcessingInstructionImpl::lookupNamespaceURI(const XMLCh* prefix) const  {return fNode.lookupNamespaceURI(prefix); }
00199            void*            DOMProcessingInstructionImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
00200 
00201 //
00202 //   Delegation of CharacerData functions.
00203 //
00204 
00205 
00206            const XMLCh*     DOMProcessingInstructionImpl::getData() const                         {return fCharacterData.getData();}
00207            void             DOMProcessingInstructionImpl::deleteData(XMLSize_t offset, XMLSize_t count)
00208                                                                                     {fCharacterData.deleteData(this, offset, count);}
00209            const XMLCh*     DOMProcessingInstructionImpl::substringData(XMLSize_t offset, XMLSize_t count) const
00210                                                                                     {return fCharacterData.substringData(this, offset, count);}
00211            void             DOMProcessingInstructionImpl::setData(const XMLCh *data)              {fCharacterData.setData(this, data);}
00212            void             DOMProcessingInstructionImpl::setNodeValue(const XMLCh  *nodeValue)   {fCharacterData.setNodeValue (this, nodeValue); }
00213 
00214 
00215 XERCES_CPP_NAMESPACE_END