GME  13
DOMCommentImpl.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: DOMCommentImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
00020  */
00021 
00022 #include "DOMCommentImpl.hpp"
00023 #include "DOMCharacterDataImpl.hpp"
00024 #include "DOMStringPool.hpp"
00025 #include "DOMCasts.hpp"
00026 #include "DOMDocumentImpl.hpp"
00027 #include "DOMRangeImpl.hpp"
00028 #include <xercesc/dom/DOMNode.hpp>
00029 #include <xercesc/dom/DOMException.hpp>
00030 #include <xercesc/util/XMLUniDefs.hpp>
00031 
00032 XERCES_CPP_NAMESPACE_BEGIN
00033 
00034 DOMCommentImpl::DOMCommentImpl(DOMDocument *ownerDoc, const XMLCh *dat)
00035     : fNode(ownerDoc),  fCharacterData(ownerDoc, dat)
00036 {
00037     fNode.setIsLeafNode(true);
00038 }
00039 
00040 
00041 DOMCommentImpl::DOMCommentImpl(const DOMCommentImpl &other, bool)
00042 
00043     : fNode(other.fNode),
00044     fChild(other.fChild),
00045     fCharacterData(other.fCharacterData)
00046 {
00047     fNode.setIsLeafNode(true);
00048 }
00049 
00050 
00051 DOMCommentImpl::~DOMCommentImpl() {
00052 }
00053 
00054 
00055 
00056 DOMNode * DOMCommentImpl::cloneNode(bool deep) const
00057 {
00058     DOMNode* newNode = new (getOwnerDocument(), DOMMemoryManager::COMMENT_OBJECT) DOMCommentImpl(*this, deep);
00059     fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
00060     return newNode;
00061 }
00062 
00063 
00064 const XMLCh * DOMCommentImpl::getNodeName() const {
00065     static const XMLCh gComment[] =
00066         {chPound, chLatin_c, chLatin_o, chLatin_m, chLatin_m, chLatin_e,chLatin_n, chLatin_t, 0};
00067     return gComment;
00068 }
00069 
00070 DOMNode::NodeType DOMCommentImpl::getNodeType() const {
00071     return DOMNode::COMMENT_NODE;
00072 }
00073 
00074 void DOMCommentImpl::release()
00075 {
00076     if (fNode.isOwned() && !fNode.isToBeReleased())
00077         throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
00078 
00079     DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
00080     if (doc) {
00081         fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
00082         fCharacterData.releaseBuffer();
00083         doc->release(this, DOMMemoryManager::COMMENT_OBJECT);
00084     }
00085     else {
00086         // shouldn't reach here
00087         throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
00088     }
00089 }
00090 
00091 
00092 // Non standard extension for the range to work
00093 DOMComment *DOMCommentImpl::splitText(XMLSize_t offset)
00094 {
00095     if (fNode.isReadOnly())
00096     {
00097         throw DOMException(
00098             DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
00099     }
00100     XMLSize_t len = fCharacterData.fDataBuf->getLen();
00101     if (offset > len)
00102         throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager);
00103 
00104     DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument();
00105     DOMComment *newText =
00106       doc->createComment(this->substringData(offset, len - offset));
00107 
00108     DOMNode *parent = getParentNode();
00109     if (parent != 0)
00110         parent->insertBefore(newText, getNextSibling());
00111 
00112     fCharacterData.fDataBuf->chop(offset);
00113 
00114     if (doc != 0) {
00115         Ranges* ranges = doc->getRanges();
00116         if (ranges != 0) {
00117             XMLSize_t sz = ranges->size();
00118             if (sz != 0) {
00119                 for (XMLSize_t i =0; i<sz; i++) {
00120                     ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
00121                 }
00122             }
00123         }
00124     }
00125 
00126     return newText;
00127 }
00128 
00129 
00130            DOMNode*         DOMCommentImpl::appendChild(DOMNode *newChild)          {return fNode.appendChild (newChild); }
00131            DOMNamedNodeMap* DOMCommentImpl::getAttributes() const                   {return fNode.getAttributes (); }
00132            DOMNodeList*     DOMCommentImpl::getChildNodes() const                   {return fNode.getChildNodes (); }
00133            DOMNode*         DOMCommentImpl::getFirstChild() const                   {return fNode.getFirstChild (); }
00134            DOMNode*         DOMCommentImpl::getLastChild() const                    {return fNode.getLastChild (); }
00135      const XMLCh*           DOMCommentImpl::getLocalName() const                    {return fNode.getLocalName (); }
00136      const XMLCh*           DOMCommentImpl::getNamespaceURI() const                 {return fNode.getNamespaceURI (); }
00137            DOMNode*         DOMCommentImpl::getNextSibling() const                  {return fChild.getNextSibling (); }
00138      const XMLCh*           DOMCommentImpl::getNodeValue() const                    {return fCharacterData.getNodeValue (); }
00139            DOMDocument*     DOMCommentImpl::getOwnerDocument() const                {return fNode.getOwnerDocument (); }
00140      const XMLCh*           DOMCommentImpl::getPrefix() const                       {return fNode.getPrefix (); }
00141            DOMNode*         DOMCommentImpl::getParentNode() const                   {return fChild.getParentNode (this); }
00142            DOMNode*         DOMCommentImpl::getPreviousSibling() const              {return fChild.getPreviousSibling (this); }
00143            bool             DOMCommentImpl::hasChildNodes() const                   {return fNode.hasChildNodes (); }
00144            DOMNode*         DOMCommentImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
00145                                                                                     {return fNode.insertBefore (newChild, refChild); }
00146            void             DOMCommentImpl::normalize()                             {fNode.normalize (); }
00147            DOMNode*         DOMCommentImpl::removeChild(DOMNode *oldChild)          {return fNode.removeChild (oldChild); }
00148            DOMNode*         DOMCommentImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
00149                                                                                     {return fNode.replaceChild (newChild, oldChild); }
00150            bool             DOMCommentImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
00151                                                                                     {return fNode.isSupported (feature, version); }
00152            void             DOMCommentImpl::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); }
00153            bool             DOMCommentImpl::hasAttributes() const                   {return fNode.hasAttributes(); }
00154            bool             DOMCommentImpl::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); }
00155            bool             DOMCommentImpl::isEqualNode(const DOMNode* arg) const   {return fNode.isEqualNode(arg); }
00156            void*            DOMCommentImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
00157                                                                                     {return fNode.setUserData(key, data, handler); }
00158            void*            DOMCommentImpl::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); }
00159            const XMLCh*     DOMCommentImpl::getBaseURI() const                      {return fNode.getBaseURI(); }
00160            short            DOMCommentImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
00161            const XMLCh*     DOMCommentImpl::getTextContent() const                  {return fNode.getTextContent(); }
00162            void             DOMCommentImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
00163            const XMLCh*     DOMCommentImpl::lookupPrefix(const XMLCh* namespaceURI) const  {return fNode.lookupPrefix(namespaceURI); }
00164            bool             DOMCommentImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
00165            const XMLCh*     DOMCommentImpl::lookupNamespaceURI(const XMLCh* prefix) const  {return fNode.lookupNamespaceURI(prefix); }
00166            void*            DOMCommentImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
00167 
00168 
00169 
00170 //
00171 //   Delegation of CharacerData functions.
00172 //
00173 
00174 
00175            const XMLCh*     DOMCommentImpl::getData() const                         {return fCharacterData.getData();}
00176            XMLSize_t        DOMCommentImpl::getLength() const                       {return fCharacterData.getLength();}
00177            const XMLCh*     DOMCommentImpl::substringData(XMLSize_t offset, XMLSize_t count) const
00178                                                                                     {return fCharacterData.substringData(this, offset, count);}
00179            void             DOMCommentImpl::appendData(const XMLCh *arg)            {fCharacterData.appendData(this, arg);}
00180            void             DOMCommentImpl::insertData(XMLSize_t offset, const  XMLCh *arg)
00181                                                                                     {fCharacterData.insertData(this, offset, arg);}
00182            void             DOMCommentImpl::deleteData(XMLSize_t offset, XMLSize_t count)
00183                                                                                     {fCharacterData.deleteData(this, offset, count);}
00184            void             DOMCommentImpl::replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh *arg)
00185                                                                                     {fCharacterData.replaceData(this, offset, count, arg);}
00186            void             DOMCommentImpl::setData(const XMLCh *data)              {fCharacterData.setData(this, data);}
00187            void             DOMCommentImpl::setNodeValue(const XMLCh  *nodeValue)   {fCharacterData.setNodeValue (this, nodeValue); }
00188 
00189 XERCES_CPP_NAMESPACE_END