LCOV - code coverage report
Current view: top level - libreoffice/unoxml/source/dom - node.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 8 100.0 %
Date: 2012-12-27 Functions: 7 7 100.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 DOM_NODE_HXX
      21             : #define DOM_NODE_HXX
      22             : 
      23             : #include <libxml/tree.h>
      24             : 
      25             : #include <sal/types.h>
      26             : #include <rtl/ref.hxx>
      27             : #include <rtl/string.hxx>
      28             : #include <rtl/ustring.hxx>
      29             : 
      30             : #include <cppuhelper/implbase3.hxx>
      31             : 
      32             : #include <sax/fastattribs.hxx>
      33             : 
      34             : #include <com/sun/star/uno/Reference.h>
      35             : #include <com/sun/star/uno/Sequence.h>
      36             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      37             : #include <com/sun/star/xml/dom/XNode.hpp>
      38             : #include <com/sun/star/xml/dom/XNodeList.hpp>
      39             : #include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
      40             : #include <com/sun/star/xml/dom/NodeType.hpp>
      41             : #include <com/sun/star/xml/dom/events/XEventTarget.hpp>
      42             : #include <com/sun/star/xml/dom/events/XEvent.hpp>
      43             : #include <com/sun/star/xml/dom/DOMException.hpp>
      44             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      45             : #include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
      46             : 
      47             : #include <boost/unordered_map.hpp>
      48             : 
      49             : using ::rtl::OUString;
      50             : using ::rtl::OString;
      51             : using namespace sax_fastparser;
      52             : using namespace com::sun::star::uno;
      53             : using namespace com::sun::star::xml::sax;
      54             : using namespace com::sun::star::xml::dom;
      55             : using namespace com::sun::star::xml::dom::events;
      56             : using com::sun::star::lang::XUnoTunnel;
      57             : 
      58             : 
      59             : namespace DOM
      60             : {
      61           6 :     struct Context
      62             :     {
      63           6 :         Context( const Reference< XFastDocumentHandler >& i_xHandler,
      64             :                  const Reference< XFastTokenHandler >& i_xTokenHandler ) :
      65             :             maNamespaces( 1, std::vector<Namespace>() ),
      66             :             maNamespaceMap(101),
      67           6 :             mxAttribList(new FastAttributeList(i_xTokenHandler)),
      68             :             mxCurrentHandler(i_xHandler, UNO_QUERY_THROW),
      69             :             mxDocHandler(i_xHandler),
      70          12 :             mxTokenHandler(i_xTokenHandler)
      71           6 :         {}
      72             : 
      73        5582 :         struct Namespace
      74             :         {
      75             :             OString     maPrefix;
      76             :             sal_Int32   mnToken;
      77             :             OUString    maNamespaceURL;
      78             : 
      79        1306 :             const OString& getPrefix() const { return maPrefix; }
      80             :         };
      81             : 
      82             :         typedef std::vector< std::vector<Namespace> > NamespaceVectorType;
      83             :         typedef boost::unordered_map< OUString,
      84             :                                sal_Int32,
      85             :                                rtl::OUStringHash > NamespaceMapType;
      86             : 
      87             :         /// outer vector: xml context; inner vector: current NS
      88             :         NamespaceVectorType                 maNamespaces;
      89             :         NamespaceMapType                    maNamespaceMap;
      90             :         ::rtl::Reference<FastAttributeList> mxAttribList;
      91             :         Reference<XFastContextHandler>      mxCurrentHandler;
      92             :         Reference<XFastDocumentHandler>     mxDocHandler;
      93             :         Reference<XFastTokenHandler>        mxTokenHandler;
      94             :     };
      95             : 
      96             :     void pushContext(Context& io_rContext);
      97             :     void popContext(Context& io_rContext);
      98             : 
      99             :     sal_Int32 getTokenWithPrefix( const Context& rContext, const sal_Char* xPrefix, const sal_Char* xName );
     100             :     sal_Int32 getToken( const Context& rContext, const sal_Char* xName );
     101             : 
     102             :     /// add namespaces on this node to context
     103             :     void addNamespaces(Context& io_rContext, xmlNodePtr pNode);
     104             : 
     105             :     class CDocument;
     106             : 
     107             :     class CNode : public cppu::WeakImplHelper3< XNode, XUnoTunnel, XEventTarget >
     108             :     {
     109             :         friend class CDocument;
     110             :         friend class CElement;
     111             :         friend class CAttributesMap;
     112             : 
     113             :     private:
     114             :         bool m_bUnlinked; /// node has been removed from document
     115             : 
     116             :     protected:
     117             :         NodeType const m_aNodeType;
     118             :         /// libxml node; NB: not const, because invalidate may reset it to 0!
     119             :         xmlNodePtr m_aNodePtr;
     120             : 
     121             :         ::rtl::Reference< CDocument > const m_xDocument;
     122             :         ::osl::Mutex & m_rMutex;
     123             : 
     124             :         // for initialization by classes derived through ImplInheritanceHelper
     125             :         CNode(CDocument const& rDocument, ::osl::Mutex const& rMutex,
     126             :                 NodeType const& reNodeType, xmlNodePtr const& rpNode);
     127             :         void invalidate();
     128             : 
     129             :         void dispatchSubtreeModified();
     130             : 
     131             :     public:
     132             : 
     133             :         virtual ~CNode();
     134             : 
     135             :         static CNode * GetImplementation(::com::sun::star::uno::Reference<
     136             :                 ::com::sun::star::uno::XInterface> const& xNode);
     137             : 
     138       29938 :         xmlNodePtr GetNodePtr() { return m_aNodePtr; }
     139             : 
     140             :         virtual CDocument & GetOwnerDocument();
     141             : 
     142             :         // recursively create SAX events
     143             :         virtual void saxify(const Reference< XDocumentHandler >& i_xHandler);
     144             : 
     145             :         // recursively create SAX events
     146             :         virtual void fastSaxify( Context& io_rContext );
     147             : 
     148             :         // constrains child relationship between nodes based on type
     149             :         virtual bool IsChildTypeAllowed(NodeType const nodeType);
     150             : 
     151             :         // ---- DOM interfaces
     152             : 
     153             :         /**
     154             :         Adds the node newChild to the end of the list of children of this node.
     155             :         */
     156             :         virtual Reference< XNode > SAL_CALL
     157             :             appendChild(Reference< XNode > const& xNewChild)
     158             :             throw (RuntimeException, DOMException);
     159             : 
     160             :         /**
     161             :         Returns a duplicate of this node, i.e., serves as a generic copy
     162             :         constructor for nodes.
     163             :         */
     164             :         virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
     165             :             throw (RuntimeException);
     166             : 
     167             :         /**
     168             :         A NamedNodeMap containing the attributes of this node
     169             :         (if it is an Element) or null otherwise.
     170             :         */
     171             :         virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
     172             :             throw (RuntimeException);
     173             : 
     174             :         /**
     175             :         A NodeList that contains all children of this node.
     176             :         */
     177             :         virtual Reference< XNodeList > SAL_CALL getChildNodes()
     178             :             throw (RuntimeException);
     179             : 
     180             :         /**
     181             :         The first child of this node.
     182             :         */
     183             :         virtual Reference< XNode > SAL_CALL getFirstChild()
     184             :             throw (RuntimeException);
     185             : 
     186             :         /**
     187             :         The last child of this node.
     188             :         */
     189             :         virtual Reference< XNode > SAL_CALL getLastChild()
     190             :             throw (RuntimeException);
     191             : 
     192             :         /**
     193             :         Returns the local part of the qualified name of this node.
     194             :         */
     195             :         virtual OUString SAL_CALL getLocalName()
     196             :             throw (RuntimeException);
     197             : 
     198             :         /**
     199             :         The namespace URI of this node, or null if it is unspecified.
     200             :         */
     201             :         virtual OUString SAL_CALL getNamespaceURI()
     202             :             throw (RuntimeException);
     203             : 
     204             :         /**
     205             :         The node immediately following this node.
     206             :         */
     207             :         virtual Reference< XNode > SAL_CALL getNextSibling()
     208             :             throw (RuntimeException);
     209             : 
     210             :         /**
     211             :         The name of this node, depending on its type; see the table above.
     212             :         -- virtual implemented by actual node types
     213             :         */
     214             :         virtual OUString SAL_CALL getNodeName()
     215             :             throw (RuntimeException);
     216             : 
     217             :         /**
     218             :         A code representing the type of the underlying object, as defined above.
     219             :         */
     220             :         virtual NodeType SAL_CALL getNodeType()
     221             :             throw (RuntimeException);
     222             : 
     223             :         /**
     224             :         The value of this node, depending on its type; see the table above.
     225             :         -- virtual implemented by actual node types
     226             :         */
     227             :         virtual OUString SAL_CALL getNodeValue()
     228             :             throw (RuntimeException);
     229             : 
     230             :         /**
     231             :         The Document object associated with this node.
     232             :         */
     233             :         virtual Reference< XDocument > SAL_CALL getOwnerDocument()
     234             :             throw (RuntimeException);
     235             : 
     236             :         /**
     237             :         The parent of this node.
     238             :         */
     239             :         virtual Reference< XNode > SAL_CALL getParentNode()
     240             :             throw (RuntimeException);
     241             : 
     242             :         /**
     243             :         The namespace prefix of this node, or null if it is unspecified.
     244             :         */
     245             :         virtual OUString SAL_CALL getPrefix()
     246             :             throw (RuntimeException);
     247             : 
     248             :         /**
     249             :         The node immediately preceding this node.
     250             :         */
     251             :         virtual Reference< XNode > SAL_CALL getPreviousSibling()
     252             :             throw (RuntimeException);
     253             : 
     254             :         /**
     255             :         Returns whether this node (if it is an element) has any attributes.
     256             :         */
     257             :         virtual sal_Bool SAL_CALL hasAttributes()
     258             :             throw (RuntimeException);
     259             : 
     260             :         /**
     261             :         Returns whether this node has any children.
     262             :         */
     263             :         virtual sal_Bool SAL_CALL hasChildNodes()
     264             :             throw (RuntimeException);
     265             : 
     266             :         /**
     267             :         Inserts the node newChild before the existing child node refChild.
     268             :         */
     269             :         virtual Reference< XNode > SAL_CALL insertBefore(
     270             :                 const Reference< XNode >& newChild, const Reference< XNode >& refChild)
     271             :             throw (RuntimeException, DOMException);
     272             : 
     273             :         /**
     274             :         Tests whether the DOM implementation implements a specific feature and
     275             :         that feature is supported by this node.
     276             :         */
     277             :         virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
     278             :             throw (RuntimeException);
     279             : 
     280             :         /**
     281             :         Puts all Text nodes in the full depth of the sub-tree underneath this
     282             :         Node, including attribute nodes, into a "normal" form where only structure
     283             :         (e.g., elements, comments, processing instructions, CDATA sections, and
     284             :         entity references) separates Text nodes, i.e., there are neither adjacent
     285             :         Text nodes nor empty Text nodes.
     286             :         */
     287             :         virtual void SAL_CALL normalize()
     288             :             throw (RuntimeException);
     289             : 
     290             :         /**
     291             :         Removes the child node indicated by oldChild from the list of children,
     292             :         and returns it.
     293             :         */
     294             :         virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
     295             :             throw (RuntimeException, DOMException);
     296             : 
     297             :         /**
     298             :         Replaces the child node oldChild with newChild in the list of children,
     299             :         and returns the oldChild node.
     300             :         */
     301             :         virtual Reference< XNode > SAL_CALL replaceChild(
     302             :                 const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
     303             :             throw (RuntimeException, DOMException);
     304             : 
     305             :         /**
     306             :         The value of this node, depending on its type; see the table above.
     307             :         */
     308             :         virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
     309             :             throw (RuntimeException, DOMException);
     310             : 
     311             :         /**
     312             :         The namespace prefix of this node, or null if it is unspecified.
     313             :         */
     314             :         virtual void SAL_CALL setPrefix(const OUString& prefix)
     315             :             throw (RuntimeException, DOMException);
     316             : 
     317             : 
     318             :         // --- XEventTarget
     319             :         virtual void SAL_CALL addEventListener(const OUString& eventType,
     320             :             const Reference< XEventListener >& listener,
     321             :             sal_Bool useCapture)
     322             :             throw (RuntimeException);
     323             : 
     324             :         virtual void SAL_CALL removeEventListener(const OUString& eventType,
     325             :             const Reference< XEventListener >& listener,
     326             :             sal_Bool useCapture)
     327             :             throw (RuntimeException);
     328             : 
     329             :         virtual sal_Bool SAL_CALL dispatchEvent(const Reference< XEvent >& evt)
     330             :             throw(RuntimeException, EventException);
     331             : 
     332             :         // --- XUnoTunnel
     333             :         virtual ::sal_Int64 SAL_CALL
     334             :             getSomething(Sequence< ::sal_Int8 > const& rId)
     335             :             throw (RuntimeException);
     336             :     };
     337             : 
     338             :     /// eliminate redundant namespace declarations
     339             :     void nscleanup(const xmlNodePtr aNode, const xmlNodePtr aParent);
     340             : }
     341             : 
     342             : #endif
     343             : 
     344             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10