LCOV - code coverage report
Current view: top level - forms/source/xforms/submission - serialization_app_xml.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 32 0.0 %
Date: 2012-08-25 Functions: 0 4 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 88 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "serialization.hxx"
      31                 :            : #include "serialization_app_xml.hxx"
      32                 :            : 
      33                 :            : #include <comphelper/processfactory.hxx>
      34                 :            : #include <com/sun/star/xml/dom/XNode.hpp>
      35                 :            : #include <com/sun/star/xml/dom/XDocument.hpp>
      36                 :            : #include <com/sun/star/xml/dom/XNodeList.hpp>
      37                 :            : #include <com/sun/star/xml/dom/NodeType.hpp>
      38                 :            : #include <com/sun/star/lang/XUnoTunnel.hpp>
      39                 :            : #include <com/sun/star/xml/xpath/XPathObjectType.hpp>
      40                 :            : 
      41                 :            : #include <libxml/tree.h>
      42                 :            : 
      43                 :          0 : CSerializationAppXML::CSerializationAppXML()
      44                 :            :     : m_aFactory(comphelper::getProcessServiceFactory())
      45         [ #  # ]:          0 :     , m_aPipe(CSS::uno::Reference< CSS::io::XOutputStream > (m_aFactory->createInstance(
      46 [ #  # ][ #  # ]:          0 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.Pipe") ) ), CSS::uno::UNO_QUERY))
         [ #  # ][ #  # ]
      47                 :            : {
      48                 :            :     OSL_ENSURE(m_aPipe.is(), "cannot create Pipe");
      49                 :          0 : }
      50                 :            : 
      51                 :            : CSS::uno::Reference< CSS::io::XInputStream >
      52                 :          0 : CSerializationAppXML::getInputStream()
      53                 :            : {
      54                 :            :     // The pipes output is provided through it's
      55                 :            :     // XOutputStream interface aspect
      56                 :          0 :     return CSS::uno::Reference< CSS::io::XInputStream >(m_aPipe, CSS::uno::UNO_QUERY);
      57                 :            : }
      58                 :            : 
      59                 :            : void
      60                 :          0 : CSerializationAppXML::serialize_node(const CSS::uno::Reference< CSS::xml::dom::XNode >& rNode)
      61                 :            : {
      62                 :          0 :     CSS::uno::Reference< CSS::xml::dom::XNode > aNode = rNode;
      63 [ #  # ][ #  # ]:          0 :     if (aNode->getNodeType() == CSS::xml::dom::NodeType_DOCUMENT_NODE)
                 [ #  # ]
      64                 :            :     {
      65         [ #  # ]:          0 :         CSS::uno::Reference< CSS::xml::dom::XDocument > aDoc(rNode, CSS::uno::UNO_QUERY_THROW);
      66 [ #  # ][ #  # ]:          0 :         aNode = CSS::uno::Reference< CSS::xml::dom::XNode >(aDoc->getDocumentElement(), CSS::uno::UNO_QUERY_THROW);
         [ #  # ][ #  # ]
      67                 :            :     }
      68 [ #  # ][ #  # ]:          0 :     if (aNode->getNodeType() != CSS::xml::dom::NodeType_ELEMENT_NODE)
                 [ #  # ]
      69                 :            :         return;
      70                 :            : 
      71                 :            :     // clone the node to a new document and serialize that document
      72         [ #  # ]:          0 :     CSS::uno::Reference< CSS::lang::XUnoTunnel > aTunnel(aNode, CSS::uno::UNO_QUERY);
      73         [ #  # ]:          0 :     if (aTunnel.is())
      74                 :            :     {
      75 [ #  # ][ #  # ]:          0 :         xmlNodePtr aNodePtr = reinterpret_cast< xmlNodePtr >( aTunnel->getSomething(CSS::uno::Sequence< sal_Int8 >()) );
         [ #  # ][ #  # ]
      76         [ #  # ]:          0 :         xmlDocPtr aDocPtr = xmlNewDoc((xmlChar*)"1.0");
      77         [ #  # ]:          0 :         xmlNodePtr aDocNodePtr = xmlDocCopyNode(aNodePtr, aDocPtr, 1);
      78         [ #  # ]:          0 :         if (aDocNodePtr != NULL) {
      79         [ #  # ]:          0 :             xmlAddChild((xmlNodePtr)aDocPtr, aDocNodePtr);
      80                 :          0 :             xmlChar *buffer = NULL;
      81                 :          0 :             sal_Int32 size = 0;
      82         [ #  # ]:          0 :             xmlDocDumpMemory(aDocPtr, &buffer, (int*)&size);
      83                 :            : 
      84                 :            :             // write the xml into the pipe through it's XOutputStream interface
      85 [ #  # ][ #  # ]:          0 :             m_aPipe->writeBytes(CSS::uno::Sequence< sal_Int8 >((sal_Int8*)buffer, size));
         [ #  # ][ #  # ]
      86         [ #  # ]:          0 :             xmlFree(buffer);
      87                 :            :         }
      88                 :            : 
      89                 :            :     } else {
      90                 :            :         // can't get tunnel to native backend
      91                 :            :         // logic for generic implementation could be implemented here...
      92                 :            :         OSL_FAIL("unkown dom implementation, cannot serialize");
      93                 :            :         return;
      94 [ #  # ][ #  # ]:          0 :     }
      95                 :            : }
      96                 :            : 
      97                 :            : void
      98                 :          0 : CSerializationAppXML::serialize()
      99                 :            : {
     100         [ #  # ]:          0 :     if (!m_aFragment.is()) return;
     101                 :            : 
     102 [ #  # ][ #  # ]:          0 :     CSS::uno::Reference< CSS::xml::dom::XNode > cur = m_aFragment->getFirstChild();
     103         [ #  # ]:          0 :     while (cur.is())
     104                 :            :     {
     105         [ #  # ]:          0 :         serialize_node(cur);
     106 [ #  # ][ #  # ]:          0 :         cur = cur->getNextSibling();
                 [ #  # ]
     107                 :            :     }
     108 [ #  # ][ #  # ]:          0 :     m_aPipe->closeOutput();
     109                 :            : }
     110                 :            : 
     111                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10