LCOV - code coverage report
Current view: top level - unoxml/source/dom - document.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 46 0.0 %
Date: 2014-04-14 Functions: 0 23 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_UNOXML_SOURCE_DOM_DOCUMENT_HXX
      21             : #define INCLUDED_UNOXML_SOURCE_DOM_DOCUMENT_HXX
      22             : 
      23             : #include <set>
      24             : #include <memory>
      25             : 
      26             : #include <libxml/tree.h>
      27             : 
      28             : #include <sal/types.h>
      29             : 
      30             : #include <cppuhelper/implbase6.hxx>
      31             : 
      32             : #include <com/sun/star/uno/Reference.h>
      33             : #include <com/sun/star/beans/StringPair.hpp>
      34             : #include <com/sun/star/xml/dom/XNode.hpp>
      35             : #include <com/sun/star/xml/dom/XAttr.hpp>
      36             : #include <com/sun/star/xml/dom/XElement.hpp>
      37             : #include <com/sun/star/xml/dom/XDOMImplementation.hpp>
      38             : #include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
      39             : #include <com/sun/star/xml/dom/events/XEvent.hpp>
      40             : #include <com/sun/star/xml/sax/XSAXSerializable.hpp>
      41             : #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
      42             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      43             : #include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
      44             : #include <com/sun/star/io/XActiveDataSource.hpp>
      45             : #include <com/sun/star/io/XActiveDataControl.hpp>
      46             : #include <com/sun/star/io/XOutputStream.hpp>
      47             : #include <com/sun/star/io/XStreamListener.hpp>
      48             : 
      49             : #include "node.hxx"
      50             : 
      51             : 
      52             : using namespace std;
      53             : using namespace com::sun::star;
      54             : using namespace com::sun::star::uno;
      55             : using namespace com::sun::star::xml::sax;
      56             : using namespace com::sun::star::io;
      57             : using namespace com::sun::star::xml::dom;
      58             : using namespace com::sun::star::xml::dom::events;
      59             : 
      60             : namespace DOM
      61             : {
      62             :     namespace events {
      63             :         class CEventDispatcher;
      64             :     }
      65             : 
      66             :     class CElement;
      67             : 
      68             :     typedef ::cppu::ImplInheritanceHelper6<
      69             :             CNode, XDocument, XDocumentEvent,
      70             :             XActiveDataControl, XActiveDataSource,
      71             :             XSAXSerializable, XFastSAXSerializable>
      72             :         CDocument_Base;
      73             : 
      74             :     class CDocument
      75             :         : public CDocument_Base
      76             :     {
      77             : 
      78             :     private:
      79             :         /// this Mutex is used for synchronization of all UNO wrapper
      80             :         /// objects that belong to this document
      81             :         ::osl::Mutex m_Mutex;
      82             :         /// the libxml document: freed in destructor
      83             :         /// => all UNO wrapper objects must keep the CDocument alive
      84             :         xmlDocPtr const m_aDocPtr;
      85             : 
      86             :         // datacontrol/source state
      87             :         typedef set< Reference< XStreamListener > > listenerlist_t;
      88             :         listenerlist_t m_streamListeners;
      89             :         Reference< XOutputStream > m_rOutputStream;
      90             : 
      91             :         typedef std::map< const xmlNodePtr,
      92             :                     ::std::pair< WeakReference<XNode>, CNode* > > nodemap_t;
      93             :         nodemap_t m_NodeMap;
      94             : 
      95             :         ::std::auto_ptr<events::CEventDispatcher> const m_pEventDispatcher;
      96             : 
      97             :         CDocument(xmlDocPtr const pDocPtr);
      98             : 
      99             : 
     100             :     public:
     101             :         /// factory: only way to create instance!
     102             :         static ::rtl::Reference<CDocument>
     103             :             CreateCDocument(xmlDocPtr const pDoc);
     104             : 
     105             :         virtual ~CDocument();
     106             : 
     107             :         // needed by CXPathAPI
     108           0 :         ::osl::Mutex & GetMutex() { return m_Mutex; }
     109             : 
     110             :         events::CEventDispatcher & GetEventDispatcher();
     111             :         ::rtl::Reference< CElement > GetDocumentElement();
     112             : 
     113             :         /// get UNO wrapper instance for a libxml node
     114             :         ::rtl::Reference<CNode> GetCNode(
     115             :                 xmlNodePtr const pNode, bool const bCreate = true);
     116             :         /// remove a UNO wrapper instance
     117             :         void RemoveCNode(xmlNodePtr const pNode, CNode const*const pCNode);
     118             : 
     119             :         virtual CDocument & GetOwnerDocument() SAL_OVERRIDE;
     120             : 
     121             :         virtual void saxify(const Reference< XDocumentHandler >& i_xHandler) SAL_OVERRIDE;
     122             : 
     123             :         virtual void fastSaxify( Context& rContext ) SAL_OVERRIDE;
     124             : 
     125             :         virtual bool IsChildTypeAllowed(NodeType const nodeType) SAL_OVERRIDE;
     126             : 
     127             :         /**
     128             :         Creates an Attr of the given name.
     129             :         */
     130             :         virtual Reference< XAttr > SAL_CALL createAttribute(const OUString& name)
     131             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE;
     132             : 
     133             :         /**
     134             :         Creates an attribute of the given qualified name and namespace URI.
     135             :         */
     136             :         virtual Reference< XAttr > SAL_CALL createAttributeNS(const OUString& namespaceURI, const OUString& qualifiedName)
     137             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE;
     138             : 
     139             :         /**
     140             :         Creates a CDATASection node whose value is the specified string.
     141             :         */
     142             :         virtual Reference< XCDATASection > SAL_CALL createCDATASection(const OUString& data)
     143             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     144             : 
     145             :         /**
     146             :         Creates a Comment node given the specified string.
     147             :         */
     148             :         virtual Reference< XComment > SAL_CALL createComment(const OUString& data)
     149             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     150             : 
     151             :         /**
     152             :         Creates an empty DocumentFragment object.
     153             :         */
     154             :         virtual Reference< XDocumentFragment > SAL_CALL createDocumentFragment()
     155             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     156             : 
     157             :         /**
     158             :         Creates an element of the type specified.
     159             :         */
     160             :         virtual Reference< XElement > SAL_CALL createElement(const OUString& tagName)
     161             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE;
     162             : 
     163             :         /**
     164             :         Creates an element of the given qualified name and namespace URI.
     165             :         */
     166             :         virtual Reference< XElement > SAL_CALL createElementNS(const OUString& namespaceURI, const OUString& qualifiedName)
     167             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE;
     168             : 
     169             :         /**
     170             :         Creates an EntityReference object.
     171             :         */
     172             :         virtual Reference< XEntityReference > SAL_CALL createEntityReference(const OUString& name)
     173             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE;
     174             : 
     175             :         /**
     176             :         Creates a ProcessingInstruction node given the specified name and
     177             :         data strings.
     178             :         */
     179             :         virtual Reference< XProcessingInstruction > SAL_CALL createProcessingInstruction(
     180             :                 const OUString& target, const OUString& data)
     181             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE;
     182             : 
     183             :         /**
     184             :         Creates a Text node given the specified string.
     185             :         */
     186             :         virtual Reference< XText > SAL_CALL createTextNode(const OUString& data)
     187             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     188             : 
     189             :         /**
     190             :         The Document Type Declaration (see DocumentType) associated with this
     191             :         document.
     192             :         */
     193             :         virtual Reference< XDocumentType > SAL_CALL getDoctype()
     194             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     195             : 
     196             :         /**
     197             :         This is a convenience attribute that allows direct access to the child
     198             :         node that is the root element of the document.
     199             :         */
     200             :         virtual Reference< XElement > SAL_CALL getDocumentElement()
     201             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     202             : 
     203             :         /**
     204             :         Returns the Element whose ID is given by elementId.
     205             :         */
     206             :         virtual Reference< XElement > SAL_CALL getElementById(const OUString& elementId)
     207             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     208             : 
     209             :         /**
     210             :         Returns a NodeList of all the Elements with a given tag name in the
     211             :         order in which they are encountered in a preorder traversal of the
     212             :         Document tree.
     213             :         */
     214             :         virtual Reference< XNodeList > SAL_CALL getElementsByTagName(const OUString& tagname)
     215             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     216             : 
     217             :         /**
     218             :         Returns a NodeList of all the Elements with a given local name and
     219             :         namespace URI in the order in which they are encountered in a preorder
     220             :         traversal of the Document tree.
     221             :         */
     222             :         virtual Reference< XNodeList > SAL_CALL getElementsByTagNameNS(const OUString& namespaceURI, const OUString& localName)
     223             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     224             : 
     225             :         /**
     226             :         The DOMImplementation object that handles this document.
     227             :         */
     228             :         virtual Reference< XDOMImplementation > SAL_CALL getImplementation()
     229             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     230             : 
     231             :         /**
     232             :         Imports a node from another document to this document.
     233             :         */
     234             :         virtual Reference< XNode > SAL_CALL importNode(const Reference< XNode >& importedNode, sal_Bool deep)
     235             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE;
     236             : 
     237             :         // XDocumentEvent
     238             :         virtual Reference< XEvent > SAL_CALL createEvent(const OUString& eventType) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     239             : 
     240             :         // XActiveDataControl,
     241             :         // see http://api.libreoffice.org/docs/common/ref/com/sun/star/io/XActiveDataControl.html
     242             :         virtual void SAL_CALL addListener(const Reference< XStreamListener >& aListener )  throw (RuntimeException, std::exception) SAL_OVERRIDE;
     243             :         virtual void SAL_CALL removeListener(const Reference< XStreamListener >& aListener ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     244             :         virtual void SAL_CALL start() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     245             :         virtual void SAL_CALL terminate() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     246             : 
     247             :         // XActiveDataSource
     248             :         // see http://api.libreoffice.org/docs/common/ref/com/sun/star/io/XActiveDataSource.html
     249             :         virtual void SAL_CALL setOutputStream(  const Reference< XOutputStream >& aStream ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     250             :         virtual Reference< XOutputStream > SAL_CALL getOutputStream() throw (RuntimeException, std::exception) SAL_OVERRIDE;
     251             : 
     252             :         // ---- resolve uno inheritance problems...
     253             :         // overrides for XNode base
     254             :         virtual OUString SAL_CALL getNodeName()
     255             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     256             :         virtual OUString SAL_CALL getNodeValue()
     257             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     258             :         virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
     259             :             throw (RuntimeException, std::exception) SAL_OVERRIDE;
     260             :         // --- delegation for XNde base.
     261           0 :         virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
     262             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE
     263             :         {
     264           0 :             return CNode::appendChild(newChild);
     265             :         }
     266           0 :         virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
     267             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     268             :         {
     269           0 :             return CNode::getAttributes();
     270             :         }
     271           0 :         virtual Reference< XNodeList > SAL_CALL getChildNodes()
     272             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     273             :         {
     274           0 :             return CNode::getChildNodes();
     275             :         }
     276           0 :         virtual Reference< XNode > SAL_CALL getFirstChild()
     277             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     278             :         {
     279           0 :             return CNode::getFirstChild();
     280             :         }
     281           0 :         virtual Reference< XNode > SAL_CALL getLastChild()
     282             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     283             :         {
     284           0 :             return CNode::getLastChild();
     285             :         }
     286           0 :         virtual OUString SAL_CALL getLocalName()
     287             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     288             :         {
     289           0 :             return CNode::getLocalName();
     290             :         }
     291           0 :         virtual OUString SAL_CALL getNamespaceURI()
     292             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     293             :         {
     294           0 :             return CNode::getNamespaceURI();
     295             :         }
     296           0 :         virtual Reference< XNode > SAL_CALL getNextSibling()
     297             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     298             :         {
     299           0 :             return CNode::getNextSibling();
     300             :         }
     301           0 :         virtual NodeType SAL_CALL getNodeType()
     302             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     303             :         {
     304           0 :             return CNode::getNodeType();
     305             :         }
     306           0 :         virtual Reference< XDocument > SAL_CALL getOwnerDocument()
     307             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     308             :         {
     309           0 :             return CNode::getOwnerDocument();
     310             :         }
     311           0 :         virtual Reference< XNode > SAL_CALL getParentNode()
     312             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     313             :         {
     314           0 :             return CNode::getParentNode();
     315             :         }
     316           0 :         virtual OUString SAL_CALL getPrefix()
     317             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     318             :         {
     319           0 :            return CNode::getPrefix();
     320             :         }
     321           0 :         virtual Reference< XNode > SAL_CALL getPreviousSibling()
     322             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     323             :         {
     324           0 :             return CNode::getPreviousSibling();
     325             :         }
     326           0 :         virtual sal_Bool SAL_CALL hasAttributes()
     327             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     328             :         {
     329           0 :             return CNode::hasAttributes();
     330             :         }
     331           0 :         virtual sal_Bool SAL_CALL hasChildNodes()
     332             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     333             :         {
     334           0 :             return CNode::hasChildNodes();
     335             :         }
     336           0 :         virtual Reference< XNode > SAL_CALL insertBefore(
     337             :                 const Reference< XNode >& newChild, const Reference< XNode >& refChild)
     338             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE
     339             :         {
     340           0 :             return CNode::insertBefore(newChild, refChild);
     341             :         }
     342           0 :         virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
     343             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     344             :         {
     345           0 :             return CNode::isSupported(feature, ver);
     346             :         }
     347           0 :         virtual void SAL_CALL normalize()
     348             :             throw (RuntimeException, std::exception) SAL_OVERRIDE
     349             :         {
     350           0 :             CNode::normalize();
     351           0 :         }
     352           0 :         virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
     353             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE
     354             :         {
     355           0 :             return CNode::removeChild(oldChild);
     356             :         }
     357           0 :         virtual Reference< XNode > SAL_CALL replaceChild(
     358             :                 const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
     359             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE
     360             :         {
     361           0 :             return CNode::replaceChild(newChild, oldChild);
     362             :         }
     363           0 :         virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
     364             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE
     365             :         {
     366           0 :             return CNode::setNodeValue(nodeValue);
     367             :         }
     368           0 :         virtual void SAL_CALL setPrefix(const OUString& prefix)
     369             :             throw (RuntimeException, DOMException, std::exception) SAL_OVERRIDE
     370             :         {
     371           0 :             return CNode::setPrefix(prefix);
     372             :         }
     373             : 
     374             :         // ::com::sun::star::xml::sax::XSAXSerializable
     375             :         virtual void SAL_CALL serialize(
     376             :             const Reference< XDocumentHandler >& i_xHandler,
     377             :             const Sequence< beans::StringPair >& i_rNamespaces)
     378             :             throw (RuntimeException, SAXException, std::exception) SAL_OVERRIDE;
     379             : 
     380             :         // ::com::sun::star::xml::sax::XFastSAXSerializable
     381             :         virtual void SAL_CALL fastSerialize( const Reference< XFastDocumentHandler >& handler,
     382             :                                              const Reference< XFastTokenHandler >& tokenHandler,
     383             :                                              const Sequence< beans::StringPair >& i_rNamespaces,
     384             :                                              const Sequence< beans::Pair< OUString, sal_Int32 > >& namespaces )
     385             :             throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
     386             :     };
     387             : }
     388             : 
     389             : #endif
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10