1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLFilter.hxx"
22 #include "MediaDescriptorHelper.hxx"
23 #include "ContainerHelper.hxx"
25 #include <svtools/sfxecode.hxx>
26 #include <unotools/saveopt.hxx>
27 #include <comphelper/genericpropertyset.hxx>
28 #include <comphelper/propertysetinfo.hxx>
29 #include <comphelper/documentconstants.hxx>
30 #include <cppuhelper/supportsservice.hxx>
32 #include <sot/storage.hxx>
33 #include <osl/diagnose.h>
34 #include <com/sun/star/beans/NamedValue.hpp>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/xml/sax/InputSource.hpp>
37 #include <com/sun/star/xml/sax/Writer.hpp>
38 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 #include <com/sun/star/embed/ElementModes.hpp>
41 #include <com/sun/star/embed/XStorage.hpp>
42 #include <com/sun/star/embed/StorageFactory.hpp>
43 #include <com/sun/star/embed/XTransactedObject.hpp>
44 #include <com/sun/star/frame/XModel.hpp>
45 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
46 #include <com/sun/star/xml/sax/Parser.hpp>
47 #include <com/sun/star/xml/sax/SAXParseException.hpp>
48 #include <com/sun/star/packages/zip/ZipIOException.hpp>
49 #include <com/sun/star/document/GraphicObjectResolver.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
52 using namespace ::com::sun::star
;
54 using ::com::sun::star::uno::Reference
;
55 using ::com::sun::star::uno::Sequence
;
56 using ::osl::MutexGuard
;
60 char const sXML_metaStreamName
[] = "meta.xml";
61 char const sXML_styleStreamName
[] = "styles.xml";
62 char const sXML_contentStreamName
[] = "content.xml";
63 char const sXML_oldContentStreamName
[] = "Content.xml";
66 char const sXML_export_chart_styles_service
[] = "com.sun.star.comp.Chart.XMLStylesExporter";
67 char const sXML_export_chart_content_service
[] = "com.sun.star.comp.Chart.XMLContentExporter";
69 char const sXML_import_chart_styles_service
[] = "com.sun.star.comp.Chart.XMLStylesImporter";
70 char const sXML_import_chart_content_service
[] = "com.sun.star.comp.Chart.XMLContentImporter";
71 char const sXML_import_chart_old_content_service
[] = "com.sun.star.office.sax.importer.Chart";
74 char const sXML_export_chart_oasis_styles_service
[] = "com.sun.star.comp.Chart.XMLOasisStylesExporter";
75 char const sXML_export_chart_oasis_content_service
[] = "com.sun.star.comp.Chart.XMLOasisContentExporter";
76 char const sXML_export_chart_oasis_meta_service
[] = "com.sun.star.comp.Chart.XMLOasisMetaExporter";
78 char const sXML_import_chart_oasis_styles_service
[] = "com.sun.star.comp.Chart.XMLOasisStylesImporter";
79 char const sXML_import_chart_oasis_content_service
[] = "com.sun.star.comp.Chart.XMLOasisContentImporter";
80 char const sXML_import_chart_oasis_meta_service
[] = "com.sun.star.comp.Chart.XMLOasisMetaImporter";
82 uno::Reference
< embed::XStorage
> lcl_getWriteStorage(
83 const Sequence
< beans::PropertyValue
>& rMediaDescriptor
,
84 const uno::Reference
< uno::XComponentContext
>& xContext
,const OUString
& _sMediaType
)
86 uno::Reference
< embed::XStorage
> xStorage
;
89 apphelper::MediaDescriptorHelper
aMDHelper( rMediaDescriptor
);
90 if( aMDHelper
.ISSET_Storage
)
92 xStorage
= aMDHelper
.Storage
;
96 Reference
< lang::XSingleServiceFactory
> xStorageFact( embed::StorageFactory::create( xContext
) );
98 ::std::vector
< beans::PropertyValue
> aPropertiesForStorage
;
100 for( sal_Int32 i
=rMediaDescriptor
.getLength(); i
--; )
102 // properties understood by storage factory
103 // (see package/source/xstor/xfactory.cxx for details)
104 if ( rMediaDescriptor
[i
].Name
== "InteractionHandler" || rMediaDescriptor
[i
].Name
== "Password" || rMediaDescriptor
[i
].Name
== "RepairPackage" )
106 aPropertiesForStorage
.push_back( rMediaDescriptor
[i
] );
110 if( aMDHelper
.ISSET_Storage
)
111 xStorage
.set( aMDHelper
.Storage
);
114 Sequence
< uno::Any
> aStorageArgs( 3 );
115 if( aMDHelper
.ISSET_OutputStream
)
116 aStorageArgs
[0] <<= aMDHelper
.OutputStream
;
118 aStorageArgs
[0] <<= aMDHelper
.URL
;
119 aStorageArgs
[1] <<= (embed::ElementModes::READWRITE
| embed::ElementModes::TRUNCATE
);
120 aStorageArgs
[2] <<= ::chart::ContainerHelper::ContainerToSequence( aPropertiesForStorage
);
123 xStorageFact
->createInstanceWithArguments( aStorageArgs
),
124 uno::UNO_QUERY_THROW
);
128 // set correct media type at storage
129 uno::Reference
<beans::XPropertySet
> xProp(xStorage
,uno::UNO_QUERY
);
132 ! ( xProp
->getPropertyValue( "MediaType") >>= aMediaType
) ||
133 ( aMediaType
.isEmpty() ))
135 xProp
->setPropertyValue( "MediaType", uno::makeAny( _sMediaType
));
138 catch (const uno::Exception
& ex
)
140 ASSERT_EXCEPTION( ex
);
145 uno::Reference
< embed::XStorage
> lcl_getReadStorage(
146 const Sequence
< beans::PropertyValue
>& rMediaDescriptor
,
147 const uno::Reference
< uno::XComponentContext
>& xContext
)
149 uno::Reference
< embed::XStorage
> xStorage
;
153 apphelper::MediaDescriptorHelper
aMDHelper( rMediaDescriptor
);
154 if( aMDHelper
.ISSET_Storage
)
156 xStorage
= aMDHelper
.Storage
;
160 // get XStream from MediaDescriptor
161 uno::Reference
< io::XInputStream
> xStream
;
162 ::std::vector
< beans::PropertyValue
> aPropertiesForStorage
;
163 for( sal_Int32 i
=rMediaDescriptor
.getLength(); i
--; )
165 if( rMediaDescriptor
[i
].Name
== "InputStream" )
166 xStream
.set( rMediaDescriptor
[i
].Value
, uno::UNO_QUERY
);
168 // properties understood by storage factory
169 // (see package/source/xstor/xfactory.cxx for details)
170 if ( rMediaDescriptor
[i
].Name
== "InteractionHandler" || rMediaDescriptor
[i
].Name
== "Password" || rMediaDescriptor
[i
].Name
== "RepairPackage" )
172 aPropertiesForStorage
.push_back( rMediaDescriptor
[i
] );
175 OSL_ENSURE( xStream
.is(), "No Stream" );
179 // convert XInputStream to XStorage via the storage factory
180 Reference
< lang::XSingleServiceFactory
> xStorageFact( embed::StorageFactory::create( xContext
) );
181 Sequence
< uno::Any
> aStorageArgs( 3 );
182 aStorageArgs
[0] <<= xStream
;
183 aStorageArgs
[1] <<= (embed::ElementModes::READ
| embed::ElementModes::NOCREATE
);
184 aStorageArgs
[2] <<= ::chart::ContainerHelper::ContainerToSequence( aPropertiesForStorage
);
186 xStorageFact
->createInstanceWithArguments( aStorageArgs
), uno::UNO_QUERY_THROW
);
189 OSL_ENSURE( xStorage
.is(), "No Storage" );
191 catch (const uno::Exception
& ex
)
193 ASSERT_EXCEPTION( ex
);
199 } // anonymous namespace
204 XMLFilter::XMLFilter( Reference
< uno::XComponentContext
> const & xContext
) :
205 m_xContext( xContext
),
206 m_bCancelOperation( false )
209 XMLFilter::~XMLFilter()
213 sal_Bool SAL_CALL
XMLFilter::filter(
214 const Sequence
< beans::PropertyValue
>& aDescriptor
)
215 throw (uno::RuntimeException
, std::exception
)
217 bool bResult
= false;
219 MutexGuard
aGuard( m_aMutex
);
221 // ignore cancel flag at start of function
222 // note: is currently ignored during import/export
223 if( m_bCancelOperation
)
224 m_bCancelOperation
= false;
226 if( m_xSourceDoc
.is())
228 OSL_ENSURE( ! m_xTargetDoc
.is(), "source doc is set -> target document should not be set" );
229 if( impl_Export( m_xSourceDoc
,
236 else if( m_xTargetDoc
.is())
238 if( impl_Import( m_xTargetDoc
,
247 OSL_FAIL( "filter() called with no document set" );
253 void SAL_CALL
XMLFilter::cancel()
254 throw (uno::RuntimeException
, std::exception
)
256 // if mutex is locked set "cancel state"
257 // note: is currently ignored in filter-method
258 if( ! m_aMutex
.tryToAcquire())
260 m_bCancelOperation
= true;
264 // ____ XImporter ____
265 void SAL_CALL
XMLFilter::setTargetDocument(
266 const Reference
< lang::XComponent
>& Document
)
267 throw (lang::IllegalArgumentException
,
268 uno::RuntimeException
, std::exception
)
270 MutexGuard
aGuard( m_aMutex
);
271 OSL_ENSURE( ! m_xSourceDoc
.is(), "Setting target doc while source doc is set" );
273 m_xTargetDoc
= Document
;
276 // ____ XExporter ____
277 void SAL_CALL
XMLFilter::setSourceDocument(
278 const Reference
< lang::XComponent
>& Document
)
279 throw (lang::IllegalArgumentException
,
280 uno::RuntimeException
, std::exception
)
282 MutexGuard
aGuard( m_aMutex
);
283 OSL_ENSURE( ! m_xTargetDoc
.is(), "Setting source doc while target doc is set" );
285 m_xSourceDoc
= Document
;
288 sal_Int32
XMLFilter::impl_Import(
289 const Reference
< lang::XComponent
> & xDocumentComp
,
290 const Sequence
< beans::PropertyValue
> & rMediaDescriptor
)
292 sal_Int32 nWarning
= 0;
294 OSL_ENSURE( xDocumentComp
.is(), "Import: No Model" );
295 OSL_ENSURE( m_xContext
.is(), "Import: No ComponentContext" );
297 if( ! (xDocumentComp
.is() &&
303 Reference
< lang::XServiceInfo
> xServInfo( xDocumentComp
, uno::UNO_QUERY_THROW
);
304 if( ! xServInfo
->supportsService( "com.sun.star.chart2.ChartDocument"))
306 OSL_FAIL( "Import: No ChartDocument" );
307 return ERRCODE_SFX_GENERAL
;
310 Reference
< lang::XMultiComponentFactory
> xFactory( m_xContext
->getServiceManager());
311 OSL_ENSURE( xFactory
.is(), "Import: No Factory" );
313 return ERRCODE_SFX_GENERAL
;
315 // create a sax parser
316 Reference
< xml::sax::XParser
> xSaxParser
= xml::sax::Parser::create(m_xContext
);
319 isOasisFormat( rMediaDescriptor
, bOasis
);
320 Reference
< embed::XStorage
> xStorage( lcl_getReadStorage( rMediaDescriptor
, m_xContext
));
322 return ERRCODE_SFX_GENERAL
;
324 Reference
< document::XGraphicObjectResolver
> xGraphicObjectResolver
;
325 uno::Reference
< lang::XMultiServiceFactory
> xServiceFactory( xFactory
, uno::UNO_QUERY
);
326 if( xServiceFactory
.is())
328 uno::Sequence
< uno::Any
> aArgs(1);
329 aArgs
[0] <<= xStorage
;
330 xGraphicObjectResolver
.set(
331 xServiceFactory
->createInstanceWithArguments(
332 "com.sun.star.comp.Svx.GraphicImportHelper", aArgs
), uno::UNO_QUERY
);
335 // create XPropertySet with extra informatio for the filter
336 /** property map for import info set */
337 comphelper::PropertyMapEntry
const aImportInfoMap
[] =
339 // necessary properties for XML progress bar at load time
340 { OUString("ProgressRange"), 0, ::cppu::UnoType
<sal_Int32
>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0},
341 { OUString("ProgressMax"), 0, ::cppu::UnoType
<sal_Int32
>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0},
342 { OUString("ProgressCurrent"), 0, ::cppu::UnoType
<sal_Int32
>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0},
343 { OUString("PrivateData"), 0,
344 cppu::UnoType
<XInterface
>::get(),
345 ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0 },
346 { OUString("BaseURI"), 0,
347 ::cppu::UnoType
<OUString
>::get(),
348 ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0 },
349 { OUString("StreamRelPath"), 0,
350 ::cppu::UnoType
<OUString
>::get(),
351 ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0 },
352 { OUString("StreamName"), 0,
353 ::cppu::UnoType
<OUString
>::get(),
354 ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0 },
355 { OUString("BuildId"), 0,
356 ::cppu::UnoType
<OUString
>::get(),
357 ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0 },
358 { OUString(), 0, css::uno::Type(), 0, 0 }
360 uno::Reference
< beans::XPropertySet
> xImportInfo(
361 comphelper::GenericPropertySet_CreateInstance(
362 new comphelper::PropertySetInfo( aImportInfoMap
) ) );
364 // Set base URI and Hierarchical Name
365 OUString aHierarchName
, aBaseUri
;
366 uno::Reference
< frame::XModel
> xModel( m_xSourceDoc
, uno::UNO_QUERY
);
369 uno::Sequence
< beans::PropertyValue
> aModProps
= xModel
->getArgs();
370 for( sal_Int32 nInd
= 0; nInd
< aModProps
.getLength(); nInd
++ )
372 if( aModProps
[nInd
].Name
== "HierarchicalDocumentName" )
374 // Actually this argument only has meaning for embedded documents
375 aModProps
[nInd
].Value
>>= aHierarchName
;
377 else if( aModProps
[nInd
].Name
== "DocumentBaseURL" )
379 aModProps
[nInd
].Value
>>= aBaseUri
;
384 if( !aBaseUri
.isEmpty() )
385 xImportInfo
->setPropertyValue( "BaseURI", uno::makeAny( aBaseUri
) );
387 if( !aHierarchName
.isEmpty() )
388 xImportInfo
->setPropertyValue( "StreamRelPath", uno::makeAny( aHierarchName
) );
390 // import meta information
392 nWarning
|= impl_ImportStream(
394 sXML_import_chart_oasis_meta_service
,
395 xStorage
, xSaxParser
, xFactory
, xGraphicObjectResolver
, xImportInfo
);
398 nWarning
|= impl_ImportStream(
399 sXML_styleStreamName
,
401 ? OUString(sXML_import_chart_oasis_styles_service
)
402 : OUString(sXML_import_chart_styles_service
),
403 xStorage
, xSaxParser
, xFactory
, xGraphicObjectResolver
, xImportInfo
);
406 sal_Int32 nContentWarning
= impl_ImportStream(
407 sXML_contentStreamName
,
409 ? OUString(sXML_import_chart_oasis_content_service
)
410 : OUString(sXML_import_chart_content_service
),
411 xStorage
, xSaxParser
, xFactory
, xGraphicObjectResolver
, xImportInfo
);
412 nWarning
|= nContentWarning
;
414 // import of "content.xml" didn't work - try old "Content.xml" stream
415 if( nContentWarning
!= 0 )
417 nWarning
= impl_ImportStream(
418 sXML_oldContentStreamName
,
419 sXML_import_chart_old_content_service
,
420 xStorage
, xSaxParser
, xFactory
, xGraphicObjectResolver
, xImportInfo
);
423 catch (const uno::Exception
& ex
)
425 ASSERT_EXCEPTION( ex
);
427 // something went awry
428 nWarning
= ERRCODE_SFX_GENERAL
;
434 sal_Int32
XMLFilter::impl_ImportStream(
435 const OUString
& rStreamName
,
436 const OUString
& rServiceName
,
437 const Reference
< embed::XStorage
> & xStorage
,
438 const Reference
< xml::sax::XParser
> & xParser
,
439 const Reference
< lang::XMultiComponentFactory
> & xFactory
,
440 const Reference
< document::XGraphicObjectResolver
> & xGraphicObjectResolver
,
441 uno::Reference
< beans::XPropertySet
>& xImportInfo
)
443 sal_Int32 nWarning
= ERRCODE_SFX_GENERAL
;
445 Reference
< container::XNameAccess
> xNameAcc( xStorage
, uno::UNO_QUERY
);
446 if( ! (xNameAcc
.is() &&
447 xNameAcc
->hasByName( rStreamName
)))
450 if( xImportInfo
.is() )
451 xImportInfo
->setPropertyValue( "StreamName", uno::makeAny( rStreamName
) );
454 xStorage
->isStreamElement( rStreamName
) )
458 xml::sax::InputSource aParserInput
;
459 aParserInput
.aInputStream
.set(
460 xStorage
->openStreamElement(
462 embed::ElementModes::READ
| embed::ElementModes::NOCREATE
),
467 if( aParserInput
.aInputStream
.is())
470 if( xGraphicObjectResolver
.is())
472 if( xImportInfo
.is())
475 uno::Sequence
< uno::Any
> aFilterCompArgs( nArgs
);
478 if( xGraphicObjectResolver
.is())
479 aFilterCompArgs
[nArgs
++] <<= xGraphicObjectResolver
;
480 if( xImportInfo
.is())
481 aFilterCompArgs
[ nArgs
++ ] <<= xImportInfo
;
483 Reference
< xml::sax::XDocumentHandler
> xDocHandler(
484 xFactory
->createInstanceWithArgumentsAndContext( rServiceName
, aFilterCompArgs
, m_xContext
),
485 uno::UNO_QUERY_THROW
);
487 Reference
< document::XImporter
> xImporter( xDocHandler
, uno::UNO_QUERY_THROW
);
488 xImporter
->setTargetDocument( Reference
< lang::XComponent
>( m_xTargetDoc
, uno::UNO_QUERY_THROW
));
490 if ( !m_sDocumentHandler
.isEmpty() )
494 uno::Sequence
< uno::Any
> aArgs(2);
495 beans::NamedValue aValue
;
496 aValue
.Name
= "DocumentHandler";
497 aValue
.Value
<<= xDocHandler
;
499 aValue
.Name
= "Model";
500 aValue
.Value
<<= m_xTargetDoc
;
503 xDocHandler
.set(xFactory
->createInstanceWithArgumentsAndContext(m_sDocumentHandler
,aArgs
,m_xContext
), uno::UNO_QUERY
);
504 xImporter
.set(xDocHandler
,uno::UNO_QUERY
);
506 catch (const uno::Exception
&)
508 OSL_FAIL("Exception caught!");
511 xParser
->setDocumentHandler( xDocHandler
);
512 xParser
->parseStream( aParserInput
);
515 // load was successful
518 catch (const xml::sax::SAXParseException
&)
520 // todo: if encrypted: ERRCODE_SFX_WRONGPASSWORD
522 catch (const xml::sax::SAXException
&)
524 // todo: if encrypted: ERRCODE_SFX_WRONGPASSWORD
526 catch (const packages::zip::ZipIOException
&)
528 nWarning
= ERRCODE_IO_BROKENPACKAGE
;
530 catch (const io::IOException
&)
533 catch (const uno::Exception
& rEx
)
535 ASSERT_EXCEPTION(rEx
);
542 sal_Int32
XMLFilter::impl_Export(
543 const Reference
< lang::XComponent
> & xDocumentComp
,
544 const Sequence
< beans::PropertyValue
> & rMediaDescriptor
)
546 m_aMediaDescriptor
= rMediaDescriptor
;
549 sal_Int32 nWarning
= 0;
551 OSL_ENSURE( xDocumentComp
.is(), "Export: No Model" );
552 OSL_ENSURE( m_xContext
.is(), "Export: No ComponentContext" );
554 if( !xDocumentComp
.is() || !m_xContext
.is() )
559 Reference
< lang::XServiceInfo
> xServInfo( xDocumentComp
, uno::UNO_QUERY_THROW
);
560 if( ! xServInfo
->supportsService( "com.sun.star.chart2.ChartDocument"))
562 OSL_FAIL( "Export: No ChartDocument" );
563 return ERRCODE_SFX_GENERAL
;
566 Reference
< lang::XMultiComponentFactory
> xFactory( m_xContext
->getServiceManager());
567 OSL_ENSURE( xFactory
.is(), "Export: No Factory" );
569 return ERRCODE_SFX_GENERAL
;
570 uno::Reference
< lang::XMultiServiceFactory
> xServiceFactory( m_xContext
->getServiceManager(), uno::UNO_QUERY
);
571 if( ! xServiceFactory
.is())
572 return ERRCODE_SFX_GENERAL
;
574 uno::Reference
< xml::sax::XWriter
> xSaxWriter
= xml::sax::Writer::create(m_xContext
);
577 isOasisFormat( rMediaDescriptor
, bOasis
);
579 uno::Reference
< embed::XStorage
> xStorage( lcl_getWriteStorage( rMediaDescriptor
, m_xContext
, getMediaType(bOasis
) ) );
580 OSL_ENSURE( xStorage
.is(), "No Storage" );
582 return ERRCODE_SFX_GENERAL
;
584 uno::Reference
< xml::sax::XDocumentHandler
> xDocHandler( xSaxWriter
, uno::UNO_QUERY
);
586 if ( !m_sDocumentHandler
.isEmpty() )
590 uno::Sequence
< uno::Any
> aArgs(2);
591 beans::NamedValue aValue
;
592 aValue
.Name
= "DocumentHandler";
593 aValue
.Value
<<= xDocHandler
;
595 aValue
.Name
= "Model";
596 aValue
.Value
<<= xDocumentComp
;
599 xDocHandler
.set(xServiceFactory
->createInstanceWithArguments(m_sDocumentHandler
,aArgs
), uno::UNO_QUERY
);
600 xSaxWriter
.set(xDocHandler
,uno::UNO_QUERY
);
602 catch (const uno::Exception
&)
604 OSL_FAIL("Exception caught!");
608 Reference
< document::XGraphicObjectResolver
> xGraphicObjectResolver
= document::GraphicObjectResolver::createWithStorage(
609 m_xContext
, xStorage
);
611 // property map for export info set
612 comphelper::PropertyMapEntry
const aExportInfoMap
[] =
614 { OUString("UsePrettyPrinting"), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::MAYBEVOID
, 0},
615 { OUString("BaseURI"), 0, ::cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::MAYBEVOID
, 0 },
616 { OUString("StreamRelPath"), 0, ::cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::MAYBEVOID
, 0 },
617 { OUString("StreamName"), 0, ::cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::MAYBEVOID
, 0 },
618 { OUString("ExportTableNumberList"), 0, cppu::UnoType
<bool>::get(), beans::PropertyAttribute::MAYBEVOID
, 0 },
619 { OUString(), 0, css::uno::Type(), 0, 0 }
622 uno::Reference
< beans::XPropertySet
> xInfoSet
=
623 comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap
) );
625 SvtSaveOptions aSaveOpt
;
626 OUString
sUsePrettyPrinting( "UsePrettyPrinting" );
627 bool bUsePrettyPrinting( aSaveOpt
.IsPrettyPrinting() );
628 xInfoSet
->setPropertyValue( sUsePrettyPrinting
, uno::makeAny( bUsePrettyPrinting
) );
630 xInfoSet
->setPropertyValue( "ExportTableNumberList", uno::makeAny( true ));
633 if( xGraphicObjectResolver
.is())
636 uno::Sequence
< uno::Any
> aFilterProperties( nArgs
);
639 aFilterProperties
[ nArgs
++ ] <<= xInfoSet
;
640 aFilterProperties
[ nArgs
++ ] <<= xDocHandler
;
641 if( xGraphicObjectResolver
.is())
642 aFilterProperties
[ nArgs
++ ] <<= xGraphicObjectResolver
;
645 // export meta information
647 nWarning
|= impl_ExportStream(
649 sXML_export_chart_oasis_meta_service
,
650 xStorage
, xSaxWriter
, xServiceFactory
, aFilterProperties
);
653 nWarning
|= impl_ExportStream(
654 sXML_styleStreamName
,
656 ? OUString(sXML_export_chart_oasis_styles_service
)
657 : OUString(sXML_export_chart_styles_service
),
658 xStorage
, xSaxWriter
, xServiceFactory
, aFilterProperties
);
661 sal_Int32 nContentWarning
= impl_ExportStream(
662 sXML_contentStreamName
,
664 ? OUString(sXML_export_chart_oasis_content_service
)
665 : OUString(sXML_export_chart_content_service
),
666 xStorage
, xSaxWriter
, xServiceFactory
, aFilterProperties
);
667 nWarning
|= nContentWarning
;
669 Reference
< lang::XComponent
> xComp( xGraphicObjectResolver
, uno::UNO_QUERY
);
673 uno::Reference
<embed::XTransactedObject
> xTransact( xStorage
,uno::UNO_QUERY
);
674 if ( xTransact
.is() )
677 catch (const uno::Exception
& ex
)
679 ASSERT_EXCEPTION( ex
);
681 // something went awry
682 nWarning
= ERRCODE_SFX_GENERAL
;
688 sal_Int32
XMLFilter::impl_ExportStream(
689 const OUString
& rStreamName
,
690 const OUString
& rServiceName
,
691 const Reference
< embed::XStorage
> & xStorage
,
692 const uno::Reference
< xml::sax::XWriter
>& xActiveDataSource
,
693 const Reference
< lang::XMultiServiceFactory
>& xServiceFactory
,
694 const Sequence
< uno::Any
> & rFilterProperties
)
696 sal_Int32 nWarning
= 0;
700 if( !xServiceFactory
.is() )
701 return ERRCODE_SFX_GENERAL
;
703 return ERRCODE_SFX_GENERAL
;
704 if ( !xActiveDataSource
.is() )
705 return ERRCODE_SFX_GENERAL
;
707 uno::Reference
< io::XStream
> xStream( xStorage
->openStreamElement(
708 rStreamName
, embed::ElementModes::READWRITE
| embed::ElementModes::TRUNCATE
) );
710 return ERRCODE_SFX_GENERAL
;
711 uno::Reference
< io::XOutputStream
> xOutputStream( xStream
->getOutputStream() );
712 if ( !xOutputStream
.is() )
713 return ERRCODE_SFX_GENERAL
;
715 uno::Reference
< beans::XPropertySet
> xStreamProp( xOutputStream
, uno::UNO_QUERY
);
716 if(xStreamProp
.is()) try
718 xStreamProp
->setPropertyValue( "MediaType", uno::makeAny( OUString("text/xml") ) );
719 xStreamProp
->setPropertyValue( "Compressed", uno::makeAny( sal_True
) );//@todo?
720 xStreamProp
->setPropertyValue( "UseCommonStoragePasswordEncryption", uno::makeAny( sal_True
) );
722 catch (const uno::Exception
& rEx
)
724 ASSERT_EXCEPTION( rEx
);
727 xActiveDataSource
->setOutputStream(xOutputStream
);
731 uno::Reference
< beans::XPropertySet
> xInfoSet
;
732 if( rFilterProperties
.getLength() > 0 )
733 rFilterProperties
.getConstArray()[0] >>= xInfoSet
;
734 OSL_ENSURE( xInfoSet
.is(), "missing infoset for export" );
736 xInfoSet
->setPropertyValue( "StreamName", uno::makeAny( rStreamName
) );
739 Reference
< XExporter
> xExporter( xServiceFactory
->createInstanceWithArguments(
740 rServiceName
, rFilterProperties
), uno::UNO_QUERY
);
741 if ( !xExporter
.is() )
742 return ERRCODE_SFX_GENERAL
;
744 xExporter
->setSourceDocument( m_xSourceDoc
);
746 uno::Reference
< document::XFilter
> xFilter( xExporter
, uno::UNO_QUERY
);
748 return ERRCODE_SFX_GENERAL
;
750 xFilter
->filter(m_aMediaDescriptor
);
752 catch (const uno::Exception
& rEx
)
754 ASSERT_EXCEPTION( rEx
);
759 Sequence
< OUString
> XMLFilter::getSupportedServiceNames_Static()
761 Sequence
< OUString
> aServices( 2 );
762 aServices
[ 0 ] = "com.sun.star.document.ImportFilter";
763 aServices
[ 1 ] = "com.sun.star.document.ExportFilter";
765 // todo: services are incomplete. Missing:
766 // XInitialization, XNamed
770 void XMLFilter::isOasisFormat(const Sequence
< beans::PropertyValue
>& _rMediaDescriptor
, bool & rOutOASIS
)
772 apphelper::MediaDescriptorHelper
aMDHelper( _rMediaDescriptor
);
773 if( aMDHelper
.ISSET_FilterName
)
774 rOutOASIS
= aMDHelper
.FilterName
== "chart8";
776 OUString
XMLFilter::getMediaType(bool _bOasis
)
778 return _bOasis
? OUString(MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII
) : OUString(MIMETYPE_VND_SUN_XML_CHART_ASCII
);
781 OUString SAL_CALL
XMLFilter::getImplementationName()
782 throw( css::uno::RuntimeException
, std::exception
)
784 return getImplementationName_Static();
787 OUString
XMLFilter::getImplementationName_Static()
789 return OUString("com.sun.star.comp.chart2.XMLFilter");
792 sal_Bool SAL_CALL
XMLFilter::supportsService( const OUString
& rServiceName
)
793 throw( css::uno::RuntimeException
, std::exception
)
795 return cppu::supportsService(this, rServiceName
);
798 css::uno::Sequence
< OUString
> SAL_CALL
XMLFilter::getSupportedServiceNames()
799 throw( css::uno::RuntimeException
, std::exception
)
801 return getSupportedServiceNames_Static();
804 void XMLReportFilterHelper::isOasisFormat(const Sequence
< beans::PropertyValue
>& _rMediaDescriptor
, bool & rOutOASIS
)
806 apphelper::MediaDescriptorHelper
aMDHelper( _rMediaDescriptor
);
807 if( aMDHelper
.ISSET_FilterName
)
808 rOutOASIS
= aMDHelper
.FilterName
== "StarOffice XML (Base) Report Chart";
810 OUString
XMLReportFilterHelper::getMediaType(bool )
812 return OUString(MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART_ASCII
);
817 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
818 com_sun_star_comp_chart2_XMLFilter_get_implementation(css::uno::XComponentContext
*context
,
819 css::uno::Sequence
<css::uno::Any
> const &)
821 return cppu::acquire(new ::chart::XMLFilter(context
));
824 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
825 com_sun_star_comp_chart2_report_XMLFilter_get_implementation(css::uno::XComponentContext
*context
,
826 css::uno::Sequence
<css::uno::Any
> const &)
828 return cppu::acquire(new ::chart::XMLReportFilterHelper(context
));
831 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */