LibreOffice Module chart2 (master) 1
XMLFilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <XMLFilter.hxx>
22
23#include <officecfg/Office/Common.hxx>
24#include <svtools/sfxecode.hxx>
30
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>
51#include <sal/log.hxx>
52
53using namespace ::com::sun::star;
54
55using ::com::sun::star::uno::Reference;
56using ::com::sun::star::uno::Sequence;
57using ::osl::MutexGuard;
58
59namespace
60{
61constexpr OUStringLiteral sXML_metaStreamName = u"meta.xml";
62constexpr OUStringLiteral sXML_styleStreamName = u"styles.xml";
63constexpr OUStringLiteral sXML_contentStreamName = u"content.xml";
64
65
66uno::Reference< embed::XStorage > lcl_getWriteStorage(
67 const Sequence< beans::PropertyValue >& rMediaDescriptor,
68 const uno::Reference< uno::XComponentContext >& xContext,const OUString& _sMediaType)
69{
70 uno::Reference< embed::XStorage > xStorage;
71 try
72 {
73 apphelper::MediaDescriptorHelper aMDHelper( rMediaDescriptor );
74 if( aMDHelper.ISSET_Storage )
75 {
76 xStorage = aMDHelper.Storage;
77 }
78 else
79 {
80 Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create( xContext ) );
81
82 std::vector< beans::PropertyValue > aPropertiesForStorage;
83
84 for( sal_Int32 i=rMediaDescriptor.getLength(); i--; )
85 {
86 // properties understood by storage factory
87 // (see package/source/xstor/xfactory.cxx for details)
88 if ( rMediaDescriptor[i].Name == "InteractionHandler" || rMediaDescriptor[i].Name == "Password" || rMediaDescriptor[i].Name == "RepairPackage" )
89 {
90 aPropertiesForStorage.push_back( rMediaDescriptor[i] );
91 }
92 }
93
94 if( aMDHelper.ISSET_Storage )
95 xStorage.set( aMDHelper.Storage );
96 else
97 {
98 Sequence< uno::Any > aStorageArgs{
99 aMDHelper.ISSET_OutputStream ? uno::Any(aMDHelper.OutputStream)
100 : uno::Any(aMDHelper.URL),
101 uno::Any(embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE),
102 uno::Any(comphelper::containerToSequence( aPropertiesForStorage ))
103 };
104
105 xStorage.set(
106 xStorageFact->createInstanceWithArguments( aStorageArgs ),
107 uno::UNO_QUERY_THROW );
108 }
109 }
110
111 // set correct media type at storage
112 uno::Reference<beans::XPropertySet> xProp(xStorage,uno::UNO_QUERY);
113 OUString aMediaType;
114 if ( ! xProp.is() ||
115 ! ( xProp->getPropertyValue( "MediaType") >>= aMediaType ) ||
116 ( aMediaType.isEmpty() ))
117 {
118 xProp->setPropertyValue( "MediaType", uno::Any( _sMediaType ));
119 }
120 }
121 catch (const uno::Exception&)
122 {
123 DBG_UNHANDLED_EXCEPTION("chart2");
124 }
125 return xStorage;
126}
127
128uno::Reference< embed::XStorage > lcl_getReadStorage(
129 const Sequence< beans::PropertyValue >& rMediaDescriptor,
130 const uno::Reference< uno::XComponentContext >& xContext)
131{
132 uno::Reference< embed::XStorage > xStorage;
133
134 try
135 {
136 apphelper::MediaDescriptorHelper aMDHelper( rMediaDescriptor );
137 if( aMDHelper.ISSET_Storage )
138 {
139 xStorage = aMDHelper.Storage;
140 }
141 else
142 {
143 // get XStream from MediaDescriptor
144 uno::Reference< io::XInputStream > xStream;
145 std::vector< beans::PropertyValue > aPropertiesForStorage;
146 for( sal_Int32 i=rMediaDescriptor.getLength(); i--; )
147 {
148 if( rMediaDescriptor[i].Name == "InputStream" )
149 xStream.set( rMediaDescriptor[i].Value, uno::UNO_QUERY );
150
151 // properties understood by storage factory
152 // (see package/source/xstor/xfactory.cxx for details)
153 if ( rMediaDescriptor[i].Name == "InteractionHandler" || rMediaDescriptor[i].Name == "Password" || rMediaDescriptor[i].Name == "RepairPackage" )
154 {
155 aPropertiesForStorage.push_back( rMediaDescriptor[i] );
156 }
157 }
158 OSL_ENSURE( xStream.is(), "No Stream" );
159 if( ! xStream.is())
160 return xStorage;
161
162 // convert XInputStream to XStorage via the storage factory
163 Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create( xContext ) );
164 Sequence< uno::Any > aStorageArgs{
165 uno::Any(xStream),
166 uno::Any(embed::ElementModes::READ | embed::ElementModes::NOCREATE),
167 uno::Any(comphelper::containerToSequence( aPropertiesForStorage ))
168 };
169 xStorage.set(
170 xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW );
171 }
172
173 OSL_ENSURE( xStorage.is(), "No Storage" );
174 }
175 catch (const uno::Exception&)
176 {
177 DBG_UNHANDLED_EXCEPTION("chart2");
178 }
179
180 return xStorage;
181}
182
183} // anonymous namespace
184
185namespace chart
186{
187
189 m_xContext( xContext ),
190 m_bCancelOperation( false )
191{}
192
194{}
195
196// ____ XFilter ____
198 const Sequence< beans::PropertyValue >& aDescriptor )
199{
200 bool bResult = false;
201
202 MutexGuard aGuard( m_aMutex );
203
204 // ignore cancel flag at start of function
205 // note: is currently ignored during import/export
207 m_bCancelOperation = false;
208
209 if( m_xSourceDoc.is())
210 {
211 OSL_ENSURE( ! m_xTargetDoc.is(), "source doc is set -> target document should not be set" );
213 aDescriptor ) == ERRCODE_NONE )
214 {
215 m_xSourceDoc = nullptr;
216 bResult = true;
217 }
218 }
219 else if( m_xTargetDoc.is())
220 {
222 aDescriptor ) == ERRCODE_NONE )
223 {
224 m_xTargetDoc = nullptr;
225 bResult = true;
226 }
227 }
228 else
229 {
230 OSL_FAIL( "filter() called with no document set" );
231 }
232
233 return bResult;
234}
235
236void SAL_CALL XMLFilter::cancel()
237{
238 // if mutex is locked set "cancel state"
239 // note: is currently ignored in filter-method
240 if( ! m_aMutex.tryToAcquire())
241 {
242 m_bCancelOperation = true;
243 }
244}
245
246// ____ XImporter ____
248 const Reference< lang::XComponent >& Document )
249{
250 MutexGuard aGuard( m_aMutex );
251 OSL_ENSURE( ! m_xSourceDoc.is(), "Setting target doc while source doc is set" );
252
254}
255
256// ____ XExporter ____
258 const Reference< lang::XComponent >& Document )
259{
260 MutexGuard aGuard( m_aMutex );
261 OSL_ENSURE( ! m_xTargetDoc.is(), "Setting source doc while target doc is set" );
262
264}
265
267 const Reference< lang::XComponent > & xDocumentComp,
268 const Sequence< beans::PropertyValue > & rMediaDescriptor )
269{
270 ErrCode nWarning = ERRCODE_NONE;
271
272 OSL_ENSURE( xDocumentComp.is(), "Import: No Model" );
273 OSL_ENSURE( m_xContext.is(), "Import: No ComponentContext" );
274
275 if( ! (xDocumentComp.is() &&
276 m_xContext.is()))
277 return nWarning;
278
279 try
280 {
281 Reference< lang::XServiceInfo > xServInfo( xDocumentComp, uno::UNO_QUERY_THROW );
282 if( ! xServInfo->supportsService( "com.sun.star.chart2.ChartDocument"))
283 {
284 OSL_FAIL( "Import: No ChartDocument" );
285 return ERRCODE_SFX_GENERAL;
286 }
287
289 OSL_ENSURE( xFactory.is(), "Import: No Factory" );
290 if( ! xFactory.is())
291 return ERRCODE_SFX_GENERAL;
292
293 bool bOasis = true;
294 isOasisFormat( rMediaDescriptor, bOasis );
295 Reference< embed::XStorage > xStorage( lcl_getReadStorage( rMediaDescriptor, m_xContext));
296 if( ! xStorage.is())
297 return ERRCODE_SFX_GENERAL;
298
300 uno::Reference<lang::XMultiServiceFactory> xServiceFactory(xFactory, uno::UNO_QUERY);
301 if (xServiceFactory.is())
302 {
303 uno::Sequence<uno::Any> aArgs{ uno::Any(xStorage) };
304 xGraphicStorageHandler.set(
305 xServiceFactory->createInstanceWithArguments(
306 "com.sun.star.comp.Svx.GraphicImportHelper", aArgs), uno::UNO_QUERY);
307 }
308
309 // create XPropertySet with extra information for the filter
311 static comphelper::PropertyMapEntry const aImportInfoMap[] =
312 {
313 // necessary properties for XML progress bar at load time
314 { OUString("ProgressRange"), 0, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},
315 { OUString("ProgressMax"), 0, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},
316 { OUString("ProgressCurrent"), 0, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},
317 { OUString("PrivateData"), 0, cppu::UnoType<XInterface>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
318 { OUString("BaseURI"), 0, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
319 { OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
320 { OUString("StreamName"), 0, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
321 { OUString("BuildId"), 0, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
322 };
325 new comphelper::PropertySetInfo( aImportInfoMap ) ) );
326
327 // Set base URI and Hierarchical Name
328 OUString aHierarchName, aBaseUri;
329 // why retrieve this from the model when it's available as rMediaDescriptor?
331 if( xModel.is() )
332 {
333 const uno::Sequence< beans::PropertyValue > aModProps = xModel->getArgs();
334 for( beans::PropertyValue const & prop : aModProps )
335 {
336 if( prop.Name == "HierarchicalDocumentName" )
337 {
338 // Actually this argument only has meaning for embedded documents
339 prop.Value >>= aHierarchName;
340 }
341 else if( prop.Name == "DocumentBaseURL" )
342 {
343 prop.Value >>= aBaseUri;
344 }
345 }
346 }
347
348 // needed for relative URLs, but in clipboard copy/paste there may be none
349 SAL_INFO_IF(aBaseUri.isEmpty(), "chart2", "chart::XMLFilter: no base URL");
350 if( !aBaseUri.isEmpty() )
351 xImportInfo->setPropertyValue( "BaseURI", uno::Any( aBaseUri ) );
352
353 if( !aHierarchName.isEmpty() )
354 xImportInfo->setPropertyValue( "StreamRelPath", uno::Any( aHierarchName ) );
355
356 // import meta information
357 if( bOasis )
358 nWarning = impl_ImportStream(
359 sXML_metaStreamName,
360 "com.sun.star.comp.Chart.XMLOasisMetaImporter",
361 xStorage, xFactory, xGraphicStorageHandler, xImportInfo );
362
363 // import styles
364 ErrCode nTmpErr = impl_ImportStream(
365 sXML_styleStreamName,
366 bOasis
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;
371
372 // import content
373 ErrCode nContentWarning = impl_ImportStream(
374 sXML_contentStreamName,
375 bOasis
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;
380 }
381 catch (const uno::Exception&)
382 {
383 DBG_UNHANDLED_EXCEPTION("chart2");
384
385 // something went awry
386 nWarning = ERRCODE_SFX_GENERAL;
387 }
388
389 return nWarning;
390}
391
393 const OUString & rStreamName,
394 const OUString & rServiceName,
395 const Reference< embed::XStorage > & xStorage,
397 const Reference< document::XGraphicStorageHandler > & xGraphicStorageHandler,
398 uno::Reference< beans::XPropertySet > const & xImportInfo )
399{
400 ErrCode nWarning = ERRCODE_SFX_GENERAL;
401
402 if( ! (xStorage.is() &&
403 xStorage->hasByName( rStreamName )))
404 return ERRCODE_NONE;
405
406 if( xImportInfo.is() )
407 xImportInfo->setPropertyValue( "StreamName", uno::Any( rStreamName ) );
408
409 if( xStorage.is() &&
410 xStorage->isStreamElement( rStreamName ) )
411 {
412 try
413 {
414 auto xInputStream =
415 xStorage->openStreamElement(
416 rStreamName,
417 embed::ElementModes::READ | embed::ElementModes::NOCREATE );
418
419 // todo: encryption
420
421 if( xInputStream.is())
422 {
423 sal_Int32 nArgs = 0;
424 if( xGraphicStorageHandler.is())
425 nArgs++;
426 if( xImportInfo.is())
427 nArgs++;
428
429 uno::Sequence< uno::Any > aFilterCompArgs( nArgs );
430 auto aFilterCompArgsRange = asNonConstRange(aFilterCompArgs);
431
432 nArgs = 0;
433 if( xGraphicStorageHandler.is())
434 aFilterCompArgsRange[nArgs++] <<= xGraphicStorageHandler;
435 if( xImportInfo.is())
436 aFilterCompArgsRange[ nArgs++ ] <<= xImportInfo;
437
438 // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler
440 xFactory->createInstanceWithArgumentsAndContext( rServiceName, aFilterCompArgs, m_xContext );
441 assert(xFilter);
442 Reference< document::XImporter > xImporter( xFilter, uno::UNO_QUERY );
443 assert(xImporter);
444 xImporter->setTargetDocument( Reference< lang::XComponent >( m_xTargetDoc, uno::UNO_SET_THROW ));
445
446 if ( !m_sDocumentHandler.isEmpty() )
447 {
448 try
449 {
451 uno::Any(beans::NamedValue("DocumentHandler", uno::Any(xFilter))),
452 uno::Any(beans::NamedValue("Model", uno::Any(m_xTargetDoc)))
453 };
454
455 xFilter = xFactory->createInstanceWithArgumentsAndContext(m_sDocumentHandler,aArgs,m_xContext);
456 }
457 catch (const uno::Exception&)
458 {
459 TOOLS_WARN_EXCEPTION("chart2", "failed to instantiate " << m_sDocumentHandler);
460 }
461 }
462 xml::sax::InputSource aParserInput;
463 aParserInput.aInputStream.set(xInputStream, uno::UNO_QUERY_THROW);
464
465 // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler
466 Reference< xml::sax::XFastParser > xFastParser(xFilter, uno::UNO_QUERY);
467 if (xFastParser.is())
468 xFastParser->parseStream(aParserInput);
469 else
470 {
471 Reference<xml::sax::XParser> xParser = xml::sax::Parser::create(m_xContext);
472 xParser->setDocumentHandler( uno::Reference<xml::sax::XDocumentHandler>(xFilter, uno::UNO_QUERY_THROW) );
473 xParser->parseStream(aParserInput);
474 }
475 }
476
477 // load was successful
478 nWarning = ERRCODE_NONE;
479 }
480 catch (const xml::sax::SAXParseException&)
481 {
482 // todo: if encrypted: ERRCODE_SFX_WRONGPASSWORD
483 }
484 catch (const xml::sax::SAXException&)
485 {
486 // todo: if encrypted: ERRCODE_SFX_WRONGPASSWORD
487 }
488 catch (const packages::zip::ZipIOException&)
489 {
490 nWarning = ERRCODE_IO_BROKENPACKAGE;
491 }
492 catch (const io::IOException&)
493 {
494 TOOLS_WARN_EXCEPTION("chart2", "");
495 }
496 catch (const uno::Exception&)
497 {
498 DBG_UNHANDLED_EXCEPTION("chart2");
499 }
500 }
501
502 return nWarning;
503}
504
506 const Reference< lang::XComponent > & xDocumentComp,
507 const Sequence< beans::PropertyValue > & rMediaDescriptor )
508{
509 m_aMediaDescriptor = rMediaDescriptor;
510 //save
511
512 ErrCode nWarning = ERRCODE_NONE;
513
514 OSL_ENSURE( xDocumentComp.is(), "Export: No Model" );
515 OSL_ENSURE( m_xContext.is(), "Export: No ComponentContext" );
516
517 if( !xDocumentComp.is() || !m_xContext.is() )
518 return nWarning;
519
520 try
521 {
522 Reference< lang::XServiceInfo > xServInfo( xDocumentComp, uno::UNO_QUERY_THROW );
523 if( ! xServInfo->supportsService( "com.sun.star.chart2.ChartDocument"))
524 {
525 OSL_FAIL( "Export: No ChartDocument" );
526 return ERRCODE_SFX_GENERAL;
527 }
528
530 OSL_ENSURE( xFactory.is(), "Export: No Factory" );
531 if( ! xFactory.is())
532 return ERRCODE_SFX_GENERAL;
533 uno::Reference< lang::XMultiServiceFactory > xServiceFactory( m_xContext->getServiceManager(), uno::UNO_QUERY);
534 if( ! xServiceFactory.is())
535 return ERRCODE_SFX_GENERAL;
536
537 uno::Reference< xml::sax::XWriter > xSaxWriter = xml::sax::Writer::create(m_xContext);
538
539 bool bOasis = true;
540 isOasisFormat( rMediaDescriptor, bOasis );
541
542 uno::Reference< embed::XStorage > xStorage( lcl_getWriteStorage( rMediaDescriptor, m_xContext, getMediaType(bOasis) ) );
543 OSL_ENSURE( xStorage.is(), "No Storage" );
544 if( ! xStorage.is())
545 return ERRCODE_SFX_GENERAL;
546
547 uno::Reference< xml::sax::XDocumentHandler> xDocHandler = xSaxWriter;
548
549 if ( !m_sDocumentHandler.isEmpty() )
550 {
551 try
552 {
554 uno::Any(beans::NamedValue("DocumentHandler", uno::Any(xDocHandler))),
555 uno::Any(beans::NamedValue("Model", uno::Any(xDocumentComp)))
556 };
557
558 xDocHandler.set(xServiceFactory->createInstanceWithArguments(m_sDocumentHandler,aArgs), uno::UNO_QUERY );
559 xSaxWriter.set(xDocHandler,uno::UNO_QUERY);
560 }
561 catch (const uno::Exception&)
562 {
563 TOOLS_WARN_EXCEPTION( "chart2", "Exception caught!");
564 }
565 }
566
567 Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
568 xGraphicStorageHandler.set(document::GraphicStorageHandler::createWithStorage(m_xContext, xStorage));
569
570 // property map for export info set
571 static comphelper::PropertyMapEntry const aExportInfoMap[] =
572 {
573 { OUString("UsePrettyPrinting"), 0, cppu::UnoType<bool>::get(), beans::PropertyAttribute::MAYBEVOID, 0},
574 { OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
575 { OUString("StreamRelPath"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
576 { OUString("StreamName"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
577 { OUString("ExportTableNumberList"), 0, cppu::UnoType<bool>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
578 };
579
582
583 bool bUsePrettyPrinting( officecfg::Office::Common::Save::Document::PrettyPrinting::get() );
584 xInfoSet->setPropertyValue( "UsePrettyPrinting", uno::Any( bUsePrettyPrinting ) );
585 if( ! bOasis )
586 xInfoSet->setPropertyValue( "ExportTableNumberList", uno::Any( true ));
587
588 sal_Int32 nArgs = 2;
589 if( xGraphicStorageHandler.is())
590 nArgs++;
591
592 uno::Sequence< uno::Any > aFilterProperties( nArgs );
593 {
594 auto pFilterProperties = aFilterProperties.getArray();
595 nArgs = 0;
596 pFilterProperties[ nArgs++ ] <<= xInfoSet;
597 pFilterProperties[ nArgs++ ] <<= xDocHandler;
598 if( xGraphicStorageHandler.is())
599 pFilterProperties[ nArgs++ ] <<= xGraphicStorageHandler;
600 }
601
602 // export meta information
603 if( bOasis )
604 nWarning = impl_ExportStream(
605 sXML_metaStreamName,
606 "com.sun.star.comp.Chart.XMLOasisMetaExporter",
607 xStorage, xSaxWriter, xServiceFactory, aFilterProperties );
608
609 // export styles
611 sXML_styleStreamName,
612 bOasis
613 ? OUString("com.sun.star.comp.Chart.XMLOasisStylesExporter")
614 : OUString("com.sun.star.comp.Chart.XMLStylesExporter"), // soffice 6/7
615 xStorage, xSaxWriter, xServiceFactory, aFilterProperties );
616 nWarning = nWarning != ERRCODE_NONE ? nWarning : nTmp;
617
618 // export content
619 ErrCode nContentWarning = impl_ExportStream(
620 sXML_contentStreamName,
621 bOasis
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;
626
627 Reference< lang::XComponent > xComp(xGraphicStorageHandler, uno::UNO_QUERY);
628 if (xComp.is())
629 xComp->dispose();
630
631 uno::Reference<embed::XTransactedObject> xTransact( xStorage ,uno::UNO_QUERY);
632 if ( xTransact.is() )
633 xTransact->commit();
634 }
635 catch (const uno::Exception&)
636 {
637 DBG_UNHANDLED_EXCEPTION("chart2");
638
639 // something went awry
640 nWarning = ERRCODE_SFX_GENERAL;
641 }
642
643 return nWarning;
644}
645
647 const OUString & rStreamName,
648 const OUString & rServiceName,
649 const Reference< embed::XStorage > & xStorage,
650 const uno::Reference< xml::sax::XWriter >& xActiveDataSource,
651 const Reference< lang::XMultiServiceFactory >& xServiceFactory,
652 const Sequence< uno::Any > & rFilterProperties )
653{
654 try
655 {
656 if( !xServiceFactory.is() )
657 return ERRCODE_SFX_GENERAL;
658 if( !xStorage.is() )
659 return ERRCODE_SFX_GENERAL;
660 if ( !xActiveDataSource.is() )
661 return ERRCODE_SFX_GENERAL;
662
663 uno::Reference< io::XStream > xStream( xStorage->openStreamElement(
664 rStreamName, embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ) );
665 if ( !xStream.is() )
666 return ERRCODE_SFX_GENERAL;
667 uno::Reference< io::XOutputStream > xOutputStream( xStream->getOutputStream() );
668 if ( !xOutputStream.is() )
669 return ERRCODE_SFX_GENERAL;
670
671 uno::Reference< beans::XPropertySet > xStreamProp( xOutputStream, uno::UNO_QUERY );
672 if(xStreamProp.is()) try
673 {
674 xStreamProp->setPropertyValue( "MediaType", uno::Any( OUString("text/xml") ) );
675 xStreamProp->setPropertyValue( "Compressed", uno::Any( true ) );//@todo?
676 xStreamProp->setPropertyValue( "UseCommonStoragePasswordEncryption", uno::Any( true ) );
677 }
678 catch (const uno::Exception&)
679 {
680 DBG_UNHANDLED_EXCEPTION("chart2");
681 }
682
683 xActiveDataSource->setOutputStream(xOutputStream);
684
685 // set Base URL
686 {
688 if( rFilterProperties.hasElements() )
689 rFilterProperties.getConstArray()[0] >>= xInfoSet;
690 OSL_ENSURE( xInfoSet.is(), "missing infoset for export" );
691 if( xInfoSet.is() )
692 xInfoSet->setPropertyValue( "StreamName", uno::Any( rStreamName ) );
693 }
694
695 Reference< XExporter > xExporter( xServiceFactory->createInstanceWithArguments(
696 rServiceName, rFilterProperties ), uno::UNO_QUERY);
697 if ( !xExporter.is() )
698 return ERRCODE_SFX_GENERAL;
699
700 xExporter->setSourceDocument( m_xSourceDoc );
701
702 uno::Reference< document::XFilter > xFilter( xExporter, uno::UNO_QUERY );
703 if ( !xFilter.is() )
704 return ERRCODE_SFX_GENERAL;
705
706 xFilter->filter(m_aMediaDescriptor);
707 }
708 catch (const uno::Exception&)
709 {
710 DBG_UNHANDLED_EXCEPTION("chart2");
711 }
712 return ERRCODE_NONE;
713}
714
715void XMLFilter::isOasisFormat(const Sequence< beans::PropertyValue >& _rMediaDescriptor, bool & rOutOASIS )
716{
717 apphelper::MediaDescriptorHelper aMDHelper( _rMediaDescriptor );
718 if( aMDHelper.ISSET_FilterName )
719 rOutOASIS = aMDHelper.FilterName == "chart8";
720}
721OUString XMLFilter::getMediaType(bool _bOasis)
722{
724}
725
727{
728 return "com.sun.star.comp.chart2.XMLFilter";
729}
730
731sal_Bool SAL_CALL XMLFilter::supportsService( const OUString& rServiceName )
732{
733 return cppu::supportsService(this, rServiceName);
734}
735
736css::uno::Sequence< OUString > SAL_CALL XMLFilter::getSupportedServiceNames()
737{
738 return {
739 "com.sun.star.document.ImportFilter",
740 "com.sun.star.document.ExportFilter"
741 };
742 // todo: services are incomplete. Missing:
743 // XInitialization, XNamed
744}
745
746void XMLReportFilterHelper::isOasisFormat(const Sequence< beans::PropertyValue >& _rMediaDescriptor, bool & rOutOASIS )
747{
748 apphelper::MediaDescriptorHelper aMDHelper( _rMediaDescriptor );
749 if( aMDHelper.ISSET_FilterName )
750 rOutOASIS = aMDHelper.FilterName == "StarOffice XML (Base) Report Chart";
751}
753{
755}
756
757} // namespace chart
758
759extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
760com_sun_star_comp_chart2_XMLFilter_get_implementation(css::uno::XComponentContext *context,
761 css::uno::Sequence<css::uno::Any> const &)
762{
763 return cppu::acquire(new ::chart::XMLFilter(context));
764}
765
766extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
768 css::uno::Sequence<css::uno::Any> const &)
769{
770 return cppu::acquire(new ::chart::XMLReportFilterHelper(context));
771}
772
773/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< uno::XComponentContext > m_xContext
Reference< XInputStream > xStream
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 &)
Definition: XMLFilter.cxx:760
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 &)
Definition: XMLFilter.cxx:767
ErrCode impl_Import(const css::uno::Reference< css::lang::XComponent > &xDocumentComp, const css::uno::Sequence< css::beans::PropertyValue > &aMediaDescriptor)
Definition: XMLFilter.cxx:266
volatile bool m_bCancelOperation
Definition: XMLFilter.hxx:127
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: XMLFilter.cxx:731
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
Definition: XMLFilter.cxx:726
OUString m_sDocumentHandler
Definition: XMLFilter.hxx:125
::osl::Mutex m_aMutex
Definition: XMLFilter.hxx:128
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)
Definition: XMLFilter.cxx:392
virtual OUString getMediaType(bool _bOasis)
Definition: XMLFilter.cxx:721
virtual sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &aDescriptor) override
Definition: XMLFilter.cxx:197
css::uno::Reference< css::lang::XComponent > m_xSourceDoc
Definition: XMLFilter.hxx:121
ErrCode impl_Export(const css::uno::Reference< css::lang::XComponent > &xDocumentComp, const css::uno::Sequence< css::beans::PropertyValue > &aMediaDescriptor)
Definition: XMLFilter.cxx:505
virtual ~XMLFilter() override
Definition: XMLFilter.cxx:193
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: XMLFilter.cxx:736
css::uno::Sequence< css::beans::PropertyValue > m_aMediaDescriptor
Definition: XMLFilter.hxx:123
virtual void SAL_CALL setSourceDocument(const css::uno::Reference< css::lang::XComponent > &Document) override
Definition: XMLFilter.cxx:257
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: XMLFilter.hxx:119
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &Document) override
Definition: XMLFilter.cxx:247
virtual void SAL_CALL cancel() override
Definition: XMLFilter.cxx:236
XMLFilter(css::uno::Reference< css::uno::XComponentContext > const &xContext)
Definition: XMLFilter.cxx:188
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)
Definition: XMLFilter.cxx:646
css::uno::Reference< css::lang::XComponent > m_xTargetDoc
Definition: XMLFilter.hxx:120
virtual void isOasisFormat(const css::uno::Sequence< css::beans::PropertyValue > &_rMediaDescriptor, bool &_rOutOASIS)
fills the oasis flag only when a filtername was set
Definition: XMLFilter.cxx:715
virtual OUString getMediaType(bool _bOasis) override
Definition: XMLFilter.cxx:752
virtual void isOasisFormat(const css::uno::Sequence< css::beans::PropertyValue > &_rMediaDescriptor, bool &_rOutOASIS) override
fills the oasis flag only when a filtername was set
Definition: XMLFilter.cxx:746
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
float u
#define ERRCODE_IO_BROKENPACKAGE
#define ERRCODE_NONE
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
unsigned char sal_Bool