23#include <officecfg/Office/Common.hxx>
31#include <osl/diagnose.h>
32#include <com/sun/star/beans/NamedValue.hpp>
33#include <com/sun/star/beans/PropertyAttribute.hpp>
34#include <com/sun/star/beans/XPropertySet.hpp>
35#include <com/sun/star/xml/sax/InputSource.hpp>
36#include <com/sun/star/xml/sax/Writer.hpp>
37#include <com/sun/star/lang/XMultiComponentFactory.hpp>
38#include <com/sun/star/lang/XSingleServiceFactory.hpp>
39#include <com/sun/star/embed/ElementModes.hpp>
40#include <com/sun/star/embed/XStorage.hpp>
41#include <com/sun/star/embed/StorageFactory.hpp>
42#include <com/sun/star/embed/XTransactedObject.hpp>
43#include <com/sun/star/frame/XModel.hpp>
44#include <com/sun/star/xml/sax/Parser.hpp>
45#include <com/sun/star/xml/sax/SAXParseException.hpp>
46#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
47#include <com/sun/star/xml/sax/XFastParser.hpp>
48#include <com/sun/star/packages/zip/ZipIOException.hpp>
49#include <com/sun/star/document/GraphicStorageHandler.hpp>
55using ::com::sun::star::uno::Reference;
56using ::com::sun::star::uno::Sequence;
57using ::osl::MutexGuard;
61constexpr OUStringLiteral sXML_metaStreamName =
u"meta.xml";
62constexpr OUStringLiteral sXML_styleStreamName =
u"styles.xml";
63constexpr OUStringLiteral sXML_contentStreamName =
u"content.xml";
66uno::Reference< embed::XStorage > lcl_getWriteStorage(
67 const Sequence< beans::PropertyValue >& rMediaDescriptor,
68 const uno::Reference< uno::XComponentContext >& xContext,
const OUString& _sMediaType)
70 uno::Reference< embed::XStorage > xStorage;
74 if( aMDHelper.ISSET_Storage )
76 xStorage = aMDHelper.Storage;
80 Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create( xContext ) );
82 std::vector< beans::PropertyValue > aPropertiesForStorage;
84 for( sal_Int32 i=rMediaDescriptor.getLength(); i--; )
88 if ( rMediaDescriptor[i].Name ==
"InteractionHandler" || rMediaDescriptor[i].Name ==
"Password" || rMediaDescriptor[i].Name ==
"RepairPackage" )
90 aPropertiesForStorage.push_back( rMediaDescriptor[i] );
94 if( aMDHelper.ISSET_Storage )
95 xStorage.set( aMDHelper.Storage );
98 Sequence< uno::Any > aStorageArgs{
99 aMDHelper.ISSET_OutputStream ?
uno::Any(aMDHelper.OutputStream)
101 uno::
Any(embed::ElementModes::
READWRITE | embed::ElementModes::TRUNCATE),
106 xStorageFact->createInstanceWithArguments( aStorageArgs ),
107 uno::UNO_QUERY_THROW );
112 uno::Reference<beans::XPropertySet> xProp(xStorage,uno::UNO_QUERY);
115 ! ( xProp->getPropertyValue(
"MediaType") >>= aMediaType ) ||
116 ( aMediaType.isEmpty() ))
118 xProp->setPropertyValue(
"MediaType",
uno::Any( _sMediaType ));
121 catch (
const uno::Exception&)
128uno::Reference< embed::XStorage > lcl_getReadStorage(
129 const Sequence< beans::PropertyValue >& rMediaDescriptor,
130 const uno::Reference< uno::XComponentContext >& xContext)
132 uno::Reference< embed::XStorage > xStorage;
137 if( aMDHelper.ISSET_Storage )
139 xStorage = aMDHelper.Storage;
144 uno::Reference< io::XInputStream >
xStream;
145 std::vector< beans::PropertyValue > aPropertiesForStorage;
146 for( sal_Int32 i=rMediaDescriptor.getLength(); i--; )
148 if( rMediaDescriptor[i].Name ==
"InputStream" )
149 xStream.set( rMediaDescriptor[i].Value, uno::UNO_QUERY );
153 if ( rMediaDescriptor[i].Name ==
"InteractionHandler" || rMediaDescriptor[i].Name ==
"Password" || rMediaDescriptor[i].Name ==
"RepairPackage" )
155 aPropertiesForStorage.push_back( rMediaDescriptor[i] );
158 OSL_ENSURE(
xStream.is(),
"No Stream" );
163 Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create( xContext ) );
164 Sequence< uno::Any > aStorageArgs{
166 uno::Any(embed::ElementModes::READ | embed::ElementModes::NOCREATE),
170 xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW );
173 OSL_ENSURE( xStorage.is(),
"No Storage" );
175 catch (
const uno::Exception&)
190 m_bCancelOperation( false )
200 bool bResult =
false;
211 OSL_ENSURE( !
m_xTargetDoc.is(),
"source doc is set -> target document should not be set" );
230 OSL_FAIL(
"filter() called with no document set" );
251 OSL_ENSURE( !
m_xSourceDoc.is(),
"Setting target doc while source doc is set" );
261 OSL_ENSURE( !
m_xTargetDoc.is(),
"Setting source doc while target doc is set" );
272 OSL_ENSURE( xDocumentComp.is(),
"Import: No Model" );
273 OSL_ENSURE(
m_xContext.is(),
"Import: No ComponentContext" );
275 if( ! (xDocumentComp.is() &&
282 if( ! xServInfo->supportsService(
"com.sun.star.chart2.ChartDocument"))
284 OSL_FAIL(
"Import: No ChartDocument" );
289 OSL_ENSURE(
xFactory.is(),
"Import: No Factory" );
301 if (xServiceFactory.is())
304 xGraphicStorageHandler.set(
305 xServiceFactory->createInstanceWithArguments(
306 "com.sun.star.comp.Svx.GraphicImportHelper", aArgs), uno::UNO_QUERY);
328 OUString aHierarchName, aBaseUri;
334 for( beans::PropertyValue
const & prop : aModProps )
336 if( prop.Name ==
"HierarchicalDocumentName" )
339 prop.Value >>= aHierarchName;
341 else if( prop.Name ==
"DocumentBaseURL" )
343 prop.Value >>= aBaseUri;
349 SAL_INFO_IF(aBaseUri.isEmpty(),
"chart2",
"chart::XMLFilter: no base URL");
350 if( !aBaseUri.isEmpty() )
351 xImportInfo->setPropertyValue(
"BaseURI",
uno::Any( aBaseUri ) );
353 if( !aHierarchName.isEmpty() )
354 xImportInfo->setPropertyValue(
"StreamRelPath",
uno::Any( aHierarchName ) );
360 "com.sun.star.comp.Chart.XMLOasisMetaImporter",
361 xStorage,
xFactory, xGraphicStorageHandler, xImportInfo );
365 sXML_styleStreamName,
367 ? OUString(
"com.sun.star.comp.Chart.XMLOasisStylesImporter")
368 : OUString(
"com.sun.star.comp.Chart.XMLStylesImporter"),
369 xStorage,
xFactory, xGraphicStorageHandler, xImportInfo );
370 nWarning = nWarning !=
ERRCODE_NONE ? nWarning : nTmpErr;
374 sXML_contentStreamName,
376 ? OUString(
"com.sun.star.comp.Chart.XMLOasisContentImporter")
377 : OUString(
"com.sun.star.comp.Chart.XMLContentImporter"),
378 xStorage,
xFactory, xGraphicStorageHandler, xImportInfo );
379 nWarning = nWarning !=
ERRCODE_NONE ? nWarning : nContentWarning;
381 catch (
const uno::Exception&)
393 const OUString & rStreamName,
394 const OUString & rServiceName,
402 if( ! (xStorage.is() &&
403 xStorage->hasByName( rStreamName )))
406 if( xImportInfo.is() )
407 xImportInfo->setPropertyValue(
"StreamName",
uno::Any( rStreamName ) );
410 xStorage->isStreamElement( rStreamName ) )
415 xStorage->openStreamElement(
417 embed::ElementModes::READ | embed::ElementModes::NOCREATE );
421 if( xInputStream.is())
424 if( xGraphicStorageHandler.is())
426 if( xImportInfo.is())
430 auto aFilterCompArgsRange = asNonConstRange(aFilterCompArgs);
433 if( xGraphicStorageHandler.is())
434 aFilterCompArgsRange[nArgs++] <<= xGraphicStorageHandler;
435 if( xImportInfo.is())
436 aFilterCompArgsRange[ nArgs++ ] <<= xImportInfo;
440 xFactory->createInstanceWithArgumentsAndContext( rServiceName, aFilterCompArgs,
m_xContext );
457 catch (
const uno::Exception&)
462 xml::sax::InputSource aParserInput;
463 aParserInput.aInputStream.set(xInputStream, uno::UNO_QUERY_THROW);
467 if (xFastParser.is())
468 xFastParser->parseStream(aParserInput);
473 xParser->parseStream(aParserInput);
480 catch (
const xml::sax::SAXParseException&)
484 catch (
const xml::sax::SAXException&)
488 catch (
const packages::zip::ZipIOException&)
492 catch (
const io::IOException&)
496 catch (
const uno::Exception&)
514 OSL_ENSURE( xDocumentComp.is(),
"Export: No Model" );
515 OSL_ENSURE(
m_xContext.is(),
"Export: No ComponentContext" );
523 if( ! xServInfo->supportsService(
"com.sun.star.chart2.ChartDocument"))
525 OSL_FAIL(
"Export: No ChartDocument" );
530 OSL_ENSURE(
xFactory.is(),
"Export: No Factory" );
534 if( ! xServiceFactory.is())
543 OSL_ENSURE( xStorage.is(),
"No Storage" );
558 xDocHandler.set(xServiceFactory->createInstanceWithArguments(
m_sDocumentHandler,aArgs), uno::UNO_QUERY );
559 xSaxWriter.set(xDocHandler,uno::UNO_QUERY);
561 catch (
const uno::Exception&)
568 xGraphicStorageHandler.set(document::GraphicStorageHandler::createWithStorage(
m_xContext, xStorage));
583 bool bUsePrettyPrinting( officecfg::Office::Common::Save::Document::PrettyPrinting::get() );
584 xInfoSet->setPropertyValue(
"UsePrettyPrinting",
uno::Any( bUsePrettyPrinting ) );
586 xInfoSet->setPropertyValue(
"ExportTableNumberList",
uno::Any(
true ));
589 if( xGraphicStorageHandler.is())
594 auto pFilterProperties = aFilterProperties.getArray();
596 pFilterProperties[ nArgs++ ] <<= xInfoSet;
597 pFilterProperties[ nArgs++ ] <<= xDocHandler;
598 if( xGraphicStorageHandler.is())
599 pFilterProperties[ nArgs++ ] <<= xGraphicStorageHandler;
606 "com.sun.star.comp.Chart.XMLOasisMetaExporter",
607 xStorage, xSaxWriter, xServiceFactory, aFilterProperties );
611 sXML_styleStreamName,
613 ? OUString(
"com.sun.star.comp.Chart.XMLOasisStylesExporter")
614 : OUString(
"com.sun.star.comp.Chart.XMLStylesExporter"),
615 xStorage, xSaxWriter, xServiceFactory, aFilterProperties );
620 sXML_contentStreamName,
622 ? OUString(
"com.sun.star.comp.Chart.XMLOasisContentExporter")
623 : OUString(
"com.sun.star.comp.Chart.XMLContentExporter"),
624 xStorage, xSaxWriter, xServiceFactory, aFilterProperties );
625 nWarning = nWarning !=
ERRCODE_NONE ? nWarning : nContentWarning;
632 if ( xTransact.is() )
635 catch (
const uno::Exception&)
647 const OUString & rStreamName,
648 const OUString & rServiceName,
656 if( !xServiceFactory.is() )
660 if ( !xActiveDataSource.is() )
664 rStreamName, embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ) );
668 if ( !xOutputStream.is() )
672 if(xStreamProp.is())
try
674 xStreamProp->setPropertyValue(
"MediaType",
uno::Any( OUString(
"text/xml") ) );
675 xStreamProp->setPropertyValue(
"Compressed",
uno::Any(
true ) );
676 xStreamProp->setPropertyValue(
"UseCommonStoragePasswordEncryption",
uno::Any(
true ) );
678 catch (
const uno::Exception&)
683 xActiveDataSource->setOutputStream(xOutputStream);
688 if( rFilterProperties.hasElements() )
689 rFilterProperties.getConstArray()[0] >>= xInfoSet;
690 OSL_ENSURE( xInfoSet.is(),
"missing infoset for export" );
692 xInfoSet->setPropertyValue(
"StreamName",
uno::Any( rStreamName ) );
696 rServiceName, rFilterProperties ), uno::UNO_QUERY);
697 if ( !xExporter.is() )
708 catch (
const uno::Exception&)
728 return "com.sun.star.comp.chart2.XMLFilter";
739 "com.sun.star.document.ImportFilter",
740 "com.sun.star.document.ExportFilter"
750 rOutOASIS = aMDHelper.
FilterName ==
"StarOffice XML (Base) Report Chart";
759extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
761 css::uno::Sequence<css::uno::Any>
const &)
763 return cppu::acquire(new ::chart::XMLFilter(context));
766extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
768 css::uno::Sequence<css::uno::Any>
const &)
770 return cppu::acquire(new ::chart::XMLReportFilterHelper(context));
Reference< uno::XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_XMLFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_report_XMLFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
ErrCode impl_Import(const css::uno::Reference< css::lang::XComponent > &xDocumentComp, const css::uno::Sequence< css::beans::PropertyValue > &aMediaDescriptor)
volatile bool m_bCancelOperation
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
OUString m_sDocumentHandler
ErrCode impl_ImportStream(const OUString &rStreamName, const OUString &rServiceName, const css::uno::Reference< css::embed::XStorage > &xStorage, const css::uno::Reference< css::lang::XMultiComponentFactory > &xFactory, const css::uno::Reference< css::document::XGraphicStorageHandler > &xGraphicStorageHandler, css::uno::Reference< css::beans::XPropertySet > const &xPropSet)
virtual OUString getMediaType(bool _bOasis)
virtual sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &aDescriptor) override
css::uno::Reference< css::lang::XComponent > m_xSourceDoc
ErrCode impl_Export(const css::uno::Reference< css::lang::XComponent > &xDocumentComp, const css::uno::Sequence< css::beans::PropertyValue > &aMediaDescriptor)
virtual ~XMLFilter() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Sequence< css::beans::PropertyValue > m_aMediaDescriptor
virtual void SAL_CALL setSourceDocument(const css::uno::Reference< css::lang::XComponent > &Document) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &Document) override
virtual void SAL_CALL cancel() override
XMLFilter(css::uno::Reference< css::uno::XComponentContext > const &xContext)
ErrCode impl_ExportStream(const OUString &rStreamName, const OUString &rServiceName, const css::uno::Reference< css::embed::XStorage > &xStorage, const css::uno::Reference< css::xml::sax::XWriter > &xActiveDataSource, const css::uno::Reference< css::lang::XMultiServiceFactory > &xFactory, const css::uno::Sequence< css::uno::Any > &rFilterProperties)
css::uno::Reference< css::lang::XComponent > m_xTargetDoc
virtual void isOasisFormat(const css::uno::Sequence< css::beans::PropertyValue > &_rMediaDescriptor, bool &_rOutOASIS)
fills the oasis flag only when a filtername was set
virtual OUString getMediaType(bool _bOasis) override
virtual void isOasisFormat(const css::uno::Sequence< css::beans::PropertyValue > &_rMediaDescriptor, bool &_rOutOASIS) override
fills the oasis flag only when a filtername was set
css::uno::Type const & get()
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
constexpr OUStringLiteral MIMETYPE_VND_SUN_XML_CHART_ASCII
constexpr OUStringLiteral MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART_ASCII
constexpr OUStringLiteral MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII
#define ERRCODE_IO_BROKENPACKAGE
Reference< XSingleServiceFactory > xFactory
#define SAL_INFO_IF(condition, area, stream)
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
#define ERRCODE_SFX_GENERAL
Reference< XModel > xModel