2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-11-16 09:58:50 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 08:05:45 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-11-16 09:58:50 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2004-11-16 09:58:50 +00:00
|
|
|
*
|
2008-04-11 08:05:45 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-11-16 09:58:50 +00:00
|
|
|
*
|
2008-04-11 08:05:45 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-11-16 09:58:50 +00:00
|
|
|
*
|
2008-04-11 08:05:45 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2004-11-16 09:58:50 +00:00
|
|
|
*
|
2008-04-11 08:05:45 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2004-11-16 09:58:50 +00:00
|
|
|
*
|
2008-04-11 08:05:45 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2004-11-16 09:58:50 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 23:07:16 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_forms.hxx"
|
|
|
|
|
2004-11-16 09:58:50 +00:00
|
|
|
#include "serialization.hxx"
|
|
|
|
#include "serialization_app_xml.hxx"
|
|
|
|
|
|
|
|
#include <unotools/processfactory.hxx>
|
|
|
|
#include <com/sun/star/xml/dom/XNode.hpp>
|
|
|
|
#include <com/sun/star/xml/dom/XDocument.hpp>
|
|
|
|
#include <com/sun/star/xml/dom/XNodeList.hpp>
|
|
|
|
#include <com/sun/star/xml/dom/NodeType.hpp>
|
|
|
|
#include <com/sun/star/lang/XUnoTunnel.hpp>
|
|
|
|
#include <com/sun/star/xml/xpath/XPathObjectType.hpp>
|
|
|
|
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
|
|
|
|
CSerializationAppXML::CSerializationAppXML()
|
|
|
|
: m_aFactory(utl::getProcessServiceFactory())
|
|
|
|
, m_aPipe(CSS::uno::Reference< CSS::io::XOutputStream > (m_aFactory->createInstance(
|
2010-11-15 23:52:56 +01:00
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.Pipe") ) ), CSS::uno::UNO_QUERY))
|
2004-11-16 09:58:50 +00:00
|
|
|
{
|
|
|
|
OSL_ENSURE(m_aPipe.is(), "cannot create Pipe");
|
|
|
|
}
|
|
|
|
|
|
|
|
CSS::uno::Reference< CSS::io::XInputStream >
|
|
|
|
CSerializationAppXML::getInputStream()
|
|
|
|
{
|
|
|
|
// The pipes output is provided through it's
|
|
|
|
// XOutputStream interface aspect
|
|
|
|
return CSS::uno::Reference< CSS::io::XInputStream >(m_aPipe, CSS::uno::UNO_QUERY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSerializationAppXML::serialize_node(const CSS::uno::Reference< CSS::xml::dom::XNode >& rNode)
|
|
|
|
{
|
|
|
|
CSS::uno::Reference< CSS::xml::dom::XNode > aNode = rNode;
|
|
|
|
if (aNode->getNodeType() == CSS::xml::dom::NodeType_DOCUMENT_NODE)
|
|
|
|
{
|
|
|
|
CSS::uno::Reference< CSS::xml::dom::XDocument > aDoc(rNode, CSS::uno::UNO_QUERY_THROW);
|
|
|
|
aNode = CSS::uno::Reference< CSS::xml::dom::XNode >(aDoc->getDocumentElement(), CSS::uno::UNO_QUERY_THROW);
|
|
|
|
}
|
|
|
|
if (aNode->getNodeType() != CSS::xml::dom::NodeType_ELEMENT_NODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// clone the node to a new document and serialize that document
|
|
|
|
CSS::uno::Reference< CSS::lang::XUnoTunnel > aTunnel(aNode, CSS::uno::UNO_QUERY);
|
|
|
|
if (aTunnel.is())
|
|
|
|
{
|
2006-06-19 12:06:06 +00:00
|
|
|
xmlNodePtr aNodePtr = reinterpret_cast< xmlNodePtr >( aTunnel->getSomething(CSS::uno::Sequence< sal_Int8 >()) );
|
2004-11-16 09:58:50 +00:00
|
|
|
xmlDocPtr aDocPtr = xmlNewDoc((xmlChar*)"1.0");
|
|
|
|
xmlNodePtr aDocNodePtr = xmlDocCopyNode(aNodePtr, aDocPtr, 1);
|
|
|
|
if (aDocNodePtr != NULL) {
|
|
|
|
xmlAddChild((xmlNodePtr)aDocPtr, aDocNodePtr);
|
|
|
|
xmlChar *buffer = NULL;
|
|
|
|
sal_Int32 size = 0;
|
|
|
|
xmlDocDumpMemory(aDocPtr, &buffer, (int*)&size);
|
|
|
|
|
|
|
|
// write the xml into the pipe through it's XOutputStream interface
|
|
|
|
m_aPipe->writeBytes(CSS::uno::Sequence< sal_Int8 >((sal_Int8*)buffer, size));
|
|
|
|
xmlFree(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// can't get tunnel to native backend
|
|
|
|
// logic for generic implementation could be implemented here...
|
|
|
|
OSL_ENSURE(sal_False, "unkown dom implementation, cannot serialize");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSerializationAppXML::serialize()
|
|
|
|
{
|
|
|
|
if (!m_aFragment.is()) return;
|
|
|
|
|
|
|
|
CSS::uno::Reference< CSS::xml::dom::XNode > cur = m_aFragment->getFirstChild();
|
|
|
|
while (cur.is())
|
|
|
|
{
|
|
|
|
serialize_node(cur);
|
|
|
|
cur = cur->getNextSibling();
|
|
|
|
}
|
|
|
|
m_aPipe->closeOutput();
|
|
|
|
}
|
2010-10-12 15:57:08 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|