DOMCommentImpl.cpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:12k
源码类别:

词法分析

开发平台:

Visual C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 2001, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Id: DOMCommentImpl.cpp,v 1.12 2003/01/16 20:12:19 tng Exp $
  58.  */
  59. #include "DOMCommentImpl.hpp"
  60. #include "DOMCharacterDataImpl.hpp"
  61. #include "DOMStringPool.hpp"
  62. #include "DOMCasts.hpp"
  63. #include "DOMDocumentImpl.hpp"
  64. #include "DOMRangeImpl.hpp"
  65. #include <xercesc/dom/DOMNode.hpp>
  66. #include <xercesc/dom/DOMException.hpp>
  67. #include <xercesc/util/XMLUniDefs.hpp>
  68. XERCES_CPP_NAMESPACE_BEGIN
  69. DOMCommentImpl::DOMCommentImpl(DOMDocument *ownerDoc, const XMLCh *dat)
  70.     : fNode(ownerDoc),  fCharacterData(ownerDoc, dat)
  71. {
  72.     fNode.setIsLeafNode(true);
  73. };
  74. DOMCommentImpl::DOMCommentImpl(const DOMCommentImpl &other, bool deep)
  75.     : fNode(other.fNode),
  76.     fChild(other.fChild),
  77.     fCharacterData(other.fCharacterData)
  78. {
  79.     fNode.setIsLeafNode(true);
  80. };
  81. DOMCommentImpl::~DOMCommentImpl() {
  82. };
  83. DOMNode * DOMCommentImpl::cloneNode(bool deep) const
  84. {
  85.     DOMNode* newNode = new (getOwnerDocument(), DOMDocumentImpl::COMMENT_OBJECT) DOMCommentImpl(*this, deep);
  86.     fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
  87.     return newNode;
  88. };
  89. const XMLCh * DOMCommentImpl::getNodeName() const {
  90.     static const XMLCh gComment[] =
  91.         {chPound, chLatin_c, chLatin_o, chLatin_m, chLatin_m, chLatin_e,chLatin_n, chLatin_t, 0};
  92.     return gComment;
  93. }
  94. short DOMCommentImpl::getNodeType() const {
  95.     return DOMNode::COMMENT_NODE;
  96. }
  97. void DOMCommentImpl::release()
  98. {
  99.     if (fNode.isOwned() && !fNode.isToBeReleased())
  100.         throw DOMException(DOMException::INVALID_ACCESS_ERR,0);
  101.     DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
  102.     if (doc) {
  103.         fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
  104.         fCharacterData.releaseBuffer();
  105.         doc->release(this, DOMDocumentImpl::COMMENT_OBJECT);
  106.     }
  107.     else {
  108.         // shouldn't reach here
  109.         throw DOMException(DOMException::INVALID_ACCESS_ERR,0);
  110.     }
  111. }
  112. // Non standard extension for the range to work
  113. DOMComment *DOMCommentImpl::splitText(XMLSize_t offset)
  114. {
  115.     if (fNode.isReadOnly())
  116.     {
  117.         throw DOMException(
  118.             DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
  119.     }
  120.     XMLSize_t len = fCharacterData.fDataBuf->getLen();
  121.     if (offset > len || offset < 0)
  122.         throw DOMException(DOMException::INDEX_SIZE_ERR, 0);
  123.     DOMComment *newText =
  124.                 getOwnerDocument()->createComment(
  125.                         this->substringData(offset, len - offset));
  126.     DOMNode *parent = getParentNode();
  127.     if (parent != 0)
  128.         parent->insertBefore(newText, getNextSibling());
  129.     fCharacterData.fDataBuf->chop(offset);
  130.     if (this->getOwnerDocument() != 0) {
  131.         Ranges* ranges = ((DOMDocumentImpl *)this->getOwnerDocument())->getRanges();
  132.         if (ranges != 0) {
  133.             XMLSize_t sz = ranges->size();
  134.             if (sz != 0) {
  135.                 for (XMLSize_t i =0; i<sz; i++) {
  136.                     ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
  137.                 }
  138.             }
  139.         }
  140.     }
  141.     return newText;
  142. };
  143.            DOMNode*         DOMCommentImpl::appendChild(DOMNode *newChild)          {return fNode.appendChild (newChild); };
  144.            DOMNamedNodeMap* DOMCommentImpl::getAttributes() const                   {return fNode.getAttributes (); };
  145.            DOMNodeList*     DOMCommentImpl::getChildNodes() const                   {return fNode.getChildNodes (); };
  146.            DOMNode*         DOMCommentImpl::getFirstChild() const                   {return fNode.getFirstChild (); };
  147.            DOMNode*         DOMCommentImpl::getLastChild() const                    {return fNode.getLastChild (); };
  148.      const XMLCh*           DOMCommentImpl::getLocalName() const                    {return fNode.getLocalName (); };
  149.      const XMLCh*           DOMCommentImpl::getNamespaceURI() const                 {return fNode.getNamespaceURI (); };
  150.            DOMNode*         DOMCommentImpl::getNextSibling() const                  {return fChild.getNextSibling (); };
  151.      const XMLCh*           DOMCommentImpl::getNodeValue() const                    {return fCharacterData.getNodeValue (); };
  152.            DOMDocument*     DOMCommentImpl::getOwnerDocument() const                {return fNode.getOwnerDocument (); };
  153.      const XMLCh*           DOMCommentImpl::getPrefix() const                       {return fNode.getPrefix (); };
  154.            DOMNode*         DOMCommentImpl::getParentNode() const                   {return fChild.getParentNode (this); };
  155.            DOMNode*         DOMCommentImpl::getPreviousSibling() const              {return fChild.getPreviousSibling (this); };
  156.            bool             DOMCommentImpl::hasChildNodes() const                   {return fNode.hasChildNodes (); };
  157.            DOMNode*         DOMCommentImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
  158.                                                                                     {return fNode.insertBefore (newChild, refChild); };
  159.            void             DOMCommentImpl::normalize()                             {fNode.normalize (); };
  160.            DOMNode*         DOMCommentImpl::removeChild(DOMNode *oldChild)          {return fNode.removeChild (oldChild); };
  161.            DOMNode*         DOMCommentImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
  162.                                                                                     {return fNode.replaceChild (newChild, oldChild); };
  163.            bool             DOMCommentImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
  164.                                                                                     {return fNode.isSupported (feature, version); };
  165.            void             DOMCommentImpl::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); };
  166.            bool             DOMCommentImpl::hasAttributes() const                   {return fNode.hasAttributes(); };
  167.            bool             DOMCommentImpl::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); };
  168.            bool             DOMCommentImpl::isEqualNode(const DOMNode* arg) const   {return fNode.isEqualNode(arg); };
  169.            void*            DOMCommentImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
  170.                                                                                     {return fNode.setUserData(key, data, handler); };
  171.            void*            DOMCommentImpl::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); };
  172.            const XMLCh*     DOMCommentImpl::getBaseURI() const                      {return fNode.getBaseURI(); };
  173.            short            DOMCommentImpl::compareTreePosition(const DOMNode* other) const {return fNode.compareTreePosition(other); };
  174.            const XMLCh*     DOMCommentImpl::getTextContent() const                  {return fNode.getTextContent(); };
  175.            void             DOMCommentImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); };
  176.            const XMLCh*     DOMCommentImpl::lookupNamespacePrefix(const XMLCh* namespaceURI, bool useDefault) const  {return fNode.lookupNamespacePrefix(namespaceURI, useDefault); };
  177.            bool             DOMCommentImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); };
  178.            const XMLCh*     DOMCommentImpl::lookupNamespaceURI(const XMLCh* prefix) const  {return fNode.lookupNamespaceURI(prefix); };
  179.            DOMNode*         DOMCommentImpl::getInterface(const XMLCh* feature)      {return fNode.getInterface(feature); };
  180. //
  181. //   Delegation of CharacerData functions.
  182. //
  183.            const XMLCh*     DOMCommentImpl::getData() const                         {return fCharacterData.getData();};
  184.            XMLSize_t        DOMCommentImpl::getLength() const                       {return fCharacterData.getLength();};
  185.            const XMLCh*     DOMCommentImpl::substringData(XMLSize_t offset, XMLSize_t count) const
  186.                                                                                     {return fCharacterData.substringData(this, offset, count);};
  187.            void             DOMCommentImpl::appendData(const XMLCh *arg)            {fCharacterData.appendData(this, arg);};
  188.            void             DOMCommentImpl::insertData(XMLSize_t offset, const  XMLCh *arg)
  189.                                                                                     {fCharacterData.insertData(this, offset, arg);};
  190.            void             DOMCommentImpl::deleteData(XMLSize_t offset, XMLSize_t count)
  191.                                                                                     {fCharacterData.deleteData(this, offset, count);};
  192.            void             DOMCommentImpl::replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh *arg)
  193.                                                                                     {fCharacterData.replaceData(this, offset, count, arg);};
  194.            void             DOMCommentImpl::setData(const XMLCh *data)              {fCharacterData.setData(this, data);};
  195.            void             DOMCommentImpl::setNodeValue(const XMLCh  *nodeValue)   {fCharacterData.setNodeValue (this, nodeValue); };
  196. XERCES_CPP_NAMESPACE_END