21#include <com/sun/star/xml/sax/InputSource.hpp>
22#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
23#include <com/sun/star/xml/sax/Writer.hpp>
24#include <com/sun/star/lang/XComponent.hpp>
25#include <com/sun/star/xml/sax/XFastParser.hpp>
26#include <com/sun/star/io/XOutputStream.hpp>
27#include <com/sun/star/document/XFilter.hpp>
28#include <com/sun/star/document/XExporter.hpp>
29#include <com/sun/star/document/XImporter.hpp>
42 return SvxDrawingLayerExport( pModel, xOut, xComponent,
"com.sun.star.comp.DrawingLayer.XMLExporter" );
45bool SvxDrawingLayerExport(
SdrModel* pModel,
const uno::Reference<io::XOutputStream>& xOut,
const Reference< lang::XComponent >& xComponent,
const char* pExportService )
47 bool bDocRet = xOut.is();
49 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
52 Reference< document::XEmbeddedObjectResolver > xObjectResolver;
55 Reference< lang::XComponent > xSourceDoc( xComponent );
58 if( !xSourceDoc.is() )
61 pModel->
setUnoModel( Reference< XInterface >::query( xSourceDoc ) );
64 uno::Reference< uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
68 uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create( xContext );
74 xObjectResolver = xObjectHelper.get();
78 xGraphicStorageHandler = xGraphicHelper.get();
80 uno::Reference<xml::sax::XDocumentHandler> xHandler = xWriter;
83 xWriter->setOutputStream( xOut );
85 uno::Sequence< uno::Any > aArgs( xObjectResolver.is() ? 3 : 2 );
86 auto pArgs = aArgs.getArray();
87 pArgs[0] <<= xHandler;
88 pArgs[1] <<= xGraphicStorageHandler;
89 if( xObjectResolver.is() )
90 pArgs[2] <<= xObjectResolver;
92 uno::Reference< document::XFilter > xFilter( xContext->getServiceManager()->createInstanceWithArgumentsAndContext( OUString::createFromAscii( pExportService ), aArgs, xContext ), uno::UNO_QUERY );
95 OSL_FAIL(
"com.sun.star.comp.Draw.XMLExporter service missing" );
101 uno::Reference< document::XExporter > xExporter( xFilter, uno::UNO_QUERY );
104 xExporter->setSourceDocument( xSourceDoc );
106 uno::Sequence< beans::PropertyValue > aDescriptor( 0 );
107 bDocRet = xFilter->filter( aDescriptor );
112 catch(uno::Exception
const&)
119 xGraphicHelper->dispose();
120 xGraphicHelper.clear();
121 xGraphicStorageHandler =
nullptr;
123 if( xObjectHelper.is() )
124 xObjectHelper->dispose();
131 Reference< lang::XComponent > xComponent;
139 return SvxDrawingLayerImport( pModel, xInputStream, xComponent,
"com.sun.star.comp.Draw.XMLOasisImporter" );
142bool SvxDrawingLayerImport(
SdrModel* pModel,
const uno::Reference<io::XInputStream>& xInputStream,
const Reference< lang::XComponent >& xComponent,
const char* pImportService )
146 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
149 Reference< document::XEmbeddedObjectResolver > xObjectResolver;
152 Reference< lang::XComponent > xTargetDocument( xComponent );
153 if( !xTargetDocument.is() )
156 pModel->
setUnoModel( Reference< XInterface >::query( xTargetDocument ) );
159 Reference< frame::XModel > xTargetModel( xTargetDocument, UNO_QUERY );
166 if ( xTargetModel.is() )
167 xTargetModel->lockControllers();
171 xGraphicStorageHandler = xGraphicHelper.get();
179 xObjectResolver = xObjectHelper.get();
184 xml::sax::InputSource aParserInput;
185 aParserInput.aInputStream = xInputStream;
188 Sequence<Any> aFilterArgs( 2 );
189 Any *pArgs = aFilterArgs.getArray();
190 *pArgs++ <<= xGraphicStorageHandler;
191 *pArgs++ <<= xObjectResolver;
194 Reference< XInterface > xFilter = xContext->getServiceManager()->createInstanceWithArgumentsAndContext( OUString::createFromAscii( pImportService ), aFilterArgs, xContext);
195 SAL_WARN_IF( !xFilter,
"svx",
"Can't instantiate filter component " << pImportService);
196 uno::Reference< xml::sax::XFastParser > xFastParser( xFilter, UNO_QUERY );
200 if( xFastParser.is() )
203 uno::Reference < document::XImporter > xImporter( xFilter, UNO_QUERY );
204 xImporter->setTargetDocument( xTargetDocument );
207 xFastParser->parseStream( aParserInput );
212 catch( uno::Exception& )
218 xGraphicHelper->dispose();
219 xGraphicHelper.clear();
220 xGraphicStorageHandler =
nullptr;
222 if( xObjectHelper.is() )
223 xObjectHelper->dispose();
224 xObjectHelper.clear();
225 xObjectResolver =
nullptr;
227 if ( xTargetModel.is() )
228 xTargetModel->unlockControllers();
235 Reference< lang::XComponent > xComponent;
::comphelper::IEmbeddedHelper * GetPersist() const
void setUnoModel(const css::uno::Reference< css::uno::XInterface > &xModel)
static rtl::Reference< SvXMLEmbeddedObjectHelper > Create(const css::uno::Reference< css::embed::XStorage > &, ::comphelper::IEmbeddedHelper &rDocPersist, SvXMLEmbeddedObjectHelperMode eCreateMode)
static rtl::Reference< SvXMLGraphicHelper > Create(const css::uno::Reference< css::embed::XStorage > &rXMLStorage, SvXMLGraphicHelperMode eCreateMode)
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN_IF(condition, area, stream)
Reference< XComponentContext > getProcessComponentContext()
bool SvxDrawingLayerExport(SdrModel *pModel, const uno::Reference< io::XOutputStream > &xOut, const Reference< lang::XComponent > &xComponent)
bool SvxDrawingLayerImport(SdrModel *pModel, const uno::Reference< io::XInputStream > &xInputStream, const Reference< lang::XComponent > &xComponent)