Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / core / xmlexp.cxx
blob8ed21181dff9695b89cfa0f25dd29ee9c38b7bc1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sal/config.h>
22 #include <stack>
23 #include <string.h>
25 #include <officecfg/Office/Common.hxx>
26 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
27 #include <osl/mutex.hxx>
28 #include <tools/urlobj.hxx>
29 #include <comphelper/genericpropertyset.hxx>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/io/XInputStream.hpp>
32 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
33 #include <com/sun/star/xml/sax/SAXInvalidCharacterException.hpp>
34 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
35 #include <com/sun/star/uri/UriReferenceFactory.hpp>
36 #include <com/sun/star/util/MeasureUnit.hpp>
37 #include <i18nlangtag/languagetag.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <xmloff/attrlist.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include <xmloff/xmluconv.hxx>
42 #include <xmloff/xmlnmspe.hxx>
43 #include <xmloff/xmltoken.hxx>
44 #include <xmloff/xmlexp.hxx>
45 #include <xmloff/xmlnumfe.hxx>
46 #include <xmloff/xmlmetae.hxx>
47 #include <xmloff/XMLSettingsExportContext.hxx>
48 #include <xmloff/families.hxx>
49 #include <xmloff/XMLEventExport.hxx>
50 #include "XMLStarBasicExportHandler.hxx"
51 #include "XMLScriptExportHandler.hxx"
52 #include <xmloff/SettingsExportHelper.hxx>
53 #include <com/sun/star/container/XIndexContainer.hpp>
54 #include <com/sun/star/document/XEventsSupplier.hpp>
55 #include <com/sun/star/document/XViewDataSupplier.hpp>
56 #include <xmloff/GradientStyle.hxx>
57 #include <xmloff/HatchStyle.hxx>
58 #include <xmloff/ImageStyle.hxx>
59 #include <TransGradientStyle.hxx>
60 #include <xmloff/MarkerStyle.hxx>
61 #include <xmloff/DashStyle.hxx>
62 #include <xmloff/XMLFontAutoStylePool.hxx>
63 #include "XMLImageMapExport.hxx"
64 #include "XMLBase64Export.hxx"
65 #include <xmloff/xmlerror.hxx>
66 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
67 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
68 #include <com/sun/star/beans/PropertyAttribute.hpp>
69 #include <xmloff/XMLFilterServiceNames.h>
70 #include <xmloff/XMLEmbeddedObjectExportFilter.hxx>
71 #include "XMLBasicExportFilter.hxx"
72 #include <cppuhelper/exc_hlp.hxx>
73 #include <cppuhelper/implbase.hxx>
74 #include <cppuhelper/supportsservice.hxx>
75 #include <comphelper/extract.hxx>
76 #include <comphelper/servicehelper.hxx>
77 #include "PropertySetMerger.hxx"
79 #include <svl/urihelper.hxx>
80 #include <xmloff/xformsexport.hxx>
82 #include <unotools/docinfohelper.hxx>
83 #include <unotools/bootstrap.hxx>
84 #include <unotools/configmgr.hxx>
85 #include <com/sun/star/document/XDocumentProperties.hpp>
86 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
87 #include <com/sun/star/document/XMLOasisBasicExporter.hpp>
88 #include <com/sun/star/embed/XEncryptionProtectedSource2.hpp>
89 #include <com/sun/star/rdf/XMetadatable.hpp>
90 #include "RDFaExportHelper.hxx"
92 #include <comphelper/xmltools.hxx>
94 using namespace ::osl;
95 using namespace ::com::sun::star;
96 using namespace ::com::sun::star::uno;
97 using namespace ::com::sun::star::frame;
98 using namespace ::com::sun::star::container;
99 using namespace ::com::sun::star::lang;
100 using namespace ::com::sun::star::document;
101 using namespace ::com::sun::star::beans;
102 using namespace ::com::sun::star::xml::sax;
103 using namespace ::com::sun::star::io;
104 using namespace ::xmloff::token;
106 sal_Char const sXML_1_1[] = "1.1";
107 sal_Char const sXML_1_2[] = "1.2";
109 #define XML_MODEL_SERVICE_WRITER "com.sun.star.text.TextDocument"
110 #define XML_MODEL_SERVICE_CALC "com.sun.star.sheet.SpreadsheetDocument"
111 #define XML_MODEL_SERVICE_DRAW "com.sun.star.drawing.DrawingDocument"
112 #define XML_MODEL_SERVICE_IMPRESS "com.sun.star.presentation.PresentationDocument"
113 #define XML_MODEL_SERVICE_MATH "com.sun.star.formula.FormulaProperties"
114 #define XML_MODEL_SERVICE_CHART "com.sun.star.chart.ChartDocument"
116 #define XML_USEPRETTYPRINTING "UsePrettyPrinting"
118 namespace {
120 struct XMLServiceMapEntry_Impl
122 const sal_Char *sModelService;
123 sal_Int32 nModelServiceLen;
124 const sal_Char *sFilterService;
125 sal_Int32 nFilterServiceLen;
130 #define SERVICE_MAP_ENTRY( app ) \
131 { XML_MODEL_SERVICE_##app, sizeof(XML_MODEL_SERVICE_##app)-1, \
132 XML_EXPORT_FILTER_##app, sizeof(XML_EXPORT_FILTER_##app)-1 }
134 const XMLServiceMapEntry_Impl aServiceMap[] =
136 SERVICE_MAP_ENTRY( WRITER ),
137 SERVICE_MAP_ENTRY( CALC ),
138 SERVICE_MAP_ENTRY( IMPRESS ),// Impress supports DrawingDocument, too, so
139 SERVICE_MAP_ENTRY( DRAW ), // it must appear before Draw
140 SERVICE_MAP_ENTRY( MATH ),
141 SERVICE_MAP_ENTRY( CHART ),
142 { nullptr, 0, nullptr, 0 }
145 class SettingsExportFacade : public ::xmloff::XMLSettingsExportContext
147 public:
148 explicit SettingsExportFacade( SvXMLExport& i_rExport )
149 :m_rExport( i_rExport )
153 virtual ~SettingsExportFacade()
157 virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName,
158 const OUString& i_rValue ) override;
159 virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName,
160 enum ::xmloff::token::XMLTokenEnum i_eValue ) override;
162 virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName ) override;
163 virtual void EndElement( const bool i_bIgnoreWhitespace ) override;
165 virtual void Characters( const OUString& i_rCharacters ) override;
167 virtual css::uno::Reference< css::uno::XComponentContext >
168 GetComponentContext() const override;
169 private:
170 SvXMLExport& m_rExport;
171 ::std::stack< OUString > m_aElements;
174 void SettingsExportFacade::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const OUString& i_rValue )
176 m_rExport.AddAttribute( XML_NAMESPACE_CONFIG, i_eName, i_rValue );
179 void SettingsExportFacade::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue )
181 m_rExport.AddAttribute( XML_NAMESPACE_CONFIG, i_eName, i_eValue );
184 void SettingsExportFacade::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName )
186 const OUString sElementName( m_rExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_CONFIG, GetXMLToken( i_eName ) ) );
187 m_rExport.StartElement( sElementName, true/*i_bIgnoreWhitespace*/ );
188 m_aElements.push( sElementName );
191 void SettingsExportFacade::EndElement( const bool i_bIgnoreWhitespace )
193 const OUString sElementName( m_aElements.top() );
194 m_rExport.EndElement( sElementName, i_bIgnoreWhitespace );
195 m_aElements.pop();
198 void SettingsExportFacade::Characters( const OUString& i_rCharacters )
200 m_rExport.GetDocHandler()->characters( i_rCharacters );
203 Reference< XComponentContext > SettingsExportFacade::GetComponentContext() const
205 return m_rExport.getComponentContext();
208 class SvXMLExportEventListener : public cppu::WeakImplHelper<
209 css::lang::XEventListener >
211 private:
212 SvXMLExport* pExport;
214 public:
215 explicit SvXMLExportEventListener(SvXMLExport* pExport);
216 virtual ~SvXMLExportEventListener();
218 // XEventListener
219 virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(css::uno::RuntimeException, std::exception) override;
222 SvXMLExportEventListener::SvXMLExportEventListener(SvXMLExport* pTempExport)
223 : pExport(pTempExport)
227 SvXMLExportEventListener::~SvXMLExportEventListener()
231 // XEventListener
232 void SAL_CALL SvXMLExportEventListener::disposing( const lang::EventObject& )
233 throw(uno::RuntimeException, std::exception)
235 if (pExport)
237 pExport->DisposingModel();
238 pExport = nullptr;
242 class SvXMLExport_Impl
244 public:
245 SvXMLExport_Impl();
247 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
248 uno::Reference< uri::XUriReferenceFactory > mxUriReferenceFactory;
249 OUString msPackageURI;
250 OUString msPackageURIScheme;
251 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
252 bool mbOutlineStyleAsNormalListStyle;
253 bool mbSaveBackwardCompatibleODF;
255 uno::Reference< embed::XStorage > mxTargetStorage;
257 SvtSaveOptions maSaveOptions;
259 /// name of stream in package, e.g., "content.xml"
260 OUString mStreamName;
262 OUString maSrcShellID;
263 OUString maDestShellID;
265 /// stack of backed up namespace maps
266 /// long: depth at which namespace map has been backed up into the stack
267 ::std::stack< ::std::pair< SvXMLNamespaceMap *, long > > mNamespaceMaps;
268 /// counts depth (number of open elements/start tags)
269 long mDepth;
271 ::std::unique_ptr< ::xmloff::RDFaExportHelper> mpRDFaHelper;
273 bool mbExportTextNumberElement;
274 bool mbNullDateInitialized;
276 void SetSchemeOf( const OUString& rOrigFileName )
278 sal_Int32 nSep = rOrigFileName.indexOf(':');
279 if( nSep != -1 )
280 msPackageURIScheme = rOrigFileName.copy( 0, nSep );
284 SvXMLExport_Impl::SvXMLExport_Impl()
285 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
286 : mbOutlineStyleAsNormalListStyle( false )
287 ,mbSaveBackwardCompatibleODF( true )
288 ,mStreamName()
289 ,mNamespaceMaps()
290 ,mDepth(0)
291 ,mpRDFaHelper() // lazy
292 ,mbExportTextNumberElement( false )
293 ,mbNullDateInitialized( false )
295 mxUriReferenceFactory = uri::UriReferenceFactory::create( comphelper::getProcessComponentContext() );
298 void SvXMLExport::SetDocHandler( const uno::Reference< xml::sax::XDocumentHandler > &rHandler )
300 mxHandler = rHandler;
301 mxExtHandler.set( mxHandler, UNO_QUERY );
304 void SvXMLExport::InitCtor_()
306 // note: it is not necessary to add XML_NP_XML (it is declared implicitly)
307 if( getExportFlags() & ~SvXMLExportFlags::OASIS )
309 mpNamespaceMap->Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE );
310 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
312 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::FONTDECLS) )
314 mpNamespaceMap->Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
316 if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SCRIPTS|SvXMLExportFlags::SETTINGS) )
318 mpNamespaceMap->Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
320 if( getExportFlags() & SvXMLExportFlags::SETTINGS )
322 mpNamespaceMap->Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG );
325 if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
327 mpNamespaceMap->Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
328 mpNamespaceMap->Add( GetXMLToken(XML_NP_META), GetXMLToken(XML_N_META), XML_NAMESPACE_META );
330 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::FONTDECLS) )
332 mpNamespaceMap->Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE );
335 // namespaces for documents
336 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
338 mpNamespaceMap->Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
339 mpNamespaceMap->Add( GetXMLToken(XML_NP_TEXT), GetXMLToken(XML_N_TEXT), XML_NAMESPACE_TEXT );
340 mpNamespaceMap->Add( GetXMLToken(XML_NP_DRAW), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW );
341 mpNamespaceMap->Add( GetXMLToken(XML_NP_DR3D), GetXMLToken(XML_N_DR3D), XML_NAMESPACE_DR3D );
342 mpNamespaceMap->Add( GetXMLToken(XML_NP_SVG), GetXMLToken(XML_N_SVG_COMPAT), XML_NAMESPACE_SVG );
343 mpNamespaceMap->Add( GetXMLToken(XML_NP_CHART), GetXMLToken(XML_N_CHART), XML_NAMESPACE_CHART );
344 mpNamespaceMap->Add( GetXMLToken(XML_NP_RPT), GetXMLToken(XML_N_RPT), XML_NAMESPACE_REPORT );
345 mpNamespaceMap->Add( GetXMLToken(XML_NP_TABLE), GetXMLToken(XML_N_TABLE), XML_NAMESPACE_TABLE );
346 mpNamespaceMap->Add( GetXMLToken(XML_NP_NUMBER),GetXMLToken(XML_N_NUMBER), XML_NAMESPACE_NUMBER );
347 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOOW), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
348 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOOC), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
349 mpNamespaceMap->Add( GetXMLToken(XML_NP_OF), GetXMLToken(XML_N_OF), XML_NAMESPACE_OF );
351 if (getDefaultVersion() > SvtSaveOptions::ODFVER_012)
353 mpNamespaceMap->Add(
354 GetXMLToken(XML_NP_TABLE_EXT), GetXMLToken(XML_N_TABLE_EXT), XML_NAMESPACE_TABLE_EXT);
355 mpNamespaceMap->Add(
356 GetXMLToken(XML_NP_CALC_EXT), GetXMLToken(XML_N_CALC_EXT), XML_NAMESPACE_CALC_EXT);
357 mpNamespaceMap->Add(
358 GetXMLToken(XML_NP_DRAW_EXT), GetXMLToken(XML_N_DRAW_EXT), XML_NAMESPACE_DRAW_EXT);
359 mpNamespaceMap->Add(
360 GetXMLToken(XML_NP_LO_EXT), GetXMLToken(XML_N_LO_EXT),
361 XML_NAMESPACE_LO_EXT);
362 mpNamespaceMap->Add( GetXMLToken(XML_NP_FIELD), GetXMLToken(XML_N_FIELD), XML_NAMESPACE_FIELD );
365 if( getExportFlags() & (SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
367 mpNamespaceMap->Add( GetXMLToken(XML_NP_MATH), GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH );
368 mpNamespaceMap->Add( GetXMLToken(XML_NP_FORM), GetXMLToken(XML_N_FORM), XML_NAMESPACE_FORM );
370 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SCRIPTS) )
372 mpNamespaceMap->Add( GetXMLToken(XML_NP_SCRIPT), GetXMLToken(XML_N_SCRIPT), XML_NAMESPACE_SCRIPT );
373 mpNamespaceMap->Add( GetXMLToken(XML_NP_DOM), GetXMLToken(XML_N_DOM), XML_NAMESPACE_DOM );
375 if( getExportFlags() & SvXMLExportFlags::CONTENT )
377 mpNamespaceMap->Add( GetXMLToken(XML_NP_XFORMS_1_0), GetXMLToken(XML_N_XFORMS_1_0), XML_NAMESPACE_XFORMS );
378 mpNamespaceMap->Add( GetXMLToken(XML_NP_XSD), GetXMLToken(XML_N_XSD), XML_NAMESPACE_XSD );
379 mpNamespaceMap->Add( GetXMLToken(XML_NP_XSI), GetXMLToken(XML_N_XSI), XML_NAMESPACE_XSI );
380 mpNamespaceMap->Add( GetXMLToken(XML_NP_FORMX), GetXMLToken(XML_N_FORMX), XML_NAMESPACE_FORMX );
383 // RDFa: needed for content and header/footer styles
384 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
386 mpNamespaceMap->Add( GetXMLToken(XML_NP_XHTML),
387 GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
389 // GRDDL: to convert RDFa and meta.xml to RDF
390 if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
392 mpNamespaceMap->Add( GetXMLToken(XML_NP_GRDDL),
393 GetXMLToken(XML_N_GRDDL), XML_NAMESPACE_GRDDL );
395 // CSS Text Level 3 for distributed text justification.
396 if ( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES) )
398 mpNamespaceMap->Add(
399 GetXMLToken(XML_NP_CSS3TEXT), GetXMLToken(XML_N_CSS3TEXT), XML_NAMESPACE_CSS3TEXT );
402 mxAttrList = static_cast<xml::sax::XAttributeList*>(mpAttrList);
404 msGraphicObjectProtocol = "vnd.sun.star.GraphicObject:";
405 msEmbeddedObjectProtocol = "vnd.sun.star.EmbeddedObject:";
407 if (mxModel.is() && !mxEventListener.is())
409 mxEventListener.set( new SvXMLExportEventListener(this));
410 mxModel->addEventListener(mxEventListener);
413 // Determine model type (#i51726#)
414 DetermineModelType_();
416 // cl: but only if we do export to current oasis format, old openoffice format *must* always be compatible
417 if( getExportFlags() & SvXMLExportFlags::OASIS )
419 mpImpl->mbSaveBackwardCompatibleODF =
420 officecfg::Office::Common::Save::Document::
421 SaveBackwardCompatibleODF::get( comphelper::getProcessComponentContext() );
425 // Shapes in Writer cannot be named via context menu (#i51726#)
426 void SvXMLExport::DetermineModelType_()
428 meModelType = SvtModuleOptions::EFactory::UNKNOWN_FACTORY;
430 if ( mxModel.is() )
432 meModelType = SvtModuleOptions::ClassifyFactoryByModel( mxModel );
436 SvXMLExport::SvXMLExport(
437 sal_Int16 const eDefaultMeasureUnit /*css::util::MeasureUnit*/,
438 const uno::Reference< uno::XComponentContext >& xContext,
439 OUString const & implementationName,
440 const enum XMLTokenEnum eClass, SvXMLExportFlags nExportFlags )
441 : mpImpl( new SvXMLExport_Impl ),
442 m_xContext(xContext), m_implementationName(implementationName),
443 mpAttrList( new SvXMLAttributeList ),
444 mpNamespaceMap( new SvXMLNamespaceMap ),
445 mpUnitConv( new SvXMLUnitConverter( xContext,
446 util::MeasureUnit::MM_100TH, eDefaultMeasureUnit) ),
447 mpNumExport(nullptr),
448 mpProgressBarHelper( nullptr ),
449 mpEventExport( nullptr ),
450 mpImageMapExport( nullptr ),
451 mpXMLErrors( nullptr ),
452 meClass( eClass ),
453 mnExportFlags( nExportFlags ),
454 mnErrorFlags( SvXMLErrorFlags::NO ),
455 msWS( GetXMLToken(XML_WS) ),
456 mbSaveLinkedSections(true)
458 SAL_WARN_IF( !xContext.is(), "xmloff.core", "got no service manager" );
459 InitCtor_();
462 SvXMLExport::SvXMLExport(
463 const css::uno::Reference< css::uno::XComponentContext >& xContext,
464 OUString const & implementationName,
465 const OUString &rFileName,
466 sal_Int16 const eDefaultMeasureUnit /*css::util::MeasureUnit*/,
467 const uno::Reference< xml::sax::XDocumentHandler > & rHandler)
468 : mpImpl( new SvXMLExport_Impl ),
469 m_xContext(xContext), m_implementationName(implementationName),
470 mxHandler( rHandler ),
471 mxExtHandler( rHandler, uno::UNO_QUERY ),
472 mpAttrList( new SvXMLAttributeList ),
473 msOrigFileName( rFileName ),
474 mpNamespaceMap( new SvXMLNamespaceMap ),
475 mpUnitConv( new SvXMLUnitConverter( xContext,
476 util::MeasureUnit::MM_100TH, eDefaultMeasureUnit) ),
477 mpNumExport(nullptr),
478 mpProgressBarHelper( nullptr ),
479 mpEventExport( nullptr ),
480 mpImageMapExport( nullptr ),
481 mpXMLErrors( nullptr ),
482 meClass( XML_TOKEN_INVALID ),
483 mnExportFlags( SvXMLExportFlags::NONE ),
484 mnErrorFlags( SvXMLErrorFlags::NO ),
485 msWS( GetXMLToken(XML_WS) ),
486 mbSaveLinkedSections(true)
488 SAL_WARN_IF( !xContext.is(), "xmloff.core", "got no service manager" );
489 mpImpl->SetSchemeOf( msOrigFileName );
490 InitCtor_();
492 if (mxNumberFormatsSupplier.is())
493 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
496 SvXMLExport::SvXMLExport(
497 const css::uno::Reference< css::uno::XComponentContext >& xContext,
498 OUString const & implementationName,
499 const OUString &rFileName,
500 const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
501 const Reference< XModel >& rModel,
502 FieldUnit const eDefaultFieldUnit)
503 : mpImpl( new SvXMLExport_Impl ),
504 m_xContext(xContext), m_implementationName(implementationName),
505 mxModel( rModel ),
506 mxHandler( rHandler ),
507 mxExtHandler( rHandler, uno::UNO_QUERY ),
508 mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
509 mpAttrList( new SvXMLAttributeList ),
510 msOrigFileName( rFileName ),
511 mpNamespaceMap( new SvXMLNamespaceMap ),
512 mpUnitConv( new SvXMLUnitConverter( xContext,
513 util::MeasureUnit::MM_100TH,
514 SvXMLUnitConverter::GetMeasureUnit(eDefaultFieldUnit)) ),
515 mpNumExport(nullptr),
516 mpProgressBarHelper( nullptr ),
517 mpEventExport( nullptr ),
518 mpImageMapExport( nullptr ),
519 mpXMLErrors( nullptr ),
520 meClass( XML_TOKEN_INVALID ),
521 mnExportFlags( SvXMLExportFlags::NONE ),
522 mnErrorFlags( SvXMLErrorFlags::NO ),
523 msWS( GetXMLToken(XML_WS) ),
524 mbSaveLinkedSections(true)
526 SAL_WARN_IF(!xContext.is(), "xmloff.core", "got no service manager" );
527 mpImpl->SetSchemeOf( msOrigFileName );
528 InitCtor_();
530 if (mxNumberFormatsSupplier.is())
531 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
534 SvXMLExport::~SvXMLExport()
536 delete mpXMLErrors;
537 delete mpImageMapExport;
538 delete mpEventExport;
539 delete mpNamespaceMap;
540 delete mpUnitConv;
541 if (mpProgressBarHelper || mpNumExport)
543 if (mxExportInfo.is())
545 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
546 if (xPropertySetInfo.is())
548 if (mpProgressBarHelper)
550 OUString sProgressMax(XML_PROGRESSMAX);
551 OUString sProgressCurrent(XML_PROGRESSCURRENT);
552 OUString sRepeat(XML_PROGRESSREPEAT);
553 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
554 xPropertySetInfo->hasPropertyByName(sProgressCurrent))
556 sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
557 sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
558 mxExportInfo->setPropertyValue(sProgressMax, uno::Any(nProgressMax));
559 mxExportInfo->setPropertyValue(sProgressCurrent, uno::Any(nProgressCurrent));
561 if (xPropertySetInfo->hasPropertyByName(sRepeat))
562 mxExportInfo->setPropertyValue(sRepeat, css::uno::makeAny(mpProgressBarHelper->GetRepeat()));
564 if (mpNumExport && (mnExportFlags & (SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::STYLES)))
566 OUString sWrittenNumberFormats(XML_WRITTENNUMBERSTYLES);
567 if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
569 uno::Sequence<sal_Int32> aWasUsed;
570 mpNumExport->GetWasUsed(aWasUsed);
571 mxExportInfo->setPropertyValue(sWrittenNumberFormats, Any(aWasUsed));
576 delete mpProgressBarHelper;
577 delete mpNumExport;
580 if (mxEventListener.is() && mxModel.is())
581 mxModel->removeEventListener(mxEventListener);
584 // XExporter
585 void SAL_CALL SvXMLExport::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
586 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
588 mxModel.set( xDoc, UNO_QUERY );
589 if( !mxModel.is() )
590 throw lang::IllegalArgumentException();
591 if (mxModel.is() && ! mxEventListener.is())
593 mxEventListener.set( new SvXMLExportEventListener(this));
594 mxModel->addEventListener(mxEventListener);
597 if(!mxNumberFormatsSupplier.is() )
599 mxNumberFormatsSupplier.set(mxModel, css::uno::UNO_QUERY);
600 if(mxNumberFormatsSupplier.is() && mxHandler.is())
601 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
603 if (mxExportInfo.is())
605 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
606 if (xPropertySetInfo.is())
608 OUString sUsePrettyPrinting(XML_USEPRETTYPRINTING);
609 if (xPropertySetInfo->hasPropertyByName(sUsePrettyPrinting))
611 uno::Any aAny = mxExportInfo->getPropertyValue(sUsePrettyPrinting);
612 if (::cppu::any2bool(aAny))
613 mnExportFlags |= SvXMLExportFlags::PRETTY;
614 else
615 mnExportFlags &= ~SvXMLExportFlags::PRETTY;
618 if (mpNumExport && (mnExportFlags & (SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::STYLES)))
620 OUString sWrittenNumberFormats(XML_WRITTENNUMBERSTYLES);
621 if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
623 uno::Any aAny = mxExportInfo->getPropertyValue(sWrittenNumberFormats);
624 uno::Sequence<sal_Int32> aWasUsed;
625 if(aAny >>= aWasUsed)
626 mpNumExport->SetWasUsed(aWasUsed);
632 if ( mpImpl->mbSaveBackwardCompatibleODF )
633 mnExportFlags |= SvXMLExportFlags::SAVEBACKWARDCOMPATIBLE;
634 else
635 mnExportFlags &= ~SvXMLExportFlags::SAVEBACKWARDCOMPATIBLE;
637 // namespaces for user defined attributes
638 Reference< XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
639 if( xFactory.is() )
643 Reference < XInterface > xIfc =
644 xFactory->createInstance("com.sun.star.xml.NamespaceMap");
645 if( xIfc.is() )
647 Reference< XNameAccess > xNamespaceMap( xIfc, UNO_QUERY );
648 if( xNamespaceMap.is() )
650 Sequence< OUString > aPrefixes( xNamespaceMap->getElementNames() );
652 OUString* pPrefix = aPrefixes.getArray();
653 const sal_Int32 nCount = aPrefixes.getLength();
654 sal_Int32 nIndex;
655 OUString aURL;
657 for( nIndex = 0; nIndex < nCount; ++nIndex, ++pPrefix )
659 if( xNamespaceMap->getByName( *pPrefix ) >>= aURL )
660 GetNamespaceMap_().Add( *pPrefix, aURL );
665 catch(const css::uno::Exception&)
670 // Determine model type (#i51726#)
671 DetermineModelType_();
674 // XInitialize
675 void SAL_CALL SvXMLExport::initialize( const uno::Sequence< uno::Any >& aArguments )
676 throw(css::uno::Exception, css::uno::RuntimeException, std::exception)
678 // #93186# we need to queryInterface every single Any with any expected outcome. This variable hold the queryInterface results.
680 const sal_Int32 nAnyCount = aArguments.getLength();
681 const uno::Any* pAny = aArguments.getConstArray();
683 for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
685 Reference<XInterface> xValue;
686 *pAny >>= xValue;
688 // status indicator
689 uno::Reference<task::XStatusIndicator> xTmpStatus( xValue, UNO_QUERY );
690 if ( xTmpStatus.is() )
691 mxStatusIndicator = xTmpStatus;
693 // graphic resolver
694 uno::Reference<document::XGraphicObjectResolver> xTmpGraphic(
695 xValue, UNO_QUERY );
696 if ( xTmpGraphic.is() )
697 mxGraphicResolver = xTmpGraphic;
699 // object resolver
700 uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
701 xValue, UNO_QUERY );
702 if ( xTmpObjectResolver.is() )
703 mxEmbeddedResolver = xTmpObjectResolver;
705 // document handler
706 uno::Reference<xml::sax::XDocumentHandler> xTmpDocHandler(
707 xValue, UNO_QUERY );
708 if( xTmpDocHandler.is() )
710 mxHandler = xTmpDocHandler;
711 *pAny >>= mxExtHandler;
713 if (mxNumberFormatsSupplier.is() && mpNumExport == nullptr)
714 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
717 // property set to transport data across
718 uno::Reference<beans::XPropertySet> xTmpPropertySet(
719 xValue, UNO_QUERY );
720 if( xTmpPropertySet.is() )
721 mxExportInfo = xTmpPropertySet;
724 if( mxExportInfo.is() )
726 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo =
727 mxExportInfo->getPropertySetInfo();
728 OUString sPropName(
729 "BaseURI" );
730 if( xPropertySetInfo->hasPropertyByName(sPropName) )
732 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
733 aAny >>= msOrigFileName;
734 mpImpl->msPackageURI = msOrigFileName;
735 mpImpl->SetSchemeOf( msOrigFileName );
737 OUString sRelPath;
738 sPropName = "StreamRelPath";
739 if( xPropertySetInfo->hasPropertyByName(sPropName) )
741 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
742 aAny >>= sRelPath;
744 OUString sName;
745 sPropName = "StreamName";
746 if( xPropertySetInfo->hasPropertyByName(sPropName) )
748 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
749 aAny >>= sName;
751 if( !msOrigFileName.isEmpty() && !sName.isEmpty() )
753 INetURLObject aBaseURL( msOrigFileName );
754 if( !sRelPath.isEmpty() )
755 aBaseURL.insertName( sRelPath );
756 aBaseURL.insertName( sName );
757 msOrigFileName = aBaseURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
759 mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
761 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
762 const OUString sOutlineStyleAsNormalListStyle(
763 "OutlineStyleAsNormalListStyle" );
764 if( xPropertySetInfo->hasPropertyByName( sOutlineStyleAsNormalListStyle ) )
766 uno::Any aAny = mxExportInfo->getPropertyValue( sOutlineStyleAsNormalListStyle );
767 aAny >>= (mpImpl->mbOutlineStyleAsNormalListStyle);
770 OUString sTargetStorage( "TargetStorage" );
771 if( xPropertySetInfo->hasPropertyByName( sTargetStorage ) )
772 mxExportInfo->getPropertyValue( sTargetStorage ) >>= mpImpl->mxTargetStorage;
774 const OUString sExportTextNumberElement(
775 "ExportTextNumberElement" );
776 if( xPropertySetInfo->hasPropertyByName( sExportTextNumberElement ) )
778 uno::Any aAny = mxExportInfo->getPropertyValue( sExportTextNumberElement );
779 aAny >>= (mpImpl->mbExportTextNumberElement);
785 // XFilter
786 sal_Bool SAL_CALL SvXMLExport::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor ) throw(uno::RuntimeException, std::exception)
788 // check for xHandler first... should have been supplied in initialize
789 if( !mxHandler.is() )
790 return false;
794 const sal_Int32 nPropCount = aDescriptor.getLength();
796 const SvXMLExportFlags nTest =
797 SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SETTINGS;
798 if( (mnExportFlags & nTest) == nTest && msOrigFileName.isEmpty() )
800 // evaluate descriptor only for flat files and if a base URI
801 // has not been provided already
803 const beans::PropertyValue* pProps = aDescriptor.getConstArray();
804 for( sal_Int32 nIndex = 0; nIndex < nPropCount; nIndex++, pProps++ )
806 const OUString& rPropName = pProps->Name;
807 const Any& rValue = pProps->Value;
809 if ( rPropName == "FileName" )
811 if( !(rValue >>= msOrigFileName ) )
812 return false;
814 else if ( rPropName == "FilterName" )
816 if( !(rValue >>= msFilterName ) )
817 return false;
822 const beans::PropertyValue* pProps = aDescriptor.getConstArray();
823 for (sal_Int32 nIndex = 0; nIndex < nPropCount; ++nIndex, ++pProps)
825 const OUString& rPropName = pProps->Name;
826 const Any& rValue = pProps->Value;
828 if (rPropName == "SourceShellID")
830 if (!(rValue >>= mpImpl->maSrcShellID))
831 return false;
833 else if (rPropName == "DestinationShellID")
835 if (!(rValue >>= mpImpl->maDestShellID))
836 return false;
841 exportDoc( meClass );
843 catch(const uno::Exception& e)
845 // We must catch exceptions, because according to the
846 // API definition export must not throw one!
847 css::uno::Any ex(cppu::getCaughtException());
848 SetError( XMLERROR_FLAG_ERROR | XMLERROR_FLAG_SEVERE | XMLERROR_API,
849 Sequence<OUString>(),
850 ex.getValueTypeName() + ": \"" + e.Message + "\"", nullptr );
853 // return true only if no error occurred
854 return (GetErrorFlags() & (SvXMLErrorFlags::DO_NOTHING|SvXMLErrorFlags::ERROR_OCCURRED)) == SvXMLErrorFlags::NO;
857 void SAL_CALL SvXMLExport::cancel() throw(uno::RuntimeException, std::exception)
859 // stop export
860 Sequence<OUString> aEmptySeq;
861 SetError(XMLERROR_CANCEL|XMLERROR_FLAG_SEVERE, aEmptySeq);
864 OUString SAL_CALL SvXMLExport::getName( )
865 throw (css::uno::RuntimeException, std::exception)
867 return msFilterName;
870 void SAL_CALL SvXMLExport::setName( const OUString& )
871 throw (css::uno::RuntimeException, std::exception)
873 // do nothing, because it is not possible to set the FilterName
876 // XServiceInfo
877 OUString SAL_CALL SvXMLExport::getImplementationName( ) throw(uno::RuntimeException, std::exception)
879 return m_implementationName;
882 sal_Bool SAL_CALL SvXMLExport::supportsService( const OUString& rServiceName ) throw(uno::RuntimeException, std::exception)
884 return cppu::supportsService(this, rServiceName);
887 uno::Sequence< OUString > SAL_CALL SvXMLExport::getSupportedServiceNames( )
888 throw(uno::RuntimeException, std::exception)
890 uno::Sequence<OUString> aSeq(2);
891 aSeq[0] = "com.sun.star.document.ExportFilter";
892 aSeq[1] = "com.sun.star.xml.XMLExportFilter";
893 return aSeq;
896 OUString
897 SvXMLExport::EnsureNamespace(OUString const & i_rNamespace)
899 OUString const aPreferredPrefix("gen");
900 OUString sPrefix;
901 sal_uInt16 nKey( GetNamespaceMap_().GetKeyByName( i_rNamespace ) );
902 if( XML_NAMESPACE_UNKNOWN == nKey )
904 // There is no prefix for the namespace, so
905 // we have to generate one and have to add it.
906 sPrefix = aPreferredPrefix;
907 nKey = GetNamespaceMap_().GetKeyByPrefix( sPrefix );
908 sal_Int32 n( 0 );
909 OUStringBuffer buf;
910 while( nKey != USHRT_MAX )
912 buf.append( aPreferredPrefix );
913 buf.append( ++n );
914 sPrefix = buf.makeStringAndClear();
915 nKey = GetNamespaceMap_().GetKeyByPrefix( sPrefix );
918 if (mpImpl->mNamespaceMaps.empty()
919 || (mpImpl->mNamespaceMaps.top().second != mpImpl->mDepth))
921 // top was created for lower depth... need a new namespace map!
922 mpImpl->mNamespaceMaps.push(
923 ::std::make_pair(mpNamespaceMap, mpImpl->mDepth) );
924 mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
927 // add the namespace to the map and as attribute
928 mpNamespaceMap->Add( sPrefix, i_rNamespace );
929 buf.append( GetXMLToken(XML_XMLNS) );
930 buf.append( ':' );
931 buf.append( sPrefix );
932 AddAttribute( buf.makeStringAndClear(), i_rNamespace );
934 else
936 // If there is a prefix for the namespace, reuse that.
937 sPrefix = GetNamespaceMap_().GetPrefixByKey( nKey );
939 return sPrefix;
942 void SvXMLExport::AddAttributeASCII( sal_uInt16 nPrefixKey,
943 const sal_Char *pName,
944 const sal_Char *pValue )
946 OUString sName( OUString::createFromAscii( pName ) );
947 OUString sValue( OUString::createFromAscii( pValue ) );
949 mpAttrList->AddAttribute(
950 GetNamespaceMap_().GetQNameByKey( nPrefixKey, sName ), sValue );
953 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const sal_Char *pName,
954 const OUString& rValue )
956 OUString sName( OUString::createFromAscii( pName ) );
958 mpAttrList->AddAttribute(
959 GetNamespaceMap_().GetQNameByKey( nPrefixKey, sName ), rValue );
962 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const OUString& rName,
963 const OUString& rValue )
965 mpAttrList->AddAttribute(
966 GetNamespaceMap_().GetQNameByKey( nPrefixKey, rName ), rValue );
969 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
970 enum XMLTokenEnum eName,
971 const OUString& rValue )
973 mpAttrList->AddAttribute(
974 GetNamespaceMap_().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
975 rValue );
978 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
979 enum XMLTokenEnum eName,
980 enum XMLTokenEnum eValue)
982 mpAttrList->AddAttribute(
983 GetNamespaceMap_().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
984 GetXMLToken(eValue) );
987 void SvXMLExport::AddAttribute( const OUString& rQName,
988 const OUString& rValue )
990 mpAttrList->AddAttribute(
991 rQName,
992 rValue );
995 void SvXMLExport::AddAttribute( const OUString& rQName,
996 enum ::xmloff::token::XMLTokenEnum eValue )
998 mpAttrList->AddAttribute(
999 rQName,
1000 GetXMLToken(eValue) );
1003 void SvXMLExport::AddLanguageTagAttributes( sal_uInt16 nPrefix, sal_uInt16 nPrefixRfc,
1004 const css::lang::Locale& rLocale, bool bWriteEmpty )
1006 if (rLocale.Variant.isEmpty())
1008 // Per convention The BCP 47 string is always stored in Variant, if
1009 // that is empty we have a plain language-country combination, no need
1010 // to convert to LanguageTag first. Also catches the case of empty
1011 // locale denoting system locale.
1012 xmloff::token::XMLTokenEnum eLanguage, eCountry;
1013 eLanguage = XML_LANGUAGE;
1014 eCountry = XML_COUNTRY;
1015 if (bWriteEmpty || !rLocale.Language.isEmpty())
1016 AddAttribute( nPrefix, eLanguage, rLocale.Language);
1017 if (bWriteEmpty || !rLocale.Country.isEmpty())
1018 AddAttribute( nPrefix, eCountry, rLocale.Country);
1020 else
1022 LanguageTag aLanguageTag( rLocale);
1023 AddLanguageTagAttributes( nPrefix, nPrefixRfc, aLanguageTag, bWriteEmpty);
1027 void SvXMLExport::AddLanguageTagAttributes( sal_uInt16 nPrefix, sal_uInt16 nPrefixRfc,
1028 const LanguageTag& rLanguageTag, bool bWriteEmpty )
1030 if (rLanguageTag.isIsoODF())
1032 if (bWriteEmpty || !rLanguageTag.isSystemLocale())
1034 AddAttribute( nPrefix, XML_LANGUAGE, rLanguageTag.getLanguage());
1035 if (rLanguageTag.hasScript() && getDefaultVersion() >= SvtSaveOptions::ODFVER_012)
1036 AddAttribute( nPrefix, XML_SCRIPT, rLanguageTag.getScript());
1037 if (bWriteEmpty || !rLanguageTag.getCountry().isEmpty())
1038 AddAttribute( nPrefix, XML_COUNTRY, rLanguageTag.getCountry());
1041 else
1043 if (getDefaultVersion() >= SvtSaveOptions::ODFVER_012)
1044 AddAttribute( nPrefixRfc, XML_RFC_LANGUAGE_TAG, rLanguageTag.getBcp47());
1045 // Also in case of non-pure-ISO tag store best matching fo: attributes
1046 // for consumers not handling *:rfc-language-tag, ensuring that only
1047 // valid ISO codes are stored. Here the bWriteEmpty parameter has no
1048 // meaning.
1049 OUString aLanguage, aScript, aCountry;
1050 rLanguageTag.getIsoLanguageScriptCountry( aLanguage, aScript, aCountry);
1051 if (!aLanguage.isEmpty())
1053 AddAttribute( nPrefix, XML_LANGUAGE, aLanguage);
1054 if (!aScript.isEmpty() && getDefaultVersion() >= SvtSaveOptions::ODFVER_012)
1055 AddAttribute( nPrefix, XML_SCRIPT, aScript);
1056 if (!aCountry.isEmpty())
1057 AddAttribute( nPrefix, XML_COUNTRY, aCountry);
1062 void SvXMLExport::AddAttributeList( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1064 if( xAttrList.is())
1065 mpAttrList->AppendAttributeList( xAttrList );
1068 void SvXMLExport::ClearAttrList()
1070 mpAttrList->Clear();
1073 #ifdef DBG_UTIL
1074 void SvXMLExport::CheckAttrList()
1076 SAL_WARN_IF( mpAttrList->getLength(), "xmloff.core", "XMLExport::CheckAttrList: list is not empty" );
1078 #endif
1080 void SvXMLExport::ImplExportMeta()
1082 CheckAttrList();
1084 ExportMeta_();
1087 void SvXMLExport::ImplExportSettings()
1089 CheckAttrList();
1091 ::std::list< SettingsGroup > aSettings;
1092 sal_Int32 nSettingsCount = 0;
1094 // view settings
1095 uno::Sequence< beans::PropertyValue > aViewSettings;
1096 GetViewSettingsAndViews( aViewSettings );
1097 aSettings.push_back( SettingsGroup( XML_VIEW_SETTINGS, aViewSettings ) );
1098 nSettingsCount += aViewSettings.getLength();
1100 // configuration settings
1101 uno::Sequence<beans::PropertyValue> aConfigSettings;
1102 GetConfigurationSettings( aConfigSettings );
1103 aSettings.push_back( SettingsGroup( XML_CONFIGURATION_SETTINGS, aConfigSettings ) );
1104 nSettingsCount += aConfigSettings.getLength();
1106 // any document specific settings
1107 nSettingsCount += GetDocumentSpecificSettings( aSettings );
1110 SvXMLElementExport aElem( *this,
1111 nSettingsCount != 0,
1112 XML_NAMESPACE_OFFICE, XML_SETTINGS,
1113 true, true );
1115 SettingsExportFacade aSettingsExportContext( *this );
1116 XMLSettingsExportHelper aSettingsExportHelper( aSettingsExportContext );
1118 for ( ::std::list< SettingsGroup >::const_iterator settings = aSettings.begin();
1119 settings != aSettings.end();
1120 ++settings
1123 if ( !settings->aSettings.getLength() )
1124 continue;
1126 const OUString& sSettingsName( GetXMLToken( settings->eGroupName ) );
1127 OUString sQName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOO, sSettingsName );
1128 aSettingsExportHelper.exportAllSettings( settings->aSettings, sQName );
1133 void SvXMLExport::ImplExportStyles()
1135 CheckAttrList();
1138 // <style:styles>
1139 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_STYLES,
1140 true, true );
1142 ExportStyles_( false );
1145 // transfer style names (+ families) TO other components (if appropriate)
1146 if( ( !( mnExportFlags & SvXMLExportFlags::CONTENT ) ) && mxExportInfo.is() )
1148 static OUString sStyleNames( "StyleNames" );
1149 static OUString sStyleFamilies( "StyleFamilies" );
1150 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
1151 if ( xPropertySetInfo->hasPropertyByName( sStyleNames ) && xPropertySetInfo->hasPropertyByName( sStyleFamilies ) )
1153 Sequence<sal_Int32> aStyleFamilies;
1154 Sequence<OUString> aStyleNames;
1155 mxAutoStylePool->GetRegisteredNames( aStyleFamilies, aStyleNames );
1156 mxExportInfo->setPropertyValue( sStyleNames, makeAny( aStyleNames ) );
1157 mxExportInfo->setPropertyValue( sStyleFamilies,
1158 makeAny( aStyleFamilies ) );
1163 void SvXMLExport::ImplExportAutoStyles()
1165 // transfer style names (+ families) FROM other components (if appropriate)
1166 OUString sStyleNames( "StyleNames" );
1167 OUString sStyleFamilies( "StyleFamilies" );
1168 if( ( !( mnExportFlags & SvXMLExportFlags::STYLES ) )
1169 && mxExportInfo.is()
1170 && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleNames )
1171 && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleFamilies ) )
1173 Sequence<sal_Int32> aStyleFamilies;
1174 mxExportInfo->getPropertyValue( sStyleFamilies ) >>= aStyleFamilies;
1175 Sequence<OUString> aStyleNames;
1176 mxExportInfo->getPropertyValue( sStyleNames ) >>= aStyleNames;
1177 mxAutoStylePool->RegisterNames( aStyleFamilies, aStyleNames );
1181 // <style:automatic-styles>
1182 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
1183 XML_AUTOMATIC_STYLES, true, true );
1185 ExportAutoStyles_();
1189 void SvXMLExport::ImplExportMasterStyles()
1192 // <style:master-styles>
1193 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_MASTER_STYLES,
1194 true, true );
1196 ExportMasterStyles_();
1201 void SvXMLExport::ImplExportContent()
1203 CheckAttrList();
1205 CheckAttrList();
1208 SvXMLElementExport aElemrnt( *this, XML_NAMESPACE_OFFICE, XML_BODY,
1209 true, true );
1211 XMLTokenEnum eClass = meClass;
1212 if( XML_TEXT_GLOBAL == eClass )
1214 AddAttribute( XML_NAMESPACE_TEXT, XML_GLOBAL,
1215 GetXMLToken( XML_TRUE ) );
1216 eClass = XML_TEXT;
1218 if ( XML_GRAPHICS == eClass )
1219 eClass = XML_DRAWING;
1220 // <office:body ...>
1221 SetBodyAttributes();
1222 SvXMLElementExport aElem( *this, meClass != XML_TOKEN_INVALID,
1223 XML_NAMESPACE_OFFICE, eClass,
1224 true, true );
1226 ExportContent_();
1231 void SvXMLExport::SetBodyAttributes()
1235 static void
1236 lcl_AddGrddl(SvXMLExport & rExport, const SvXMLExportFlags /*nExportMode*/)
1238 // check version >= 1.2
1239 switch (rExport.getDefaultVersion()) {
1240 case SvtSaveOptions::ODFVER_011: // fall through
1241 case SvtSaveOptions::ODFVER_010: return;
1242 default: break;
1245 // #i115030#: disabled, the XSLT is not finished, and not available via HTTP
1246 #if 0
1247 if (SvXMLExportFlags::SETTINGS != nExportMode) // meta, content, styles
1249 rExport.AddAttribute( XML_NAMESPACE_GRDDL, XML_TRANSFORMATION,
1250 OUString("http://FIXME") );
1252 #endif
1255 void SvXMLExport::addChaffWhenEncryptedStorage()
1257 uno::Reference< embed::XEncryptionProtectedSource2 > xEncr(mpImpl->mxTargetStorage, uno::UNO_QUERY);
1259 if (xEncr.is() && xEncr->hasEncryptionData() && mxExtHandler.is())
1261 mxExtHandler->comment(OStringToOUString(comphelper::xml::makeXMLChaff(), RTL_TEXTENCODING_ASCII_US));
1265 sal_uInt32 SvXMLExport::exportDoc( enum ::xmloff::token::XMLTokenEnum eClass )
1267 bool bOwnGraphicResolver = false;
1268 bool bOwnEmbeddedResolver = false;
1270 if( !mxGraphicResolver.is() || !mxEmbeddedResolver.is() )
1272 Reference< XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
1273 if( xFactory.is() )
1277 if( !mxGraphicResolver.is() )
1279 mxGraphicResolver.set(
1280 xFactory->createInstance( "com.sun.star.document.ExportGraphicObjectResolver" ), UNO_QUERY);
1281 bOwnGraphicResolver = mxGraphicResolver.is();
1284 if( !mxEmbeddedResolver.is() )
1286 mxEmbeddedResolver.set(
1287 xFactory->createInstance( "com.sun.star.document.ExportEmbeddedObjectResolver" ), UNO_QUERY);
1288 bOwnEmbeddedResolver = mxEmbeddedResolver.is();
1291 catch(const css::uno::Exception&)
1296 if( (getExportFlags() & SvXMLExportFlags::OASIS) == SvXMLExportFlags::NONE )
1300 ::comphelper::PropertyMapEntry const aInfoMap[] =
1302 { OUString("Class"), 0,
1303 ::cppu::UnoType<OUString>::get(),
1304 PropertyAttribute::MAYBEVOID, 0},
1305 { OUString(), 0, css::uno::Type(), 0, 0 }
1307 Reference< XPropertySet > xConvPropSet(
1308 ::comphelper::GenericPropertySet_CreateInstance(
1309 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
1311 xConvPropSet->setPropertyValue( "Class", Any(GetXMLToken( eClass )) );
1313 Reference< XPropertySet > xPropSet =
1314 mxExportInfo.is()
1315 ? PropertySetMerger_CreateInstance( mxExportInfo,
1316 xConvPropSet )
1317 : xConvPropSet;
1319 Sequence<Any> aArgs( 3 );
1320 aArgs[0] <<= mxHandler;
1321 aArgs[1] <<= xPropSet;
1322 aArgs[2] <<= mxModel;
1324 // get filter component
1325 Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
1326 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.Oasis2OOoTransformer", aArgs, m_xContext),
1327 UNO_QUERY);
1328 SAL_WARN_IF(!xTmpDocHandler.is(), "xmloff.core", "can't instantiate OASIS transformer component" );
1329 if( xTmpDocHandler.is() )
1331 mxHandler = xTmpDocHandler;
1332 mxExtHandler.set( mxHandler, UNO_QUERY );
1335 catch(const css::uno::Exception&)
1340 mxHandler->startDocument();
1342 addChaffWhenEncryptedStorage();
1344 // <office:document ...>
1345 CheckAttrList();
1347 // namespace attributes
1348 // ( The namespace decls should be first attributes in the element;
1349 // some faulty XML parsers (JAXP1.1) have a problem with this,
1350 // also it's more elegant )
1351 sal_uInt16 nPos = mpNamespaceMap->GetFirstKey();
1352 while( USHRT_MAX != nPos )
1354 mpAttrList->AddAttribute( mpNamespaceMap->GetAttrNameByKey( nPos ),
1355 mpNamespaceMap->GetNameByKey( nPos ) );
1356 nPos = mpNamespaceMap->GetNextKey( nPos );
1359 // office:version = ...
1360 const sal_Char* pVersion = nullptr;
1361 switch (getDefaultVersion())
1363 case SvtSaveOptions::ODFVER_LATEST: pVersion = sXML_1_2; break;
1364 case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = sXML_1_2; break;
1365 case SvtSaveOptions::ODFVER_012: pVersion = sXML_1_2; break;
1366 case SvtSaveOptions::ODFVER_011: pVersion = sXML_1_1; break;
1367 case SvtSaveOptions::ODFVER_010: break;
1369 default:
1370 SAL_WARN("xmloff.core", "xmloff::SvXMLExport::exportDoc(), unexpected odf default version!");
1373 if (pVersion)
1375 AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
1376 OUString::createFromAscii(pVersion) );
1380 enum XMLTokenEnum eRootService = XML_TOKEN_INVALID;
1381 const SvXMLExportFlags nExportMode = mnExportFlags & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SETTINGS);
1383 lcl_AddGrddl(*this, nExportMode);
1385 if( SvXMLExportFlags::META == nExportMode )
1387 // export only meta
1388 eRootService = XML_DOCUMENT_META;
1390 else if ( SvXMLExportFlags::SETTINGS == nExportMode )
1392 // export only settings
1393 eRootService = XML_DOCUMENT_SETTINGS;
1395 else if( SvXMLExportFlags::STYLES == nExportMode )
1397 // export only styles
1398 eRootService = XML_DOCUMENT_STYLES;
1400 else if( SvXMLExportFlags::CONTENT == nExportMode )
1402 // export only content
1403 eRootService = XML_DOCUMENT_CONTENT;
1405 else
1407 // the god'ol one4all element
1408 eRootService = XML_DOCUMENT;
1409 // office:mimetype = ... (only for stream containing the content)
1410 if( eClass != XML_TOKEN_INVALID )
1412 OUString aTmp( "application/vnd.oasis.opendocument." );
1413 aTmp += GetXMLToken( eClass );
1414 AddAttribute( XML_NAMESPACE_OFFICE, XML_MIMETYPE, aTmp );
1418 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, eRootService, true, true );
1420 // meta information
1421 if( mnExportFlags & SvXMLExportFlags::META )
1422 ImplExportMeta();
1424 // settings
1425 if( mnExportFlags & SvXMLExportFlags::SETTINGS )
1426 ImplExportSettings();
1428 // scripts
1429 if( mnExportFlags & SvXMLExportFlags::SCRIPTS )
1430 ExportScripts_();
1432 // font declarations
1433 if( mnExportFlags & SvXMLExportFlags::FONTDECLS )
1434 ExportFontDecls_();
1436 // styles
1437 if( mnExportFlags & SvXMLExportFlags::STYLES )
1438 ImplExportStyles();
1440 // autostyles
1441 if( mnExportFlags & SvXMLExportFlags::AUTOSTYLES )
1442 ImplExportAutoStyles();
1444 // masterstyles
1445 if( mnExportFlags & SvXMLExportFlags::MASTERSTYLES )
1446 ImplExportMasterStyles();
1448 // content
1449 if( mnExportFlags & SvXMLExportFlags::CONTENT )
1450 ImplExportContent();
1453 mxHandler->endDocument();
1455 if( bOwnGraphicResolver )
1457 Reference< XComponent > xComp( mxGraphicResolver, UNO_QUERY );
1458 xComp->dispose();
1461 if( bOwnEmbeddedResolver )
1463 Reference< XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
1464 xComp->dispose();
1467 return 0;
1470 void SvXMLExport::ResetNamespaceMap()
1472 delete mpNamespaceMap; mpNamespaceMap = new SvXMLNamespaceMap;
1475 OUString SvXMLExport::GetSourceShellID() const
1477 return mpImpl->maSrcShellID;
1480 OUString SvXMLExport::GetDestinationShellID() const
1482 return mpImpl->maDestShellID;
1485 void SvXMLExport::ExportMeta_()
1487 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
1488 Reference< XDocumentPropertiesSupplier > xDocPropsSupplier(mxModel,
1489 UNO_QUERY);
1490 if (xDocPropsSupplier.is()) {
1491 Reference<XDocumentProperties> xDocProps(
1492 xDocPropsSupplier->getDocumentProperties());
1493 if (!xDocProps.is()) throw;
1494 // update generator here
1495 xDocProps->setGenerator(generator);
1496 SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, xDocProps);
1497 uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
1498 pMeta->Export();
1499 } else {
1500 // office:meta
1501 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_META,
1502 true, true );
1504 // BM: #i60323# export generator even if xInfoProp is empty (which is the
1505 // case for charts). The generator does not depend on xInfoProp
1506 SvXMLElementExport anElem( *this, XML_NAMESPACE_META, XML_GENERATOR,
1507 true, true );
1508 Characters(generator);
1513 void SvXMLExport::ExportScripts_()
1515 SvXMLElementExport aElement( *this, XML_NAMESPACE_OFFICE, XML_SCRIPTS, true, true );
1517 // export Basic macros (only for FlatXML)
1518 if ( mnExportFlags & SvXMLExportFlags::EMBEDDED )
1520 OUString aValue( GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) );
1521 aValue += ":Basic";
1522 AddAttribute( XML_NAMESPACE_SCRIPT, XML_LANGUAGE, aValue );
1524 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_SCRIPT, true, true );
1526 // initialize Basic
1527 if ( mxModel.is() )
1529 Reference< beans::XPropertySet > xPSet( mxModel, UNO_QUERY );
1530 if ( xPSet.is() )
1531 xPSet->getPropertyValue("BasicLibraries");
1534 Reference < XDocumentHandler > xHdl( new XMLBasicExportFilter( mxHandler ) );
1535 Reference< document::XXMLBasicExporter > xExporter = document::XMLOasisBasicExporter::createWithHandler( m_xContext, xHdl );
1537 Reference< XComponent > xComp( mxModel, UNO_QUERY );
1538 xExporter->setSourceDocument( xComp );
1539 Sequence< PropertyValue > aMediaDesc( 0 );
1540 xExporter->filter( aMediaDesc );
1543 // export document events
1544 Reference< document::XEventsSupplier > xEvents( GetModel(), UNO_QUERY );
1545 GetEventExport().Export( xEvents );
1548 void SvXMLExport::ExportFontDecls_()
1550 if( mxFontAutoStylePool.is() )
1551 mxFontAutoStylePool->exportXML();
1554 void SvXMLExport::ExportStyles_( bool )
1556 uno::Reference< lang::XMultiServiceFactory > xFact( GetModel(), uno::UNO_QUERY );
1557 if( xFact.is())
1559 // export (fill-)gradient-styles
1562 uno::Reference< container::XNameAccess > xGradient( xFact->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
1563 if( xGradient.is() )
1565 XMLGradientStyleExport aGradientStyle( *this );
1567 if( xGradient->hasElements() )
1569 uno::Sequence< OUString > aNamesSeq ( xGradient->getElementNames() );
1570 sal_Int32 nCount = aNamesSeq.getLength();
1571 for( sal_Int32 i=0; i<nCount; i++ )
1573 const OUString& rStrName = aNamesSeq[ i ];
1577 uno::Any aValue = xGradient->getByName( rStrName );
1579 aGradientStyle.exportXML( rStrName, aValue );
1581 catch(const container::NoSuchElementException&)
1588 catch(const lang::ServiceNotRegisteredException&)
1592 // export (fill-)hatch-styles
1595 uno::Reference< container::XNameAccess > xHatch( xFact->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
1596 if( xHatch.is() )
1598 XMLHatchStyleExport aHatchStyle( *this );
1600 if( xHatch->hasElements() )
1602 uno::Sequence< OUString > aNamesSeq ( xHatch->getElementNames() );
1603 sal_Int32 nCount = aNamesSeq.getLength();
1604 for( sal_Int32 i=0; i<nCount; i++ )
1606 const OUString& rStrName = aNamesSeq[ i ];
1610 uno::Any aValue = xHatch->getByName( rStrName );
1612 aHatchStyle.exportXML( rStrName, aValue );
1614 catch(const container::NoSuchElementException&)
1620 catch(const lang::ServiceNotRegisteredException&)
1624 // export (fill-)bitmap-styles
1627 uno::Reference< container::XNameAccess > xBitmap( xFact->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
1628 if( xBitmap.is() )
1630 XMLImageStyle aImageStyle;
1632 if( xBitmap->hasElements() )
1634 uno::Sequence< OUString > aNamesSeq ( xBitmap->getElementNames() );
1635 sal_Int32 nCount = aNamesSeq.getLength();
1636 for( sal_Int32 i=0; i<nCount; i++ )
1638 const OUString& rStrName = aNamesSeq[ i ];
1642 uno::Any aValue = xBitmap->getByName( rStrName );
1644 aImageStyle.exportXML( rStrName, aValue, *this );
1646 catch(const container::NoSuchElementException&)
1653 catch(const lang::ServiceNotRegisteredException&)
1657 // export transparency-gradient -styles
1660 uno::Reference< container::XNameAccess > xTransGradient( xFact->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
1661 if( xTransGradient.is() )
1663 XMLTransGradientStyleExport aTransGradientstyle( *this );
1665 if( xTransGradient->hasElements() )
1667 uno::Sequence< OUString > aNamesSeq ( xTransGradient->getElementNames() );
1668 sal_Int32 nCount = aNamesSeq.getLength();
1669 for( sal_Int32 i=0; i<nCount; i++ )
1671 const OUString& rStrName = aNamesSeq[ i ];
1675 uno::Any aValue = xTransGradient->getByName( rStrName );
1677 aTransGradientstyle.exportXML( rStrName, aValue );
1679 catch(const container::NoSuchElementException&)
1686 catch(const lang::ServiceNotRegisteredException&)
1690 // export marker-styles
1693 uno::Reference< container::XNameAccess > xMarker( xFact->createInstance("com.sun.star.drawing.MarkerTable"), uno::UNO_QUERY );
1694 if( xMarker.is() )
1696 XMLMarkerStyleExport aMarkerStyle( *this );
1698 if( xMarker->hasElements() )
1700 uno::Sequence< OUString > aNamesSeq ( xMarker->getElementNames() );
1701 sal_Int32 nCount = aNamesSeq.getLength();
1702 for( sal_Int32 i=0; i<nCount; i++ )
1704 const OUString& rStrName = aNamesSeq[ i ];
1708 uno::Any aValue = xMarker->getByName( rStrName );
1710 aMarkerStyle.exportXML( rStrName, aValue );
1712 catch(const container::NoSuchElementException&)
1719 catch(const lang::ServiceNotRegisteredException&)
1723 // export dash-styles
1726 uno::Reference< container::XNameAccess > xDashes( xFact->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
1727 if( xDashes.is() )
1729 XMLDashStyleExport aDashStyle( *this );
1731 if( xDashes->hasElements() )
1733 uno::Sequence< OUString > aNamesSeq ( xDashes->getElementNames() );
1734 sal_Int32 nCount = aNamesSeq.getLength();
1735 for( sal_Int32 i=0; i<nCount; i++ )
1737 const OUString& rStrName = aNamesSeq[ i ];
1741 uno::Any aValue = xDashes->getByName( rStrName );
1743 aDashStyle.exportXML( rStrName, aValue );
1745 catch(const container::NoSuchElementException&)
1752 catch(const lang::ServiceNotRegisteredException&)
1758 XMLTextParagraphExport* SvXMLExport::CreateTextParagraphExport()
1760 return new XMLTextParagraphExport( *this, *(GetAutoStylePool().get()) );
1763 XMLShapeExport* SvXMLExport::CreateShapeExport()
1765 return new XMLShapeExport(*this);
1768 SvXMLAutoStylePoolP* SvXMLExport::CreateAutoStylePool()
1770 return new SvXMLAutoStylePoolP(*this);
1773 XMLPageExport* SvXMLExport::CreatePageExport()
1775 return new XMLPageExport( *this );
1778 SchXMLExportHelper* SvXMLExport::CreateChartExport()
1780 return new SchXMLExportHelper(*this,*GetAutoStylePool().get());
1783 XMLFontAutoStylePool* SvXMLExport::CreateFontAutoStylePool()
1785 return new XMLFontAutoStylePool( *this );
1788 xmloff::OFormLayerXMLExport* SvXMLExport::CreateFormExport()
1790 return new xmloff::OFormLayerXMLExport(*this);
1793 void SvXMLExport::GetViewSettingsAndViews(uno::Sequence<beans::PropertyValue>& rProps)
1795 GetViewSettings(rProps);
1796 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetModel(), uno::UNO_QUERY);
1797 if(xViewDataSupplier.is())
1799 uno::Reference<container::XIndexAccess> xIndexAccess;
1800 xViewDataSupplier->setViewData( xIndexAccess ); // make sure we get a newly created sequence
1801 xIndexAccess = xViewDataSupplier->getViewData();
1802 bool bAdd = false;
1803 uno::Any aAny;
1804 if(xIndexAccess.is() && xIndexAccess->hasElements() )
1806 sal_Int32 nCount = xIndexAccess->getCount();
1807 for (sal_Int32 i = 0; i < nCount; i++)
1809 aAny = xIndexAccess->getByIndex(i);
1810 uno::Sequence<beans::PropertyValue> aProps;
1811 if( aAny >>= aProps )
1813 if( aProps.getLength() > 0 )
1815 bAdd = true;
1816 break;
1822 if( bAdd )
1824 sal_Int32 nOldLength(rProps.getLength());
1825 rProps.realloc(nOldLength + 1);
1826 beans::PropertyValue aProp;
1827 aProp.Name = "Views";
1828 aProp.Value <<= xIndexAccess;
1829 rProps[nOldLength] = aProp;
1834 void SvXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>&)
1838 void SvXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>&)
1842 sal_Int32 SvXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup >& _out_rSettings )
1844 (void)_out_rSettings;
1845 return 0;
1848 void SvXMLExport::addDataStyle(const sal_Int32 nNumberFormat, bool /*bTimeFormat*/ )
1850 if(mpNumExport)
1851 mpNumExport->SetUsed(nNumberFormat);
1854 void SvXMLExport::exportDataStyles()
1856 if(mpNumExport)
1857 mpNumExport->Export(false);
1860 void SvXMLExport::exportAutoDataStyles()
1862 if(mpNumExport)
1863 mpNumExport->Export(true);
1865 if (mxFormExport.is())
1866 mxFormExport->exportAutoControlNumberStyles();
1869 OUString SvXMLExport::getDataStyleName(const sal_Int32 nNumberFormat, bool /*bTimeFormat*/ ) const
1871 OUString sTemp;
1872 if(mpNumExport)
1873 sTemp = mpNumExport->GetStyleName(nNumberFormat);
1874 return sTemp;
1877 void SvXMLExport::exportAnnotationMeta(const uno::Reference<drawing::XShape>&)
1881 sal_Int32 SvXMLExport::dataStyleForceSystemLanguage(sal_Int32 nFormat) const
1883 return ( mpNumExport != nullptr )
1884 ? mpNumExport->ForceSystemLanguage( nFormat ) : nFormat;
1887 OUString SvXMLExport::AddEmbeddedGraphicObject( const OUString& rGraphicObjectURL )
1889 OUString sRet( rGraphicObjectURL );
1890 if( rGraphicObjectURL.startsWith( msGraphicObjectProtocol ) &&
1891 mxGraphicResolver.is() )
1893 if( !(getExportFlags() & SvXMLExportFlags::EMBEDDED) )
1894 sRet = mxGraphicResolver->resolveGraphicObjectURL( rGraphicObjectURL );
1895 else
1896 sRet.clear();
1898 else
1899 sRet = GetRelativeReference( sRet );
1901 return sRet;
1904 bool SvXMLExport::AddEmbeddedGraphicObjectAsBase64( const OUString& rGraphicObjectURL )
1906 bool bRet = false;
1908 if( (getExportFlags() & SvXMLExportFlags::EMBEDDED) &&
1909 rGraphicObjectURL.startsWith( msGraphicObjectProtocol ) &&
1910 mxGraphicResolver.is() )
1912 Reference< XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1914 if( xStmResolver.is() )
1916 Reference< XInputStream > xIn( xStmResolver->getInputStream( rGraphicObjectURL ) );
1918 if( xIn.is() )
1920 XMLBase64Export aBase64Exp( *this );
1921 bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
1926 return bRet;
1929 OUString SvXMLExport::AddEmbeddedObject( const OUString& rEmbeddedObjectURL )
1931 OUString sRet;
1932 if( (rEmbeddedObjectURL.startsWith( msEmbeddedObjectProtocol ) ||
1933 rEmbeddedObjectURL.startsWith( msGraphicObjectProtocol ) ) &&
1934 mxEmbeddedResolver.is() )
1936 sRet =
1937 mxEmbeddedResolver->resolveEmbeddedObjectURL( rEmbeddedObjectURL );
1939 else
1940 sRet = GetRelativeReference( rEmbeddedObjectURL );
1942 return sRet;
1945 bool SvXMLExport::AddEmbeddedObjectAsBase64( const OUString& rEmbeddedObjectURL )
1947 bool bRet = false;
1948 if( (rEmbeddedObjectURL.startsWith( msEmbeddedObjectProtocol ) ||
1949 rEmbeddedObjectURL.startsWith( msGraphicObjectProtocol ) ) &&
1950 mxEmbeddedResolver.is() )
1952 Reference < XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
1953 if( xNA.is() )
1955 Any aAny = xNA->getByName( rEmbeddedObjectURL );
1956 Reference < XInputStream > xIn;
1957 aAny >>= xIn;
1958 if( xIn.is() )
1960 XMLBase64Export aBase64Exp( *this );
1961 bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
1966 return bRet;
1969 OUString SvXMLExport::EncodeStyleName(
1970 const OUString& rName,
1971 bool *pEncoded ) const
1973 return GetMM100UnitConverter().encodeStyleName( rName, pEncoded );
1976 ProgressBarHelper* SvXMLExport::GetProgressBarHelper()
1978 if (!mpProgressBarHelper)
1980 mpProgressBarHelper = new ProgressBarHelper(mxStatusIndicator, true);
1982 if (mxExportInfo.is())
1984 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
1985 if (xPropertySetInfo.is())
1987 OUString sProgressRange(XML_PROGRESSRANGE);
1988 OUString sProgressMax(XML_PROGRESSMAX);
1989 OUString sProgressCurrent(XML_PROGRESSCURRENT);
1990 OUString sRepeat(XML_PROGRESSREPEAT);
1991 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
1992 xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
1993 xPropertySetInfo->hasPropertyByName(sProgressRange))
1995 uno::Any aAny;
1996 sal_Int32 nProgressMax(0);
1997 sal_Int32 nProgressCurrent(0);
1998 sal_Int32 nProgressRange(0);
1999 aAny = mxExportInfo->getPropertyValue(sProgressRange);
2000 if (aAny >>= nProgressRange)
2001 mpProgressBarHelper->SetRange(nProgressRange);
2002 aAny = mxExportInfo->getPropertyValue(sProgressMax);
2003 if (aAny >>= nProgressMax)
2004 mpProgressBarHelper->SetReference(nProgressMax);
2005 aAny = mxExportInfo->getPropertyValue(sProgressCurrent);
2006 if (aAny >>= nProgressCurrent)
2007 mpProgressBarHelper->SetValue(nProgressCurrent);
2009 if (xPropertySetInfo->hasPropertyByName(sRepeat))
2011 uno::Any aAny = mxExportInfo->getPropertyValue(sRepeat);
2012 if (aAny.getValueType() == cppu::UnoType<bool>::get())
2013 mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
2014 else {
2015 SAL_WARN("xmloff.core", "why is it no boolean?" );
2021 return mpProgressBarHelper;
2024 XMLEventExport& SvXMLExport::GetEventExport()
2026 if( nullptr == mpEventExport)
2028 // create EventExport on demand
2029 mpEventExport = new XMLEventExport(*this, nullptr);
2031 // and register standard handlers + names
2032 OUString sStarBasic("StarBasic");
2033 mpEventExport->AddHandler(sStarBasic, new XMLStarBasicExportHandler());
2034 OUString sScript("Script");
2035 mpEventExport->AddHandler(sScript, new XMLScriptExportHandler());
2036 mpEventExport->AddTranslationTable(aStandardEventTable);
2039 return *mpEventExport;
2042 XMLImageMapExport& SvXMLExport::GetImageMapExport()
2044 // image map export, create on-demand
2045 if( nullptr == mpImageMapExport )
2047 mpImageMapExport = new XMLImageMapExport(*this);
2050 return *mpImageMapExport;
2053 namespace
2055 class theSvXMLExportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvXMLExportUnoTunnelId> {};
2058 // XUnoTunnel & co
2059 const uno::Sequence< sal_Int8 > & SvXMLExport::getUnoTunnelId() throw()
2061 return theSvXMLExportUnoTunnelId::get().getSeq();
2064 SvXMLExport* SvXMLExport::getImplementation( const uno::Reference< uno::XInterface >& xInt ) throw()
2066 uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
2067 if( xUT.is() )
2069 return
2070 reinterpret_cast<SvXMLExport*>(
2071 sal::static_int_cast<sal_IntPtr>(
2072 xUT->getSomething( SvXMLExport::getUnoTunnelId())));
2074 else
2075 return nullptr;
2078 // XUnoTunnel
2079 sal_Int64 SAL_CALL SvXMLExport::getSomething( const uno::Sequence< sal_Int8 >& rId )
2080 throw( uno::RuntimeException, std::exception )
2082 if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
2083 rId.getConstArray(), 16 ) )
2085 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2087 return 0;
2090 void SvXMLExport::ExportEmbeddedOwnObject( Reference< XComponent >& rComp )
2092 OUString sFilterService;
2094 Reference < lang::XServiceInfo > xServiceInfo( rComp, UNO_QUERY );
2095 if( xServiceInfo.is() )
2097 const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
2098 while( pEntry->sModelService )
2100 OUString sModelService( pEntry->sModelService,
2101 pEntry->nModelServiceLen,
2102 RTL_TEXTENCODING_ASCII_US );
2103 if( xServiceInfo->supportsService( sModelService ) )
2105 sFilterService = OUString( pEntry->sFilterService,
2106 pEntry->nFilterServiceLen,
2107 RTL_TEXTENCODING_ASCII_US );
2108 break;
2110 pEntry++;
2114 SAL_WARN_IF( !sFilterService.getLength(), "xmloff.core", "no export filter for own object" );
2116 if( sFilterService.isEmpty() )
2117 return;
2119 Reference < XDocumentHandler > xHdl =
2120 new XMLEmbeddedObjectExportFilter( mxHandler );
2122 Sequence < Any > aArgs( 1 );
2123 aArgs[0] <<= xHdl;
2125 Reference< document::XExporter > xExporter(
2126 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(sFilterService, aArgs, m_xContext),
2127 UNO_QUERY);
2128 SAL_WARN_IF( !xExporter.is(), "xmloff.core", "can't instantiate export filter component for own object" );
2129 if( !xExporter.is() )
2130 return;
2132 xExporter->setSourceDocument( rComp );
2134 Reference<XFilter> xFilter( xExporter, UNO_QUERY );
2136 Sequence < PropertyValue > aMediaDesc( 0 );
2137 xFilter->filter( aMediaDesc );
2140 OUString SvXMLExport::GetRelativeReference(const OUString& rValue)
2142 OUString sValue( rValue );
2143 // #i65474# handling of fragment URLs ("#....") is undefined
2144 // they are stored 'as is'
2145 uno::Reference< uri::XUriReference > xUriRef;
2146 if(!sValue.isEmpty() && sValue[0] != '#')
2150 xUriRef = mpImpl->mxUriReferenceFactory->parse( rValue );
2151 if( xUriRef.is() && !xUriRef->isAbsolute() )
2153 //#i61943# relative URLs need special handling
2154 INetURLObject aTemp( mpImpl->msPackageURI );
2155 bool bWasAbsolute = false;
2156 sValue = aTemp.smartRel2Abs(sValue, bWasAbsolute ).GetMainURL(INetURLObject::DECODE_TO_IURI);
2159 catch(const uno::Exception&)
2163 if( xUriRef.is() )//no conversion for empty values or for fragments
2165 //conversion for matching schemes only
2166 if( xUriRef->getScheme() == mpImpl->msPackageURIScheme )
2168 sValue = INetURLObject::GetRelURL( msOrigFileName, sValue );
2171 return sValue;
2174 void SvXMLExport::StartElement(sal_uInt16 nPrefix,
2175 enum ::xmloff::token::XMLTokenEnum eName,
2176 bool bIgnWSOutside )
2178 StartElement(GetNamespaceMap_().GetQNameByKey( nPrefix,
2179 GetXMLToken(eName) ), bIgnWSOutside);
2182 void SvXMLExport::StartElement(const OUString& rName,
2183 bool bIgnWSOutside )
2185 if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2189 if( bIgnWSOutside && ((mnExportFlags & SvXMLExportFlags::PRETTY) == SvXMLExportFlags::PRETTY))
2190 mxHandler->ignorableWhitespace( msWS );
2191 mxHandler->startElement( rName, GetXAttrList() );
2193 catch (const SAXInvalidCharacterException& e)
2195 Sequence<OUString> aPars { rName };
2196 SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, nullptr );
2198 catch (const SAXException& e)
2200 Sequence<OUString> aPars { rName };
2201 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2202 aPars, e.Message, nullptr );
2205 ClearAttrList();
2206 ++mpImpl->mDepth; // increment nesting depth counter
2209 void SvXMLExport::Characters(const OUString& rChars)
2211 if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2215 mxHandler->characters(rChars);
2217 catch (const SAXInvalidCharacterException& e)
2219 Sequence<OUString> aPars { rChars };
2220 SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, nullptr );
2222 catch (const SAXException& e)
2224 Sequence<OUString> aPars { rChars };
2225 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2226 aPars, e.Message, nullptr );
2231 void SvXMLExport::EndElement(sal_uInt16 nPrefix,
2232 enum ::xmloff::token::XMLTokenEnum eName,
2233 bool bIgnWSInside )
2235 EndElement(GetNamespaceMap_().GetQNameByKey( nPrefix, GetXMLToken(eName) ),
2236 bIgnWSInside);
2239 void SvXMLExport::EndElement(const OUString& rName,
2240 bool bIgnWSInside )
2242 // decrement nesting depth counter & (maybe) restore namespace map
2243 --mpImpl->mDepth;
2244 if (!mpImpl->mNamespaceMaps.empty() &&
2245 (mpImpl->mNamespaceMaps.top().second == mpImpl->mDepth))
2247 delete mpNamespaceMap;
2248 mpNamespaceMap = mpImpl->mNamespaceMaps.top().first;
2249 mpImpl->mNamespaceMaps.pop();
2251 SAL_WARN_IF(!mpImpl->mNamespaceMaps.empty() &&
2252 (mpImpl->mNamespaceMaps.top().second >= mpImpl->mDepth), "xmloff.core", "SvXMLExport: NamespaceMaps corrupted");
2254 if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2258 if( bIgnWSInside && ((mnExportFlags & SvXMLExportFlags::PRETTY) == SvXMLExportFlags::PRETTY))
2259 mxHandler->ignorableWhitespace( msWS );
2260 mxHandler->endElement( rName );
2262 catch (const SAXException& e)
2264 Sequence<OUString> aPars { rName };
2265 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2266 aPars, e.Message, nullptr );
2271 void SvXMLExport::IgnorableWhitespace()
2273 if ((mnExportFlags & SvXMLExportFlags::PRETTY) != SvXMLExportFlags::PRETTY)
2274 return;
2276 if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2280 mxHandler->ignorableWhitespace( msWS );
2282 catch (const SAXException& e)
2284 Sequence<OUString> aPars(0);
2285 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2286 aPars, e.Message, nullptr );
2291 void SvXMLExport::SetError(
2292 sal_Int32 nId,
2293 const Sequence<OUString>& rMsgParams,
2294 const OUString& rExceptionMessage,
2295 const Reference<XLocator>& rLocator )
2297 // allow multi-threaded access to the cancel() method
2298 static osl::Mutex aMutex;
2299 osl::MutexGuard aGuard(aMutex);
2301 // maintain error flags
2302 if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
2303 mnErrorFlags |= SvXMLErrorFlags::ERROR_OCCURRED;
2304 if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
2305 mnErrorFlags |= SvXMLErrorFlags::WARNING_OCCURRED;
2306 if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
2307 mnErrorFlags |= SvXMLErrorFlags::DO_NOTHING;
2309 // create error list on demand
2310 if ( mpXMLErrors == nullptr )
2311 mpXMLErrors = new XMLErrors();
2313 // save error information
2314 mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage, rLocator );
2317 void SvXMLExport::SetError(
2318 sal_Int32 nId,
2319 const Sequence<OUString>& rMsgParams)
2321 SetError( nId, rMsgParams, "", nullptr );
2324 void SvXMLExport::DisposingModel()
2326 mxModel.clear();
2327 // Shapes in Writer cannot be named via context menu (#i51726#)
2328 meModelType = SvtModuleOptions::EFactory::UNKNOWN_FACTORY;
2329 mxEventListener.clear();
2333 ::comphelper::UnoInterfaceToUniqueIdentifierMapper& SvXMLExport::getInterfaceToIdentifierMapper()
2335 return mpImpl->maInterfaceToIdentifierMapper;
2338 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
2339 bool SvXMLExport::writeOutlineStyleAsNormalListStyle() const
2341 return mpImpl->mbOutlineStyleAsNormalListStyle;
2344 uno::Reference< embed::XStorage > SvXMLExport::GetTargetStorage()
2346 return mpImpl->mxTargetStorage;
2349 /// returns the currently configured default version for ODF export
2350 SvtSaveOptions::ODFDefaultVersion SvXMLExport::getDefaultVersion() const
2352 if( mpImpl )
2353 return mpImpl->maSaveOptions.GetODFDefaultVersion();
2355 // fatal error, use current version as default
2356 return SvtSaveOptions::ODFVER_012;
2359 SvtSaveOptions::ODFSaneDefaultVersion SvXMLExport::getSaneDefaultVersion() const
2361 if( mpImpl )
2362 return mpImpl->maSaveOptions.GetODFSaneDefaultVersion();
2364 // fatal error, use current version as default
2365 return SvtSaveOptions::ODFSVER_LATEST;
2368 OUString SvXMLExport::GetStreamName() const
2370 return mpImpl->mStreamName;
2373 void
2374 SvXMLExport::AddAttributeIdLegacy(
2375 sal_uInt16 const nLegacyPrefix, OUString const& rValue)
2377 switch (getDefaultVersion()) {
2378 case SvtSaveOptions::ODFVER_011: // fall through
2379 case SvtSaveOptions::ODFVER_010: break;
2380 default: // ODF 1.2: xml:id
2381 AddAttribute(XML_NAMESPACE_XML, XML_ID, rValue);
2383 // in ODF 1.1 this was form:id, anim:id, draw:id, or text:id
2384 // backward compatibility: in ODF 1.2 write _both_ id attrs
2385 AddAttribute(nLegacyPrefix, XML_ID, rValue);
2386 // FIXME: this function simply assumes that rValue is unique
2389 void
2390 SvXMLExport::AddAttributeXmlId(uno::Reference<uno::XInterface> const & i_xIfc)
2392 // check version >= 1.2
2393 switch (getDefaultVersion()) {
2394 case SvtSaveOptions::ODFVER_011: // fall through
2395 case SvtSaveOptions::ODFVER_010: return;
2396 default: break;
2398 const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
2399 uno::UNO_QUERY);
2400 //FIXME not yet...
2401 if ( xMeta.is() )
2403 const beans::StringPair mdref( xMeta->getMetadataReference() );
2404 if ( !mdref.Second.isEmpty() )
2406 const OUString streamName( GetStreamName() );
2407 if ( !streamName.isEmpty() )
2409 if ( streamName.equals(mdref.First) )
2411 AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2413 else
2415 SAL_WARN("xmloff.core","SvXMLExport::AddAttributeXmlId: invalid stream name");
2418 else
2420 // FIXME: this is ugly
2421 // there is no stream name (e.g. XSLT, flat-xml format)!
2422 // but how do we ensure uniqueness in this case?
2423 // a) just omit styles.xml ids -- they are unlikely anyway...
2424 // b) somehow find out whether we are currently exporting styles
2425 // or content, and prefix "s" or "c" => unique
2426 if ( mdref.First == "content.xml" )
2428 AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2430 else
2432 SAL_INFO("xmloff.core", "SvXMLExport::AddAttributeXmlId: no stream name given: dropping styles.xml xml:id");
2439 void
2440 SvXMLExport::AddAttributesRDFa(
2441 uno::Reference<text::XTextContent> const & i_xTextContent)
2443 // check version >= 1.2
2444 switch (getDefaultVersion()) {
2445 case SvtSaveOptions::ODFVER_011: // fall through
2446 case SvtSaveOptions::ODFVER_010: return;
2447 default: break;
2450 const uno::Reference<rdf::XMetadatable> xMeta(
2451 i_xTextContent, uno::UNO_QUERY);
2452 if (!xMeta.is() || xMeta->getMetadataReference().Second.isEmpty())
2454 return; // no xml:id => no RDFa
2457 if (!mpImpl->mpRDFaHelper.get())
2459 mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaExportHelper(*this) );
2461 mpImpl->mpRDFaHelper->AddRDFa(xMeta);
2464 bool SvXMLExport::exportTextNumberElement() const
2466 return mpImpl->mbExportTextNumberElement;
2469 bool SvXMLExport::SetNullDateOnUnitConverter()
2471 // if the null date has already been set, don't set it again (performance)
2472 if (!mpImpl->mbNullDateInitialized)
2473 mpImpl->mbNullDateInitialized = GetMM100UnitConverter().setNullDate(GetModel());
2475 return mpImpl->mbNullDateInitialized;
2479 void SvXMLElementExport::StartElement(
2480 const sal_uInt16 nPrefixKey,
2481 const OUString& rLName,
2482 const bool bIgnoreWhitespaceOutside )
2484 maElementName = mrExport.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
2485 mrExport.StartElement(maElementName, bIgnoreWhitespaceOutside);
2488 SvXMLElementExport::SvXMLElementExport(
2489 SvXMLExport& rExp,
2490 sal_uInt16 nPrefixKey,
2491 const sal_Char *pLName,
2492 bool bIWSOutside,
2493 bool bIWSInside )
2494 : mrExport( rExp )
2495 , maElementName()
2496 , mbIgnoreWhitespaceInside( bIWSInside )
2497 , mbDoSomething( true )
2499 const OUString sLName( OUString::createFromAscii( pLName ) );
2500 StartElement( nPrefixKey, sLName, bIWSOutside );
2503 SvXMLElementExport::SvXMLElementExport(
2504 SvXMLExport& rExp,
2505 sal_uInt16 nPrefixKey,
2506 const OUString& rLName,
2507 bool bIWSOutside,
2508 bool bIWSInside )
2509 : mrExport( rExp )
2510 , maElementName()
2511 , mbIgnoreWhitespaceInside( bIWSInside )
2512 , mbDoSomething( true )
2514 StartElement( nPrefixKey, rLName, bIWSOutside );
2517 SvXMLElementExport::SvXMLElementExport(
2518 SvXMLExport& rExp,
2519 sal_uInt16 nPrefixKey,
2520 enum XMLTokenEnum eLName,
2521 bool bIWSOutside,
2522 bool bIWSInside )
2523 : mrExport( rExp )
2524 , maElementName()
2525 , mbIgnoreWhitespaceInside( bIWSInside )
2526 , mbDoSomething( true )
2528 StartElement( nPrefixKey, GetXMLToken(eLName), bIWSOutside );
2531 SvXMLElementExport::SvXMLElementExport(
2532 SvXMLExport& rExp,
2533 bool bDoSth,
2534 sal_uInt16 nPrefixKey,
2535 enum XMLTokenEnum eLName,
2536 bool bIWSOutside,
2537 bool bIWSInside )
2538 : mrExport( rExp )
2539 , maElementName()
2540 , mbIgnoreWhitespaceInside( bIWSInside )
2541 , mbDoSomething( bDoSth )
2543 if ( mbDoSomething )
2544 StartElement( nPrefixKey, GetXMLToken( eLName ), bIWSOutside );
2547 SvXMLElementExport::SvXMLElementExport(
2548 SvXMLExport& rExp,
2549 const OUString& rQName,
2550 bool bIWSOutside,
2551 bool bIWSInside )
2552 : mrExport( rExp )
2553 , maElementName()
2554 , mbIgnoreWhitespaceInside( bIWSInside )
2555 , mbDoSomething( true )
2557 maElementName = rQName;
2558 rExp.StartElement( rQName, bIWSOutside );
2561 SvXMLElementExport::~SvXMLElementExport()
2563 if ( mbDoSomething )
2565 mrExport.EndElement( maElementName, mbIgnoreWhitespaceInside );
2569 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */