bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / core / xmlexp.cxx
blob72cc29f77f20683008211d2e6edff3749979dd43
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/implbase1.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 { 0, 0, 0, 0 }
145 class SettingsExportFacade : public ::xmloff::XMLSettingsExportContext
147 public:
148 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 ) SAL_OVERRIDE;
159 virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName,
160 enum ::xmloff::token::XMLTokenEnum i_eValue ) SAL_OVERRIDE;
162 virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName,
163 const bool i_bIgnoreWhitespace ) SAL_OVERRIDE;
164 virtual void EndElement( const bool i_bIgnoreWhitespace ) SAL_OVERRIDE;
166 virtual void Characters( const OUString& i_rCharacters ) SAL_OVERRIDE;
168 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
169 GetComponentContext() const SAL_OVERRIDE;
170 private:
171 SvXMLExport& m_rExport;
172 ::std::stack< OUString > m_aElements;
175 void SettingsExportFacade::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const OUString& i_rValue )
177 m_rExport.AddAttribute( XML_NAMESPACE_CONFIG, i_eName, i_rValue );
180 void SettingsExportFacade::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue )
182 m_rExport.AddAttribute( XML_NAMESPACE_CONFIG, i_eName, i_eValue );
185 void SettingsExportFacade::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const bool i_bIgnoreWhitespace )
187 const OUString sElementName( m_rExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_CONFIG, GetXMLToken( i_eName ) ) );
188 m_rExport.StartElement( sElementName, i_bIgnoreWhitespace );
189 m_aElements.push( sElementName );
192 void SettingsExportFacade::EndElement( const bool i_bIgnoreWhitespace )
194 const OUString sElementName( m_aElements.top() );
195 m_rExport.EndElement( sElementName, i_bIgnoreWhitespace );
196 m_aElements.pop();
199 void SettingsExportFacade::Characters( const OUString& i_rCharacters )
201 m_rExport.GetDocHandler()->characters( i_rCharacters );
204 Reference< XComponentContext > SettingsExportFacade::GetComponentContext() const
206 return m_rExport.getComponentContext();
209 class SvXMLExportEventListener : public cppu::WeakImplHelper1<
210 com::sun::star::lang::XEventListener >
212 private:
213 SvXMLExport* pExport;
215 public:
216 SvXMLExportEventListener(SvXMLExport* pExport);
217 virtual ~SvXMLExportEventListener();
219 // XEventListener
220 virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
223 SvXMLExportEventListener::SvXMLExportEventListener(SvXMLExport* pTempExport)
224 : pExport(pTempExport)
228 SvXMLExportEventListener::~SvXMLExportEventListener()
232 // XEventListener
233 void SAL_CALL SvXMLExportEventListener::disposing( const lang::EventObject& )
234 throw(uno::RuntimeException, std::exception)
236 if (pExport)
238 pExport->DisposingModel();
239 pExport = NULL;
243 class SvXMLExport_Impl
245 public:
246 SvXMLExport_Impl();
248 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
249 uno::Reference< uri::XUriReferenceFactory > mxUriReferenceFactory;
250 OUString msPackageURI;
251 OUString msPackageURIScheme;
252 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
253 bool mbOutlineStyleAsNormalListStyle;
254 bool mbSaveBackwardCompatibleODF;
256 uno::Reference< embed::XStorage > mxTargetStorage;
258 SvtSaveOptions maSaveOptions;
260 /// relative path of stream in package, e.g. "someobject/content.xml"
261 OUString mStreamPath;
263 /// name of stream in package, e.g., "content.xml"
264 OUString mStreamName;
266 OUString maSrcShellID;
267 OUString maDestShellID;
269 /// stack of backed up namespace maps
270 /// long: depth at which namespace map has been backed up into the stack
271 ::std::stack< ::std::pair< SvXMLNamespaceMap *, long > > mNamespaceMaps;
272 /// counts depth (number of open elements/start tags)
273 long mDepth;
275 ::std::unique_ptr< ::xmloff::RDFaExportHelper> mpRDFaHelper;
277 bool mbExportTextNumberElement;
278 bool mbNullDateInitialized;
280 void SetSchemeOf( const OUString& rOrigFileName )
282 sal_Int32 nSep = rOrigFileName.indexOf(':');
283 if( nSep != -1 )
284 msPackageURIScheme = rOrigFileName.copy( 0, nSep );
288 SvXMLExport_Impl::SvXMLExport_Impl()
289 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
290 : mbOutlineStyleAsNormalListStyle( false )
291 ,mbSaveBackwardCompatibleODF( true )
292 ,mStreamName()
293 ,mNamespaceMaps()
294 ,mDepth(0)
295 ,mpRDFaHelper() // lazy
296 ,mbExportTextNumberElement( false )
297 ,mbNullDateInitialized( false )
299 mxUriReferenceFactory = uri::UriReferenceFactory::create( comphelper::getProcessComponentContext() );
302 void SvXMLExport::SetDocHandler( const uno::Reference< xml::sax::XDocumentHandler > &rHandler )
304 mxHandler = rHandler;
305 mxExtHandler = uno::Reference<xml::sax::XExtendedDocumentHandler>( mxHandler, UNO_QUERY );
308 void SvXMLExport::_InitCtor()
310 // note: it is not necessary to add XML_NP_XML (it is declared implicitly)
311 if( getExportFlags() & ~SvXMLExportFlags::OASIS )
313 mpNamespaceMap->Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE );
314 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
316 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::FONTDECLS) )
318 mpNamespaceMap->Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
320 if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SCRIPTS|SvXMLExportFlags::SETTINGS) )
322 mpNamespaceMap->Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
324 if( getExportFlags() & SvXMLExportFlags::SETTINGS )
326 mpNamespaceMap->Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG );
329 if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
331 mpNamespaceMap->Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
332 mpNamespaceMap->Add( GetXMLToken(XML_NP_META), GetXMLToken(XML_N_META), XML_NAMESPACE_META );
334 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::FONTDECLS) )
336 mpNamespaceMap->Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE );
339 // namespaces for documents
340 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
342 mpNamespaceMap->Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
343 mpNamespaceMap->Add( GetXMLToken(XML_NP_TEXT), GetXMLToken(XML_N_TEXT), XML_NAMESPACE_TEXT );
344 mpNamespaceMap->Add( GetXMLToken(XML_NP_DRAW), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW );
345 mpNamespaceMap->Add( GetXMLToken(XML_NP_DR3D), GetXMLToken(XML_N_DR3D), XML_NAMESPACE_DR3D );
346 mpNamespaceMap->Add( GetXMLToken(XML_NP_SVG), GetXMLToken(XML_N_SVG_COMPAT), XML_NAMESPACE_SVG );
347 mpNamespaceMap->Add( GetXMLToken(XML_NP_CHART), GetXMLToken(XML_N_CHART), XML_NAMESPACE_CHART );
348 mpNamespaceMap->Add( GetXMLToken(XML_NP_RPT), GetXMLToken(XML_N_RPT), XML_NAMESPACE_REPORT );
349 mpNamespaceMap->Add( GetXMLToken(XML_NP_TABLE), GetXMLToken(XML_N_TABLE), XML_NAMESPACE_TABLE );
350 mpNamespaceMap->Add( GetXMLToken(XML_NP_NUMBER),GetXMLToken(XML_N_NUMBER), XML_NAMESPACE_NUMBER );
351 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOOW), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
352 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOOC), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
353 mpNamespaceMap->Add( GetXMLToken(XML_NP_OF), GetXMLToken(XML_N_OF), XML_NAMESPACE_OF );
355 if (getDefaultVersion() > SvtSaveOptions::ODFVER_012)
357 mpNamespaceMap->Add(
358 GetXMLToken(XML_NP_TABLE_EXT), GetXMLToken(XML_N_TABLE_EXT), XML_NAMESPACE_TABLE_EXT);
359 mpNamespaceMap->Add(
360 GetXMLToken(XML_NP_CALC_EXT), GetXMLToken(XML_N_CALC_EXT), XML_NAMESPACE_CALC_EXT);
361 mpNamespaceMap->Add(
362 GetXMLToken(XML_NP_DRAW_EXT), GetXMLToken(XML_N_DRAW_EXT), XML_NAMESPACE_DRAW_EXT);
363 mpNamespaceMap->Add(
364 GetXMLToken(XML_NP_LO_EXT), GetXMLToken(XML_N_LO_EXT),
365 XML_NAMESPACE_LO_EXT);
366 mpNamespaceMap->Add( GetXMLToken(XML_NP_FIELD), GetXMLToken(XML_N_FIELD), XML_NAMESPACE_FIELD );
369 if( getExportFlags() & (SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
371 mpNamespaceMap->Add( GetXMLToken(XML_NP_MATH), GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH );
372 mpNamespaceMap->Add( GetXMLToken(XML_NP_FORM), GetXMLToken(XML_N_FORM), XML_NAMESPACE_FORM );
374 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SCRIPTS) )
376 mpNamespaceMap->Add( GetXMLToken(XML_NP_SCRIPT), GetXMLToken(XML_N_SCRIPT), XML_NAMESPACE_SCRIPT );
377 mpNamespaceMap->Add( GetXMLToken(XML_NP_DOM), GetXMLToken(XML_N_DOM), XML_NAMESPACE_DOM );
379 if( getExportFlags() & SvXMLExportFlags::CONTENT )
381 mpNamespaceMap->Add( GetXMLToken(XML_NP_XFORMS_1_0), GetXMLToken(XML_N_XFORMS_1_0), XML_NAMESPACE_XFORMS );
382 mpNamespaceMap->Add( GetXMLToken(XML_NP_XSD), GetXMLToken(XML_N_XSD), XML_NAMESPACE_XSD );
383 mpNamespaceMap->Add( GetXMLToken(XML_NP_XSI), GetXMLToken(XML_N_XSI), XML_NAMESPACE_XSI );
384 mpNamespaceMap->Add( GetXMLToken(XML_NP_FORMX), GetXMLToken(XML_N_FORMX), XML_NAMESPACE_FORMX );
387 // RDFa: needed for content and header/footer styles
388 if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
390 mpNamespaceMap->Add( GetXMLToken(XML_NP_XHTML),
391 GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
393 // GRDDL: to convert RDFa and meta.xml to RDF
394 if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) )
396 mpNamespaceMap->Add( GetXMLToken(XML_NP_GRDDL),
397 GetXMLToken(XML_N_GRDDL), XML_NAMESPACE_GRDDL );
399 // CSS Text Level 3 for distributed text justification.
400 if ( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES) )
402 mpNamespaceMap->Add(
403 GetXMLToken(XML_NP_CSS3TEXT), GetXMLToken(XML_N_CSS3TEXT), XML_NAMESPACE_CSS3TEXT );
406 mxAttrList = (xml::sax::XAttributeList*)mpAttrList;
408 msGraphicObjectProtocol = "vnd.sun.star.GraphicObject:";
409 msEmbeddedObjectProtocol = "vnd.sun.star.EmbeddedObject:";
411 if (mxModel.is() && !mxEventListener.is())
413 mxEventListener.set( new SvXMLExportEventListener(this));
414 mxModel->addEventListener(mxEventListener);
417 // Determine model type (#i51726#)
418 _DetermineModelType();
420 // cl: but only if we do export to current oasis format, old openoffice format *must* always be compatible
421 if( getExportFlags() & SvXMLExportFlags::OASIS )
423 mpImpl->mbSaveBackwardCompatibleODF =
424 officecfg::Office::Common::Save::Document::
425 SaveBackwardCompatibleODF::get( comphelper::getProcessComponentContext() );
429 // Shapes in Writer cannot be named via context menu (#i51726#)
430 void SvXMLExport::_DetermineModelType()
432 meModelType = SvtModuleOptions::EFactory::UNKNOWN_FACTORY;
434 if ( mxModel.is() )
436 meModelType = SvtModuleOptions::ClassifyFactoryByModel( mxModel );
440 SvXMLExport::SvXMLExport(
441 sal_Int16 const eDefaultMeasureUnit /*css::util::MeasureUnit*/,
442 const uno::Reference< uno::XComponentContext >& xContext,
443 OUString const & implementationName,
444 const enum XMLTokenEnum eClass, SvXMLExportFlags nExportFlags )
445 : mpImpl( new SvXMLExport_Impl ),
446 m_xContext(xContext), m_implementationName(implementationName),
447 mpAttrList( new SvXMLAttributeList ),
448 mpNamespaceMap( new SvXMLNamespaceMap ),
449 mpUnitConv( new SvXMLUnitConverter( xContext,
450 util::MeasureUnit::MM_100TH, eDefaultMeasureUnit) ),
451 mpNumExport(0L),
452 mpProgressBarHelper( NULL ),
453 mpEventExport( NULL ),
454 mpImageMapExport( NULL ),
455 mpXMLErrors( NULL ),
456 mbExtended( false ),
457 meClass( eClass ),
458 mnExportFlags( nExportFlags ),
459 mnErrorFlags( SvXMLErrorFlags::NO ),
460 msWS( GetXMLToken(XML_WS) ),
461 mbSaveLinkedSections(true)
463 SAL_WARN_IF( !xContext.is(), "xmloff.core", "got no service manager" );
464 _InitCtor();
467 SvXMLExport::SvXMLExport(
468 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
469 OUString const & implementationName,
470 const OUString &rFileName,
471 sal_Int16 const eDefaultMeasureUnit /*css::util::MeasureUnit*/,
472 const uno::Reference< xml::sax::XDocumentHandler > & rHandler)
473 : mpImpl( new SvXMLExport_Impl ),
474 m_xContext(xContext), m_implementationName(implementationName),
475 mxHandler( rHandler ),
476 mxExtHandler( rHandler, uno::UNO_QUERY ),
477 mpAttrList( new SvXMLAttributeList ),
478 msOrigFileName( rFileName ),
479 mpNamespaceMap( new SvXMLNamespaceMap ),
480 mpUnitConv( new SvXMLUnitConverter( xContext,
481 util::MeasureUnit::MM_100TH, eDefaultMeasureUnit) ),
482 mpNumExport(0L),
483 mpProgressBarHelper( NULL ),
484 mpEventExport( NULL ),
485 mpImageMapExport( NULL ),
486 mpXMLErrors( NULL ),
487 mbExtended( false ),
488 meClass( XML_TOKEN_INVALID ),
489 mnExportFlags( SvXMLExportFlags::NONE ),
490 mnErrorFlags( SvXMLErrorFlags::NO ),
491 msWS( GetXMLToken(XML_WS) ),
492 mbSaveLinkedSections(true)
494 SAL_WARN_IF( !xContext.is(), "xmloff.core", "got no service manager" );
495 mpImpl->SetSchemeOf( msOrigFileName );
496 _InitCtor();
498 if (mxNumberFormatsSupplier.is())
499 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
502 SvXMLExport::SvXMLExport(
503 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
504 OUString const & implementationName,
505 const OUString &rFileName,
506 const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
507 const Reference< XModel >& rModel,
508 FieldUnit const eDefaultFieldUnit)
509 : mpImpl( new SvXMLExport_Impl ),
510 m_xContext(xContext), m_implementationName(implementationName),
511 mxModel( rModel ),
512 mxHandler( rHandler ),
513 mxExtHandler( rHandler, uno::UNO_QUERY ),
514 mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
515 mpAttrList( new SvXMLAttributeList ),
516 msOrigFileName( rFileName ),
517 mpNamespaceMap( new SvXMLNamespaceMap ),
518 mpUnitConv( new SvXMLUnitConverter( xContext,
519 util::MeasureUnit::MM_100TH,
520 SvXMLUnitConverter::GetMeasureUnit(eDefaultFieldUnit)) ),
521 mpNumExport(0L),
522 mpProgressBarHelper( NULL ),
523 mpEventExport( NULL ),
524 mpImageMapExport( NULL ),
525 mpXMLErrors( NULL ),
526 mbExtended( false ),
527 meClass( XML_TOKEN_INVALID ),
528 mnExportFlags( SvXMLExportFlags::NONE ),
529 mnErrorFlags( SvXMLErrorFlags::NO ),
530 msWS( GetXMLToken(XML_WS) ),
531 mbSaveLinkedSections(true)
533 SAL_WARN_IF(!xContext.is(), "xmloff.core", "got no service manager" );
534 mpImpl->SetSchemeOf( msOrigFileName );
535 _InitCtor();
537 if (mxNumberFormatsSupplier.is())
538 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
541 SvXMLExport::~SvXMLExport()
543 delete mpXMLErrors;
544 delete mpImageMapExport;
545 delete mpEventExport;
546 delete mpNamespaceMap;
547 delete mpUnitConv;
548 if (mpProgressBarHelper || mpNumExport)
550 if (mxExportInfo.is())
552 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
553 if (xPropertySetInfo.is())
555 if (mpProgressBarHelper)
557 OUString sProgressMax(XML_PROGRESSMAX);
558 OUString sProgressCurrent(XML_PROGRESSCURRENT);
559 OUString sRepeat(XML_PROGRESSREPEAT);
560 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
561 xPropertySetInfo->hasPropertyByName(sProgressCurrent))
563 sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
564 sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
565 uno::Any aAny;
566 aAny <<= nProgressMax;
567 mxExportInfo->setPropertyValue(sProgressMax, aAny);
568 aAny <<= nProgressCurrent;
569 mxExportInfo->setPropertyValue(sProgressCurrent, aAny);
571 if (xPropertySetInfo->hasPropertyByName(sRepeat))
572 mxExportInfo->setPropertyValue(sRepeat, css::uno::makeAny(mpProgressBarHelper->GetRepeat()));
574 if (mpNumExport && (mnExportFlags & (SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::STYLES)))
576 OUString sWrittenNumberFormats(XML_WRITTENNUMBERSTYLES);
577 if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
579 uno::Sequence<sal_Int32> aWasUsed;
580 mpNumExport->GetWasUsed(aWasUsed);
581 uno::Any aAny;
582 aAny <<= aWasUsed;
583 mxExportInfo->setPropertyValue(sWrittenNumberFormats, aAny);
588 delete mpProgressBarHelper;
589 delete mpNumExport;
592 if (mxEventListener.is() && mxModel.is())
593 mxModel->removeEventListener(mxEventListener);
595 delete mpImpl;
598 // XExporter
599 void SAL_CALL SvXMLExport::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
600 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
602 mxModel = uno::Reference< frame::XModel >::query( xDoc );
603 if( !mxModel.is() )
604 throw lang::IllegalArgumentException();
605 if (mxModel.is() && ! mxEventListener.is())
607 mxEventListener.set( new SvXMLExportEventListener(this));
608 mxModel->addEventListener(mxEventListener);
611 if(!mxNumberFormatsSupplier.is() )
613 mxNumberFormatsSupplier.set(mxModel, css::uno::UNO_QUERY);
614 if(mxNumberFormatsSupplier.is() && mxHandler.is())
615 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
617 if (mxExportInfo.is())
619 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
620 if (xPropertySetInfo.is())
622 OUString sUsePrettyPrinting(XML_USEPRETTYPRINTING);
623 if (xPropertySetInfo->hasPropertyByName(sUsePrettyPrinting))
625 uno::Any aAny = mxExportInfo->getPropertyValue(sUsePrettyPrinting);
626 if (::cppu::any2bool(aAny))
627 mnExportFlags |= SvXMLExportFlags::PRETTY;
628 else
629 mnExportFlags &= ~SvXMLExportFlags::PRETTY;
632 if (mpNumExport && (mnExportFlags & (SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::STYLES)))
634 OUString sWrittenNumberFormats(XML_WRITTENNUMBERSTYLES);
635 if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
637 uno::Any aAny = mxExportInfo->getPropertyValue(sWrittenNumberFormats);
638 uno::Sequence<sal_Int32> aWasUsed;
639 if(aAny >>= aWasUsed)
640 mpNumExport->SetWasUsed(aWasUsed);
646 if ( mpImpl->mbSaveBackwardCompatibleODF )
647 mnExportFlags |= SvXMLExportFlags::SAVEBACKWARDCOMPATIBLE;
648 else
649 mnExportFlags &= ~SvXMLExportFlags::SAVEBACKWARDCOMPATIBLE;
651 // namespaces for user defined attributes
652 Reference< XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
653 if( xFactory.is() )
657 Reference < XInterface > xIfc =
658 xFactory->createInstance("com.sun.star.xml.NamespaceMap");
659 if( xIfc.is() )
661 Reference< XNameAccess > xNamespaceMap( xIfc, UNO_QUERY );
662 if( xNamespaceMap.is() )
664 Sequence< OUString > aPrefixes( xNamespaceMap->getElementNames() );
666 OUString* pPrefix = aPrefixes.getArray();
667 const sal_Int32 nCount = aPrefixes.getLength();
668 sal_Int32 nIndex;
669 OUString aURL;
671 for( nIndex = 0; nIndex < nCount; ++nIndex, ++pPrefix )
673 if( xNamespaceMap->getByName( *pPrefix ) >>= aURL )
674 _GetNamespaceMap().Add( *pPrefix, aURL, XML_NAMESPACE_UNKNOWN );
679 catch(const com::sun::star::uno::Exception&)
684 // Determine model type (#i51726#)
685 _DetermineModelType();
688 // XInitialize
689 void SAL_CALL SvXMLExport::initialize( const uno::Sequence< uno::Any >& aArguments )
690 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception)
692 // #93186# we need to queryInterface every single Any with any expected outcome. This variable hold the queryInterface results.
694 const sal_Int32 nAnyCount = aArguments.getLength();
695 const uno::Any* pAny = aArguments.getConstArray();
697 for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
699 Reference<XInterface> xValue;
700 *pAny >>= xValue;
702 // status indicator
703 uno::Reference<task::XStatusIndicator> xTmpStatus( xValue, UNO_QUERY );
704 if ( xTmpStatus.is() )
705 mxStatusIndicator = xTmpStatus;
707 // graphic resolver
708 uno::Reference<document::XGraphicObjectResolver> xTmpGraphic(
709 xValue, UNO_QUERY );
710 if ( xTmpGraphic.is() )
711 mxGraphicResolver = xTmpGraphic;
713 // object resolver
714 uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
715 xValue, UNO_QUERY );
716 if ( xTmpObjectResolver.is() )
717 mxEmbeddedResolver = xTmpObjectResolver;
719 // document handler
720 uno::Reference<xml::sax::XDocumentHandler> xTmpDocHandler(
721 xValue, UNO_QUERY );
722 if( xTmpDocHandler.is() )
724 mxHandler = xTmpDocHandler;
725 *pAny >>= mxExtHandler;
727 if (mxNumberFormatsSupplier.is() && mpNumExport == NULL)
728 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
731 // property set to transport data across
732 uno::Reference<beans::XPropertySet> xTmpPropertySet(
733 xValue, UNO_QUERY );
734 if( xTmpPropertySet.is() )
735 mxExportInfo = xTmpPropertySet;
738 if( mxExportInfo.is() )
740 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo =
741 mxExportInfo->getPropertySetInfo();
742 OUString sPropName(
743 "BaseURI" );
744 if( xPropertySetInfo->hasPropertyByName(sPropName) )
746 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
747 aAny >>= msOrigFileName;
748 mpImpl->msPackageURI = msOrigFileName;
749 mpImpl->SetSchemeOf( msOrigFileName );
751 OUString sRelPath;
752 sPropName = "StreamRelPath";
753 if( xPropertySetInfo->hasPropertyByName(sPropName) )
755 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
756 aAny >>= sRelPath;
758 OUString sName;
759 sPropName = "StreamName";
760 if( xPropertySetInfo->hasPropertyByName(sPropName) )
762 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
763 aAny >>= sName;
765 if( !msOrigFileName.isEmpty() && !sName.isEmpty() )
767 INetURLObject aBaseURL( msOrigFileName );
768 if( !sRelPath.isEmpty() )
769 aBaseURL.insertName( sRelPath );
770 aBaseURL.insertName( sName );
771 msOrigFileName = aBaseURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
773 mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
775 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
776 const OUString sOutlineStyleAsNormalListStyle(
777 "OutlineStyleAsNormalListStyle" );
778 if( xPropertySetInfo->hasPropertyByName( sOutlineStyleAsNormalListStyle ) )
780 uno::Any aAny = mxExportInfo->getPropertyValue( sOutlineStyleAsNormalListStyle );
781 aAny >>= (mpImpl->mbOutlineStyleAsNormalListStyle);
784 OUString sTargetStorage( "TargetStorage" );
785 if( xPropertySetInfo->hasPropertyByName( sTargetStorage ) )
786 mxExportInfo->getPropertyValue( sTargetStorage ) >>= mpImpl->mxTargetStorage;
788 const OUString sExportTextNumberElement(
789 "ExportTextNumberElement" );
790 if( xPropertySetInfo->hasPropertyByName( sExportTextNumberElement ) )
792 uno::Any aAny = mxExportInfo->getPropertyValue( sExportTextNumberElement );
793 aAny >>= (mpImpl->mbExportTextNumberElement);
799 // XFilter
800 sal_Bool SAL_CALL SvXMLExport::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor ) throw(uno::RuntimeException, std::exception)
802 // check for xHandler first... should have been supplied in initialize
803 if( !mxHandler.is() )
804 return sal_False;
808 const sal_Int32 nPropCount = aDescriptor.getLength();
810 const SvXMLExportFlags nTest =
811 SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SETTINGS;
812 if( (mnExportFlags & nTest) == nTest && msOrigFileName.isEmpty() )
814 // evaluate descriptor only for flat files and if a base URI
815 // has not been provided already
817 const beans::PropertyValue* pProps = aDescriptor.getConstArray();
818 for( sal_Int32 nIndex = 0; nIndex < nPropCount; nIndex++, pProps++ )
820 const OUString& rPropName = pProps->Name;
821 const Any& rValue = pProps->Value;
823 if ( rPropName == "FileName" )
825 if( !(rValue >>= msOrigFileName ) )
826 return sal_False;
828 else if ( rPropName == "FilterName" )
830 if( !(rValue >>= msFilterName ) )
831 return sal_False;
836 const beans::PropertyValue* pProps = aDescriptor.getConstArray();
837 for (sal_Int32 nIndex = 0; nIndex < nPropCount; ++nIndex, ++pProps)
839 const OUString& rPropName = pProps->Name;
840 const Any& rValue = pProps->Value;
842 if (rPropName == "SourceShellID")
844 if (!(rValue >>= mpImpl->maSrcShellID))
845 return false;
847 else if (rPropName == "DestinationShellID")
849 if (!(rValue >>= mpImpl->maDestShellID))
850 return false;
855 exportDoc( meClass );
857 catch(const uno::Exception& e)
859 // We must catch exceptions, because according to the
860 // API definition export must not throw one!
861 css::uno::Any ex(cppu::getCaughtException());
862 SetError( XMLERROR_FLAG_ERROR | XMLERROR_FLAG_SEVERE | XMLERROR_API,
863 Sequence<OUString>(),
864 ex.getValueTypeName() + ": \"" + e.Message + "\"", NULL );
867 // return true only if no error occurred
868 return (GetErrorFlags() & (SvXMLErrorFlags::DO_NOTHING|SvXMLErrorFlags::ERROR_OCCURRED)) == SvXMLErrorFlags::NO;
871 void SAL_CALL SvXMLExport::cancel() throw(uno::RuntimeException, std::exception)
873 // stop export
874 Sequence<OUString> aEmptySeq;
875 SetError(XMLERROR_CANCEL|XMLERROR_FLAG_SEVERE, aEmptySeq);
878 OUString SAL_CALL SvXMLExport::getName( )
879 throw (::com::sun::star::uno::RuntimeException, std::exception)
881 return msFilterName;
884 void SAL_CALL SvXMLExport::setName( const OUString& )
885 throw (::com::sun::star::uno::RuntimeException, std::exception)
887 // do nothing, because it is not possible to set the FilterName
890 // XServiceInfo
891 OUString SAL_CALL SvXMLExport::getImplementationName( ) throw(uno::RuntimeException, std::exception)
893 return m_implementationName;
896 sal_Bool SAL_CALL SvXMLExport::supportsService( const OUString& rServiceName ) throw(uno::RuntimeException, std::exception)
898 return cppu::supportsService(this, rServiceName);
901 uno::Sequence< OUString > SAL_CALL SvXMLExport::getSupportedServiceNames( )
902 throw(uno::RuntimeException, std::exception)
904 uno::Sequence<OUString> aSeq(2);
905 aSeq[0] = "com.sun.star.document.ExportFilter";
906 aSeq[1] = "com.sun.star.xml.XMLExportFilter";
907 return aSeq;
910 OUString
911 SvXMLExport::EnsureNamespace(OUString const & i_rNamespace,
912 OUString const & i_rPreferredPrefix)
914 OUString sPrefix;
915 sal_uInt16 nKey( _GetNamespaceMap().GetKeyByName( i_rNamespace ) );
916 if( XML_NAMESPACE_UNKNOWN == nKey )
918 // There is no prefix for the namespace, so
919 // we have to generate one and have to add it.
920 sPrefix = i_rPreferredPrefix;
921 nKey = _GetNamespaceMap().GetKeyByPrefix( sPrefix );
922 sal_Int32 n( 0 );
923 OUStringBuffer buf;
924 while( nKey != USHRT_MAX )
926 buf.append( i_rPreferredPrefix );
927 buf.append( ++n );
928 sPrefix = buf.makeStringAndClear();
929 nKey = _GetNamespaceMap().GetKeyByPrefix( sPrefix );
932 if (mpImpl->mNamespaceMaps.empty()
933 || (mpImpl->mNamespaceMaps.top().second != mpImpl->mDepth))
935 // top was created for lower depth... need a new namespace map!
936 mpImpl->mNamespaceMaps.push(
937 ::std::make_pair(mpNamespaceMap, mpImpl->mDepth) );
938 mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
941 // add the namespace to the map and as attribute
942 mpNamespaceMap->Add( sPrefix, i_rNamespace );
943 buf.append( GetXMLToken(XML_XMLNS) );
944 buf.append( ':' );
945 buf.append( sPrefix );
946 AddAttribute( buf.makeStringAndClear(), i_rNamespace );
948 else
950 // If there is a prefix for the namespace, reuse that.
951 sPrefix = _GetNamespaceMap().GetPrefixByKey( nKey );
953 return sPrefix;
956 void SvXMLExport::AddAttributeASCII( sal_uInt16 nPrefixKey,
957 const sal_Char *pName,
958 const sal_Char *pValue )
960 OUString sName( OUString::createFromAscii( pName ) );
961 OUString sValue( OUString::createFromAscii( pValue ) );
963 mpAttrList->AddAttribute(
964 _GetNamespaceMap().GetQNameByKey( nPrefixKey, sName ), sValue );
967 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const sal_Char *pName,
968 const OUString& rValue )
970 OUString sName( OUString::createFromAscii( pName ) );
972 mpAttrList->AddAttribute(
973 _GetNamespaceMap().GetQNameByKey( nPrefixKey, sName ), rValue );
976 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const OUString& rName,
977 const OUString& rValue )
979 mpAttrList->AddAttribute(
980 _GetNamespaceMap().GetQNameByKey( nPrefixKey, rName ), rValue );
983 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
984 enum XMLTokenEnum eName,
985 const OUString& rValue )
987 mpAttrList->AddAttribute(
988 _GetNamespaceMap().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
989 rValue );
992 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
993 enum XMLTokenEnum eName,
994 enum XMLTokenEnum eValue)
996 mpAttrList->AddAttribute(
997 _GetNamespaceMap().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
998 GetXMLToken(eValue) );
1001 void SvXMLExport::AddAttribute( const OUString& rQName,
1002 const OUString& rValue )
1004 mpAttrList->AddAttribute(
1005 rQName,
1006 rValue );
1009 void SvXMLExport::AddAttribute( const OUString& rQName,
1010 enum ::xmloff::token::XMLTokenEnum eValue )
1012 mpAttrList->AddAttribute(
1013 rQName,
1014 GetXMLToken(eValue) );
1017 void SvXMLExport::AddLanguageTagAttributes( sal_uInt16 nPrefix, sal_uInt16 nPrefixRfc,
1018 const ::com::sun::star::lang::Locale& rLocale, bool bWriteEmpty,
1019 enum ::xmloff::token::XMLTokenEnum eClass )
1021 if (rLocale.Variant.isEmpty())
1023 // Per convention The BCP 47 string is always stored in Variant, if
1024 // that is empty we have a plain language-country combination, no need
1025 // to convert to LanguageTag first. Also catches the case of empty
1026 // locale denoting system locale.
1027 xmloff::token::XMLTokenEnum eLanguage, eCountry;
1028 switch (eClass)
1030 default:
1031 case XML_LANGUAGE:
1032 eLanguage = XML_LANGUAGE;
1033 eCountry = XML_COUNTRY;
1034 break;
1035 case XML_LANGUAGE_ASIAN:
1036 eLanguage = XML_LANGUAGE_ASIAN;
1037 eCountry = XML_COUNTRY_ASIAN;
1038 if (nPrefix == XML_NAMESPACE_FO)
1039 nPrefix = XML_NAMESPACE_STYLE;
1040 break;
1041 case XML_LANGUAGE_COMPLEX:
1042 eLanguage = XML_LANGUAGE_COMPLEX;
1043 eCountry = XML_COUNTRY_COMPLEX;
1044 if (nPrefix == XML_NAMESPACE_FO)
1045 nPrefix = XML_NAMESPACE_STYLE;
1046 break;
1048 if (bWriteEmpty || !rLocale.Language.isEmpty())
1049 AddAttribute( nPrefix, eLanguage, rLocale.Language);
1050 if (bWriteEmpty || !rLocale.Country.isEmpty())
1051 AddAttribute( nPrefix, eCountry, rLocale.Country);
1053 else
1055 LanguageTag aLanguageTag( rLocale);
1056 AddLanguageTagAttributes( nPrefix, nPrefixRfc, aLanguageTag, bWriteEmpty, eClass);
1060 void SvXMLExport::AddLanguageTagAttributes( sal_uInt16 nPrefix, sal_uInt16 nPrefixRfc,
1061 const LanguageTag& rLanguageTag, bool bWriteEmpty, xmloff::token::XMLTokenEnum eClass )
1063 xmloff::token::XMLTokenEnum eLanguage, eScript, eCountry, eRfcLanguageTag;
1064 switch (eClass)
1066 default:
1067 case XML_LANGUAGE:
1068 eLanguage = XML_LANGUAGE;
1069 eScript = XML_SCRIPT;
1070 eCountry = XML_COUNTRY;
1071 eRfcLanguageTag = XML_RFC_LANGUAGE_TAG;
1072 break;
1073 case XML_LANGUAGE_ASIAN:
1074 eLanguage = XML_LANGUAGE_ASIAN;
1075 eScript = XML_SCRIPT_ASIAN;
1076 eCountry = XML_COUNTRY_ASIAN;
1077 eRfcLanguageTag = XML_RFC_LANGUAGE_TAG_ASIAN;
1078 if (nPrefix == XML_NAMESPACE_FO)
1079 nPrefix = XML_NAMESPACE_STYLE;
1080 break;
1081 case XML_LANGUAGE_COMPLEX:
1082 eLanguage = XML_LANGUAGE_COMPLEX;
1083 eScript = XML_SCRIPT_COMPLEX;
1084 eCountry = XML_COUNTRY_COMPLEX;
1085 eRfcLanguageTag = XML_RFC_LANGUAGE_TAG_COMPLEX;
1086 if (nPrefix == XML_NAMESPACE_FO)
1087 nPrefix = XML_NAMESPACE_STYLE;
1088 break;
1090 if (rLanguageTag.isIsoODF())
1092 if (bWriteEmpty || !rLanguageTag.isSystemLocale())
1094 AddAttribute( nPrefix, eLanguage, rLanguageTag.getLanguage());
1095 if (rLanguageTag.hasScript() && getDefaultVersion() >= SvtSaveOptions::ODFVER_012)
1096 AddAttribute( nPrefix, eScript, rLanguageTag.getScript());
1097 if (bWriteEmpty || !rLanguageTag.getCountry().isEmpty())
1098 AddAttribute( nPrefix, eCountry, rLanguageTag.getCountry());
1101 else
1103 if (getDefaultVersion() >= SvtSaveOptions::ODFVER_012)
1104 AddAttribute( nPrefixRfc, eRfcLanguageTag, rLanguageTag.getBcp47());
1105 // Also in case of non-pure-ISO tag store best matching fo: attributes
1106 // for consumers not handling *:rfc-language-tag, ensuring that only
1107 // valid ISO codes are stored. Here the bWriteEmpty parameter has no
1108 // meaning.
1109 OUString aLanguage, aScript, aCountry;
1110 rLanguageTag.getIsoLanguageScriptCountry( aLanguage, aScript, aCountry);
1111 if (!aLanguage.isEmpty())
1113 AddAttribute( nPrefix, eLanguage, aLanguage);
1114 if (!aScript.isEmpty() && getDefaultVersion() >= SvtSaveOptions::ODFVER_012)
1115 AddAttribute( nPrefix, eScript, aScript);
1116 if (!aCountry.isEmpty())
1117 AddAttribute( nPrefix, eCountry, aCountry);
1122 void SvXMLExport::AddAttributeList( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1124 if( xAttrList.is())
1125 mpAttrList->AppendAttributeList( xAttrList );
1128 void SvXMLExport::ClearAttrList()
1130 mpAttrList->Clear();
1133 #ifdef DBG_UTIL
1134 void SvXMLExport::CheckAttrList()
1136 SAL_WARN_IF( mpAttrList->getLength(), "xmloff.core", "XMLExport::CheckAttrList: list is not empty" );
1138 #endif
1140 void SvXMLExport::ImplExportMeta()
1142 CheckAttrList();
1144 _ExportMeta();
1147 void SvXMLExport::ImplExportSettings()
1149 CheckAttrList();
1151 ::std::list< SettingsGroup > aSettings;
1152 sal_Int32 nSettingsCount = 0;
1154 // view settings
1155 uno::Sequence< beans::PropertyValue > aViewSettings;
1156 GetViewSettingsAndViews( aViewSettings );
1157 aSettings.push_back( SettingsGroup( XML_VIEW_SETTINGS, aViewSettings ) );
1158 nSettingsCount += aViewSettings.getLength();
1160 // configuration settings
1161 uno::Sequence<beans::PropertyValue> aConfigSettings;
1162 GetConfigurationSettings( aConfigSettings );
1163 aSettings.push_back( SettingsGroup( XML_CONFIGURATION_SETTINGS, aConfigSettings ) );
1164 nSettingsCount += aConfigSettings.getLength();
1166 // any document specific settings
1167 nSettingsCount += GetDocumentSpecificSettings( aSettings );
1170 SvXMLElementExport aElem( *this,
1171 nSettingsCount != 0,
1172 XML_NAMESPACE_OFFICE, XML_SETTINGS,
1173 true, true );
1175 SettingsExportFacade aSettingsExportContext( *this );
1176 XMLSettingsExportHelper aSettingsExportHelper( aSettingsExportContext );
1178 for ( ::std::list< SettingsGroup >::const_iterator settings = aSettings.begin();
1179 settings != aSettings.end();
1180 ++settings
1183 if ( !settings->aSettings.getLength() )
1184 continue;
1186 OUString sSettingsName( GetXMLToken( settings->eGroupName ) );
1187 OUString sQName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOO, sSettingsName );
1188 aSettingsExportHelper.exportAllSettings( settings->aSettings, sQName );
1193 void SvXMLExport::ImplExportStyles( bool )
1195 CheckAttrList();
1198 // <style:styles>
1199 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_STYLES,
1200 true, true );
1202 _ExportStyles( false );
1205 // transfer style names (+ families) TO other components (if appropriate)
1206 if( ( !( mnExportFlags & SvXMLExportFlags::CONTENT ) ) && mxExportInfo.is() )
1208 static OUString sStyleNames( "StyleNames" );
1209 static OUString sStyleFamilies( "StyleFamilies" );
1210 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
1211 if ( xPropertySetInfo->hasPropertyByName( sStyleNames ) && xPropertySetInfo->hasPropertyByName( sStyleFamilies ) )
1213 Sequence<sal_Int32> aStyleFamilies;
1214 Sequence<OUString> aStyleNames;
1215 mxAutoStylePool->GetRegisteredNames( aStyleFamilies, aStyleNames );
1216 mxExportInfo->setPropertyValue( sStyleNames, makeAny( aStyleNames ) );
1217 mxExportInfo->setPropertyValue( sStyleFamilies,
1218 makeAny( aStyleFamilies ) );
1223 void SvXMLExport::ImplExportAutoStyles( bool )
1225 // transfer style names (+ families) FROM other components (if appropriate)
1226 OUString sStyleNames( "StyleNames" );
1227 OUString sStyleFamilies( "StyleFamilies" );
1228 if( ( !( mnExportFlags & SvXMLExportFlags::STYLES ) )
1229 && mxExportInfo.is()
1230 && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleNames )
1231 && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleFamilies ) )
1233 Sequence<sal_Int32> aStyleFamilies;
1234 mxExportInfo->getPropertyValue( sStyleFamilies ) >>= aStyleFamilies;
1235 Sequence<OUString> aStyleNames;
1236 mxExportInfo->getPropertyValue( sStyleNames ) >>= aStyleNames;
1237 mxAutoStylePool->RegisterNames( aStyleFamilies, aStyleNames );
1241 // <style:automatic-styles>
1242 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
1243 XML_AUTOMATIC_STYLES, true, true );
1245 _ExportAutoStyles();
1249 void SvXMLExport::ImplExportMasterStyles( bool )
1252 // <style:master-styles>
1253 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_MASTER_STYLES,
1254 true, true );
1256 _ExportMasterStyles();
1261 void SvXMLExport::ImplExportContent()
1263 CheckAttrList();
1265 CheckAttrList();
1268 SvXMLElementExport aElemrnt( *this, XML_NAMESPACE_OFFICE, XML_BODY,
1269 true, true );
1271 XMLTokenEnum eClass = meClass;
1272 if( XML_TEXT_GLOBAL == eClass )
1274 AddAttribute( XML_NAMESPACE_TEXT, XML_GLOBAL,
1275 GetXMLToken( XML_TRUE ) );
1276 eClass = XML_TEXT;
1278 if ( XML_GRAPHICS == eClass )
1279 eClass = XML_DRAWING;
1280 // <office:body ...>
1281 SetBodyAttributes();
1282 SvXMLElementExport aElem( *this, meClass != XML_TOKEN_INVALID,
1283 XML_NAMESPACE_OFFICE, eClass,
1284 true, true );
1286 _ExportContent();
1291 void SvXMLExport::SetBodyAttributes()
1295 static void
1296 lcl_AddGrddl(SvXMLExport & rExport, const SvXMLExportFlags /*nExportMode*/)
1298 // check version >= 1.2
1299 switch (rExport.getDefaultVersion()) {
1300 case SvtSaveOptions::ODFVER_011: // fall through
1301 case SvtSaveOptions::ODFVER_010: return;
1302 default: break;
1305 // #i115030#: disabled, the XSLT is not finished, and not available via HTTP
1306 #if 0
1307 if (SvXMLExportFlags::SETTINGS != nExportMode) // meta, content, styles
1309 rExport.AddAttribute( XML_NAMESPACE_GRDDL, XML_TRANSFORMATION,
1310 OUString("http://FIXME") );
1312 #endif
1315 void SvXMLExport::addChaffWhenEncryptedStorage()
1317 uno::Reference< embed::XEncryptionProtectedSource2 > xEncr(mpImpl->mxTargetStorage, uno::UNO_QUERY);
1319 if (xEncr.is() && xEncr->hasEncryptionData() && mxExtHandler.is())
1321 mxExtHandler->comment(OStringToOUString(comphelper::xml::makeXMLChaff(), RTL_TEXTENCODING_ASCII_US));
1325 sal_uInt32 SvXMLExport::exportDoc( enum ::xmloff::token::XMLTokenEnum eClass )
1327 bool bOwnGraphicResolver = false;
1328 bool bOwnEmbeddedResolver = false;
1330 if( !mxGraphicResolver.is() || !mxEmbeddedResolver.is() )
1332 Reference< XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
1333 if( xFactory.is() )
1337 if( !mxGraphicResolver.is() )
1339 mxGraphicResolver = Reference< XGraphicObjectResolver >::query(
1340 xFactory->createInstance(
1341 OUString( "com.sun.star.document.ExportGraphicObjectResolver")));
1342 bOwnGraphicResolver = mxGraphicResolver.is();
1345 if( !mxEmbeddedResolver.is() )
1347 mxEmbeddedResolver = Reference< XEmbeddedObjectResolver >::query(
1348 xFactory->createInstance(
1349 OUString( "com.sun.star.document.ExportEmbeddedObjectResolver")));
1350 bOwnEmbeddedResolver = mxEmbeddedResolver.is();
1353 catch(const com::sun::star::uno::Exception&)
1358 if( (getExportFlags() & SvXMLExportFlags::OASIS) == SvXMLExportFlags::NONE )
1362 ::comphelper::PropertyMapEntry const aInfoMap[] =
1364 { OUString("Class"), 0,
1365 ::cppu::UnoType<OUString>::get(),
1366 PropertyAttribute::MAYBEVOID, 0},
1367 { OUString(), 0, css::uno::Type(), 0, 0 }
1369 Reference< XPropertySet > xConvPropSet(
1370 ::comphelper::GenericPropertySet_CreateInstance(
1371 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
1373 Any aAny;
1374 aAny <<= GetXMLToken( eClass );
1375 xConvPropSet->setPropertyValue(
1376 OUString("Class"), aAny );
1378 Reference< XPropertySet > xPropSet =
1379 mxExportInfo.is()
1380 ? PropertySetMerger_CreateInstance( mxExportInfo,
1381 xConvPropSet )
1382 : xConvPropSet;
1384 Sequence<Any> aArgs( 3 );
1385 aArgs[0] <<= mxHandler;
1386 aArgs[1] <<= xPropSet;
1387 aArgs[2] <<= mxModel;
1389 // get filter component
1390 Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
1391 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.Oasis2OOoTransformer", aArgs, m_xContext),
1392 UNO_QUERY);
1393 SAL_WARN_IF(!xTmpDocHandler.is(), "xmloff.core", "can't instantiate OASIS transformer component" );
1394 if( xTmpDocHandler.is() )
1396 mxHandler = xTmpDocHandler;
1397 mxExtHandler = uno::Reference<xml::sax::XExtendedDocumentHandler>( mxHandler, UNO_QUERY );
1400 catch(const com::sun::star::uno::Exception&)
1405 mxHandler->startDocument();
1407 addChaffWhenEncryptedStorage();
1409 // <office:document ...>
1410 CheckAttrList();
1412 // namespace attributes
1413 // ( The namespace decls should be first attributes in the element;
1414 // some faulty XML parsers (JAXP1.1) have a problem with this,
1415 // also it's more elegant )
1416 sal_uInt16 nPos = mpNamespaceMap->GetFirstKey();
1417 while( USHRT_MAX != nPos )
1419 mpAttrList->AddAttribute( mpNamespaceMap->GetAttrNameByKey( nPos ),
1420 mpNamespaceMap->GetNameByKey( nPos ) );
1421 nPos = mpNamespaceMap->GetNextKey( nPos );
1424 // office:version = ...
1425 if( !mbExtended )
1427 const sal_Char* pVersion = 0;
1428 switch( getDefaultVersion() )
1430 case SvtSaveOptions::ODFVER_LATEST: pVersion = sXML_1_2; break;
1431 case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = sXML_1_2; break;
1432 case SvtSaveOptions::ODFVER_012: pVersion = sXML_1_2; break;
1433 case SvtSaveOptions::ODFVER_011: pVersion = sXML_1_1; break;
1434 case SvtSaveOptions::ODFVER_010: break;
1436 default:
1437 SAL_WARN("xmloff.core", "xmloff::SvXMLExport::exportDoc(), unexpected odf default version!");
1440 if( pVersion )
1441 AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
1442 OUString::createFromAscii(pVersion) );
1446 enum XMLTokenEnum eRootService = XML_TOKEN_INVALID;
1447 const SvXMLExportFlags nExportMode = mnExportFlags & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SETTINGS);
1449 lcl_AddGrddl(*this, nExportMode);
1451 if( SvXMLExportFlags::META == nExportMode )
1453 // export only meta
1454 eRootService = XML_DOCUMENT_META;
1456 else if ( SvXMLExportFlags::SETTINGS == nExportMode )
1458 // export only settings
1459 eRootService = XML_DOCUMENT_SETTINGS;
1461 else if( SvXMLExportFlags::STYLES == nExportMode )
1463 // export only styles
1464 eRootService = XML_DOCUMENT_STYLES;
1466 else if( SvXMLExportFlags::CONTENT == nExportMode )
1468 // export only content
1469 eRootService = XML_DOCUMENT_CONTENT;
1471 else
1473 // the god'ol one4all element
1474 eRootService = XML_DOCUMENT;
1475 // office:mimetype = ... (only for stream containing the content)
1476 if( eClass != XML_TOKEN_INVALID )
1478 OUString aTmp( "application/vnd.oasis.opendocument." );
1479 aTmp += GetXMLToken( eClass );
1480 AddAttribute( XML_NAMESPACE_OFFICE, XML_MIMETYPE, aTmp );
1484 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, eRootService, true, true );
1486 // meta information
1487 if( mnExportFlags & SvXMLExportFlags::META )
1488 ImplExportMeta();
1490 // settings
1491 if( mnExportFlags & SvXMLExportFlags::SETTINGS )
1492 ImplExportSettings();
1494 // scripts
1495 if( mnExportFlags & SvXMLExportFlags::SCRIPTS )
1496 _ExportScripts();
1498 // font declerations
1499 if( mnExportFlags & SvXMLExportFlags::FONTDECLS )
1500 _ExportFontDecls();
1502 // styles
1503 if( mnExportFlags & SvXMLExportFlags::STYLES )
1504 ImplExportStyles( false );
1506 // autostyles
1507 if( mnExportFlags & SvXMLExportFlags::AUTOSTYLES )
1508 ImplExportAutoStyles( false );
1510 // masterstyles
1511 if( mnExportFlags & SvXMLExportFlags::MASTERSTYLES )
1512 ImplExportMasterStyles( false );
1514 // contnt
1515 if( mnExportFlags & SvXMLExportFlags::CONTENT )
1516 ImplExportContent();
1519 mxHandler->endDocument();
1521 if( bOwnGraphicResolver )
1523 Reference< XComponent > xComp( mxGraphicResolver, UNO_QUERY );
1524 xComp->dispose();
1527 if( bOwnEmbeddedResolver )
1529 Reference< XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
1530 xComp->dispose();
1533 return 0;
1536 void SvXMLExport::ResetNamespaceMap()
1538 delete mpNamespaceMap; mpNamespaceMap = new SvXMLNamespaceMap;
1541 OUString SvXMLExport::GetSourceShellID() const
1543 return mpImpl->maSrcShellID;
1546 OUString SvXMLExport::GetDestinationShellID() const
1548 return mpImpl->maDestShellID;
1551 void SvXMLExport::_ExportMeta()
1553 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
1554 Reference< XDocumentPropertiesSupplier > xDocPropsSupplier(mxModel,
1555 UNO_QUERY);
1556 if (xDocPropsSupplier.is()) {
1557 Reference<XDocumentProperties> xDocProps(
1558 xDocPropsSupplier->getDocumentProperties());
1559 if (!xDocProps.is()) throw;
1560 // update generator here
1561 xDocProps->setGenerator(generator);
1562 SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, xDocProps);
1563 uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
1564 pMeta->Export();
1565 } else {
1566 // office:meta
1567 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_META,
1568 true, true );
1570 // BM: #i60323# export generator even if xInfoProp is empty (which is the
1571 // case for charts). The generator does not depend on xInfoProp
1572 SvXMLElementExport anElem( *this, XML_NAMESPACE_META, XML_GENERATOR,
1573 true, true );
1574 Characters(generator);
1579 void SvXMLExport::_ExportScripts()
1581 SvXMLElementExport aElement( *this, XML_NAMESPACE_OFFICE, XML_SCRIPTS, true, true );
1583 // export Basic macros (only for FlatXML)
1584 if ( mnExportFlags & SvXMLExportFlags::EMBEDDED )
1586 OUString aValue( GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) );
1587 aValue += ":Basic";
1588 AddAttribute( XML_NAMESPACE_SCRIPT, XML_LANGUAGE, aValue );
1590 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_SCRIPT, true, true );
1592 // initialize Basic
1593 if ( mxModel.is() )
1595 Reference< beans::XPropertySet > xPSet( mxModel, UNO_QUERY );
1596 if ( xPSet.is() )
1597 xPSet->getPropertyValue("BasicLibraries");
1600 Reference < XDocumentHandler > xHdl( new XMLBasicExportFilter( mxHandler ) );
1601 Reference< document::XXMLBasicExporter > xExporter = document::XMLOasisBasicExporter::createWithHandler( m_xContext, xHdl );
1603 Reference< XComponent > xComp( mxModel, UNO_QUERY );
1604 xExporter->setSourceDocument( xComp );
1605 Sequence< PropertyValue > aMediaDesc( 0 );
1606 xExporter->filter( aMediaDesc );
1609 // export document events
1610 Reference< document::XEventsSupplier > xEvents( GetModel(), UNO_QUERY );
1611 GetEventExport().Export( xEvents, true );
1614 void SvXMLExport::_ExportFontDecls()
1616 if( mxFontAutoStylePool.is() )
1617 mxFontAutoStylePool->exportXML();
1620 void SvXMLExport::_ExportStyles( bool )
1622 uno::Reference< lang::XMultiServiceFactory > xFact( GetModel(), uno::UNO_QUERY );
1623 if( xFact.is())
1625 // export (fill-)gradient-styles
1628 uno::Reference< container::XNameAccess > xGradient( xFact->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
1629 if( xGradient.is() )
1631 XMLGradientStyleExport aGradientStyle( *this );
1633 if( xGradient->hasElements() )
1635 uno::Sequence< OUString > aNamesSeq ( xGradient->getElementNames() );
1636 sal_Int32 nCount = aNamesSeq.getLength();
1637 for( sal_Int32 i=0; i<nCount; i++ )
1639 const OUString& rStrName = aNamesSeq[ i ];
1643 uno::Any aValue = xGradient->getByName( rStrName );
1645 aGradientStyle.exportXML( rStrName, aValue );
1647 catch(const container::NoSuchElementException&)
1654 catch(const lang::ServiceNotRegisteredException&)
1658 // export (fill-)hatch-styles
1661 uno::Reference< container::XNameAccess > xHatch( xFact->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
1662 if( xHatch.is() )
1664 XMLHatchStyleExport aHatchStyle( *this );
1666 if( xHatch->hasElements() )
1668 uno::Sequence< OUString > aNamesSeq ( xHatch->getElementNames() );
1669 sal_Int32 nCount = aNamesSeq.getLength();
1670 for( sal_Int32 i=0; i<nCount; i++ )
1672 const OUString& rStrName = aNamesSeq[ i ];
1676 uno::Any aValue = xHatch->getByName( rStrName );
1678 aHatchStyle.exportXML( rStrName, aValue );
1680 catch(const container::NoSuchElementException&)
1686 catch(const lang::ServiceNotRegisteredException&)
1690 // export (fill-)bitmap-styles
1693 uno::Reference< container::XNameAccess > xBitmap( xFact->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
1694 if( xBitmap.is() )
1696 XMLImageStyle aImageStyle;
1698 if( xBitmap->hasElements() )
1700 uno::Sequence< OUString > aNamesSeq ( xBitmap->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 = xBitmap->getByName( rStrName );
1710 aImageStyle.exportXML( rStrName, aValue, *this );
1712 catch(const container::NoSuchElementException&)
1719 catch(const lang::ServiceNotRegisteredException&)
1723 // export transparency-gradient -styles
1726 uno::Reference< container::XNameAccess > xTransGradient( xFact->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
1727 if( xTransGradient.is() )
1729 XMLTransGradientStyleExport aTransGradientstyle( *this );
1731 if( xTransGradient->hasElements() )
1733 uno::Sequence< OUString > aNamesSeq ( xTransGradient->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 = xTransGradient->getByName( rStrName );
1743 aTransGradientstyle.exportXML( rStrName, aValue );
1745 catch(const container::NoSuchElementException&)
1752 catch(const lang::ServiceNotRegisteredException&)
1756 // export marker-styles
1759 uno::Reference< container::XNameAccess > xMarker( xFact->createInstance("com.sun.star.drawing.MarkerTable"), uno::UNO_QUERY );
1760 if( xMarker.is() )
1762 XMLMarkerStyleExport aMarkerStyle( *this );
1764 if( xMarker->hasElements() )
1766 uno::Sequence< OUString > aNamesSeq ( xMarker->getElementNames() );
1767 sal_Int32 nCount = aNamesSeq.getLength();
1768 for( sal_Int32 i=0; i<nCount; i++ )
1770 const OUString& rStrName = aNamesSeq[ i ];
1774 uno::Any aValue = xMarker->getByName( rStrName );
1776 aMarkerStyle.exportXML( rStrName, aValue );
1778 catch(const container::NoSuchElementException&)
1785 catch(const lang::ServiceNotRegisteredException&)
1789 // export dash-styles
1792 uno::Reference< container::XNameAccess > xDashes( xFact->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
1793 if( xDashes.is() )
1795 XMLDashStyleExport aDashStyle( *this );
1797 if( xDashes->hasElements() )
1799 uno::Sequence< OUString > aNamesSeq ( xDashes->getElementNames() );
1800 sal_Int32 nCount = aNamesSeq.getLength();
1801 for( sal_Int32 i=0; i<nCount; i++ )
1803 const OUString& rStrName = aNamesSeq[ i ];
1807 uno::Any aValue = xDashes->getByName( rStrName );
1809 aDashStyle.exportXML( rStrName, aValue );
1811 catch(const container::NoSuchElementException&)
1818 catch(const lang::ServiceNotRegisteredException&)
1824 XMLTextParagraphExport* SvXMLExport::CreateTextParagraphExport()
1826 return new XMLTextParagraphExport( *this, *(GetAutoStylePool().get()) );
1829 XMLShapeExport* SvXMLExport::CreateShapeExport()
1831 return new XMLShapeExport(*this);
1834 SvXMLAutoStylePoolP* SvXMLExport::CreateAutoStylePool()
1836 return new SvXMLAutoStylePoolP(*this);
1839 XMLPageExport* SvXMLExport::CreatePageExport()
1841 return new XMLPageExport( *this );
1844 SchXMLExportHelper* SvXMLExport::CreateChartExport()
1846 return new SchXMLExportHelper(*this,*GetAutoStylePool().get());
1849 XMLFontAutoStylePool* SvXMLExport::CreateFontAutoStylePool()
1851 return new XMLFontAutoStylePool( *this );
1854 xmloff::OFormLayerXMLExport* SvXMLExport::CreateFormExport()
1856 return new xmloff::OFormLayerXMLExport(*this);
1859 void SvXMLExport::GetViewSettingsAndViews(uno::Sequence<beans::PropertyValue>& rProps)
1861 GetViewSettings(rProps);
1862 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetModel(), uno::UNO_QUERY);
1863 if(xViewDataSupplier.is())
1865 uno::Reference<container::XIndexAccess> xIndexAccess;
1866 xViewDataSupplier->setViewData( xIndexAccess ); // make sure we get a newly created sequence
1867 xIndexAccess = xViewDataSupplier->getViewData();
1868 bool bAdd = false;
1869 uno::Any aAny;
1870 if(xIndexAccess.is() && xIndexAccess->hasElements() )
1872 sal_Int32 nCount = xIndexAccess->getCount();
1873 for (sal_Int32 i = 0; i < nCount; i++)
1875 aAny = xIndexAccess->getByIndex(i);
1876 uno::Sequence<beans::PropertyValue> aProps;
1877 if( aAny >>= aProps )
1879 if( aProps.getLength() > 0 )
1881 bAdd = true;
1882 break;
1888 if( bAdd )
1890 sal_Int32 nOldLength(rProps.getLength());
1891 rProps.realloc(nOldLength + 1);
1892 beans::PropertyValue aProp;
1893 aProp.Name = "Views";
1894 aProp.Value <<= xIndexAccess;
1895 rProps[nOldLength] = aProp;
1900 void SvXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>&)
1904 void SvXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>&)
1908 sal_Int32 SvXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup >& _out_rSettings )
1910 (void)_out_rSettings;
1911 return 0;
1914 void SvXMLExport::addDataStyle(const sal_Int32 nNumberFormat, bool /*bTimeFormat*/ )
1916 if(mpNumExport)
1917 mpNumExport->SetUsed(nNumberFormat);
1920 void SvXMLExport::exportDataStyles()
1922 if(mpNumExport)
1923 mpNumExport->Export(false);
1926 void SvXMLExport::exportAutoDataStyles()
1928 if(mpNumExport)
1929 mpNumExport->Export(true);
1931 if (mxFormExport.is())
1932 mxFormExport->exportAutoControlNumberStyles();
1935 OUString SvXMLExport::getDataStyleName(const sal_Int32 nNumberFormat, bool /*bTimeFormat*/ ) const
1937 OUString sTemp;
1938 if(mpNumExport)
1939 sTemp = mpNumExport->GetStyleName(nNumberFormat);
1940 return sTemp;
1943 void SvXMLExport::exportAnnotationMeta(const uno::Reference<drawing::XShape>&)
1947 sal_Int32 SvXMLExport::dataStyleForceSystemLanguage(sal_Int32 nFormat) const
1949 return ( mpNumExport != NULL )
1950 ? mpNumExport->ForceSystemLanguage( nFormat ) : nFormat;
1953 OUString SvXMLExport::AddEmbeddedGraphicObject( const OUString& rGraphicObjectURL )
1955 OUString sRet( rGraphicObjectURL );
1956 if( rGraphicObjectURL.startsWith( msGraphicObjectProtocol ) &&
1957 mxGraphicResolver.is() )
1959 if( !(getExportFlags() & SvXMLExportFlags::EMBEDDED) )
1960 sRet = mxGraphicResolver->resolveGraphicObjectURL( rGraphicObjectURL );
1961 else
1962 sRet.clear();
1964 else
1965 sRet = GetRelativeReference( sRet );
1967 return sRet;
1970 bool SvXMLExport::AddEmbeddedGraphicObjectAsBase64( const OUString& rGraphicObjectURL )
1972 bool bRet = false;
1974 if( (getExportFlags() & SvXMLExportFlags::EMBEDDED) &&
1975 rGraphicObjectURL.startsWith( msGraphicObjectProtocol ) &&
1976 mxGraphicResolver.is() )
1978 Reference< XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1980 if( xStmResolver.is() )
1982 Reference< XInputStream > xIn( xStmResolver->getInputStream( rGraphicObjectURL ) );
1984 if( xIn.is() )
1986 XMLBase64Export aBase64Exp( *this );
1987 bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
1992 return bRet;
1995 OUString SvXMLExport::AddEmbeddedObject( const OUString& rEmbeddedObjectURL )
1997 OUString sRet;
1998 if( (rEmbeddedObjectURL.startsWith( msEmbeddedObjectProtocol ) ||
1999 rEmbeddedObjectURL.startsWith( msGraphicObjectProtocol ) ) &&
2000 mxEmbeddedResolver.is() )
2002 sRet =
2003 mxEmbeddedResolver->resolveEmbeddedObjectURL( rEmbeddedObjectURL );
2005 else
2006 sRet = GetRelativeReference( rEmbeddedObjectURL );
2008 return sRet;
2011 bool SvXMLExport::AddEmbeddedObjectAsBase64( const OUString& rEmbeddedObjectURL )
2013 bool bRet = false;
2014 if( (rEmbeddedObjectURL.startsWith( msEmbeddedObjectProtocol ) ||
2015 rEmbeddedObjectURL.startsWith( msGraphicObjectProtocol ) ) &&
2016 mxEmbeddedResolver.is() )
2018 Reference < XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
2019 if( xNA.is() )
2021 Any aAny = xNA->getByName( rEmbeddedObjectURL );
2022 Reference < XInputStream > xIn;
2023 aAny >>= xIn;
2024 if( xIn.is() )
2026 XMLBase64Export aBase64Exp( *this );
2027 bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
2032 return bRet;
2035 OUString SvXMLExport::EncodeStyleName(
2036 const OUString& rName,
2037 bool *pEncoded ) const
2039 return GetMM100UnitConverter().encodeStyleName( rName, pEncoded );
2042 ProgressBarHelper* SvXMLExport::GetProgressBarHelper()
2044 if (!mpProgressBarHelper)
2046 mpProgressBarHelper = new ProgressBarHelper(mxStatusIndicator, true);
2048 if (mxExportInfo.is())
2050 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
2051 if (xPropertySetInfo.is())
2053 OUString sProgressRange(XML_PROGRESSRANGE);
2054 OUString sProgressMax(XML_PROGRESSMAX);
2055 OUString sProgressCurrent(XML_PROGRESSCURRENT);
2056 OUString sRepeat(XML_PROGRESSREPEAT);
2057 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
2058 xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
2059 xPropertySetInfo->hasPropertyByName(sProgressRange))
2061 uno::Any aAny;
2062 sal_Int32 nProgressMax(0);
2063 sal_Int32 nProgressCurrent(0);
2064 sal_Int32 nProgressRange(0);
2065 aAny = mxExportInfo->getPropertyValue(sProgressRange);
2066 if (aAny >>= nProgressRange)
2067 mpProgressBarHelper->SetRange(nProgressRange);
2068 aAny = mxExportInfo->getPropertyValue(sProgressMax);
2069 if (aAny >>= nProgressMax)
2070 mpProgressBarHelper->SetReference(nProgressMax);
2071 aAny = mxExportInfo->getPropertyValue(sProgressCurrent);
2072 if (aAny >>= nProgressCurrent)
2073 mpProgressBarHelper->SetValue(nProgressCurrent);
2075 if (xPropertySetInfo->hasPropertyByName(sRepeat))
2077 uno::Any aAny = mxExportInfo->getPropertyValue(sRepeat);
2078 if (aAny.getValueType() == cppu::UnoType<bool>::get())
2079 mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
2080 else {
2081 SAL_WARN("xmloff.core", "why is it no boolean?" );
2087 return mpProgressBarHelper;
2090 XMLEventExport& SvXMLExport::GetEventExport()
2092 if( NULL == mpEventExport)
2094 // create EventExport on demand
2095 mpEventExport = new XMLEventExport(*this, NULL);
2097 // and register standard handlers + names
2098 OUString sStarBasic("StarBasic");
2099 mpEventExport->AddHandler(sStarBasic, new XMLStarBasicExportHandler());
2100 OUString sScript("Script");
2101 mpEventExport->AddHandler(sScript, new XMLScriptExportHandler());
2102 mpEventExport->AddTranslationTable(aStandardEventTable);
2105 return *mpEventExport;
2108 XMLImageMapExport& SvXMLExport::GetImageMapExport()
2110 // image map export, create on-demand
2111 if( NULL == mpImageMapExport )
2113 mpImageMapExport = new XMLImageMapExport(*this);
2116 return *mpImageMapExport;
2119 namespace
2121 class theSvXMLExportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvXMLExportUnoTunnelId> {};
2124 // XUnoTunnel & co
2125 const uno::Sequence< sal_Int8 > & SvXMLExport::getUnoTunnelId() throw()
2127 return theSvXMLExportUnoTunnelId::get().getSeq();
2130 SvXMLExport* SvXMLExport::getImplementation( uno::Reference< uno::XInterface > xInt ) throw()
2132 uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
2133 if( xUT.is() )
2135 return
2136 reinterpret_cast<SvXMLExport*>(
2137 sal::static_int_cast<sal_IntPtr>(
2138 xUT->getSomething( SvXMLExport::getUnoTunnelId())));
2140 else
2141 return NULL;
2144 // XUnoTunnel
2145 sal_Int64 SAL_CALL SvXMLExport::getSomething( const uno::Sequence< sal_Int8 >& rId )
2146 throw( uno::RuntimeException, std::exception )
2148 if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
2149 rId.getConstArray(), 16 ) )
2151 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2153 return 0;
2156 bool SvXMLExport::ExportEmbeddedOwnObject( Reference< XComponent >& rComp )
2158 OUString sFilterService;
2160 Reference < lang::XServiceInfo > xServiceInfo( rComp, UNO_QUERY );
2161 if( xServiceInfo.is() )
2163 const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
2164 while( pEntry->sModelService )
2166 OUString sModelService( pEntry->sModelService,
2167 pEntry->nModelServiceLen,
2168 RTL_TEXTENCODING_ASCII_US );
2169 if( xServiceInfo->supportsService( sModelService ) )
2171 sFilterService = OUString( pEntry->sFilterService,
2172 pEntry->nFilterServiceLen,
2173 RTL_TEXTENCODING_ASCII_US );
2174 break;
2176 pEntry++;
2180 SAL_WARN_IF( !sFilterService.getLength(), "xmloff.core", "no export filter for own object" );
2182 if( sFilterService.isEmpty() )
2183 return false;
2185 Reference < XDocumentHandler > xHdl =
2186 new XMLEmbeddedObjectExportFilter( mxHandler );
2188 Sequence < Any > aArgs( 1 );
2189 aArgs[0] <<= xHdl;
2191 Reference< document::XExporter > xExporter(
2192 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(sFilterService, aArgs, m_xContext),
2193 UNO_QUERY);
2194 SAL_WARN_IF( !xExporter.is(), "xmloff.core", "can't instantiate export filter component for own object" );
2195 if( !xExporter.is() )
2196 return false;
2198 xExporter->setSourceDocument( rComp );
2200 Reference<XFilter> xFilter( xExporter, UNO_QUERY );
2202 Sequence < PropertyValue > aMediaDesc( 0 );
2203 return xFilter->filter( aMediaDesc );
2206 OUString SvXMLExport::GetRelativeReference(const OUString& rValue)
2208 OUString sValue( rValue );
2209 // #i65474# handling of fragment URLs ("#....") is undefined
2210 // they are stored 'as is'
2211 uno::Reference< uri::XUriReference > xUriRef;
2212 if(!sValue.isEmpty() && sValue[0] != '#')
2216 xUriRef = mpImpl->mxUriReferenceFactory->parse( rValue );
2217 if( xUriRef.is() && !xUriRef->isAbsolute() )
2219 //#i61943# relative URLs need special handling
2220 INetURLObject aTemp( mpImpl->msPackageURI );
2221 bool bWasAbsolute = false;
2222 sValue = aTemp.smartRel2Abs(sValue, bWasAbsolute ).GetMainURL(INetURLObject::DECODE_TO_IURI);
2225 catch(const uno::Exception&)
2229 if( xUriRef.is() )//no conversion for empty values or for fragments
2231 //conversion for matching schemes only
2232 if( xUriRef->getScheme() == mpImpl->msPackageURIScheme )
2234 sValue = INetURLObject::GetRelURL( msOrigFileName, sValue,
2235 INetURLObject::WAS_ENCODED, INetURLObject::DECODE_TO_IURI, RTL_TEXTENCODING_UTF8, INetURLObject::FSYS_DETECT);
2238 return sValue;
2241 void SvXMLExport::StartElement(sal_uInt16 nPrefix,
2242 enum ::xmloff::token::XMLTokenEnum eName,
2243 bool bIgnWSOutside )
2245 StartElement(_GetNamespaceMap().GetQNameByKey( nPrefix,
2246 GetXMLToken(eName) ), bIgnWSOutside);
2249 void SvXMLExport::StartElement(const OUString& rName,
2250 bool bIgnWSOutside )
2252 if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2256 if( bIgnWSOutside && ((mnExportFlags & SvXMLExportFlags::PRETTY) == SvXMLExportFlags::PRETTY))
2257 mxHandler->ignorableWhitespace( msWS );
2258 mxHandler->startElement( rName, GetXAttrList() );
2260 catch (const SAXInvalidCharacterException& e)
2262 Sequence<OUString> aPars(1);
2263 aPars[0] = rName;
2264 SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, NULL );
2266 catch (const SAXException& e)
2268 Sequence<OUString> aPars(1);
2269 aPars[0] = rName;
2270 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2271 aPars, e.Message, NULL );
2274 ClearAttrList();
2275 ++mpImpl->mDepth; // increment nesting depth counter
2278 void SvXMLExport::Characters(const OUString& rChars)
2280 if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2284 mxHandler->characters(rChars);
2286 catch (const SAXInvalidCharacterException& e)
2288 Sequence<OUString> aPars(1);
2289 aPars[0] = rChars;
2290 SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, NULL );
2292 catch (const SAXException& e)
2294 Sequence<OUString> aPars(1);
2295 aPars[0] = rChars;
2296 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2297 aPars, e.Message, NULL );
2302 void SvXMLExport::EndElement(sal_uInt16 nPrefix,
2303 enum ::xmloff::token::XMLTokenEnum eName,
2304 bool bIgnWSInside )
2306 EndElement(_GetNamespaceMap().GetQNameByKey( nPrefix, GetXMLToken(eName) ),
2307 bIgnWSInside);
2310 void SvXMLExport::EndElement(const OUString& rName,
2311 bool bIgnWSInside )
2313 // decrement nesting depth counter & (maybe) restore namespace map
2314 --mpImpl->mDepth;
2315 if (!mpImpl->mNamespaceMaps.empty() &&
2316 (mpImpl->mNamespaceMaps.top().second == mpImpl->mDepth))
2318 delete mpNamespaceMap;
2319 mpNamespaceMap = mpImpl->mNamespaceMaps.top().first;
2320 mpImpl->mNamespaceMaps.pop();
2322 SAL_WARN_IF(!mpImpl->mNamespaceMaps.empty() &&
2323 (mpImpl->mNamespaceMaps.top().second >= mpImpl->mDepth), "xmloff.core", "SvXMLExport: NamespaceMaps corrupted");
2325 if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2329 if( bIgnWSInside && ((mnExportFlags & SvXMLExportFlags::PRETTY) == SvXMLExportFlags::PRETTY))
2330 mxHandler->ignorableWhitespace( msWS );
2331 mxHandler->endElement( rName );
2333 catch (const SAXException& e)
2335 Sequence<OUString> aPars(1);
2336 aPars[0] = rName;
2337 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2338 aPars, e.Message, NULL );
2343 void SvXMLExport::IgnorableWhitespace()
2345 if ((mnExportFlags & SvXMLExportFlags::PRETTY) != SvXMLExportFlags::PRETTY)
2346 return;
2348 if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2352 mxHandler->ignorableWhitespace( msWS );
2354 catch (const SAXException& e)
2356 Sequence<OUString> aPars(0);
2357 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2358 aPars, e.Message, NULL );
2363 void SvXMLExport::SetError(
2364 sal_Int32 nId,
2365 const Sequence<OUString>& rMsgParams,
2366 const OUString& rExceptionMessage,
2367 const Reference<XLocator>& rLocator )
2369 // allow multi-threaded access to the cancel() method
2370 static osl::Mutex aMutex;
2371 osl::MutexGuard aGuard(aMutex);
2373 // maintain error flags
2374 if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
2375 mnErrorFlags |= SvXMLErrorFlags::ERROR_OCCURRED;
2376 if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
2377 mnErrorFlags |= SvXMLErrorFlags::WARNING_OCCURRED;
2378 if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
2379 mnErrorFlags |= SvXMLErrorFlags::DO_NOTHING;
2381 // create error lsit on demand
2382 if ( mpXMLErrors == NULL )
2383 mpXMLErrors = new XMLErrors();
2385 // save error information
2386 mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage, rLocator );
2389 void SvXMLExport::SetError(
2390 sal_Int32 nId,
2391 const Sequence<OUString>& rMsgParams)
2393 OUString sEmpty;
2394 SetError( nId, rMsgParams, sEmpty, NULL );
2397 void SvXMLExport::DisposingModel()
2399 mxModel.clear();
2400 // Shapes in Writer cannot be named via context menu (#i51726#)
2401 meModelType = SvtModuleOptions::EFactory::UNKNOWN_FACTORY;
2402 mxEventListener.clear();
2406 ::comphelper::UnoInterfaceToUniqueIdentifierMapper& SvXMLExport::getInterfaceToIdentifierMapper()
2408 return mpImpl->maInterfaceToIdentifierMapper;
2411 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
2412 bool SvXMLExport::writeOutlineStyleAsNormalListStyle() const
2414 return mpImpl->mbOutlineStyleAsNormalListStyle;
2417 uno::Reference< embed::XStorage > SvXMLExport::GetTargetStorage()
2419 return mpImpl->mxTargetStorage;
2422 /// returns the currently configured default version for ODF export
2423 SvtSaveOptions::ODFDefaultVersion SvXMLExport::getDefaultVersion() const
2425 if( mpImpl )
2426 return mpImpl->maSaveOptions.GetODFDefaultVersion();
2428 // fatal error, use current version as default
2429 return SvtSaveOptions::ODFVER_012;
2432 SvtSaveOptions::ODFSaneDefaultVersion SvXMLExport::getSaneDefaultVersion() const
2434 if( mpImpl )
2435 return mpImpl->maSaveOptions.GetODFSaneDefaultVersion();
2437 // fatal error, use current version as default
2438 return SvtSaveOptions::ODFSVER_012;
2441 OUString SvXMLExport::GetStreamName() const
2443 return mpImpl->mStreamName;
2446 void
2447 SvXMLExport::AddAttributeIdLegacy(
2448 sal_uInt16 const nLegacyPrefix, OUString const& rValue)
2450 switch (getDefaultVersion()) {
2451 case SvtSaveOptions::ODFVER_011: // fall through
2452 case SvtSaveOptions::ODFVER_010: break;
2453 default: // ODF 1.2: xml:id
2454 AddAttribute(XML_NAMESPACE_XML, XML_ID, rValue);
2456 // in ODF 1.1 this was form:id, anim:id, draw:id, or text:id
2457 // backward compatibility: in ODF 1.2 write _both_ id attrs
2458 AddAttribute(nLegacyPrefix, XML_ID, rValue);
2459 // FIXME: this function simply assumes that rValue is unique
2462 void
2463 SvXMLExport::AddAttributeXmlId(uno::Reference<uno::XInterface> const & i_xIfc)
2465 // check version >= 1.2
2466 switch (getDefaultVersion()) {
2467 case SvtSaveOptions::ODFVER_011: // fall through
2468 case SvtSaveOptions::ODFVER_010: return;
2469 default: break;
2471 const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
2472 uno::UNO_QUERY);
2473 //FIXME not yet...
2474 if ( xMeta.is() )
2476 const beans::StringPair mdref( xMeta->getMetadataReference() );
2477 if ( !mdref.Second.isEmpty() )
2479 const OUString streamName( GetStreamName() );
2480 if ( !streamName.isEmpty() )
2482 if ( streamName.equals(mdref.First) )
2484 AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2486 else
2488 SAL_WARN("xmloff.core","SvXMLExport::AddAttributeXmlId: invalid stream name");
2491 else
2493 // FIXME: this is ugly
2494 // there is no stream name (e.g. XSLT, flat-xml format)!
2495 // but how do we ensure uniqueness in this case?
2496 // a) just omit styles.xml ids -- they are unlikely anyway...
2497 // b) somehow find out whether we are currently exporting styles
2498 // or content, and prefix "s" or "c" => unique
2499 if ( mdref.First == "content.xml" )
2501 AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2503 else
2505 SAL_INFO("xmloff.core", "SvXMLExport::AddAttributeXmlId: no stream name given: dropping styles.xml xml:id");
2512 void
2513 SvXMLExport::AddAttributesRDFa(
2514 uno::Reference<text::XTextContent> const & i_xTextContent)
2516 // check version >= 1.2
2517 switch (getDefaultVersion()) {
2518 case SvtSaveOptions::ODFVER_011: // fall through
2519 case SvtSaveOptions::ODFVER_010: return;
2520 default: break;
2523 const uno::Reference<rdf::XMetadatable> xMeta(
2524 i_xTextContent, uno::UNO_QUERY);
2525 if (!xMeta.is() || xMeta->getMetadataReference().Second.isEmpty())
2527 return; // no xml:id => no RDFa
2530 if (!mpImpl->mpRDFaHelper.get())
2532 mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaExportHelper(*this) );
2534 mpImpl->mpRDFaHelper->AddRDFa(xMeta);
2537 bool SvXMLExport::exportTextNumberElement() const
2539 return mpImpl->mbExportTextNumberElement;
2542 bool SvXMLExport::SetNullDateOnUnitConverter()
2544 // if the null date has already been set, don't set it again (performance)
2545 if (!mpImpl->mbNullDateInitialized)
2546 mpImpl->mbNullDateInitialized = GetMM100UnitConverter().setNullDate(GetModel());
2548 return mpImpl->mbNullDateInitialized;
2553 void SvXMLElementExport::StartElement(
2554 const sal_uInt16 nPrefixKey,
2555 const OUString& rLName,
2556 const bool bIgnoreWhitespaceOutside )
2558 maElementName = mrExport.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
2559 mrExport.StartElement(maElementName, bIgnoreWhitespaceOutside);
2562 SvXMLElementExport::SvXMLElementExport(
2563 SvXMLExport& rExp,
2564 sal_uInt16 nPrefixKey,
2565 const sal_Char *pLName,
2566 bool bIWSOutside,
2567 bool bIWSInside )
2568 : mrExport( rExp )
2569 , maElementName()
2570 , mbIgnoreWhitespaceInside( bIWSInside )
2571 , mbDoSomething( true )
2573 const OUString sLName( OUString::createFromAscii( pLName ) );
2574 StartElement( nPrefixKey, sLName, bIWSOutside );
2577 SvXMLElementExport::SvXMLElementExport(
2578 SvXMLExport& rExp,
2579 sal_uInt16 nPrefixKey,
2580 const OUString& rLName,
2581 bool bIWSOutside,
2582 bool bIWSInside )
2583 : mrExport( rExp )
2584 , maElementName()
2585 , mbIgnoreWhitespaceInside( bIWSInside )
2586 , mbDoSomething( true )
2588 StartElement( nPrefixKey, rLName, bIWSOutside );
2591 SvXMLElementExport::SvXMLElementExport(
2592 SvXMLExport& rExp,
2593 sal_uInt16 nPrefixKey,
2594 enum XMLTokenEnum eLName,
2595 bool bIWSOutside,
2596 bool bIWSInside )
2597 : mrExport( rExp )
2598 , maElementName()
2599 , mbIgnoreWhitespaceInside( bIWSInside )
2600 , mbDoSomething( true )
2602 StartElement( nPrefixKey, GetXMLToken(eLName), bIWSOutside );
2605 SvXMLElementExport::SvXMLElementExport(
2606 SvXMLExport& rExp,
2607 bool bDoSth,
2608 sal_uInt16 nPrefixKey,
2609 enum XMLTokenEnum eLName,
2610 bool bIWSOutside,
2611 bool bIWSInside )
2612 : mrExport( rExp )
2613 , maElementName()
2614 , mbIgnoreWhitespaceInside( bIWSInside )
2615 , mbDoSomething( bDoSth )
2617 if ( mbDoSomething )
2618 StartElement( nPrefixKey, GetXMLToken( eLName ), bIWSOutside );
2621 SvXMLElementExport::SvXMLElementExport(
2622 SvXMLExport& rExp,
2623 const OUString& rQName,
2624 bool bIWSOutside,
2625 bool bIWSInside )
2626 : mrExport( rExp )
2627 , maElementName()
2628 , mbIgnoreWhitespaceInside( bIWSInside )
2629 , mbDoSomething( true )
2631 maElementName = rQName;
2632 rExp.StartElement( rQName, bIWSOutside );
2635 SvXMLElementExport::~SvXMLElementExport()
2637 if ( mbDoSomething )
2639 mrExport.EndElement( maElementName, mbIgnoreWhitespaceInside );
2643 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */