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

词法分析

开发平台:

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: DOMCDATASectionImpl.cpp,v 1.12 2002/11/04 15:07:34 tng Exp $
  58.  */
  59. #include "DOMCDATASectionImpl.hpp"
  60. #include "DOMNodeImpl.hpp"
  61. #include "DOMRangeImpl.hpp"
  62. #include "DOMDocumentImpl.hpp"
  63. #include "DOMCasts.hpp"
  64. #include "DOMStringPool.hpp"
  65. #include <xercesc/dom/DOMException.hpp>
  66. #include <xercesc/util/XMLUniDefs.hpp>
  67. XERCES_CPP_NAMESPACE_BEGIN
  68. DOMCDATASectionImpl::DOMCDATASectionImpl(DOMDocument *ownerDoc,
  69.                                    const XMLCh *dat)
  70.     : fNode(ownerDoc), fParent(ownerDoc), fCharacterData(ownerDoc, dat)
  71. {
  72. };
  73. DOMCDATASectionImpl::DOMCDATASectionImpl(const DOMCDATASectionImpl &other, bool deep)
  74.     : fNode(*castToNodeImpl(&other)),
  75.     fParent(*castToParentImpl(&other)),
  76.     fChild(*castToChildImpl(&other)),
  77.     fCharacterData(other.fCharacterData)
  78. {
  79.     // revisit.  SOmething nees to make "deep" work.
  80. };
  81. DOMCDATASectionImpl::~DOMCDATASectionImpl()
  82. {
  83. };
  84. DOMNode  *DOMCDATASectionImpl::cloneNode(bool deep) const
  85. {
  86.     DOMNode* newNode = new (this->getOwnerDocument(), DOMDocumentImpl::CDATA_SECTION_OBJECT) DOMCDATASectionImpl(*this, deep);
  87.     fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
  88.     return newNode;
  89. };
  90. const XMLCh * DOMCDATASectionImpl::getNodeName() const {
  91.     static const XMLCh gcdata_section[] = {chPound, chLatin_c, chLatin_d, chLatin_a, chLatin_t, chLatin_a,
  92.         chDash, chLatin_s, chLatin_e, chLatin_c, chLatin_t, chLatin_i, chLatin_o, chLatin_n, 0};
  93.     return gcdata_section;
  94. };
  95. short DOMCDATASectionImpl::getNodeType() const {
  96.     return DOMNode::CDATA_SECTION_NODE;
  97. };
  98. bool DOMCDATASectionImpl::isIgnorableWhitespace() const
  99. {
  100.     return fNode.ignorableWhitespace();
  101. }
  102. //
  103. //  splitText.   revist - factor into a common function for use
  104. //                             here and in DOMTextImpl
  105. //
  106. DOMText *DOMCDATASectionImpl::splitText(XMLSize_t offset)
  107. {
  108.     if (fNode.isReadOnly())
  109.     {
  110.         throw DOMException(
  111.             DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
  112.     }
  113.     XMLSize_t len = fCharacterData.fDataBuf->getLen();
  114.     if (offset > len || offset < 0)
  115.         throw DOMException(DOMException::INDEX_SIZE_ERR, 0);
  116.     DOMText *newText =
  117.                 getOwnerDocument()->createCDATASection(
  118.                         this->substringData(offset, len - offset));
  119.     DOMNode *parent = getParentNode();
  120.     if (parent != 0)
  121.         parent->insertBefore(newText, getNextSibling());
  122.     fCharacterData.fDataBuf->chop(offset);
  123.     if (this->getOwnerDocument() != 0) {
  124.         Ranges* ranges = ((DOMDocumentImpl *)this->getOwnerDocument())->getRanges();
  125.         if (ranges != 0) {
  126.             XMLSize_t sz = ranges->size();
  127.             if (sz != 0) {
  128.                 for (XMLSize_t i =0; i<sz; i++) {
  129.                     ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
  130.                 }
  131.             }
  132.         }
  133.     }
  134.     return newText;
  135. };
  136. bool DOMCDATASectionImpl::getIsWhitespaceInElementContent() const
  137. {
  138.     return isIgnorableWhitespace();
  139. }
  140. const XMLCh* DOMCDATASectionImpl::getWholeText() {
  141.     throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
  142.     return 0;
  143. }
  144. DOMText* DOMCDATASectionImpl::replaceWholeText(const XMLCh* content){
  145.     throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
  146.     return 0;
  147. }
  148. void DOMCDATASectionImpl::release()
  149. {
  150.     if (fNode.isOwned() && !fNode.isToBeReleased())
  151.         throw DOMException(DOMException::INVALID_ACCESS_ERR,0);
  152.     DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
  153.     if (doc) {
  154.         fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
  155.         fParent.release();
  156.         fCharacterData.releaseBuffer();
  157.         doc->release(this, DOMDocumentImpl::CDATA_SECTION_OBJECT);
  158.     }
  159.     else {
  160.         // shouldn't reach here
  161.         throw DOMException(DOMException::INVALID_ACCESS_ERR,0);
  162.     }
  163. }
  164. //
  165. //  Delegation stubs for other DOM_Node inherited functions.
  166. //
  167.            DOMNode*         DOMCDATASectionImpl::appendChild(DOMNode *newChild)          {return fParent.appendChild (newChild); };
  168.            DOMNamedNodeMap* DOMCDATASectionImpl::getAttributes() const                   {return fNode.getAttributes (); };
  169.            DOMNodeList*     DOMCDATASectionImpl::getChildNodes() const                   {return fParent.getChildNodes (); };
  170.            DOMNode*         DOMCDATASectionImpl::getFirstChild() const                   {return fParent.getFirstChild (); };
  171.            DOMNode*         DOMCDATASectionImpl::getLastChild() const                    {return fParent.getLastChild (); };
  172.      const XMLCh*           DOMCDATASectionImpl::getLocalName() const                    {return fNode.getLocalName (); };
  173.      const XMLCh*           DOMCDATASectionImpl::getNamespaceURI() const                 {return fNode.getNamespaceURI (); };
  174.            DOMNode*         DOMCDATASectionImpl::getNextSibling() const                  {return fChild.getNextSibling (); };
  175.      const XMLCh*           DOMCDATASectionImpl::getNodeValue() const                    {return fCharacterData.getNodeValue (); };
  176.            DOMDocument*     DOMCDATASectionImpl::getOwnerDocument() const                {return fParent.fOwnerDocument; };
  177.      const XMLCh*           DOMCDATASectionImpl::getPrefix() const                       {return fNode.getPrefix (); };
  178.            DOMNode*         DOMCDATASectionImpl::getParentNode() const                   {return fChild.getParentNode (this); };
  179.            DOMNode*         DOMCDATASectionImpl::getPreviousSibling() const              {return fChild.getPreviousSibling (this); };
  180.            bool             DOMCDATASectionImpl::hasChildNodes() const                   {return fParent.hasChildNodes (); };
  181.            DOMNode*         DOMCDATASectionImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
  182.                                                                                          {return fParent.insertBefore (newChild, refChild); };
  183.            void             DOMCDATASectionImpl::normalize()                             {fNode.normalize (); };
  184.            DOMNode*         DOMCDATASectionImpl::removeChild(DOMNode *oldChild)          {return fParent.removeChild (oldChild); };
  185.            DOMNode*         DOMCDATASectionImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
  186.                                                                                          {return fParent.replaceChild (newChild, oldChild); };
  187.            bool             DOMCDATASectionImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
  188.                                                                                          {return fNode.isSupported (feature, version); };
  189.            void             DOMCDATASectionImpl::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); };
  190.            bool             DOMCDATASectionImpl::hasAttributes() const                   {return fNode.hasAttributes(); };
  191.            bool             DOMCDATASectionImpl::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); };
  192.            bool             DOMCDATASectionImpl::isEqualNode(const DOMNode* arg) const   {return fParent.isEqualNode(arg); };
  193.            void*            DOMCDATASectionImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
  194.                                                                                          {return fNode.setUserData(key, data, handler); };
  195.            void*            DOMCDATASectionImpl::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); };
  196.            const XMLCh*     DOMCDATASectionImpl::getBaseURI() const                      {return fNode.getBaseURI(); };
  197.            short            DOMCDATASectionImpl::compareTreePosition(const DOMNode* other) const {return fNode.compareTreePosition(other); };
  198.            const XMLCh*     DOMCDATASectionImpl::getTextContent() const                  {return fNode.getTextContent(); };
  199.            void             DOMCDATASectionImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); };
  200.            const XMLCh*     DOMCDATASectionImpl::lookupNamespacePrefix(const XMLCh* namespaceURI, bool useDefault) const  {return fNode.lookupNamespacePrefix(namespaceURI, useDefault); };
  201.            bool             DOMCDATASectionImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); };
  202.            const XMLCh*     DOMCDATASectionImpl::lookupNamespaceURI(const XMLCh* prefix) const  {return fNode.lookupNamespaceURI(prefix); };
  203.            DOMNode*         DOMCDATASectionImpl::getInterface(const XMLCh* feature)      {return fNode.getInterface(feature); };
  204. //
  205. //   Delegation of CharacerData functions.
  206. //
  207.            const XMLCh*     DOMCDATASectionImpl::getData() const                         {return fCharacterData.getData();};
  208.            XMLSize_t        DOMCDATASectionImpl::getLength() const                       {return fCharacterData.getLength();};
  209.            const XMLCh*     DOMCDATASectionImpl::substringData(XMLSize_t offset, XMLSize_t count) const
  210.                                                                                          {return fCharacterData.substringData(this, offset, count);};
  211.            void             DOMCDATASectionImpl::appendData(const XMLCh *arg)            {fCharacterData.appendData(this, arg);};
  212.            void             DOMCDATASectionImpl::insertData(XMLSize_t offset, const  XMLCh *arg)
  213.                                                                                          {fCharacterData.insertData(this, offset, arg);};
  214.            void             DOMCDATASectionImpl::deleteData(XMLSize_t offset, XMLSize_t count)
  215.                                                                                          {fCharacterData.deleteData(this, offset, count);};
  216.            void             DOMCDATASectionImpl::replaceData(XMLSize_t offset, XMLSize_t count, const XMLCh *arg)
  217.                                                                                          {fCharacterData.replaceData(this, offset, count, arg);};
  218.            void             DOMCDATASectionImpl::setData(const XMLCh *data)              {fCharacterData.setData(this, data);};
  219.            void             DOMCDATASectionImpl::setNodeValue(const XMLCh  *nodeValue)   {fCharacterData.setNodeValue (this, nodeValue); };
  220. XERCES_CPP_NAMESPACE_END