DOMProcessingInstructionImpl.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: DOMProcessingInstructionImpl.cpp,v 1.11 2003/01/16 20:12:19 tng Exp $
  58.  */
  59. #include "DOMProcessingInstructionImpl.hpp"
  60. #include "DOMDocumentImpl.hpp"
  61. #include "DOMNodeImpl.hpp"
  62. #include "DOMStringPool.hpp"
  63. #include "DOMRangeImpl.hpp"
  64. #include <xercesc/dom/DOMException.hpp>
  65. #include <xercesc/dom/DOMNode.hpp>
  66. XERCES_CPP_NAMESPACE_BEGIN
  67. DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(DOMDocument *ownerDoc,
  68.                                                      const XMLCh *targt,
  69.                                                      const XMLCh *dat)
  70.     : fNode(ownerDoc), fBaseURI(0),  fCharacterData(ownerDoc, dat)
  71. {
  72.     fNode.setIsLeafNode(true);
  73.     this->fTarget = ((DOMDocumentImpl *)ownerDoc)->cloneString(targt);
  74. };
  75. DOMProcessingInstructionImpl::DOMProcessingInstructionImpl(
  76.                                         const DOMProcessingInstructionImpl &other,
  77.                                         bool deep)
  78.     : fNode(other.fNode), fChild(other.fChild), fCharacterData(other.fCharacterData)
  79. {
  80.     fNode.setIsLeafNode(true);
  81.     fTarget = other.fTarget;
  82.     fBaseURI = other.fBaseURI;
  83. };
  84. DOMProcessingInstructionImpl::~DOMProcessingInstructionImpl()
  85. {
  86. };
  87. DOMNode *DOMProcessingInstructionImpl::cloneNode(bool deep) const
  88. {
  89.     DOMNode* newNode = new (getOwnerDocument(), DOMDocumentImpl::PROCESSING_INSTRUCTION_OBJECT) DOMProcessingInstructionImpl(*this, deep);
  90.     fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
  91.     return newNode;
  92. };
  93. const XMLCh * DOMProcessingInstructionImpl::getNodeName() const
  94. {
  95.     return fTarget;
  96. };
  97. short DOMProcessingInstructionImpl::getNodeType() const {
  98.     return DOMNode::PROCESSING_INSTRUCTION_NODE;
  99. };
  100. /** A PI's "target" states what processor channel the PI's data
  101. should be directed to. It is defined differently in HTML and XML.
  102.   In XML, a PI's "target" is the first (whitespace-delimited) token
  103.   following the "<?" token that begins the PI.
  104.     In HTML, target is always 0.
  105.       Note that getNodeName is aliased to getTarget.
  106. */
  107. const XMLCh * DOMProcessingInstructionImpl::getTarget() const
  108. {
  109.     return fTarget;
  110. };
  111. void DOMProcessingInstructionImpl::release()
  112. {
  113.     if (fNode.isOwned() && !fNode.isToBeReleased())
  114.         throw DOMException(DOMException::INVALID_ACCESS_ERR,0);
  115.     DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
  116.     if (doc) {
  117.         fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
  118.         fCharacterData.releaseBuffer();
  119.         doc->release(this, DOMDocumentImpl::PROCESSING_INSTRUCTION_OBJECT);
  120.     }
  121.     else {
  122.         // shouldn't reach here
  123.         throw DOMException(DOMException::INVALID_ACCESS_ERR,0);
  124.     }
  125. }
  126. void DOMProcessingInstructionImpl::setBaseURI(const XMLCh* baseURI) {
  127.     this->fBaseURI = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(baseURI);
  128. }
  129. const XMLCh* DOMProcessingInstructionImpl::getBaseURI() const
  130. {
  131.     return fBaseURI? fBaseURI : fNode.fOwnerNode->getBaseURI();
  132. }
  133. // Non standard extension for the range to work
  134. DOMProcessingInstruction *DOMProcessingInstructionImpl::splitText(XMLSize_t offset)
  135. {
  136.     if (fNode.isReadOnly())
  137.     {
  138.         throw DOMException(
  139.             DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
  140.     }
  141.     XMLSize_t len = fCharacterData.fDataBuf->getLen();
  142.     if (offset > len || offset < 0)
  143.         throw DOMException(DOMException::INDEX_SIZE_ERR, 0);
  144.     DOMProcessingInstruction *newText =
  145.                 getOwnerDocument()->createProcessingInstruction(fTarget,
  146.                         this->substringData(offset, len - offset));
  147.     DOMNode *parent = getParentNode();
  148.     if (parent != 0)
  149.         parent->insertBefore(newText, getNextSibling());
  150.     fCharacterData.fDataBuf->chop(offset);
  151.     if (this->getOwnerDocument() != 0) {
  152.         Ranges* ranges = ((DOMDocumentImpl *)this->getOwnerDocument())->getRanges();
  153.         if (ranges != 0) {
  154.             XMLSize_t sz = ranges->size();
  155.             if (sz != 0) {
  156.                 for (XMLSize_t i =0; i<sz; i++) {
  157.                     ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
  158.                 }
  159.             }
  160.         }
  161.     }
  162.     return newText;
  163. };
  164. //
  165. //    Delegation stubs for inherited functions
  166. //
  167.            DOMNode*         DOMProcessingInstructionImpl::appendChild(DOMNode *newChild)          {return fNode.appendChild (newChild); };
  168.            DOMNamedNodeMap* DOMProcessingInstructionImpl::getAttributes() const                   {return fNode.getAttributes (); };
  169.            DOMNodeList*     DOMProcessingInstructionImpl::getChildNodes() const                   {return fNode.getChildNodes (); };
  170.            DOMNode*         DOMProcessingInstructionImpl::getFirstChild() const                   {return fNode.getFirstChild (); };
  171.            DOMNode*         DOMProcessingInstructionImpl::getLastChild() const                    {return fNode.getLastChild (); };
  172.      const XMLCh*           DOMProcessingInstructionImpl::getLocalName() const                    {return fNode.getLocalName (); };
  173.      const XMLCh*           DOMProcessingInstructionImpl::getNamespaceURI() const                 {return fNode.getNamespaceURI (); };
  174.            DOMNode*         DOMProcessingInstructionImpl::getNextSibling() const                  {return fChild.getNextSibling (); };
  175.      const XMLCh*           DOMProcessingInstructionImpl::getNodeValue() const                    {return fCharacterData.getNodeValue (); };
  176.            DOMDocument*     DOMProcessingInstructionImpl::getOwnerDocument() const                {return fNode.getOwnerDocument (); };
  177.      const XMLCh*           DOMProcessingInstructionImpl::getPrefix() const                       {return fNode.getPrefix (); };
  178.            DOMNode*         DOMProcessingInstructionImpl::getParentNode() const                   {return fChild.getParentNode (this); };
  179.            DOMNode*         DOMProcessingInstructionImpl::getPreviousSibling() const              {return fChild.getPreviousSibling (this); };
  180.            bool             DOMProcessingInstructionImpl::hasChildNodes() const                   {return fNode.hasChildNodes (); };
  181.            DOMNode*         DOMProcessingInstructionImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
  182.                                                                                                   {return fNode.insertBefore (newChild, refChild); };
  183.            void             DOMProcessingInstructionImpl::normalize()                             {fNode.normalize (); };
  184.            DOMNode*         DOMProcessingInstructionImpl::removeChild(DOMNode *oldChild)          {return fNode.removeChild (oldChild); };
  185.            DOMNode*         DOMProcessingInstructionImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
  186.                                                                                                   {return fNode.replaceChild (newChild, oldChild); };
  187.            bool             DOMProcessingInstructionImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
  188.                                                                                                   {return fNode.isSupported (feature, version); };
  189.            void             DOMProcessingInstructionImpl::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); };
  190.            bool             DOMProcessingInstructionImpl::hasAttributes() const                   {return fNode.hasAttributes(); };
  191.            bool             DOMProcessingInstructionImpl::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); };
  192.            bool             DOMProcessingInstructionImpl::isEqualNode(const DOMNode* arg) const   {return fNode.isEqualNode(arg); };
  193.            void*            DOMProcessingInstructionImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
  194.                                                                                                   {return fNode.setUserData(key, data, handler); };
  195.            void*            DOMProcessingInstructionImpl::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); };
  196.            short            DOMProcessingInstructionImpl::compareTreePosition(const DOMNode* other) const {return fNode.compareTreePosition(other); };
  197.            const XMLCh*     DOMProcessingInstructionImpl::getTextContent() const                  {return fNode.getTextContent(); };
  198.            void             DOMProcessingInstructionImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); };
  199.            const XMLCh*     DOMProcessingInstructionImpl::lookupNamespacePrefix(const XMLCh* namespaceURI, bool useDefault) const  {return fNode.lookupNamespacePrefix(namespaceURI, useDefault); };
  200.            bool             DOMProcessingInstructionImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); };
  201.            const XMLCh*     DOMProcessingInstructionImpl::lookupNamespaceURI(const XMLCh* prefix) const  {return fNode.lookupNamespaceURI(prefix); };
  202.            DOMNode*         DOMProcessingInstructionImpl::getInterface(const XMLCh* feature)      {return fNode.getInterface(feature); };
  203. //
  204. //   Delegation of CharacerData functions.
  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. XERCES_CPP_NAMESPACE_END