masterfix DEV300: #i10000# build fix
[LibreOffice.git] / forms / source / xforms / submission / serialization_app_xml.cxx
blob85cf066d63437be81c5ff4d49c8e364a6afd4d64
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
31 #include "serialization.hxx"
32 #include "serialization_app_xml.hxx"
34 #include <unotools/processfactory.hxx>
35 #include <com/sun/star/xml/dom/XNode.hpp>
36 #include <com/sun/star/xml/dom/XDocument.hpp>
37 #include <com/sun/star/xml/dom/XNodeList.hpp>
38 #include <com/sun/star/xml/dom/NodeType.hpp>
39 #include <com/sun/star/lang/XUnoTunnel.hpp>
40 #include <com/sun/star/xml/xpath/XPathObjectType.hpp>
42 #include <libxml/tree.h>
44 CSerializationAppXML::CSerializationAppXML()
45 : m_aFactory(utl::getProcessServiceFactory())
46 , m_aPipe(CSS::uno::Reference< CSS::io::XOutputStream > (m_aFactory->createInstance(
47 rtl::OUString::createFromAscii("com.sun.star.io.Pipe")), CSS::uno::UNO_QUERY))
49 OSL_ENSURE(m_aPipe.is(), "cannot create Pipe");
52 CSS::uno::Reference< CSS::io::XInputStream >
53 CSerializationAppXML::getInputStream()
55 // The pipes output is provided through it's
56 // XOutputStream interface aspect
57 return CSS::uno::Reference< CSS::io::XInputStream >(m_aPipe, CSS::uno::UNO_QUERY);
60 void
61 CSerializationAppXML::serialize_node(const CSS::uno::Reference< CSS::xml::dom::XNode >& rNode)
63 CSS::uno::Reference< CSS::xml::dom::XNode > aNode = rNode;
64 if (aNode->getNodeType() == CSS::xml::dom::NodeType_DOCUMENT_NODE)
66 CSS::uno::Reference< CSS::xml::dom::XDocument > aDoc(rNode, CSS::uno::UNO_QUERY_THROW);
67 aNode = CSS::uno::Reference< CSS::xml::dom::XNode >(aDoc->getDocumentElement(), CSS::uno::UNO_QUERY_THROW);
69 if (aNode->getNodeType() != CSS::xml::dom::NodeType_ELEMENT_NODE)
70 return;
72 // clone the node to a new document and serialize that document
73 CSS::uno::Reference< CSS::lang::XUnoTunnel > aTunnel(aNode, CSS::uno::UNO_QUERY);
74 if (aTunnel.is())
76 xmlNodePtr aNodePtr = reinterpret_cast< xmlNodePtr >( aTunnel->getSomething(CSS::uno::Sequence< sal_Int8 >()) );
77 xmlDocPtr aDocPtr = xmlNewDoc((xmlChar*)"1.0");
78 xmlNodePtr aDocNodePtr = xmlDocCopyNode(aNodePtr, aDocPtr, 1);
79 if (aDocNodePtr != NULL) {
80 xmlAddChild((xmlNodePtr)aDocPtr, aDocNodePtr);
81 xmlChar *buffer = NULL;
82 sal_Int32 size = 0;
83 xmlDocDumpMemory(aDocPtr, &buffer, (int*)&size);
85 // write the xml into the pipe through it's XOutputStream interface
86 m_aPipe->writeBytes(CSS::uno::Sequence< sal_Int8 >((sal_Int8*)buffer, size));
87 xmlFree(buffer);
90 } else {
91 // can't get tunnel to native backend
92 // logic for generic implementation could be implemented here...
93 OSL_ENSURE(sal_False, "unkown dom implementation, cannot serialize");
94 return;
99 void
100 CSerializationAppXML::serialize_nodeset()
102 CSS::uno::Reference< CSS::xml::dom::XNodeList > aNodeList = m_aXPathObject->getNodeList();
103 for (sal_Int32 i=0; i<aNodeList->getLength(); i++)
104 serialize_node(aNodeList->item(i));
105 m_aPipe->closeOutput();
109 void
110 CSerializationAppXML::serialize()
112 if (!m_aFragment.is()) return;
114 CSS::uno::Reference< CSS::xml::dom::XNode > cur = m_aFragment->getFirstChild();
115 while (cur.is())
117 serialize_node(cur);
118 cur = cur->getNextSibling();
120 m_aPipe->closeOutput();