LCOV - code coverage report
Current view: top level - libreoffice/unoxml/source/dom - document.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 206 460 44.8 %
Date: 2012-12-17 Functions: 21 49 42.9 %
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             : #include <com/sun/star/uno/Sequence.h>
      21             : 
      22             : #include "document.hxx"
      23             : #include "attr.hxx"
      24             : #include "element.hxx"
      25             : #include "cdatasection.hxx"
      26             : #include "documentfragment.hxx"
      27             : #include "text.hxx"
      28             : #include "cdatasection.hxx"
      29             : #include "comment.hxx"
      30             : #include "processinginstruction.hxx"
      31             : #include "entityreference.hxx"
      32             : #include "documenttype.hxx"
      33             : #include "elementlist.hxx"
      34             : #include "domimplementation.hxx"
      35             : #include <entity.hxx>
      36             : #include <notation.hxx>
      37             : 
      38             : #include "../events/event.hxx"
      39             : #include "../events/mutationevent.hxx"
      40             : #include "../events/uievent.hxx"
      41             : #include "../events/mouseevent.hxx"
      42             : #include "../events/eventdispatcher.hxx"
      43             : 
      44             : #include <string.h>
      45             : 
      46             : #include <com/sun/star/xml/sax/FastToken.hpp>
      47             : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      48             : 
      49             : namespace DOM
      50             : {
      51           0 :     static xmlNodePtr lcl_getDocumentType(xmlDocPtr const i_pDocument)
      52             :     {
      53             :         // find the doc type
      54           0 :         xmlNodePtr cur = i_pDocument->children;
      55           0 :         while (cur != NULL)
      56             :         {
      57           0 :             if ((cur->type == XML_DOCUMENT_TYPE_NODE) ||
      58             :                 (cur->type == XML_DTD_NODE)) {
      59           0 :                     return cur;
      60             :             }
      61             :         }
      62           0 :         return 0;
      63             :     }
      64             : 
      65             :     /// get the pointer to the root element node of the document
      66        2495 :     static xmlNodePtr lcl_getDocumentRootPtr(xmlDocPtr const i_pDocument)
      67             :     {
      68             :         // find the document element
      69        2495 :         xmlNodePtr cur = i_pDocument->children;
      70        4990 :         while (cur != NULL)
      71             :         {
      72         136 :             if (cur->type == XML_ELEMENT_NODE)
      73         136 :                 break;
      74           0 :             cur = cur->next;
      75             :         }
      76        2495 :         return cur;
      77             :     }
      78             : 
      79        2383 :     CDocument::CDocument(xmlDocPtr const pDoc)
      80             :         : CDocument_Base(*this, m_Mutex,
      81             :                 NodeType_DOCUMENT_NODE, reinterpret_cast<xmlNodePtr>(pDoc))
      82             :         , m_aDocPtr(pDoc)
      83             :         , m_streamListeners()
      84        2383 :         , m_pEventDispatcher(new events::CEventDispatcher())
      85             :     {
      86        2383 :     }
      87             : 
      88        2383 :     ::rtl::Reference<CDocument> CDocument::CreateCDocument(xmlDocPtr const pDoc)
      89             :     {
      90        2383 :         ::rtl::Reference<CDocument> const xDoc(new CDocument(pDoc));
      91             :         // add the doc itself to its nodemap!
      92        2383 :         xDoc->m_NodeMap.insert(
      93             :             nodemap_t::value_type(reinterpret_cast<xmlNodePtr>(pDoc),
      94             :                 ::std::make_pair(
      95        2383 :                     WeakReference<XNode>(static_cast<XDocument*>(xDoc.get())),
      96        7149 :                     xDoc.get())));
      97        2383 :         return xDoc;
      98             :     }
      99             : 
     100        5619 :     CDocument::~CDocument()
     101             :     {
     102        1873 :         ::osl::MutexGuard const g(m_Mutex);
     103             : #ifdef DBG_UTIL
     104             :         // node map must be empty now, otherwise CDocument must not die!
     105             :         for (nodemap_t::iterator i = m_NodeMap.begin();
     106             :                 i != m_NodeMap.end(); ++i)
     107             :         {
     108             :             Reference<XNode> const xNode(i->second.first);
     109             :             OSL_ENSURE(!xNode.is(),
     110             :             "CDocument::~CDocument(): ERROR: live node in document node map!");
     111             :         }
     112             : #endif
     113        1873 :         xmlFreeDoc(m_aDocPtr);
     114        3746 :     }
     115             : 
     116             : 
     117       36372 :     events::CEventDispatcher & CDocument::GetEventDispatcher()
     118             :     {
     119       36372 :         return *m_pEventDispatcher;
     120             :     }
     121             : 
     122           0 :     ::rtl::Reference< CElement > CDocument::GetDocumentElement()
     123             :     {
     124           0 :         xmlNodePtr const pNode = lcl_getDocumentRootPtr(m_aDocPtr);
     125             :         ::rtl::Reference< CElement > const xRet(
     126           0 :             dynamic_cast<CElement*>(GetCNode(pNode).get()));
     127           0 :         return xRet;
     128             :     }
     129             : 
     130             :     void
     131       36212 :     CDocument::RemoveCNode(xmlNodePtr const pNode, CNode const*const pCNode)
     132             :     {
     133       36212 :         nodemap_t::iterator const i = m_NodeMap.find(pNode);
     134       36212 :         if (i != m_NodeMap.end()) {
     135             :             // #i113681# consider this scenario:
     136             :             // T1 calls ~CNode
     137             :             // T2 calls getCNode:    lookup will find i->second->first invalid
     138             :             //                       so a new CNode is created and inserted
     139             :             // T1 calls removeCNode: i->second->second now points to a
     140             :             //                       different CNode instance!
     141             :             //
     142             :             // check that the CNode is the right one
     143       36212 :             CNode *const pCurrent = i->second.second;
     144       36212 :             if (pCurrent == pCNode) {
     145       36212 :                 m_NodeMap.erase(i);
     146             :             }
     147             :         }
     148       36212 :     }
     149             : 
     150             :     /** NB: this is the CNode factory.
     151             :         it is the only place where CNodes may be instantiated.
     152             :         all CNodes must be registered at the m_NodeMap.
     153             :      */
     154             :     ::rtl::Reference<CNode>
     155      165351 :     CDocument::GetCNode(xmlNodePtr const pNode, bool const bCreate)
     156             :     {
     157      165351 :         if (0 == pNode) {
     158       42273 :             return 0;
     159             :         }
     160             :         //check whether there is already an instance for this node
     161      123078 :         nodemap_t::const_iterator const i = m_NodeMap.find(pNode);
     162      123078 :         if (i != m_NodeMap.end()) {
     163             :             // #i113681# check that the CNode is still alive
     164       84894 :             uno::Reference<XNode> const xNode(i->second.first);
     165       84894 :             if (xNode.is())
     166             :             {
     167       84894 :                 ::rtl::Reference<CNode> ret(i->second.second);
     168             :                 OSL_ASSERT(ret.is());
     169       84894 :                 return ret;
     170       84894 :             }
     171             :         }
     172             : 
     173       38184 :         if (!bCreate) { return 0; }
     174             : 
     175             :         // there is not yet an instance wrapping this node,
     176             :         // create it and store it in the map
     177             : 
     178       38184 :         ::rtl::Reference<CNode> pCNode;
     179       38184 :         switch (pNode->type)
     180             :         {
     181             :             case XML_ELEMENT_NODE:
     182             :                 // m_aNodeType = NodeType::ELEMENT_NODE;
     183             :                 pCNode = static_cast< CNode* >(
     184       23835 :                         new CElement(*this, m_Mutex, pNode));
     185       23835 :             break;
     186             :             case XML_TEXT_NODE:
     187             :                 // m_aNodeType = NodeType::TEXT_NODE;
     188             :                 pCNode = static_cast< CNode* >(
     189        5571 :                         new CText(*this, m_Mutex, pNode));
     190        5571 :             break;
     191             :             case XML_CDATA_SECTION_NODE:
     192             :                 // m_aNodeType = NodeType::CDATA_SECTION_NODE;
     193             :                 pCNode = static_cast< CNode* >(
     194           0 :                         new CCDATASection(*this, m_Mutex, pNode));
     195           0 :             break;
     196             :             case XML_ENTITY_REF_NODE:
     197             :                 // m_aNodeType = NodeType::ENTITY_REFERENCE_NODE;
     198             :                 pCNode = static_cast< CNode* >(
     199           0 :                         new CEntityReference(*this, m_Mutex, pNode));
     200           0 :             break;
     201             :             case XML_ENTITY_NODE:
     202             :                 // m_aNodeType = NodeType::ENTITY_NODE;
     203             :                 pCNode = static_cast< CNode* >(new CEntity(*this, m_Mutex,
     204           0 :                             reinterpret_cast<xmlEntityPtr>(pNode)));
     205           0 :             break;
     206             :             case XML_PI_NODE:
     207             :                 // m_aNodeType = NodeType::PROCESSING_INSTRUCTION_NODE;
     208             :                 pCNode = static_cast< CNode* >(
     209           0 :                         new CProcessingInstruction(*this, m_Mutex, pNode));
     210           0 :             break;
     211             :             case XML_COMMENT_NODE:
     212             :                 // m_aNodeType = NodeType::COMMENT_NODE;
     213             :                 pCNode = static_cast< CNode* >(
     214           0 :                         new CComment(*this, m_Mutex, pNode));
     215           0 :             break;
     216             :             case XML_DOCUMENT_NODE:
     217             :                 // m_aNodeType = NodeType::DOCUMENT_NODE;
     218             :                 OSL_ENSURE(false, "CDocument::GetCNode is not supposed to"
     219             :                         " create a CDocument!!!");
     220             :                 pCNode = static_cast< CNode* >(new CDocument(
     221           0 :                             reinterpret_cast<xmlDocPtr>(pNode)));
     222           0 :             break;
     223             :             case XML_DOCUMENT_TYPE_NODE:
     224             :             case XML_DTD_NODE:
     225             :                 // m_aNodeType = NodeType::DOCUMENT_TYPE_NODE;
     226             :                 pCNode = static_cast< CNode* >(new CDocumentType(*this, m_Mutex,
     227           0 :                             reinterpret_cast<xmlDtdPtr>(pNode)));
     228           0 :             break;
     229             :             case XML_DOCUMENT_FRAG_NODE:
     230             :                 // m_aNodeType = NodeType::DOCUMENT_FRAGMENT_NODE;
     231             :                 pCNode = static_cast< CNode* >(
     232           0 :                         new CDocumentFragment(*this, m_Mutex, pNode));
     233           0 :             break;
     234             :             case XML_NOTATION_NODE:
     235             :                 // m_aNodeType = NodeType::NOTATION_NODE;
     236             :                 pCNode = static_cast< CNode* >(new CNotation(*this, m_Mutex,
     237           0 :                             reinterpret_cast<xmlNotationPtr>(pNode)));
     238           0 :             break;
     239             :             case XML_ATTRIBUTE_NODE:
     240             :                 // m_aNodeType = NodeType::ATTRIBUTE_NODE;
     241             :                 pCNode = static_cast< CNode* >(new CAttr(*this, m_Mutex,
     242        8778 :                             reinterpret_cast<xmlAttrPtr>(pNode)));
     243        8778 :             break;
     244             :             // unsupported node types
     245             :             case XML_HTML_DOCUMENT_NODE:
     246             :             case XML_ELEMENT_DECL:
     247             :             case XML_ATTRIBUTE_DECL:
     248             :             case XML_ENTITY_DECL:
     249             :             case XML_NAMESPACE_DECL:
     250             :             default:
     251           0 :             break;
     252             :         }
     253             : 
     254       38184 :         if (pCNode != 0) {
     255             :             bool const bInserted = m_NodeMap.insert(
     256             :                     nodemap_t::value_type(pNode,
     257       38184 :                         ::std::make_pair(WeakReference<XNode>(pCNode.get()),
     258       38184 :                         pCNode.get()))
     259       76368 :                 ).second;
     260             :             OSL_ASSERT(bInserted);
     261       38184 :             if (!bInserted) {
     262             :                 // if insertion failed, delete new instance and return null
     263           0 :                 return 0;
     264             :             }
     265             :         }
     266             : 
     267             :         OSL_ENSURE(pCNode.is(), "no node produced during CDocument::GetCNode!");
     268       38184 :         return pCNode;
     269             :     }
     270             : 
     271             : 
     272       17522 :     CDocument & CDocument::GetOwnerDocument()
     273             :     {
     274       17522 :         return *this;
     275             :     }
     276             : 
     277           8 :     void CDocument::saxify(const Reference< XDocumentHandler >& i_xHandler)
     278             :     {
     279           8 :         i_xHandler->startDocument();
     280          16 :         for (xmlNodePtr pChild = m_aNodePtr->children;
     281             :                         pChild != 0; pChild = pChild->next) {
     282           8 :             ::rtl::Reference<CNode> const pNode = GetCNode(pChild);
     283             :             OSL_ENSURE(pNode != 0, "CNode::get returned 0");
     284           8 :             pNode->saxify(i_xHandler);
     285           8 :         }
     286           8 :         i_xHandler->endDocument();
     287           8 :     }
     288             : 
     289          12 :     void CDocument::fastSaxify( Context& rContext )
     290             :     {
     291          12 :         rContext.mxDocHandler->startDocument();
     292          24 :         for (xmlNodePtr pChild = m_aNodePtr->children;
     293             :                         pChild != 0; pChild = pChild->next) {
     294          12 :             ::rtl::Reference<CNode> const pNode = GetCNode(pChild);
     295             :             OSL_ENSURE(pNode != 0, "CNode::get returned 0");
     296          12 :             pNode->fastSaxify(rContext);
     297          12 :         }
     298          12 :         rContext.mxDocHandler->endDocument();
     299          12 :     }
     300             : 
     301        2359 :     bool CDocument::IsChildTypeAllowed(NodeType const nodeType)
     302             :     {
     303        2359 :         switch (nodeType) {
     304             :             case NodeType_PROCESSING_INSTRUCTION_NODE:
     305             :             case NodeType_COMMENT_NODE:
     306           0 :                 return true;
     307             :             case NodeType_ELEMENT_NODE:
     308             :                  // there may be only one!
     309        2359 :                 return 0 == lcl_getDocumentRootPtr(m_aDocPtr);
     310             :             case NodeType_DOCUMENT_TYPE_NODE:
     311             :                  // there may be only one!
     312           0 :                 return 0 == lcl_getDocumentType(m_aDocPtr);
     313             :             default:
     314           0 :                 return false;
     315             :         }
     316             :     }
     317             : 
     318             : 
     319           0 :     void SAL_CALL CDocument::addListener(const Reference< XStreamListener >& aListener )
     320             :         throw (RuntimeException)
     321             :     {
     322           0 :         ::osl::MutexGuard const g(m_Mutex);
     323             : 
     324           0 :         m_streamListeners.insert(aListener);
     325           0 :     }
     326             : 
     327           0 :     void SAL_CALL CDocument::removeListener(const Reference< XStreamListener >& aListener )
     328             :         throw (RuntimeException)
     329             :     {
     330           0 :         ::osl::MutexGuard const g(m_Mutex);
     331             : 
     332           0 :         m_streamListeners.erase(aListener);
     333           0 :     }
     334             : 
     335             :     // IO context functions for libxml2 interaction
     336             :     typedef struct {
     337             :         Reference< XOutputStream > stream;
     338             :         bool allowClose;
     339           0 :     } IOContext;
     340             : 
     341             :     extern "C" {
     342             :     // write callback
     343             :     // int xmlOutputWriteCallback (void * context, const char * buffer, int len)
     344           0 :     static int writeCallback(void *context, const char* buffer, int len){
     345             :         // create a sequence and write it to the stream
     346           0 :         IOContext *pContext = static_cast<IOContext*>(context);
     347           0 :         Sequence<sal_Int8> bs(reinterpret_cast<const sal_Int8*>(buffer), len);
     348           0 :         pContext->stream->writeBytes(bs);
     349           0 :         return len;
     350             :     }
     351             : 
     352             :     // clsoe callback
     353             :     //int xmlOutputCloseCallback (void * context)
     354           0 :     static int closeCallback(void *context)
     355             :     {
     356           0 :         IOContext *pContext = static_cast<IOContext*>(context);
     357           0 :         if (pContext->allowClose) {
     358           0 :             pContext->stream->closeOutput();
     359             :         }
     360           0 :         return 0;
     361             :     }
     362             :     } // extern "C"
     363             : 
     364           0 :     void SAL_CALL CDocument::start()
     365             :         throw (RuntimeException)
     366             :     {
     367           0 :         listenerlist_t streamListeners;
     368             :         {
     369           0 :             ::osl::MutexGuard const g(m_Mutex);
     370             : 
     371           0 :             if (! m_rOutputStream.is()) { throw RuntimeException(); }
     372           0 :             streamListeners = m_streamListeners;
     373             :         }
     374             : 
     375             :         // notify listeners about start
     376           0 :         listenerlist_t::const_iterator iter1 = streamListeners.begin();
     377           0 :         while (iter1 != streamListeners.end()) {
     378           0 :             Reference< XStreamListener > aListener = *iter1;
     379           0 :             aListener->started();
     380           0 :             ++iter1;
     381           0 :         }
     382             : 
     383             :         {
     384           0 :             ::osl::MutexGuard const g(m_Mutex);
     385             : 
     386             :             // check again! could have been reset...
     387           0 :             if (! m_rOutputStream.is()) { throw RuntimeException(); }
     388             : 
     389             :             // setup libxml IO and write data to output stream
     390           0 :             IOContext ioctx = {m_rOutputStream, false};
     391             :             xmlOutputBufferPtr pOut = xmlOutputBufferCreateIO(
     392           0 :                 writeCallback, closeCallback, &ioctx, NULL);
     393           0 :             xmlSaveFileTo(pOut, m_aNodePtr->doc, NULL);
     394             :         }
     395             : 
     396             :         // call listeners
     397           0 :         listenerlist_t::const_iterator iter2 = streamListeners.begin();
     398           0 :         while (iter2 != streamListeners.end()) {
     399           0 :             Reference< XStreamListener > aListener = *iter2;
     400           0 :             aListener->closed();
     401           0 :             ++iter2;
     402           0 :         }
     403           0 :     }
     404             : 
     405           0 :     void SAL_CALL CDocument::terminate()
     406             :         throw (RuntimeException)
     407             :     {
     408             :         // not supported
     409           0 :     }
     410             : 
     411           0 :     void SAL_CALL CDocument::setOutputStream( const Reference< XOutputStream >& aStream )
     412             :         throw (RuntimeException)
     413             :     {
     414           0 :         ::osl::MutexGuard const g(m_Mutex);
     415             : 
     416           0 :         m_rOutputStream = aStream;
     417           0 :     }
     418             : 
     419           0 :     Reference< XOutputStream > SAL_CALL  CDocument::getOutputStream() throw (RuntimeException)
     420             :     {
     421           0 :         ::osl::MutexGuard const g(m_Mutex);
     422             : 
     423           0 :         return m_rOutputStream;
     424             :     }
     425             : 
     426             :     // Creates an Attr of the given name.
     427           0 :     Reference< XAttr > SAL_CALL CDocument::createAttribute(const OUString& name)
     428             :         throw (RuntimeException, DOMException)
     429             :     {
     430           0 :         ::osl::MutexGuard const g(m_Mutex);
     431             : 
     432           0 :         OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
     433           0 :         xmlChar *xName = (xmlChar*)o1.getStr();
     434           0 :         xmlAttrPtr const pAttr = xmlNewDocProp(m_aDocPtr, xName, NULL);
     435             :         ::rtl::Reference< CAttr > const pCAttr(
     436             :             dynamic_cast< CAttr* >(GetCNode(
     437           0 :                     reinterpret_cast<xmlNodePtr>(pAttr)).get()));
     438           0 :         pCAttr->m_bUnlinked = true;
     439           0 :         return pCAttr.get();
     440             :     };
     441             : 
     442             :     // Creates an attribute of the given qualified name and namespace URI.
     443           0 :     Reference< XAttr > SAL_CALL CDocument::createAttributeNS(
     444             :             const OUString& ns, const OUString& qname)
     445             :         throw (RuntimeException, DOMException)
     446             :     {
     447           0 :         ::osl::MutexGuard const g(m_Mutex);
     448             : 
     449             :         // libxml does not allow a NS definition to be attached to an
     450             :         // attribute node - which is a good thing, since namespaces are
     451             :         // only defined as parts of element nodes
     452             :         // thus the namespace data is stored in CAttr::m_pNamespace
     453           0 :         sal_Int32 i = qname.indexOf(':');
     454           0 :         OString oPrefix, oName, oUri;
     455           0 :         if (i != -1)
     456             :         {
     457           0 :             oPrefix = OUStringToOString(qname.copy(0, i), RTL_TEXTENCODING_UTF8);
     458           0 :             oName = OUStringToOString(qname.copy(i+1, qname.getLength()-i-1), RTL_TEXTENCODING_UTF8);
     459             :         }
     460             :         else
     461             :         {
     462           0 :             oName = OUStringToOString(qname, RTL_TEXTENCODING_UTF8);
     463             :         }
     464           0 :         oUri = OUStringToOString(ns, RTL_TEXTENCODING_UTF8);
     465             :         xmlAttrPtr const pAttr = xmlNewDocProp(m_aDocPtr,
     466           0 :                 reinterpret_cast<xmlChar const*>(oName.getStr()), 0);
     467             :         ::rtl::Reference< CAttr > const pCAttr(
     468             :             dynamic_cast< CAttr* >(GetCNode(
     469           0 :                     reinterpret_cast<xmlNodePtr>(pAttr)).get()));
     470           0 :         if (!pCAttr.is()) { throw RuntimeException(); }
     471             :         // store the namespace data!
     472           0 :         pCAttr->m_pNamespace.reset( new stringpair_t(oUri, oPrefix) );
     473           0 :         pCAttr->m_bUnlinked = true;
     474             : 
     475           0 :         return pCAttr.get();
     476             :     };
     477             : 
     478             :     // Creates a CDATASection node whose value is the specified string.
     479           0 :     Reference< XCDATASection > SAL_CALL CDocument::createCDATASection(const OUString& data)
     480             :         throw (RuntimeException)
     481             :     {
     482           0 :         ::osl::MutexGuard const g(m_Mutex);
     483             : 
     484             :         OString const oData(
     485           0 :                 ::rtl::OUStringToOString(data, RTL_TEXTENCODING_UTF8));
     486             :         xmlChar const*const pData =
     487           0 :             reinterpret_cast<xmlChar const*>(oData.getStr());
     488             :         xmlNodePtr const pText =
     489           0 :             xmlNewCDataBlock(m_aDocPtr, pData, strlen(oData.getStr()));
     490             :         Reference< XCDATASection > const xRet(
     491           0 :             static_cast< XNode* >(GetCNode(pText).get()),
     492           0 :             UNO_QUERY_THROW);
     493           0 :         return xRet;
     494             :     }
     495             : 
     496             :     // Creates a Comment node given the specified string.
     497           0 :     Reference< XComment > SAL_CALL CDocument::createComment(const OUString& data)
     498             :         throw (RuntimeException)
     499             :     {
     500           0 :         ::osl::MutexGuard const g(m_Mutex);
     501             : 
     502           0 :         OString o1 = OUStringToOString(data, RTL_TEXTENCODING_UTF8);
     503           0 :         xmlChar *xData = (xmlChar*)o1.getStr();
     504           0 :         xmlNodePtr pComment = xmlNewDocComment(m_aDocPtr, xData);
     505             :         Reference< XComment > const xRet(
     506           0 :             static_cast< XNode* >(GetCNode(pComment).get()),
     507           0 :             UNO_QUERY_THROW);
     508           0 :         return xRet;
     509             :     }
     510             : 
     511             :     //Creates an empty DocumentFragment object.
     512           0 :     Reference< XDocumentFragment > SAL_CALL CDocument::createDocumentFragment()
     513             :         throw (RuntimeException)
     514             :     {
     515           0 :         ::osl::MutexGuard const g(m_Mutex);
     516             : 
     517           0 :         xmlNodePtr pFrag = xmlNewDocFragment(m_aDocPtr);
     518             :         Reference< XDocumentFragment > const xRet(
     519           0 :             static_cast< XNode* >(GetCNode(pFrag).get()),
     520           0 :             UNO_QUERY_THROW);
     521           0 :         return xRet;
     522             :     }
     523             : 
     524             :     // Creates an element of the type specified.
     525           0 :     Reference< XElement > SAL_CALL CDocument::createElement(const OUString& tagName)
     526             :         throw (RuntimeException, DOMException)
     527             :     {
     528           0 :         ::osl::MutexGuard const g(m_Mutex);
     529             : 
     530           0 :         OString o1 = OUStringToOString(tagName, RTL_TEXTENCODING_UTF8);
     531           0 :         xmlChar *xName = (xmlChar*)o1.getStr();
     532           0 :         xmlNodePtr const pNode = xmlNewDocNode(m_aDocPtr, NULL, xName, NULL);
     533             :         Reference< XElement > const xRet(
     534           0 :             static_cast< XNode* >(GetCNode(pNode).get()),
     535           0 :             UNO_QUERY_THROW);
     536           0 :         return xRet;
     537             :     }
     538             : 
     539             :     // Creates an element of the given qualified name and namespace URI.
     540        8744 :     Reference< XElement > SAL_CALL CDocument::createElementNS(
     541             :             const OUString& ns, const OUString& qname)
     542             :         throw (RuntimeException, DOMException)
     543             :     {
     544        8744 :         ::osl::MutexGuard const g(m_Mutex);
     545             : 
     546        8744 :         sal_Int32 i = qname.indexOf(':');
     547        8744 :         if (ns.isEmpty()) throw RuntimeException();
     548             :         xmlChar *xPrefix;
     549             :         xmlChar *xName;
     550        8744 :         OString o1, o2, o3;
     551        8744 :         if ( i != -1) {
     552        8744 :             o1 = OUStringToOString(qname.copy(0, i), RTL_TEXTENCODING_UTF8);
     553        8744 :             xPrefix = (xmlChar*)o1.getStr();
     554        8744 :             o2 = OUStringToOString(qname.copy(i+1, qname.getLength()-i-1), RTL_TEXTENCODING_UTF8);
     555        8744 :             xName = (xmlChar*)o2.getStr();
     556             :         } else {
     557             :             // default prefix
     558           0 :             xPrefix = (xmlChar*)"";
     559           0 :             o2 = OUStringToOString(qname, RTL_TEXTENCODING_UTF8);
     560           0 :             xName = (xmlChar*)o2.getStr();
     561             :         }
     562        8744 :         o3 = OUStringToOString(ns, RTL_TEXTENCODING_UTF8);
     563        8744 :         xmlChar *xUri = (xmlChar*)o3.getStr();
     564             : 
     565             :         // xmlNsPtr aNsPtr = xmlNewReconciledNs?
     566             :         // xmlNsPtr aNsPtr = xmlNewGlobalNs?
     567        8744 :         xmlNodePtr const pNode = xmlNewDocNode(m_aDocPtr, NULL, xName, NULL);
     568        8744 :         xmlNsPtr const pNs = xmlNewNs(pNode, xUri, xPrefix);
     569        8744 :         xmlSetNs(pNode, pNs);
     570             :         Reference< XElement > const xRet(
     571       17488 :             static_cast< XNode* >(GetCNode(pNode).get()),
     572        8744 :             UNO_QUERY_THROW);
     573        8744 :         return xRet;
     574             :     }
     575             : 
     576             :     //Creates an EntityReference object.
     577           0 :     Reference< XEntityReference > SAL_CALL CDocument::createEntityReference(const OUString& name)
     578             :         throw (RuntimeException, DOMException)
     579             :     {
     580           0 :         ::osl::MutexGuard const g(m_Mutex);
     581             : 
     582           0 :         OString o1 = OUStringToOString(name, RTL_TEXTENCODING_UTF8);
     583           0 :         xmlChar *xName = (xmlChar*)o1.getStr();
     584           0 :         xmlNodePtr const pNode = xmlNewReference(m_aDocPtr, xName);
     585             :         Reference< XEntityReference > const xRet(
     586           0 :             static_cast< XNode* >(GetCNode(pNode).get()),
     587           0 :             UNO_QUERY_THROW);
     588           0 :         return xRet;
     589             :     }
     590             : 
     591             :     // Creates a ProcessingInstruction node given the specified name and
     592             :     // data strings.
     593           0 :     Reference< XProcessingInstruction > SAL_CALL CDocument::createProcessingInstruction(
     594             :             const OUString& target, const OUString& data)
     595             :         throw (RuntimeException, DOMException)
     596             :     {
     597           0 :         ::osl::MutexGuard const g(m_Mutex);
     598             : 
     599           0 :         OString o1 = OUStringToOString(target, RTL_TEXTENCODING_UTF8);
     600           0 :         xmlChar *xTarget = (xmlChar*)o1.getStr();
     601           0 :         OString o2 = OUStringToOString(data, RTL_TEXTENCODING_UTF8);
     602           0 :         xmlChar *xData = (xmlChar*)o2.getStr();
     603           0 :         xmlNodePtr const pNode = xmlNewDocPI(m_aDocPtr, xTarget, xData);
     604           0 :         pNode->doc = m_aDocPtr;
     605             :         Reference< XProcessingInstruction > const xRet(
     606           0 :             static_cast< XNode* >(GetCNode(pNode).get()),
     607           0 :             UNO_QUERY_THROW);
     608           0 :         return xRet;
     609             :     }
     610             : 
     611             :     // Creates a Text node given the specified string.
     612        3360 :     Reference< XText > SAL_CALL CDocument::createTextNode(const OUString& data)
     613             :         throw (RuntimeException)
     614             :     {
     615        3360 :         ::osl::MutexGuard const g(m_Mutex);
     616             : 
     617        3360 :         OString o1 = OUStringToOString(data, RTL_TEXTENCODING_UTF8);
     618        3360 :         xmlChar *xData = (xmlChar*)o1.getStr();
     619        3360 :         xmlNodePtr const pNode = xmlNewDocText(m_aDocPtr, xData);
     620             :         Reference< XText > const xRet(
     621        6720 :             static_cast< XNode* >(GetCNode(pNode).get()),
     622        3360 :             UNO_QUERY_THROW);
     623        3360 :         return xRet;
     624             :     }
     625             : 
     626             :     // The Document Type Declaration (see DocumentType) associated with this
     627             :     // document.
     628           0 :     Reference< XDocumentType > SAL_CALL CDocument::getDoctype()
     629             :         throw (RuntimeException)
     630             :     {
     631           0 :         ::osl::MutexGuard const g(m_Mutex);
     632             : 
     633           0 :         xmlNodePtr const pDocType(lcl_getDocumentType(m_aDocPtr));
     634             :         Reference< XDocumentType > const xRet(
     635           0 :             static_cast< XNode* >(GetCNode(pDocType).get()),
     636           0 :             UNO_QUERY);
     637           0 :         return xRet;
     638             :     }
     639             : 
     640             :     // This is a convenience attribute that allows direct access to the child
     641             :     // node that is the root element of the document.
     642         116 :     Reference< XElement > SAL_CALL CDocument::getDocumentElement()
     643             :         throw (RuntimeException)
     644             :     {
     645         116 :         ::osl::MutexGuard const g(m_Mutex);
     646             : 
     647         116 :         xmlNodePtr const pNode = lcl_getDocumentRootPtr(m_aDocPtr);
     648         116 :         if (!pNode) { return 0; }
     649             :         Reference< XElement > const xRet(
     650         232 :             static_cast< XNode* >(GetCNode(pNode).get()),
     651         116 :             UNO_QUERY);
     652         116 :         return xRet;
     653             :     }
     654             : 
     655             :     static xmlNodePtr
     656           0 :     lcl_search_element_by_id(const xmlNodePtr cur, const xmlChar* id)
     657             :     {
     658           0 :         if (cur == NULL)
     659           0 :             return NULL;
     660             :         // look in current node
     661           0 :         if (cur->type == XML_ELEMENT_NODE)
     662             :         {
     663           0 :             xmlAttrPtr a = cur->properties;
     664           0 :             while (a != NULL)
     665             :             {
     666           0 :                 if (a->atype == XML_ATTRIBUTE_ID) {
     667           0 :                     if (strcmp((char*)a->children->content, (char*)id) == 0)
     668           0 :                         return cur;
     669             :                 }
     670           0 :                 a = a->next;
     671             :             }
     672             :         }
     673             :         // look in children
     674           0 :         xmlNodePtr result = lcl_search_element_by_id(cur->children, id);
     675           0 :         if (result != NULL)
     676           0 :             return result;
     677           0 :         result = lcl_search_element_by_id(cur->next, id);
     678           0 :             return result;
     679             :     }
     680             : 
     681             :     // Returns the Element whose ID is given by elementId.
     682             :     Reference< XElement > SAL_CALL
     683           0 :     CDocument::getElementById(const OUString& elementId)
     684             :         throw (RuntimeException)
     685             :     {
     686           0 :         ::osl::MutexGuard const g(m_Mutex);
     687             : 
     688             :         // search the tree for an element with the given ID
     689           0 :         OString o1 = OUStringToOString(elementId, RTL_TEXTENCODING_UTF8);
     690           0 :         xmlChar *xId = (xmlChar*)o1.getStr();
     691           0 :         xmlNodePtr const pStart = lcl_getDocumentRootPtr(m_aDocPtr);
     692           0 :         if (!pStart) { return 0; }
     693           0 :         xmlNodePtr const pNode = lcl_search_element_by_id(pStart, xId);
     694             :         Reference< XElement > const xRet(
     695           0 :             static_cast< XNode* >(GetCNode(pNode).get()),
     696           0 :             UNO_QUERY);
     697           0 :         return xRet;
     698             :     }
     699             : 
     700             : 
     701             :     Reference< XNodeList > SAL_CALL
     702           0 :     CDocument::getElementsByTagName(OUString const& rTagname)
     703             :             throw (RuntimeException)
     704             :     {
     705           0 :         ::osl::MutexGuard const g(m_Mutex);
     706             : 
     707             :         Reference< XNodeList > const xRet(
     708           0 :             new CElementList(this->GetDocumentElement(), m_Mutex, rTagname));
     709           0 :         return xRet;
     710             :     }
     711             : 
     712           0 :     Reference< XNodeList > SAL_CALL CDocument::getElementsByTagNameNS(
     713             :             OUString const& rNamespaceURI, OUString const& rLocalName)
     714             :         throw (RuntimeException)
     715             :     {
     716           0 :         ::osl::MutexGuard const g(m_Mutex);
     717             : 
     718             :         Reference< XNodeList > const xRet(
     719             :             new CElementList(this->GetDocumentElement(), m_Mutex,
     720           0 :                 rLocalName, &rNamespaceURI));
     721           0 :         return xRet;
     722             :     }
     723             : 
     724           0 :     Reference< XDOMImplementation > SAL_CALL CDocument::getImplementation()
     725             :         throw (RuntimeException)
     726             :     {
     727             :         // does not need mutex currently
     728           0 :         return Reference< XDOMImplementation >(CDOMImplementation::get());
     729             :     }
     730             : 
     731             :     // helper function to recursively import siblings
     732         606 :     static void lcl_ImportSiblings(
     733             :         Reference< XDocument > const& xTargetDocument,
     734             :         Reference< XNode > const& xTargetParent,
     735             :         Reference< XNode > const& xChild)
     736             :     {
     737         606 :         Reference< XNode > xSibling = xChild;
     738        2216 :         while (xSibling.is())
     739             :         {
     740             :             Reference< XNode > const xTmp(
     741        1004 :                     xTargetDocument->importNode(xSibling, sal_True));
     742        1004 :             xTargetParent->appendChild(xTmp);
     743        1004 :             xSibling = xSibling->getNextSibling();
     744        1610 :         }
     745         606 :     }
     746             : 
     747             :     static Reference< XNode >
     748        1120 :     lcl_ImportNode( Reference< XDocument > const& xDocument,
     749             :             Reference< XNode > const& xImportedNode, sal_Bool deep)
     750             :     {
     751        1120 :         Reference< XNode > xNode;
     752        1120 :         NodeType aNodeType = xImportedNode->getNodeType();
     753        1120 :         switch (aNodeType)
     754             :         {
     755             :         case NodeType_ATTRIBUTE_NODE:
     756             :         {
     757           0 :             Reference< XAttr > const xAttr(xImportedNode, UNO_QUERY_THROW);
     758             :             Reference< XAttr > const xNew =
     759           0 :                 xDocument->createAttribute(xAttr->getName());
     760           0 :             xNew->setValue(xAttr->getValue());
     761           0 :             xNode.set(xNew, UNO_QUERY);
     762           0 :             break;
     763             :         }
     764             :         case NodeType_CDATA_SECTION_NODE:
     765             :         {
     766             :             Reference< XCDATASection > const xCData(xImportedNode,
     767           0 :                     UNO_QUERY_THROW);
     768             :             Reference< XCDATASection > const xNewCData =
     769           0 :                 xDocument->createCDATASection(xCData->getData());
     770           0 :             xNode.set(xNewCData, UNO_QUERY);
     771           0 :             break;
     772             :         }
     773             :         case NodeType_COMMENT_NODE:
     774             :         {
     775             :             Reference< XComment > const xComment(xImportedNode,
     776           0 :                     UNO_QUERY_THROW);
     777             :             Reference< XComment > const xNewComment =
     778           0 :                 xDocument->createComment(xComment->getData());
     779           0 :             xNode.set(xNewComment, UNO_QUERY);
     780           0 :             break;
     781             :         }
     782             :         case NodeType_DOCUMENT_FRAGMENT_NODE:
     783             :         {
     784             :             Reference< XDocumentFragment > const xFrag(xImportedNode,
     785           0 :                     UNO_QUERY_THROW);
     786             :             Reference< XDocumentFragment > const xNewFrag =
     787           0 :                 xDocument->createDocumentFragment();
     788           0 :             xNode.set(xNewFrag, UNO_QUERY);
     789           0 :             break;
     790             :         }
     791             :         case NodeType_ELEMENT_NODE:
     792             :         {
     793             :             Reference< XElement > const xElement(xImportedNode,
     794         702 :                     UNO_QUERY_THROW);
     795         702 :             OUString const aNsUri = xImportedNode->getNamespaceURI();
     796         702 :             OUString const aNsPrefix = xImportedNode->getPrefix();
     797         702 :             OUString aQName = xElement->getTagName();
     798         702 :             Reference< XElement > xNewElement;
     799         702 :             if (!aNsUri.isEmpty())
     800             :             {
     801         702 :                 if (!aNsPrefix.isEmpty()) {
     802         702 :                     aQName = aNsPrefix + ":" + aQName;
     803             :                 }
     804         702 :                 xNewElement = xDocument->createElementNS(aNsUri, aQName);
     805             :             } else {
     806           0 :                 xNewElement = xDocument->createElement(aQName);
     807             :             }
     808             : 
     809             :             // get attributes
     810         702 :             if (xElement->hasAttributes())
     811             :             {
     812         260 :                 Reference< XNamedNodeMap > attribs = xElement->getAttributes();
     813         834 :                 for (sal_Int32 i = 0; i < attribs->getLength(); i++)
     814             :                 {
     815         574 :                     Reference< XAttr > const curAttr(attribs->item(i),
     816         574 :                             UNO_QUERY_THROW);
     817         574 :                     OUString const aAttrUri = curAttr->getNamespaceURI();
     818         574 :                     OUString const aAttrPrefix = curAttr->getPrefix();
     819         574 :                     OUString aAttrName = curAttr->getName();
     820         574 :                     OUString const sValue = curAttr->getValue();
     821         574 :                     if (!aAttrUri.isEmpty())
     822             :                     {
     823         574 :                         if (!aAttrPrefix.isEmpty()) {
     824         574 :                             aAttrName = aAttrPrefix + ":" + aAttrName;
     825             :                         }
     826         574 :                         xNewElement->setAttributeNS(
     827         574 :                                 aAttrUri, aAttrName, sValue);
     828             :                     } else {
     829           0 :                         xNewElement->setAttribute(aAttrName, sValue);
     830             :                     }
     831         834 :                 }
     832             :             }
     833         702 :             xNode.set(xNewElement, UNO_QUERY);
     834         702 :             break;
     835             :         }
     836             :         case NodeType_ENTITY_REFERENCE_NODE:
     837             :         {
     838             :             Reference< XEntityReference > const xRef(xImportedNode,
     839           0 :                     UNO_QUERY_THROW);
     840             :             Reference< XEntityReference > const xNewRef(
     841           0 :                 xDocument->createEntityReference(xRef->getNodeName()));
     842           0 :             xNode.set(xNewRef, UNO_QUERY);
     843           0 :             break;
     844             :         }
     845             :         case NodeType_PROCESSING_INSTRUCTION_NODE:
     846             :         {
     847             :             Reference< XProcessingInstruction > const xPi(xImportedNode,
     848           0 :                     UNO_QUERY_THROW);
     849             :             Reference< XProcessingInstruction > const xNewPi(
     850           0 :                 xDocument->createProcessingInstruction(
     851           0 :                     xPi->getTarget(), xPi->getData()));
     852           0 :             xNode.set(xNewPi, UNO_QUERY);
     853           0 :             break;
     854             :         }
     855             :         case NodeType_TEXT_NODE:
     856             :         {
     857         418 :             Reference< XText > const xText(xImportedNode, UNO_QUERY_THROW);
     858             :             Reference< XText > const xNewText(
     859         418 :                 xDocument->createTextNode(xText->getData()));
     860         418 :             xNode.set(xNewText, UNO_QUERY);
     861         418 :             break;
     862             :         }
     863             :         case NodeType_ENTITY_NODE:
     864             :         case NodeType_DOCUMENT_NODE:
     865             :         case NodeType_DOCUMENT_TYPE_NODE:
     866             :         case NodeType_NOTATION_NODE:
     867             :         default:
     868             :             // can't be imported
     869           0 :             throw RuntimeException();
     870             : 
     871             :         }
     872        1120 :         if (deep)
     873             :         {
     874             :             // get children and import them
     875        1120 :             Reference< XNode > const xChild = xImportedNode->getFirstChild();
     876        1120 :             if (xChild.is())
     877             :             {
     878         606 :                 lcl_ImportSiblings(xDocument, xNode, xChild);
     879        1120 :             }
     880             :         }
     881             : 
     882             :         /* DOMNodeInsertedIntoDocument
     883             :          * Fired when a node is being inserted into a document,
     884             :          * either through direct insertion of the Node or insertion of a
     885             :          * subtree in which it is contained. This event is dispatched after
     886             :          * the insertion has taken place. The target of this event is the node
     887             :          * being inserted. If the Node is being directly inserted the DOMNodeInserted
     888             :          * event will fire before the DOMNodeInsertedIntoDocument event.
     889             :          *   Bubbles: No
     890             :          *   Cancelable: No
     891             :          *   Context Info: None
     892             :          */
     893        1120 :         if (xNode.is())
     894             :         {
     895        1120 :             Reference< XDocumentEvent > const xDocevent(xDocument, UNO_QUERY);
     896        1120 :             Reference< XMutationEvent > const event(xDocevent->createEvent(
     897        1120 :                 "DOMNodeInsertedIntoDocument"), UNO_QUERY_THROW);
     898        1120 :             event->initMutationEvent(
     899             :                 "DOMNodeInsertedIntoDocument", sal_True, sal_False, Reference< XNode >(),
     900        1120 :                 OUString(), OUString(), OUString(), (AttrChangeType)0 );
     901        1120 :             Reference< XEventTarget > const xDocET(xDocument, UNO_QUERY);
     902        1120 :             xDocET->dispatchEvent(Reference< XEvent >(event, UNO_QUERY));
     903             :         }
     904             : 
     905        1120 :         return xNode;
     906             :     }
     907             : 
     908        1120 :     Reference< XNode > SAL_CALL CDocument::importNode(
     909             :             Reference< XNode > const& xImportedNode, sal_Bool deep)
     910             :         throw (RuntimeException, DOMException)
     911             :     {
     912        1120 :         if (!xImportedNode.is()) { throw RuntimeException(); }
     913             : 
     914             :         // NB: this whole operation inherently accesses 2 distinct documents.
     915             :         // The imported node could even be from a different DOM implementation,
     916             :         // so this implementation cannot make any assumptions about the
     917             :         // locking strategy of the imported node.
     918             :         // So the import takes no lock on this document;
     919             :         // it only calls UNO methods on this document that temporarily
     920             :         // lock the document, and UNO methods on the imported node that
     921             :         // may temporarily lock the other document.
     922             :         // As a consequence, the import is not atomic with regard to
     923             :         // concurrent modifications of either document, but it should not
     924             :         // deadlock.
     925             :         // To ensure that no members are accessed, the implementation is in
     926             :         // static non-member functions.
     927             : 
     928        1120 :         Reference< XDocument > const xDocument(this);
     929             :         // already in doc?
     930        1120 :         if (xImportedNode->getOwnerDocument() == xDocument) {
     931           0 :             return xImportedNode;
     932             :         }
     933             : 
     934             :         Reference< XNode > const xNode(
     935        1120 :             lcl_ImportNode(xDocument, xImportedNode, deep) );
     936        1120 :         return xNode;
     937             :     }
     938             : 
     939           0 :     OUString SAL_CALL CDocument::getNodeName()throw (RuntimeException)
     940             :     {
     941             :         // does not need mutex currently
     942           0 :         return OUString("#document");
     943             :     }
     944             : 
     945           0 :     OUString SAL_CALL CDocument::getNodeValue() throw (RuntimeException)
     946             :     {
     947             :         // does not need mutex currently
     948           0 :         return OUString();
     949             :     }
     950             : 
     951           0 :     Reference< XNode > SAL_CALL CDocument::cloneNode(sal_Bool bDeep)
     952             :         throw (RuntimeException)
     953             :     {
     954           0 :         ::osl::MutexGuard const g(m_rMutex);
     955             : 
     956             :         OSL_ASSERT(0 != m_aNodePtr);
     957           0 :         if (0 == m_aNodePtr) {
     958           0 :             return 0;
     959             :         }
     960           0 :         xmlDocPtr const pClone(xmlCopyDoc(m_aDocPtr, (bDeep) ? 1 : 0));
     961           0 :         if (0 == pClone) { return 0; }
     962             :         Reference< XNode > const xRet(
     963           0 :             static_cast<CNode*>(CDocument::CreateCDocument(pClone).get()));
     964           0 :         return xRet;
     965             :     }
     966             : 
     967       36372 :     Reference< XEvent > SAL_CALL CDocument::createEvent(const OUString& aType) throw (RuntimeException)
     968             :     {
     969             :         // does not need mutex currently
     970       36372 :         events::CEvent *pEvent = 0;
     971       54126 :         if ( aType == "DOMSubtreeModified" || aType == "DOMNodeInserted" || aType == "DOMNodeRemoved"
     972       17672 :           || aType == "DOMNodeRemovedFromDocument" || aType == "DOMNodeInsertedIntoDocument" || aType == "DOMAttrModified"
     973          82 :           || aType == "DOMCharacterDataModified")
     974             :         {
     975       36372 :             pEvent = new events::CMutationEvent;
     976             : 
     977           0 :         } else if ( aType == "DOMFocusIn" || aType == "DOMFocusOut" || aType == "DOMActivate")
     978             :         {
     979           0 :             pEvent = new events::CUIEvent;
     980           0 :         } else if ( aType == "click"     || aType == "mousedown" || aType == "mouseup"
     981           0 :                  || aType == "mouseover" || aType == "mousemove" || aType == "mouseout" )
     982             :         {
     983           0 :             pEvent = new events::CMouseEvent;
     984             :         }
     985             :         else // generic event
     986             :         {
     987           0 :             pEvent = new events::CEvent;
     988             :         }
     989       36372 :         return Reference< XEvent >(pEvent);
     990             :     }
     991             : 
     992             :     // ::com::sun::star::xml::sax::XSAXSerializable
     993           8 :     void SAL_CALL CDocument::serialize(
     994             :             const Reference< XDocumentHandler >& i_xHandler,
     995             :             const Sequence< beans::StringPair >& i_rNamespaces)
     996             :         throw (RuntimeException, SAXException)
     997             :     {
     998           8 :         ::osl::MutexGuard const g(m_Mutex);
     999             : 
    1000             :         // add new namespaces to root node
    1001           8 :         xmlNodePtr const pRoot = lcl_getDocumentRootPtr(m_aDocPtr);
    1002           8 :         if (0 != pRoot) {
    1003           8 :             const beans::StringPair * pSeq = i_rNamespaces.getConstArray();
    1004         112 :             for (const beans::StringPair *pNsDef = pSeq;
    1005          56 :                  pNsDef < pSeq + i_rNamespaces.getLength(); ++pNsDef) {
    1006             :                 OString prefix = OUStringToOString(pNsDef->First,
    1007          48 :                                     RTL_TEXTENCODING_UTF8);
    1008             :                 OString href   = OUStringToOString(pNsDef->Second,
    1009          48 :                                     RTL_TEXTENCODING_UTF8);
    1010             :                 // this will only add the ns if it does not exist already
    1011          48 :                 xmlNewNs(pRoot, reinterpret_cast<const xmlChar*>(href.getStr()),
    1012          96 :                          reinterpret_cast<const xmlChar*>(prefix.getStr()));
    1013          48 :             }
    1014             :             // eliminate duplicate namespace declarations
    1015           8 :             nscleanup(pRoot->children, pRoot);
    1016             :         }
    1017           8 :         saxify(i_xHandler);
    1018           8 :     }
    1019             : 
    1020             :     // ::com::sun::star::xml::sax::XFastSAXSerializable
    1021          12 :     void SAL_CALL CDocument::fastSerialize( const Reference< XFastDocumentHandler >& i_xHandler,
    1022             :                                             const Reference< XFastTokenHandler >& i_xTokenHandler,
    1023             :                                             const Sequence< beans::StringPair >& i_rNamespaces,
    1024             :                                             const Sequence< beans::Pair< rtl::OUString, sal_Int32 > >& i_rRegisterNamespaces )
    1025             :         throw (SAXException, RuntimeException)
    1026             :     {
    1027          12 :         ::osl::MutexGuard const g(m_Mutex);
    1028             : 
    1029             :         // add new namespaces to root node
    1030          12 :         xmlNodePtr const pRoot = lcl_getDocumentRootPtr(m_aDocPtr);
    1031          12 :         if (0 != pRoot) {
    1032          12 :             const beans::StringPair * pSeq = i_rNamespaces.getConstArray();
    1033          24 :             for (const beans::StringPair *pNsDef = pSeq;
    1034          12 :                  pNsDef < pSeq + i_rNamespaces.getLength(); ++pNsDef) {
    1035             :                 OString prefix = OUStringToOString(pNsDef->First,
    1036           0 :                                     RTL_TEXTENCODING_UTF8);
    1037             :                 OString href   = OUStringToOString(pNsDef->Second,
    1038           0 :                                     RTL_TEXTENCODING_UTF8);
    1039             :                 // this will only add the ns if it does not exist already
    1040           0 :                 xmlNewNs(pRoot, reinterpret_cast<const xmlChar*>(href.getStr()),
    1041           0 :                          reinterpret_cast<const xmlChar*>(prefix.getStr()));
    1042           0 :             }
    1043             :             // eliminate duplicate namespace declarations
    1044          12 :             nscleanup(pRoot->children, pRoot);
    1045             :         }
    1046             : 
    1047             :         Context aContext(i_xHandler,
    1048          12 :                          i_xTokenHandler);
    1049             : 
    1050             :         // register namespace ids
    1051          12 :         const beans::Pair<OUString,sal_Int32>* pSeq = i_rRegisterNamespaces.getConstArray();
    1052         528 :         for (const beans::Pair<OUString,sal_Int32>* pNs = pSeq;
    1053         264 :              pNs < pSeq + i_rRegisterNamespaces.getLength(); ++pNs)
    1054             :         {
    1055             :             OSL_ENSURE(pNs->Second >= FastToken::NAMESPACE,
    1056             :                        "CDocument::fastSerialize(): invalid NS token id");
    1057         252 :             aContext.maNamespaceMap[ pNs->First ] = pNs->Second;
    1058             :         }
    1059             : 
    1060          12 :         fastSaxify(aContext);
    1061          12 :     }
    1062             : }
    1063             : 
    1064             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10