Logo Search packages:      
Sourcecode: poco version File versions  Download package

Document.cpp

//
// Document.cpp
//
// $Id: //poco/1.2/XML/src/Document.cpp#2 $
//
// Library: XML
// Package: DOM
// Module:  DOM
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
// 
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//


#include "Poco/DOM/Document.h"
#include "Poco/DOM/DocumentType.h"
#include "Poco/DOM/DOMImplementation.h"
#include "Poco/DOM/Element.h"
#include "Poco/DOM/Attr.h"
#include "Poco/DOM/DocumentFragment.h"
#include "Poco/DOM/Text.h"
#include "Poco/DOM/Comment.h"
#include "Poco/DOM/CDATASection.h"
#include "Poco/DOM/ProcessingInstruction.h"
#include "Poco/DOM/EntityReference.h"
#include "Poco/DOM/DOMException.h"
#include "Poco/DOM/ElementsByTagNameList.h"
#include "Poco/DOM/Entity.h"
#include "Poco/DOM/Notation.h"
#include "Poco/XML/Name.h"
#include "Poco/XML/NamePool.h"


namespace Poco {
namespace XML {


const XMLString Document::NODE_NAME = toXMLString("#document");


Document::Document(NamePool* pNamePool): 
      AbstractContainerNode(0),
      _pDocumentType(0),
      _eventSuspendLevel(0)
{
      if (pNamePool)
      {
            _pNamePool = pNamePool;
            _pNamePool->duplicate();
      }
      else
      {
            _pNamePool = new NamePool;
      }
}


00080 Document::Document(DocumentType* pDocumentType, NamePool* pNamePool): 
      AbstractContainerNode(0),
      _pDocumentType(pDocumentType),
      _eventSuspendLevel(0)
{
      if (pNamePool)
      {
            _pNamePool = pNamePool;
            _pNamePool->duplicate();
      }
      else
      {
            _pNamePool = new NamePool;
      }
      if (_pDocumentType)
      {
            _pDocumentType->duplicate();
            _pDocumentType->setOwnerDocument(this);
      }
}


00102 Document::~Document()
{
      if (_pDocumentType) _pDocumentType->release();
      _pNamePool->release();
}


00109 bool Document::dispatchEvent(Event* evt)
{
      return _eventSuspendLevel > 0 || AbstractContainerNode::dispatchEvent(evt);
}


00115 void Document::collectGarbage()
{
      _autoReleasePool.release();
}


00121 void Document::suspendEvents()
{
      ++_eventSuspendLevel;
}


00127 void Document::resumeEvents()
{
      poco_assert_dbg (_eventSuspendLevel > 0);

      --_eventSuspendLevel;
}


00135 const DOMImplementation& Document::implementation() const
{
      return DOMImplementation::instance();
}


00141 Element* Document::documentElement() const
{
      // Skip non-element nodes before the document element
      Node* pCur = firstChild();
      while (pCur)
      {
            if (dynamic_cast<Element*>(pCur))
                  return static_cast<Element*>(pCur);
            pCur = pCur->nextSibling();
      }
      return 0;
}


00155 Element* Document::createElement(const XMLString& tagName) const
{
      return new Element(const_cast<Document*>(this), EMPTY_STRING, EMPTY_STRING, tagName); 
}


00161 DocumentFragment* Document::createDocumentFragment() const
{
      return new DocumentFragment(const_cast<Document*>(this));
}


00167 Text* Document::createTextNode(const XMLString& data) const
{
      return new Text(const_cast<Document*>(this), data);
}


00173 Comment* Document::createComment(const XMLString& data) const
{
      return new Comment(const_cast<Document*>(this), data);
}


00179 CDATASection* Document::createCDATASection(const XMLString& data) const
{
      return new CDATASection(const_cast<Document*>(this), data);
}


00185 ProcessingInstruction* Document::createProcessingInstruction(const XMLString& target, const XMLString& data) const
{
      return new ProcessingInstruction(const_cast<Document*>(this), target, data);
}


00191 Attr* Document::createAttribute(const XMLString& name) const
{
      return new Attr(const_cast<Document*>(this), 0, EMPTY_STRING, EMPTY_STRING, name, EMPTY_STRING);
}


00197 EntityReference* Document::createEntityReference(const XMLString& name) const
{
      return new EntityReference(const_cast<Document*>(this), name);
}


00203 NodeList* Document::getElementsByTagName(const XMLString& name) const
{
      return new ElementsByTagNameList(const_cast<Document*>(this), name);    
}


const XMLString& Document::nodeName() const
{
      return NODE_NAME;
}


00215 unsigned short Document::nodeType() const
{
      return Node::DOCUMENT_NODE;
}


00221 Node* Document::importNode(Node* importedNode, bool deep)
{
      return static_cast<AbstractNode*>(importedNode)->copyNode(deep, this);
}


00227 Element* Document::createElementNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const
{
      return new Element(const_cast<Document*>(this), namespaceURI, Name::localName(qualifiedName), qualifiedName);
}


00233 Attr* Document::createAttributeNS(const XMLString& namespaceURI, const XMLString& qualifiedName) const
{
      return new Attr(const_cast<Document*>(this), 0, namespaceURI, Name::localName(qualifiedName), qualifiedName, EMPTY_STRING);
}


00239 NodeList* Document::getElementsByTagNameNS(const XMLString& namespaceURI, const XMLString& localName) const
{
      return new ElementsByTagNameListNS(const_cast<Document*>(this), namespaceURI, localName); 
}


00245 Element* Document::getElementById(const XMLString& elementId) const
{
      return 0;
}


00251 Event* Document::createEvent(const XMLString& eventType) const
{
      if (eventType == MutationEvent::DOMSubtreeModified          ||
          eventType == MutationEvent::DOMNodeInserted             ||
            eventType == MutationEvent::DOMNodeRemoved              ||
            eventType == MutationEvent::DOMNodeRemovedFromDocument  ||
            eventType == MutationEvent::DOMNodeInsertedIntoDocument ||
            eventType == MutationEvent::DOMAttrModified             ||
            eventType == MutationEvent::DOMCharacterDataModified)
      {
            return new MutationEvent(const_cast<Document*>(this), eventType);
      }
      throw DOMException(DOMException::NOT_SUPPORTED_ERR);
}


Node* Document::copyNode(bool deep, Document* pOwnerDocument) const
{
      throw DOMException(DOMException::NOT_SUPPORTED_ERR);
}


void Document::setDoctype(DocumentType* pDoctype)
{
      if (_pDocumentType) _pDocumentType->release();
      _pDocumentType = pDoctype;
      if (_pDocumentType)
      {
            _pDocumentType->duplicate();
            _pDocumentType->setOwnerDocument(this);
      }
}


00285 bool Document::eventsSuspended() const
{
      return _eventSuspendLevel > 0;
}


00291 bool Document::events() const
{
      return _eventSuspendLevel == 0;
}


Entity* Document::createEntity(const XMLString& name, const XMLString& publicId, const XMLString& systemId, const XMLString& notationName) const
{
      return new Entity(const_cast<Document*>(this), name, publicId, systemId, notationName);
}


00303 Notation* Document::createNotation(const XMLString& name, const XMLString& publicId, const XMLString& systemId) const
{
      return new Notation(const_cast<Document*>(this), name, publicId, systemId);
}


00309 Element* Document::getElementById(const XMLString& elementId, const XMLString& idAttribute) const
{
      Element* pElem = documentElement();
      if (pElem) pElem = pElem->getElementById(elementId, idAttribute);
      return pElem;
}


00317 Element* Document::getElementByIdNS(const XMLString& elementId, const XMLString& idAttributeURI, const XMLString& idAttributeLocalName) const
{
      Element* pElem = documentElement();
      if (pElem) pElem = pElem->getElementByIdNS(elementId, idAttributeURI, idAttributeLocalName);
      return pElem;
}


} } // namespace Poco::XML

Generated by  Doxygen 1.6.0   Back to index