merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / core / xmlexp.cxx
blob9a47637abf051a859cf70af1e92859fb7742002a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlexp.cxx,v $
10 * $Revision: 1.143 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #ifdef PRECOMPILED
35 #include "filt_pch.hxx"
36 #endif
37 #include "unointerfacetouniqueidentifiermapper.hxx"
38 #include <osl/mutex.hxx>
39 #include <rtl/uuid.h>
40 #include <tools/debug.hxx>
41 #include <tools/urlobj.hxx>
42 #include <comphelper/genericpropertyset.hxx>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/io/XInputStream.hpp>
45 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
46 #include <com/sun/star/xml/sax/SAXInvalidCharacterException.hpp>
47 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
48 #include <com/sun/star/uri/UriReferenceFactory.hpp>
49 #include <comphelper/processfactory.hxx>
50 #include <comphelper/configurationhelper.hxx>
51 #include <xmloff/attrlist.hxx>
52 #include <xmloff/nmspmap.hxx>
53 #include <xmloff/xmluconv.hxx>
54 #include "xmlnmspe.hxx"
55 #include <xmloff/xmltoken.hxx>
56 #include <xmloff/xmlexp.hxx>
57 #include <xmloff/xmlnumfe.hxx>
58 #include <xmloff/xmlmetae.hxx>
59 #include <xmloff/families.hxx>
60 #include <xmloff/XMLEventExport.hxx>
61 #include "XMLStarBasicExportHandler.hxx"
62 #include "XMLScriptExportHandler.hxx"
63 #include <xmloff/SettingsExportHelper.hxx>
64 #include <com/sun/star/container/XNameAccess.hpp>
65 #include <com/sun/star/container/XIndexContainer.hpp>
66 #include <com/sun/star/document/XEventsSupplier.hpp>
67 #include <com/sun/star/document/XViewDataSupplier.hpp>
68 #include <GradientStyle.hxx>
69 #include <HatchStyle.hxx>
70 #include <ImageStyle.hxx>
71 #include <TransGradientStyle.hxx>
72 #include <MarkerStyle.hxx>
73 #include <DashStyle.hxx>
74 #include <xmloff/XMLFontAutoStylePool.hxx>
75 #include "XMLImageMapExport.hxx"
76 #include "XMLBase64Export.hxx"
77 #include "xmlerror.hxx"
78 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
79 #include <com/sun/star/beans/PropertyAttribute.hpp>
80 #include "XMLFilterServiceNames.h"
81 #include "XMLEmbeddedObjectExportFilter.hxx"
82 #include "XMLBasicExportFilter.hxx"
83 #include <vos/mutex.hxx>
84 #include <rtl/logfile.hxx>
85 #include <cppuhelper/implbase1.hxx>
86 #include <comphelper/extract.hxx>
87 #include "PropertySetMerger.hxx"
89 #include "svtools/urihelper.hxx"
90 #include "xformsexport.hxx"
92 #include <unotools/docinfohelper.hxx>
93 #include <unotools/bootstrap.hxx>
94 #include <unotools/configmgr.hxx>
95 #include <tools/inetdef.hxx>
96 #include <com/sun/star/document/XDocumentProperties.hpp>
97 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
99 #include <com/sun/star/rdf/XMetadatable.hpp>
100 #include "RDFaExportHelper.hxx"
103 using ::rtl::OUString;
105 using namespace ::osl;
106 using namespace ::com::sun::star;
107 using namespace ::com::sun::star::uno;
108 using namespace ::com::sun::star::frame;
109 using namespace ::com::sun::star::container;
110 using namespace ::com::sun::star::lang;
111 using namespace ::com::sun::star::document;
112 using namespace ::com::sun::star::beans;
113 using namespace ::com::sun::star::xml::sax;
114 using namespace ::com::sun::star::io;
115 using namespace ::xmloff::token;
117 sal_Char __READONLY_DATA sXML_1_1[] = "1.1";
118 sal_Char __READONLY_DATA sXML_1_2[] = "1.2";
120 const sal_Char *sOpenOfficeOrgProject ="OpenOffice.org_project";
122 const sal_Char s_grddl_xsl[] =
123 "http://docs.oasis-open.org/office/1.2/xslt/odf2rdf.xsl";
125 #define LOGFILE_AUTHOR "mb93740"
127 #define XML_MODEL_SERVICE_WRITER "com.sun.star.text.TextDocument"
128 #define XML_MODEL_SERVICE_CALC "com.sun.star.sheet.SpreadsheetDocument"
129 #define XML_MODEL_SERVICE_DRAW "com.sun.star.drawing.DrawingDocument"
130 #define XML_MODEL_SERVICE_IMPRESS "com.sun.star.presentation.PresentationDocument"
131 #define XML_MODEL_SERVICE_MATH "com.sun.star.formula.FormulaProperties"
132 #define XML_MODEL_SERVICE_CHART "com.sun.star.chart.ChartDocument"
134 #define XML_USEPRETTYPRINTING "UsePrettyPrinting"
135 #define XML_GENEROUSLISTLEVELS "GenerousListLevels"
137 #define C2U(cChar) OUString( RTL_CONSTASCII_USTRINGPARAM(cChar) )
139 struct XMLServiceMapEntry_Impl
141 const sal_Char *sModelService;
142 sal_Int32 nModelServiceLen;
143 const sal_Char *sFilterService;
144 sal_Int32 nFilterServiceLen;
147 #define SERVICE_MAP_ENTRY( app ) \
148 { XML_MODEL_SERVICE_##app, sizeof(XML_MODEL_SERVICE_##app)-1, \
149 XML_EXPORT_FILTER_##app, sizeof(XML_EXPORT_FILTER_##app)-1 }
151 const XMLServiceMapEntry_Impl aServiceMap[] =
153 SERVICE_MAP_ENTRY( WRITER ),
154 SERVICE_MAP_ENTRY( CALC ),
155 SERVICE_MAP_ENTRY( IMPRESS ),// Impress supports DrawingDocument, too, so
156 SERVICE_MAP_ENTRY( DRAW ), // it must appear before Draw
157 SERVICE_MAP_ENTRY( MATH ),
158 SERVICE_MAP_ENTRY( CHART ),
159 { 0, 0, 0, 0 }
162 //==============================================================================
164 class SvXMLExportEventListener : public cppu::WeakImplHelper1<
165 com::sun::star::lang::XEventListener >
167 private:
168 SvXMLExport* pExport;
170 public:
171 SvXMLExportEventListener(SvXMLExport* pExport);
172 virtual ~SvXMLExportEventListener();
174 // XEventListener
175 virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException);
178 SvXMLExportEventListener::SvXMLExportEventListener(SvXMLExport* pTempExport)
179 : pExport(pTempExport)
183 SvXMLExportEventListener::~SvXMLExportEventListener()
187 // XEventListener
188 void SAL_CALL SvXMLExportEventListener::disposing( const lang::EventObject& )
189 throw(uno::RuntimeException)
191 if (pExport)
193 pExport->DisposingModel();
194 pExport = NULL;
198 //==============================================================================
200 class SvXMLExport_Impl
202 public:
203 SvXMLExport_Impl();
205 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
206 uno::Reference< uri::XUriReferenceFactory > mxUriReferenceFactory;
207 rtl::OUString msPackageURI;
208 rtl::OUString msPackageURIScheme;
209 // --> OD 2006-09-27 #i69627#
210 sal_Bool mbOutlineStyleAsNormalListStyle;
211 // <--
212 // --> PB 2007-07-06 #i146851#
213 sal_Bool mbSaveBackwardCompatibleODF;
214 // <--
216 uno::Reference< embed::XStorage > mxTargetStorage;
218 SvtSaveOptions maSaveOptions;
220 /// relative path of stream in package, e.g. "someobject/content.xml"
221 ::rtl::OUString mStreamPath;
223 const uno::Reference< uno::XComponentContext > mxComponentContext;
225 /// name of stream in package, e.g., "content.xml"
226 ::rtl::OUString mStreamName;
228 /// stack of backed up namespace maps
229 /// long: depth at which namespace map has been backed up into the stack
230 ::std::stack< ::std::pair< SvXMLNamespaceMap *, long > > mNamespaceMaps;
231 /// counts depth (number of open elements/start tags)
232 long mDepth;
234 ::std::auto_ptr< ::xmloff::RDFaExportHelper> mpRDFaHelper;
236 // --> OD 2008-11-26 #158694#
237 sal_Bool mbExportTextNumberElement;
238 // <--
239 sal_Bool mbNullDateInitialized;
241 void SetSchemeOf( const ::rtl::OUString& rOrigFileName )
243 sal_Int32 nSep = rOrigFileName.indexOf(':');
244 if( nSep != -1 )
245 msPackageURIScheme = rOrigFileName.copy( 0, nSep );
249 SvXMLExport_Impl::SvXMLExport_Impl()
250 // --> OD 2006-09-27 #i69627#
251 : mbOutlineStyleAsNormalListStyle( false )
252 // <--
253 // --> PB 2007-07-06 #i146851#
254 ,mbSaveBackwardCompatibleODF( sal_True )
255 // <--
256 ,mxComponentContext( ::comphelper::getProcessComponentContext() )
257 ,mStreamName()
258 ,mNamespaceMaps()
259 ,mDepth(0)
260 ,mpRDFaHelper() // lazy
261 // --> OD 2008-11-26 #158694#
262 ,mbExportTextNumberElement( sal_False )
263 // <--
264 ,mbNullDateInitialized( sal_False )
266 OSL_ENSURE(mxComponentContext.is(), "SvXMLExport: no ComponentContext");
267 if (!mxComponentContext.is()) throw uno::RuntimeException();
268 mxUriReferenceFactory = uri::UriReferenceFactory::create(
269 mxComponentContext );
272 //==============================================================================
274 void SvXMLExport::SetDocHandler( const uno::Reference< xml::sax::XDocumentHandler > &rHandler )
276 mxHandler = rHandler;
277 mxExtHandler = uno::Reference<xml::sax::XExtendedDocumentHandler>( mxHandler, UNO_QUERY );
280 void SvXMLExport::_InitCtor()
282 // note: it is not necessary to add XML_NP_XML (it is declared implicitly)
283 if( (getExportFlags() & ~EXPORT_OASIS) != 0 )
285 mpNamespaceMap->Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE );
286 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
288 if( (getExportFlags() & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS) ) != 0 )
290 mpNamespaceMap->Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
292 if( (getExportFlags() & (EXPORT_META|EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_SETTINGS) ) != 0 )
294 mpNamespaceMap->Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
296 if( (getExportFlags() & EXPORT_SETTINGS) != 0 )
298 mpNamespaceMap->Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG );
301 if( (getExportFlags() & (EXPORT_META|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
303 mpNamespaceMap->Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
304 mpNamespaceMap->Add( GetXMLToken(XML_NP_META), GetXMLToken(XML_N_META), XML_NAMESPACE_META );
306 if( (getExportFlags() & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_FONTDECLS) ) != 0 )
308 mpNamespaceMap->Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE );
311 // namespaces for documents
312 if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
314 mpNamespaceMap->Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
315 mpNamespaceMap->Add( GetXMLToken(XML_NP_TEXT), GetXMLToken(XML_N_TEXT), XML_NAMESPACE_TEXT );
316 mpNamespaceMap->Add( GetXMLToken(XML_NP_DRAW), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW );
317 mpNamespaceMap->Add( GetXMLToken(XML_NP_DR3D), GetXMLToken(XML_N_DR3D), XML_NAMESPACE_DR3D );
318 mpNamespaceMap->Add( GetXMLToken(XML_NP_SVG), GetXMLToken(XML_N_SVG_COMPAT), XML_NAMESPACE_SVG );
319 mpNamespaceMap->Add( GetXMLToken(XML_NP_CHART), GetXMLToken(XML_N_CHART), XML_NAMESPACE_CHART );
320 mpNamespaceMap->Add( GetXMLToken(XML_NP_RPT), GetXMLToken(XML_N_RPT), XML_NAMESPACE_REPORT );
321 mpNamespaceMap->Add( GetXMLToken(XML_NP_TABLE), GetXMLToken(XML_N_TABLE), XML_NAMESPACE_TABLE );
322 mpNamespaceMap->Add( GetXMLToken(XML_NP_NUMBER),GetXMLToken(XML_N_NUMBER), XML_NAMESPACE_NUMBER );
323 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOOW), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
324 mpNamespaceMap->Add( GetXMLToken(XML_NP_OOOC), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
325 mpNamespaceMap->Add( GetXMLToken(XML_NP_OF), GetXMLToken(XML_N_OF), XML_NAMESPACE_OF );
327 if( (getExportFlags() & (EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
329 mpNamespaceMap->Add( GetXMLToken(XML_NP_MATH), GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH );
330 mpNamespaceMap->Add( GetXMLToken(XML_NP_FORM), GetXMLToken(XML_N_FORM), XML_NAMESPACE_FORM );
332 if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS) ) != 0 )
334 mpNamespaceMap->Add( GetXMLToken(XML_NP_SCRIPT), GetXMLToken(XML_N_SCRIPT), XML_NAMESPACE_SCRIPT );
335 mpNamespaceMap->Add( GetXMLToken(XML_NP_DOM), GetXMLToken(XML_N_DOM), XML_NAMESPACE_DOM );
337 if( (getExportFlags() & EXPORT_CONTENT ) != 0 )
339 mpNamespaceMap->Add( GetXMLToken(XML_NP_XFORMS_1_0), GetXMLToken(XML_N_XFORMS_1_0), XML_NAMESPACE_XFORMS );
340 mpNamespaceMap->Add( GetXMLToken(XML_NP_XSD), GetXMLToken(XML_N_XSD), XML_NAMESPACE_XSD );
341 mpNamespaceMap->Add( GetXMLToken(XML_NP_XSI), GetXMLToken(XML_N_XSI), XML_NAMESPACE_XSI );
342 mpNamespaceMap->Add( GetXMLToken(XML_NP_FIELD), GetXMLToken(XML_N_FIELD), XML_NAMESPACE_FIELD );
343 mpNamespaceMap->Add( GetXMLToken(XML_NP_FORMX), GetXMLToken(XML_N_FORMX), XML_NAMESPACE_FORMX );
345 // RDFa: needed for content and header/footer styles
346 if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
348 mpNamespaceMap->Add( GetXMLToken(XML_NP_XHTML),
349 GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
351 // GRDDL: to convert RDFa and meta.xml to RDF
352 if( (getExportFlags() & (EXPORT_META|EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
354 mpNamespaceMap->Add( GetXMLToken(XML_NP_GRDDL),
355 GetXMLToken(XML_N_GRDDL), XML_NAMESPACE_GRDDL );
358 mxAttrList = (xml::sax::XAttributeList*)mpAttrList;
360 msPicturesPath = OUString( RTL_CONSTASCII_USTRINGPARAM( "#Pictures/" ) );
361 msObjectsPath = OUString( RTL_CONSTASCII_USTRINGPARAM( "#./" ) );
362 msGraphicObjectProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.GraphicObject:" ) );
363 msEmbeddedObjectProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.EmbeddedObject:" ) );
365 if (mxModel.is() && !mxEventListener.is())
367 mxEventListener.set( new SvXMLExportEventListener(this));
368 mxModel->addEventListener(mxEventListener);
371 // --> OD 2006-03-10 #i51726# - determine model type
372 _DetermineModelType();
373 // <--
375 mbEnableExperimentalOdfExport = getenv("ENABLE_EXPERIMENTAL_ODF_EXPORT") != NULL;
377 // --> PB 2007-07-06 #146851# - load mbSaveBackwardCompatibleODF from configuration
379 // cl: but only if we do export to current oasis format, old openoffice format *must* always be compatible
380 if( (getExportFlags() & EXPORT_OASIS) != 0 )
382 sal_Bool bTemp = sal_True;
383 if ( ::comphelper::ConfigurationHelper::readDirectKey(
384 getServiceFactory(),
385 C2U("org.openoffice.Office.Common/"), C2U("Save/Document"), C2U("SaveBackwardCompatibleODF"),
386 ::comphelper::ConfigurationHelper::E_READONLY ) >>= bTemp )
388 mpImpl->mbSaveBackwardCompatibleODF = bTemp;
391 // <--
394 // --> OD 2006-03-14 #i51726#
395 void SvXMLExport::_DetermineModelType()
397 meModelType = SvtModuleOptions::E_UNKNOWN_FACTORY;
399 if ( mxModel.is() )
401 meModelType = SvtModuleOptions::ClassifyFactoryByModel( mxModel );
404 // <--
406 // #110680#
407 SvXMLExport::SvXMLExport(
408 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
409 MapUnit eDfltUnit, const enum XMLTokenEnum eClass, sal_uInt16 nExportFlags )
410 : mpImpl( new SvXMLExport_Impl ),
411 // #110680#
412 mxServiceFactory(xServiceFactory),
413 mpAttrList( new SvXMLAttributeList ),
414 mpNamespaceMap( new SvXMLNamespaceMap ),
415 // #110680#
416 mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, eDfltUnit, getServiceFactory() ) ),
417 mpNumExport(0L),
418 mpProgressBarHelper( NULL ),
419 mpEventExport( NULL ),
420 mpImageMapExport( NULL ),
421 mpXMLErrors( NULL ),
422 mbExtended( sal_False ),
423 meClass( eClass ),
424 mnExportFlags( nExportFlags ),
425 mnErrorFlags( ERROR_NO ),
426 msWS( GetXMLToken(XML_WS) ),
427 mbSaveLinkedSections(sal_True)
429 DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
430 _InitCtor();
433 // #110680#
434 SvXMLExport::SvXMLExport(
435 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
436 const OUString &rFileName,
437 const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
438 MapUnit eDfltUnit )
439 : mpImpl( new SvXMLExport_Impl ),
440 // #110680#
441 mxServiceFactory(xServiceFactory),
442 mxHandler( rHandler ),
443 mxExtHandler( rHandler, uno::UNO_QUERY ),
444 mpAttrList( new SvXMLAttributeList ),
445 msOrigFileName( rFileName ),
446 mpNamespaceMap( new SvXMLNamespaceMap ),
447 // #110680#
448 mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, eDfltUnit, getServiceFactory() ) ),
449 mpNumExport(0L),
450 mpProgressBarHelper( NULL ),
451 mpEventExport( NULL ),
452 mpImageMapExport( NULL ),
453 mpXMLErrors( NULL ),
454 mbExtended( sal_False ),
455 meClass( XML_TOKEN_INVALID ),
456 mnExportFlags( 0 ),
457 mnErrorFlags( ERROR_NO ),
458 msWS( GetXMLToken(XML_WS) ),
459 mbSaveLinkedSections(sal_True)
461 mpImpl->SetSchemeOf( msOrigFileName );
462 DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
463 _InitCtor();
465 if (mxNumberFormatsSupplier.is())
466 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
469 // #110680#
470 SvXMLExport::SvXMLExport(
471 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
472 const OUString &rFileName,
473 const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
474 const Reference< XModel >& rModel,
475 sal_Int16 eDfltUnit )
476 : mpImpl( new SvXMLExport_Impl ),
477 // #110680#
478 mxServiceFactory(xServiceFactory),
479 mxModel( rModel ),
480 mxHandler( rHandler ),
481 mxExtHandler( rHandler, uno::UNO_QUERY ),
482 mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
483 mpAttrList( new SvXMLAttributeList ),
484 msOrigFileName( rFileName ),
485 mpNamespaceMap( new SvXMLNamespaceMap ),
486 // #110680#
487 // pUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, SvXMLUnitConverter::GetMapUnit(eDfltUnit) ) ),
488 mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, SvXMLUnitConverter::GetMapUnit(eDfltUnit), getServiceFactory() ) ),
489 mpNumExport(0L),
490 mpProgressBarHelper( NULL ),
491 mpEventExport( NULL ),
492 mpImageMapExport( NULL ),
493 mpXMLErrors( NULL ),
494 mbExtended( sal_False ),
495 meClass( XML_TOKEN_INVALID ),
496 mnExportFlags( 0 ),
497 mnErrorFlags( ERROR_NO ),
498 msWS( GetXMLToken(XML_WS) ),
499 mbSaveLinkedSections(sal_True)
501 mpImpl->SetSchemeOf( msOrigFileName );
502 DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
503 _InitCtor();
505 if (mxNumberFormatsSupplier.is())
506 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
509 // #110680#
510 SvXMLExport::SvXMLExport(
511 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
512 const OUString &rFileName,
513 const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
514 const Reference< XModel >& rModel,
515 const Reference< document::XGraphicObjectResolver >& rEmbeddedGraphicObjects,
516 sal_Int16 eDfltUnit )
517 : mpImpl( new SvXMLExport_Impl ),
518 // #110680#
519 mxServiceFactory(xServiceFactory),
520 mxModel( rModel ),
521 mxHandler( rHandler ),
522 mxExtHandler( rHandler, uno::UNO_QUERY ),
523 mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
524 mxGraphicResolver( rEmbeddedGraphicObjects ),
525 mpAttrList( new SvXMLAttributeList ),
526 msOrigFileName( rFileName ),
527 mpNamespaceMap( new SvXMLNamespaceMap ),
528 // #110680#
529 mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, SvXMLUnitConverter::GetMapUnit(eDfltUnit), getServiceFactory() ) ),
530 mpNumExport(0L),
531 mpProgressBarHelper( NULL ),
532 mpEventExport( NULL ),
533 mpImageMapExport( NULL ),
534 mpXMLErrors( NULL ),
535 mbExtended( sal_False ),
536 meClass( XML_TOKEN_INVALID ),
537 mnExportFlags( 0 ),
538 mnErrorFlags( ERROR_NO ),
539 msWS( GetXMLToken(XML_WS) ),
540 mbSaveLinkedSections(sal_True)
542 mpImpl->SetSchemeOf( msOrigFileName );
543 DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
544 _InitCtor();
546 if (mxNumberFormatsSupplier.is())
547 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
550 SvXMLExport::~SvXMLExport()
552 delete mpXMLErrors;
553 delete mpImageMapExport;
554 delete mpEventExport;
555 delete mpNamespaceMap;
556 delete mpUnitConv;
557 if (mpProgressBarHelper || mpNumExport)
559 if (mxExportInfo.is())
561 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
562 if (xPropertySetInfo.is())
564 if (mpProgressBarHelper)
566 OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
567 OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
568 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
569 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
570 xPropertySetInfo->hasPropertyByName(sProgressCurrent))
572 sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
573 sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
574 uno::Any aAny;
575 aAny <<= nProgressMax;
576 mxExportInfo->setPropertyValue(sProgressMax, aAny);
577 aAny <<= nProgressCurrent;
578 mxExportInfo->setPropertyValue(sProgressCurrent, aAny);
580 if (xPropertySetInfo->hasPropertyByName(sRepeat))
581 mxExportInfo->setPropertyValue(sRepeat, cppu::bool2any(mpProgressBarHelper->GetRepeat()));
583 if (mpNumExport && (mnExportFlags & (EXPORT_AUTOSTYLES | EXPORT_STYLES)))
585 OUString sWrittenNumberFormats(RTL_CONSTASCII_USTRINGPARAM(XML_WRITTENNUMBERSTYLES));
586 if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
588 uno::Sequence<sal_Int32> aWasUsed;
589 mpNumExport->GetWasUsed(aWasUsed);
590 uno::Any aAny;
591 aAny <<= aWasUsed;
592 mxExportInfo->setPropertyValue(sWrittenNumberFormats, aAny);
597 delete mpProgressBarHelper;
598 delete mpNumExport;
601 xmloff::token::ResetTokens();
603 if (mxEventListener.is() && mxModel.is())
604 mxModel->removeEventListener(mxEventListener);
606 delete mpImpl;
609 ///////////////////////////////////////////////////////////////////////
611 // XExporter
612 void SAL_CALL SvXMLExport::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
613 throw(lang::IllegalArgumentException, uno::RuntimeException)
615 mxModel = uno::Reference< frame::XModel >::query( xDoc );
616 if( !mxModel.is() )
617 throw lang::IllegalArgumentException();
618 if (mxModel.is() && ! mxEventListener.is())
620 mxEventListener.set( new SvXMLExportEventListener(this));
621 mxModel->addEventListener(mxEventListener);
624 if(!mxNumberFormatsSupplier.is() )
626 mxNumberFormatsSupplier = mxNumberFormatsSupplier.query( mxModel );
627 if(mxNumberFormatsSupplier.is() && mxHandler.is())
628 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
630 if (mxExportInfo.is())
632 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
633 if (xPropertySetInfo.is())
635 OUString sUsePrettyPrinting(RTL_CONSTASCII_USTRINGPARAM(XML_USEPRETTYPRINTING));
636 if (xPropertySetInfo->hasPropertyByName(sUsePrettyPrinting))
638 uno::Any aAny = mxExportInfo->getPropertyValue(sUsePrettyPrinting);
639 if (::cppu::any2bool(aAny))
640 mnExportFlags |= EXPORT_PRETTY;
641 else
642 mnExportFlags &= ~EXPORT_PRETTY;
645 OUString sGenerousListLevels(RTL_CONSTASCII_USTRINGPARAM(XML_GENEROUSLISTLEVELS));
646 if (!xPropertySetInfo->hasPropertyByName(sGenerousListLevels)
647 || !mxExportInfo->getPropertyValue(sGenerousListLevels).get<bool>())
649 mnExportFlags &= ~EXPORT_GENEROUS_LIST_LEVELS;
651 else
653 mnExportFlags |= EXPORT_GENEROUS_LIST_LEVELS;
656 if (mpNumExport && (mnExportFlags & (EXPORT_AUTOSTYLES | EXPORT_STYLES)))
658 OUString sWrittenNumberFormats(RTL_CONSTASCII_USTRINGPARAM(XML_WRITTENNUMBERSTYLES));
659 if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
661 uno::Any aAny = mxExportInfo->getPropertyValue(sWrittenNumberFormats);
662 uno::Sequence<sal_Int32> aWasUsed;
663 if(aAny >>= aWasUsed)
664 mpNumExport->SetWasUsed(aWasUsed);
670 // --> PB 2007-07-06 #i146851#
671 if ( mpImpl->mbSaveBackwardCompatibleODF )
672 mnExportFlags |= EXPORT_SAVEBACKWARDCOMPATIBLE;
673 else
674 mnExportFlags &= ~EXPORT_SAVEBACKWARDCOMPATIBLE;
675 // <--
677 // namespaces for user defined attributes
678 Reference< XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
679 if( xFactory.is() )
683 Reference < XInterface > xIfc =
684 xFactory->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM(
685 "com.sun.star.xml.NamespaceMap")) );
686 if( xIfc.is() )
688 Reference< XNameAccess > xNamespaceMap( xIfc, UNO_QUERY );
689 if( xNamespaceMap.is() )
691 Sequence< OUString > aPrefixes( xNamespaceMap->getElementNames() );
693 OUString* pPrefix = aPrefixes.getArray();
694 const sal_Int32 nCount = aPrefixes.getLength();
695 sal_Int32 nIndex;
696 OUString aURL;
698 for( nIndex = 0; nIndex < nCount; nIndex++, *pPrefix++ )
700 if( xNamespaceMap->getByName( *pPrefix ) >>= aURL )
701 _GetNamespaceMap().Add( *pPrefix, aURL, XML_NAMESPACE_UNKNOWN );
706 catch( com::sun::star::uno::Exception& )
711 // --> OD 2006-03-10 #i51726# - determine model type
712 _DetermineModelType();
713 // <--
716 // XInitialize
717 void SAL_CALL SvXMLExport::initialize( const uno::Sequence< uno::Any >& aArguments )
718 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
720 // #93186# we need to queryInterface every single Any with any expected outcome. This variable hold the queryInterface results.
722 const sal_Int32 nAnyCount = aArguments.getLength();
723 const uno::Any* pAny = aArguments.getConstArray();
725 for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
727 Reference<XInterface> xValue;
728 *pAny >>= xValue;
730 // status indicator
731 uno::Reference<task::XStatusIndicator> xTmpStatus( xValue, UNO_QUERY );
732 if ( xTmpStatus.is() )
733 mxStatusIndicator = xTmpStatus;
735 // graphic resolver
736 uno::Reference<document::XGraphicObjectResolver> xTmpGraphic(
737 xValue, UNO_QUERY );
738 if ( xTmpGraphic.is() )
739 mxGraphicResolver = xTmpGraphic;
741 // object resolver
742 uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
743 xValue, UNO_QUERY );
744 if ( xTmpObjectResolver.is() )
745 mxEmbeddedResolver = xTmpObjectResolver;
747 // document handler
748 uno::Reference<xml::sax::XDocumentHandler> xTmpDocHandler(
749 xValue, UNO_QUERY );
750 if( xTmpDocHandler.is() )
752 mxHandler = xTmpDocHandler;
753 *pAny >>= mxExtHandler;
755 if (mxNumberFormatsSupplier.is() && mpNumExport == NULL)
756 mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
759 // property set to transport data across
760 uno::Reference<beans::XPropertySet> xTmpPropertySet(
761 xValue, UNO_QUERY );
762 if( xTmpPropertySet.is() )
763 mxExportInfo = xTmpPropertySet;
766 if( mxExportInfo.is() )
768 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo =
769 mxExportInfo->getPropertySetInfo();
770 OUString sPropName(
771 RTL_CONSTASCII_USTRINGPARAM("BaseURI" ) );
772 if( xPropertySetInfo->hasPropertyByName(sPropName) )
774 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
775 aAny >>= msOrigFileName;
776 mpImpl->msPackageURI = msOrigFileName;
777 mpImpl->SetSchemeOf( msOrigFileName );
779 OUString sRelPath;
780 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamRelPath" ) );
781 if( xPropertySetInfo->hasPropertyByName(sPropName) )
783 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
784 aAny >>= sRelPath;
786 OUString sName;
787 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamName" ) );
788 if( xPropertySetInfo->hasPropertyByName(sPropName) )
790 uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
791 aAny >>= sName;
793 if( msOrigFileName.getLength() && sName.getLength() )
795 INetURLObject aBaseURL( msOrigFileName );
796 if( sRelPath.getLength() )
797 aBaseURL.insertName( sRelPath );
798 aBaseURL.insertName( sName );
799 msOrigFileName = aBaseURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
801 mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
803 // --> OD 2006-09-26 #i69627#
804 const ::rtl::OUString sOutlineStyleAsNormalListStyle(
805 RTL_CONSTASCII_USTRINGPARAM("OutlineStyleAsNormalListStyle") );
806 if( xPropertySetInfo->hasPropertyByName( sOutlineStyleAsNormalListStyle ) )
808 uno::Any aAny = mxExportInfo->getPropertyValue( sOutlineStyleAsNormalListStyle );
809 aAny >>= (mpImpl->mbOutlineStyleAsNormalListStyle);
811 // <--
813 OUString sTargetStorage( RTL_CONSTASCII_USTRINGPARAM("TargetStorage") );
814 if( xPropertySetInfo->hasPropertyByName( sTargetStorage ) )
815 mxExportInfo->getPropertyValue( sTargetStorage ) >>= mpImpl->mxTargetStorage;
817 // --> OD 2008-11-26 #158694#
818 const ::rtl::OUString sExportTextNumberElement(
819 RTL_CONSTASCII_USTRINGPARAM("ExportTextNumberElement") );
820 if( xPropertySetInfo->hasPropertyByName( sExportTextNumberElement ) )
822 uno::Any aAny = mxExportInfo->getPropertyValue( sExportTextNumberElement );
823 aAny >>= (mpImpl->mbExportTextNumberElement);
825 // <--
830 // XFilter
831 sal_Bool SAL_CALL SvXMLExport::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor ) throw(uno::RuntimeException)
833 RTL_LOGFILE_CONTEXT_AUTHOR( aLogContext, "xmloff", LOGFILE_AUTHOR,
834 "SvXMLExport::filter" );
836 // check for xHandler first... should have been supplied in initialize
837 if( !mxHandler.is() )
838 return sal_False;
842 const sal_uInt32 nTest =
843 EXPORT_META|EXPORT_STYLES|EXPORT_CONTENT|EXPORT_SETTINGS;
844 if( (mnExportFlags & nTest) == nTest && !msOrigFileName.getLength() )
846 // evaluate descriptor only for flat files and if a base URI
847 // has not been provided already
848 const sal_Int32 nPropCount = aDescriptor.getLength();
849 const beans::PropertyValue* pProps = aDescriptor.getConstArray();
851 for( sal_Int32 nIndex = 0; nIndex < nPropCount; nIndex++, pProps++ )
853 const OUString& rPropName = pProps->Name;
854 const Any& rValue = pProps->Value;
856 if( rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FileName" ) ) )
858 if( !(rValue >>= msOrigFileName ) )
859 return sal_False;
861 else if (rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FilterName" ) ) )
863 if( !(rValue >>= msFilterName ) )
864 return sal_False;
869 #ifdef TIMELOG
870 if (GetModel().is())
872 // print a trace message with the URL
873 ByteString aUrl( (String) GetModel()->getURL(),
874 RTL_TEXTENCODING_ASCII_US );
875 RTL_LOGFILE_CONTEXT_TRACE1( aLogContext, "%s", aUrl.GetBuffer() );
877 // we also want a trace message with the document class
878 ByteString aClass( (String)GetXMLToken(meClass),
879 RTL_TEXTENCODING_ASCII_US );
880 RTL_LOGFILE_CONTEXT_TRACE1( aLogContext, "class=\"%s\"",
881 aClass.GetBuffer() );
883 #endif
885 exportDoc( meClass );
887 catch( uno::Exception e )
889 // We must catch exceptions, because according to the
890 // API definition export must not throw one!
891 Sequence<OUString> aSeq(0);
892 SetError( XMLERROR_FLAG_ERROR | XMLERROR_FLAG_SEVERE | XMLERROR_API,
893 aSeq, e.Message, NULL );
896 // return true only if no error occured
897 return (GetErrorFlags() & (ERROR_DO_NOTHING|ERROR_ERROR_OCCURED)) == 0;
900 void SAL_CALL SvXMLExport::cancel() throw(uno::RuntimeException)
902 // stop export
903 Sequence<OUString> aEmptySeq;
904 SetError(XMLERROR_CANCEL|XMLERROR_FLAG_SEVERE, aEmptySeq);
907 ::rtl::OUString SAL_CALL SvXMLExport::getName( )
908 throw (::com::sun::star::uno::RuntimeException)
910 return msFilterName;
913 void SAL_CALL SvXMLExport::setName( const ::rtl::OUString& )
914 throw (::com::sun::star::uno::RuntimeException)
916 // do nothing, because it is not possible to set the FilterName
920 // XServiceInfo
921 OUString SAL_CALL SvXMLExport::getImplementationName( ) throw(uno::RuntimeException)
923 OUString aStr;
924 return aStr;
927 sal_Bool SAL_CALL SvXMLExport::supportsService( const OUString& rServiceName ) throw(uno::RuntimeException)
929 return
930 rServiceName.equalsAsciiL(
931 "com.sun.star.document.ExportFilter",
932 sizeof("com.sun.star.document.ExportFilter")-1 ) ||
933 rServiceName.equalsAsciiL(
934 "com.sun.star.xml.XMLExportFilter",
935 sizeof("com.sun.star.xml.XMLExportFilter")-1);
938 uno::Sequence< OUString > SAL_CALL SvXMLExport::getSupportedServiceNames( )
939 throw(uno::RuntimeException)
941 uno::Sequence<OUString> aSeq(2);
942 aSeq[0] = OUString(
943 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ExportFilter"));
944 aSeq[1] = OUString(
945 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLExportFilter"));
946 return aSeq;
949 ///////////////////////////////////////////////////////////////////////
951 ::rtl::OUString
952 SvXMLExport::EnsureNamespace(::rtl::OUString const & i_rNamespace,
953 ::rtl::OUString const & i_rPreferredPrefix)
955 ::rtl::OUString sPrefix;
956 sal_uInt16 nKey( _GetNamespaceMap().GetKeyByName( i_rNamespace ) );
957 if( XML_NAMESPACE_UNKNOWN == nKey )
959 // There is no prefix for the namespace, so
960 // we have to generate one and have to add it.
961 sPrefix = i_rPreferredPrefix;
962 nKey = _GetNamespaceMap().GetKeyByPrefix( sPrefix );
963 sal_Int32 n( 0 );
964 ::rtl::OUStringBuffer buf;
965 while( nKey != USHRT_MAX )
967 buf.append( i_rPreferredPrefix );
968 buf.append( ++n );
969 sPrefix = buf.makeStringAndClear();
970 nKey = _GetNamespaceMap().GetKeyByPrefix( sPrefix );
973 if (mpImpl->mNamespaceMaps.empty()
974 || (mpImpl->mNamespaceMaps.top().second != mpImpl->mDepth))
976 // top was created for lower depth... need a new namespace map!
977 mpImpl->mNamespaceMaps.push(
978 ::std::make_pair(mpNamespaceMap, mpImpl->mDepth) );
979 mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
982 // add the namespace to the map and as attribute
983 mpNamespaceMap->Add( sPrefix, i_rNamespace );
984 buf.append( GetXMLToken(XML_XMLNS) );
985 buf.append( sal_Unicode(':') );
986 buf.append( sPrefix );
987 AddAttribute( buf.makeStringAndClear(), i_rNamespace );
989 else
991 // If there is a prefix for the namespace, reuse that.
992 sPrefix = _GetNamespaceMap().GetPrefixByKey( nKey );
994 return sPrefix;
997 ///////////////////////////////////////////////////////////////////////
999 void SvXMLExport::AddAttributeASCII( sal_uInt16 nPrefixKey,
1000 const sal_Char *pName,
1001 const sal_Char *pValue )
1003 OUString sName( OUString::createFromAscii( pName ) );
1004 OUString sValue( OUString::createFromAscii( pValue ) );
1006 mpAttrList->AddAttribute(
1007 _GetNamespaceMap().GetQNameByKey( nPrefixKey, sName ), sValue );
1010 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const sal_Char *pName,
1011 const OUString& rValue )
1013 OUString sName( OUString::createFromAscii( pName ) );
1015 mpAttrList->AddAttribute(
1016 _GetNamespaceMap().GetQNameByKey( nPrefixKey, sName ), rValue );
1019 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const OUString& rName,
1020 const OUString& rValue )
1022 mpAttrList->AddAttribute(
1023 _GetNamespaceMap().GetQNameByKey( nPrefixKey, rName ), rValue );
1026 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
1027 enum XMLTokenEnum eName,
1028 const OUString& rValue )
1030 mpAttrList->AddAttribute(
1031 _GetNamespaceMap().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
1032 rValue );
1035 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
1036 enum XMLTokenEnum eName,
1037 enum XMLTokenEnum eValue)
1039 mpAttrList->AddAttribute(
1040 _GetNamespaceMap().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
1041 GetXMLToken(eValue) );
1044 void SvXMLExport::AddAttribute( const ::rtl::OUString& rQName,
1045 const ::rtl::OUString& rValue )
1047 mpAttrList->AddAttribute(
1048 rQName,
1049 rValue );
1052 void SvXMLExport::AddAttribute( const ::rtl::OUString& rQName,
1053 enum ::xmloff::token::XMLTokenEnum eValue )
1055 mpAttrList->AddAttribute(
1056 rQName,
1057 GetXMLToken(eValue) );
1060 void SvXMLExport::AddAttributeList( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1062 if( xAttrList.is())
1063 mpAttrList->AppendAttributeList( xAttrList );
1066 void SvXMLExport::ClearAttrList()
1068 mpAttrList->Clear();
1071 #ifndef PRODUCT
1072 void SvXMLExport::CheckAttrList()
1074 DBG_ASSERT( !mpAttrList->getLength(),
1075 "XMLExport::CheckAttrList: list is not empty" );
1077 #endif
1079 void SvXMLExport::ImplExportMeta()
1081 CheckAttrList();
1083 _ExportMeta();
1086 void SvXMLExport::ImplExportSettings()
1088 CheckAttrList();
1090 ::std::list< SettingsGroup > aSettings;
1091 sal_Int32 nSettingsCount = 0;
1093 // view settings
1094 uno::Sequence< beans::PropertyValue > aViewSettings;
1095 GetViewSettingsAndViews( aViewSettings );
1096 aSettings.push_back( SettingsGroup( XML_VIEW_SETTINGS, aViewSettings ) );
1097 nSettingsCount += aViewSettings.getLength();
1099 // configuration settings
1100 uno::Sequence<beans::PropertyValue> aConfigSettings;
1101 GetConfigurationSettings( aConfigSettings );
1102 aSettings.push_back( SettingsGroup( XML_CONFIGURATION_SETTINGS, aConfigSettings ) );
1103 nSettingsCount += aConfigSettings.getLength();
1105 // any document specific settings
1106 nSettingsCount += GetDocumentSpecificSettings( aSettings );
1109 SvXMLElementExport aElem( *this,
1110 nSettingsCount != 0,
1111 XML_NAMESPACE_OFFICE, XML_SETTINGS,
1112 sal_True, sal_True );
1113 XMLSettingsExportHelper aSettingsExportHelper(*this);
1115 for ( ::std::list< SettingsGroup >::const_iterator settings = aSettings.begin();
1116 settings != aSettings.end();
1117 ++settings
1120 if ( !settings->aSettings.getLength() )
1121 continue;
1123 OUString sSettingsName( GetXMLToken( settings->eGroupName ) );
1124 aSettingsExportHelper.exportSettings( settings->aSettings, sSettingsName );
1129 void SvXMLExport::ImplExportStyles( sal_Bool )
1131 CheckAttrList();
1133 // AddAttribute( XML_NAMESPACE_NONE, XML_ID, XML_STYLES_ID );
1135 // <style:styles>
1136 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_STYLES,
1137 sal_True, sal_True );
1139 _ExportStyles( sal_False );
1142 // transfer style names (+ families) TO other components (if appropriate)
1143 if( ( ( mnExportFlags & EXPORT_CONTENT ) == 0 ) && mxExportInfo.is() )
1145 static OUString sStyleNames( RTL_CONSTASCII_USTRINGPARAM("StyleNames") );
1146 static OUString sStyleFamilies( RTL_CONSTASCII_USTRINGPARAM("StyleFamilies") );
1147 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
1148 if ( xPropertySetInfo->hasPropertyByName( sStyleNames ) && xPropertySetInfo->hasPropertyByName( sStyleFamilies ) )
1150 Sequence<sal_Int32> aStyleFamilies;
1151 Sequence<OUString> aStyleNames;
1152 mxAutoStylePool->GetRegisteredNames( aStyleFamilies, aStyleNames );
1153 mxExportInfo->setPropertyValue( sStyleNames, makeAny( aStyleNames ) );
1154 mxExportInfo->setPropertyValue( sStyleFamilies,
1155 makeAny( aStyleFamilies ) );
1160 void SvXMLExport::ImplExportAutoStyles( sal_Bool )
1162 // transfer style names (+ families) FROM other components (if appropriate)
1163 OUString sStyleNames( RTL_CONSTASCII_USTRINGPARAM("StyleNames") );
1164 OUString sStyleFamilies( RTL_CONSTASCII_USTRINGPARAM("StyleFamilies") );
1165 if( ( ( mnExportFlags & EXPORT_STYLES ) == 0 )
1166 && mxExportInfo.is()
1167 && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleNames )
1168 && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleFamilies ) )
1170 Sequence<sal_Int32> aStyleFamilies;
1171 mxExportInfo->getPropertyValue( sStyleFamilies ) >>= aStyleFamilies;
1172 Sequence<OUString> aStyleNames;
1173 mxExportInfo->getPropertyValue( sStyleNames ) >>= aStyleNames;
1174 mxAutoStylePool->RegisterNames( aStyleFamilies, aStyleNames );
1177 // AddAttributeASCII( XML_NAMESPACE_NONE, XML_ID, XML_AUTO_STYLES_ID );
1179 // <style:automatic-styles>
1180 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
1181 XML_AUTOMATIC_STYLES, sal_True, sal_True );
1183 #if 0
1184 AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
1185 AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, XML_STYLES_HREF );
1186 AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
1187 AddAttribute( XML_NAMESPACE_XLINK, XML_ROLE,
1188 pNamespaceMap->GetQNameByKey( XML_NAMESPACE_OFFICE,
1189 GetXMLToken(XML_STYLESHEET)) );
1191 // <style:use-styles>
1192 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
1193 XML_USE_STYLES, sal_True, sal_True );
1195 #endif
1196 _ExportAutoStyles();
1200 void SvXMLExport::ImplExportMasterStyles( sal_Bool )
1203 // <style:master-styles>
1204 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_MASTER_STYLES,
1205 sal_True, sal_True );
1207 _ExportMasterStyles();
1210 #if 0
1211 AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
1212 AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, XML_AUTO_STYLES_HREF );
1213 AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
1214 AddAttribute( XML_NAMESPACE_XLINK, XML_ROLE,
1215 pNamespaceMap->GetQNameByKey( XML_NAMESPACE_OFFICE,
1216 GetXMLToken(XML_STYLESHEET) ) );
1218 // <style:use-styles>
1219 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
1220 XML_USE_STYLES, sal_True, sal_True );
1222 #endif
1225 void SvXMLExport::ImplExportContent()
1227 CheckAttrList();
1229 CheckAttrList();
1232 SvXMLElementExport aElemrnt( *this, XML_NAMESPACE_OFFICE, XML_BODY,
1233 sal_True, sal_True );
1235 XMLTokenEnum eClass = meClass;
1236 if( XML_TEXT_GLOBAL == eClass )
1238 AddAttribute( XML_NAMESPACE_TEXT, XML_GLOBAL,
1239 GetXMLToken( XML_TRUE ) );
1240 eClass = XML_TEXT;
1242 // <office:body ...>
1243 SetBodyAttributes();
1244 SvXMLElementExport aElem( *this, meClass != XML_TOKEN_INVALID,
1245 XML_NAMESPACE_OFFICE, eClass,
1246 sal_True, sal_True );
1248 _ExportContent();
1253 void SvXMLExport::SetBodyAttributes()
1257 sal_uInt32 SvXMLExport::exportDoc( enum ::xmloff::token::XMLTokenEnum eClass )
1259 bool bOwnGraphicResolver = false;
1260 bool bOwnEmbeddedResolver = false;
1262 if( !mxGraphicResolver.is() || !mxEmbeddedResolver.is() )
1264 Reference< XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
1265 if( xFactory.is() )
1269 if( !mxGraphicResolver.is() )
1271 mxGraphicResolver = Reference< XGraphicObjectResolver >::query(
1272 xFactory->createInstance(
1273 OUString(RTL_CONSTASCII_USTRINGPARAM(
1274 "com.sun.star.document.ExportGraphicObjectResolver"))));
1275 bOwnGraphicResolver = mxGraphicResolver.is();
1278 if( !mxEmbeddedResolver.is() )
1280 mxEmbeddedResolver = Reference< XEmbeddedObjectResolver >::query(
1281 xFactory->createInstance(
1282 OUString(RTL_CONSTASCII_USTRINGPARAM(
1283 "com.sun.star.document.ExportEmbeddedObjectResolver"))));
1284 bOwnEmbeddedResolver = mxEmbeddedResolver.is();
1287 catch( com::sun::star::uno::Exception& )
1292 if( (getExportFlags() & EXPORT_OASIS) == 0 )
1294 Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory();
1295 if( xFactory.is() )
1299 ::comphelper::PropertyMapEntry aInfoMap[] =
1301 { "Class", sizeof("Class")-1, 0,
1302 &::getCppuType((::rtl::OUString*)0),
1303 PropertyAttribute::MAYBEVOID, 0},
1304 { NULL, 0, 0, NULL, 0, 0 }
1306 Reference< XPropertySet > xConvPropSet(
1307 ::comphelper::GenericPropertySet_CreateInstance(
1308 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
1310 Any aAny;
1311 aAny <<= GetXMLToken( eClass );
1312 xConvPropSet->setPropertyValue(
1313 OUString(RTL_CONSTASCII_USTRINGPARAM("Class")), aAny );
1315 Reference< XPropertySet > xPropSet =
1316 mxExportInfo.is()
1317 ? PropertySetMerger_CreateInstance( mxExportInfo,
1318 xConvPropSet )
1319 : xConvPropSet;
1321 Sequence<Any> aArgs( 3 );
1322 aArgs[0] <<= mxHandler;
1323 aArgs[1] <<= xPropSet;
1324 aArgs[2] <<= mxModel;
1326 // get filter component
1327 Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
1328 xFactory->createInstanceWithArguments(
1329 OUString::createFromAscii("com.sun.star.comp.Oasis2OOoTransformer"),
1330 aArgs), UNO_QUERY);
1331 OSL_ENSURE( xTmpDocHandler.is(),
1332 "can't instantiate OASIS transformer component" );
1333 if( xTmpDocHandler.is() )
1335 mxHandler = xTmpDocHandler;
1336 mxExtHandler = uno::Reference<xml::sax::XExtendedDocumentHandler>( mxHandler, UNO_QUERY );
1339 catch( com::sun::star::uno::Exception& )
1346 mxHandler->startDocument();
1348 // <?xml version="1.0" encoding="UTF-8"?>
1349 // xHandler->processingInstruction( S2U( sXML_xml ), S2U( sXML_xml_pi ) );
1351 // <office:document ...>
1352 CheckAttrList();
1354 // namespace attributes
1355 // ( The namespace decls should be first attributes in the element;
1356 // some faulty XML parsers (JAXP1.1) have a problem with this,
1357 // also it's more elegant )
1358 sal_uInt16 nPos = mpNamespaceMap->GetFirstKey();
1359 while( USHRT_MAX != nPos )
1361 mpAttrList->AddAttribute( mpNamespaceMap->GetAttrNameByKey( nPos ),
1362 mpNamespaceMap->GetNameByKey( nPos ) );
1363 nPos = mpNamespaceMap->GetNextKey( nPos );
1368 // office:version = ...
1369 if( !mbExtended )
1371 const sal_Char* pVersion = 0;
1372 switch( getDefaultVersion() )
1374 case SvtSaveOptions::ODFVER_LATEST: pVersion = sXML_1_2; break;
1375 case SvtSaveOptions::ODFVER_012: pVersion = sXML_1_2; break;
1376 case SvtSaveOptions::ODFVER_011: pVersion = sXML_1_1; break;
1377 case SvtSaveOptions::ODFVER_010: break;
1379 default:
1380 DBG_ERROR("xmloff::SvXMLExport::exportDoc(), unexpected odf default version!");
1383 if( pVersion )
1384 AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
1385 OUString::createFromAscii(pVersion) );
1389 enum XMLTokenEnum eRootService = XML_TOKEN_INVALID;
1390 const sal_Int32 nExportMode = mnExportFlags & (EXPORT_META|EXPORT_STYLES|EXPORT_CONTENT|EXPORT_SETTINGS);
1392 if ( EXPORT_SETTINGS != nExportMode ) // meta, content, styles
1394 AddAttribute( XML_NAMESPACE_GRDDL, XML_TRANSFORMATION,
1395 OUString::createFromAscii(s_grddl_xsl) );
1398 if( EXPORT_META == nExportMode )
1400 // export only meta
1401 eRootService = XML_DOCUMENT_META;
1403 else if ( EXPORT_SETTINGS == nExportMode )
1405 // export only settings
1406 eRootService = XML_DOCUMENT_SETTINGS;
1408 else if( EXPORT_STYLES == nExportMode )
1410 // export only styles
1411 eRootService = XML_DOCUMENT_STYLES;
1413 else if( EXPORT_CONTENT == nExportMode )
1415 // export only content
1416 eRootService = XML_DOCUMENT_CONTENT;
1418 else
1420 // the god'ol one4all element
1421 eRootService = XML_DOCUMENT;
1422 // office:mimetype = ... (only for stream containing the content)
1423 if( eClass != XML_TOKEN_INVALID )
1425 OUString aTmp( RTL_CONSTASCII_USTRINGPARAM("application/vnd.oasis.opendocument.") );
1426 aTmp += GetXMLToken( eClass );
1427 AddAttribute( XML_NAMESPACE_OFFICE, XML_MIMETYPE, aTmp );
1431 // if( (getExportFlags() & EXPORT_NODOCTYPE) == 0 &&
1432 // xExtHandler.is() )
1433 // {
1434 // OUStringBuffer aDocType(
1435 // GetXMLToken(XML_XML_DOCTYPE_PREFIX).getLength() +
1436 // GetXMLToken(XML_XML_DOCTYPE_SUFFIX).getLength() + 30 );
1438 // aDocType.append( GetXMLToken(XML_XML_DOCTYPE_PREFIX) );
1439 // aDocType.append( GetNamespaceMap().GetQNameByKey(
1440 // XML_NAMESPACE_OFFICE, GetXMLToken(eRootService) ) );
1441 // aDocType.append( GetXMLToken(XML_XML_DOCTYPE_SUFFIX) );
1442 // xExtHandler->unknown( aDocType.makeStringAndClear() );
1443 // }
1445 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, eRootService, sal_True, sal_True );
1447 // meta information
1448 if( mnExportFlags & EXPORT_META )
1449 ImplExportMeta();
1451 // settings
1452 if( mnExportFlags & EXPORT_SETTINGS )
1453 ImplExportSettings();
1455 // scripts
1456 if( mnExportFlags & EXPORT_SCRIPTS )
1457 _ExportScripts();
1459 // font declerations
1460 if( mnExportFlags & EXPORT_FONTDECLS )
1461 _ExportFontDecls();
1463 // styles
1464 if( mnExportFlags & EXPORT_STYLES )
1465 ImplExportStyles( sal_False );
1467 // autostyles
1468 if( mnExportFlags & EXPORT_AUTOSTYLES )
1469 ImplExportAutoStyles( sal_False );
1471 // masterstyles
1472 if( mnExportFlags & EXPORT_MASTERSTYLES )
1473 ImplExportMasterStyles( sal_False );
1475 // contnt
1476 if( mnExportFlags & EXPORT_CONTENT )
1477 ImplExportContent();
1481 mxHandler->endDocument();
1483 if( bOwnGraphicResolver )
1485 Reference< XComponent > xComp( mxGraphicResolver, UNO_QUERY );
1486 xComp->dispose();
1489 if( bOwnEmbeddedResolver )
1491 Reference< XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
1492 xComp->dispose();
1495 return 0;
1498 void SvXMLExport::ResetNamespaceMap()
1500 delete mpNamespaceMap; mpNamespaceMap = new SvXMLNamespaceMap;
1503 void SvXMLExport::_ExportMeta()
1505 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
1506 Reference< XDocumentPropertiesSupplier > xDocPropsSupplier(mxModel,
1507 UNO_QUERY);
1508 if (xDocPropsSupplier.is()) {
1509 Reference<XDocumentProperties> xDocProps(
1510 xDocPropsSupplier->getDocumentProperties());
1511 if (!xDocProps.is()) throw;
1512 // update generator here
1513 xDocProps->setGenerator(generator);
1514 SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, xDocProps);
1515 uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
1516 pMeta->Export();
1517 } else {
1518 // office:meta
1519 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_META,
1520 sal_True, sal_True );
1522 // BM: #i60323# export generator even if xInfoProp is empty (which is the
1523 // case for charts). The generator does not depend on xInfoProp
1524 SvXMLElementExport anElem( *this, XML_NAMESPACE_META, XML_GENERATOR,
1525 sal_True, sal_True );
1526 Characters(generator);
1531 void SvXMLExport::_ExportScripts()
1533 SvXMLElementExport aElement( *this, XML_NAMESPACE_OFFICE, XML_SCRIPTS, sal_True, sal_True );
1535 // export Basic macros (only for FlatXML)
1536 if ( mnExportFlags & EXPORT_EMBEDDED )
1538 ::rtl::OUString aValue( GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) );
1539 aValue += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":Basic" ) );
1540 AddAttribute( XML_NAMESPACE_SCRIPT, XML_LANGUAGE, aValue );
1542 SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_SCRIPT, sal_True, sal_True );
1544 // initialize Basic
1545 if ( mxModel.is() )
1547 Reference< beans::XPropertySet > xPSet( mxModel, UNO_QUERY );
1548 if ( xPSet.is() )
1549 xPSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) );
1552 Reference< document::XExporter > xExporter;
1553 Reference< lang::XMultiServiceFactory > xMSF( getServiceFactory() );
1554 if ( xMSF.is() )
1556 Reference < XDocumentHandler > xHdl( new XMLBasicExportFilter( mxHandler ) );
1557 Sequence < Any > aArgs( 1 );
1558 aArgs[0] <<= xHdl;
1559 xExporter.set( xMSF->createInstanceWithArguments(
1560 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicExporter" ) ), aArgs ),
1561 UNO_QUERY );
1564 OSL_ENSURE( xExporter.is(),
1565 "SvXMLExport::_ExportScripts: can't instantiate export filter component for Basic macros" );
1567 if ( xExporter.is() )
1569 Reference< XComponent > xComp( mxModel, UNO_QUERY );
1570 xExporter->setSourceDocument( xComp );
1571 Reference< XFilter > xFilter( xExporter, UNO_QUERY );
1572 if ( xFilter.is() )
1574 Sequence < PropertyValue > aMediaDesc( 0 );
1575 xFilter->filter( aMediaDesc );
1580 // export document events
1581 Reference< document::XEventsSupplier > xEvents( GetModel(), UNO_QUERY );
1582 GetEventExport().Export( xEvents, sal_True );
1585 void SvXMLExport::_ExportFontDecls()
1587 if( mxFontAutoStylePool.is() )
1588 mxFontAutoStylePool->exportXML();
1591 void SvXMLExport::_ExportStyles( sal_Bool )
1593 uno::Reference< lang::XMultiServiceFactory > xFact( GetModel(), uno::UNO_QUERY );
1594 if( xFact.is())
1596 // export (fill-)gradient-styles
1599 uno::Reference< container::XNameAccess > xGradient( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GradientTable") ) ), uno::UNO_QUERY );
1600 if( xGradient.is() )
1602 XMLGradientStyleExport aGradientStyle( *this );
1604 if( xGradient->hasElements() )
1606 uno::Sequence< OUString > aNamesSeq ( xGradient->getElementNames() );
1607 sal_Int32 nCount = aNamesSeq.getLength();
1608 for( sal_Int32 i=0; i<nCount; i++ )
1610 const OUString& rStrName = aNamesSeq[ i ];
1614 uno::Any aValue = xGradient->getByName( rStrName );
1616 aGradientStyle.exportXML( rStrName, aValue );
1618 catch( container::NoSuchElementException& )
1624 catch( lang::ServiceNotRegisteredException& )
1627 // export (fill-)hatch-styles
1630 uno::Reference< container::XNameAccess > xHatch( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.HatchTable") ) ), uno::UNO_QUERY );
1631 if( xHatch.is() )
1633 XMLHatchStyleExport aHatchStyle( *this );
1635 if( xHatch->hasElements() )
1637 uno::Sequence< OUString > aNamesSeq ( xHatch->getElementNames() );
1638 sal_Int32 nCount = aNamesSeq.getLength();
1639 for( sal_Int32 i=0; i<nCount; i++ )
1641 const OUString& rStrName = aNamesSeq[ i ];
1645 uno::Any aValue = xHatch->getByName( rStrName );
1647 aHatchStyle.exportXML( rStrName, aValue );
1649 catch( container::NoSuchElementException& )
1655 catch( lang::ServiceNotRegisteredException& )
1658 // export (fill-)bitmap-styles
1661 uno::Reference< container::XNameAccess > xBitmap( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.BitmapTable") ) ), uno::UNO_QUERY );
1662 if( xBitmap.is() )
1664 XMLImageStyle aImageStyle;
1666 if( xBitmap->hasElements() )
1668 uno::Sequence< OUString > aNamesSeq ( xBitmap->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 = xBitmap->getByName( rStrName );
1678 aImageStyle.exportXML( rStrName, aValue, *this );
1680 catch( container::NoSuchElementException& )
1686 catch( lang::ServiceNotRegisteredException& )
1689 // export transparency-gradient -styles
1692 uno::Reference< container::XNameAccess > xTransGradient( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) ), uno::UNO_QUERY );
1693 if( xTransGradient.is() )
1695 XMLTransGradientStyleExport aTransGradientstyle( *this );
1697 if( xTransGradient->hasElements() )
1699 uno::Sequence< OUString > aNamesSeq ( xTransGradient->getElementNames() );
1700 sal_Int32 nCount = aNamesSeq.getLength();
1701 for( sal_Int32 i=0; i<nCount; i++ )
1703 const OUString& rStrName = aNamesSeq[ i ];
1707 uno::Any aValue = xTransGradient->getByName( rStrName );
1709 aTransGradientstyle.exportXML( rStrName, aValue );
1711 catch( container::NoSuchElementException& )
1717 catch( lang::ServiceNotRegisteredException& )
1720 // export marker-styles
1723 uno::Reference< container::XNameAccess > xMarker( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.MarkerTable") ) ), uno::UNO_QUERY );
1724 if( xMarker.is() )
1726 XMLMarkerStyleExport aMarkerStyle( *this );
1728 if( xMarker->hasElements() )
1730 uno::Sequence< OUString > aNamesSeq ( xMarker->getElementNames() );
1731 sal_Int32 nCount = aNamesSeq.getLength();
1732 for( sal_Int32 i=0; i<nCount; i++ )
1734 const OUString& rStrName = aNamesSeq[ i ];
1738 uno::Any aValue = xMarker->getByName( rStrName );
1740 aMarkerStyle.exportXML( rStrName, aValue );
1742 catch( container::NoSuchElementException& )
1748 catch( lang::ServiceNotRegisteredException& )
1751 // export dash-styles
1754 uno::Reference< container::XNameAccess > xDashes( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DashTable") ) ), uno::UNO_QUERY );
1755 if( xDashes.is() )
1757 XMLDashStyleExport aDashStyle( *this );
1759 if( xDashes->hasElements() )
1761 uno::Sequence< OUString > aNamesSeq ( xDashes->getElementNames() );
1762 sal_Int32 nCount = aNamesSeq.getLength();
1763 for( sal_Int32 i=0; i<nCount; i++ )
1765 const OUString& rStrName = aNamesSeq[ i ];
1769 uno::Any aValue = xDashes->getByName( rStrName );
1771 aDashStyle.exportXML( rStrName, aValue );
1773 catch( container::NoSuchElementException& )
1779 catch( lang::ServiceNotRegisteredException& )
1784 XMLTextParagraphExport* SvXMLExport::CreateTextParagraphExport()
1786 return new XMLTextParagraphExport( *this, *(GetAutoStylePool().get()) );
1789 XMLShapeExport* SvXMLExport::CreateShapeExport()
1791 return new XMLShapeExport(*this);
1794 SvXMLAutoStylePoolP* SvXMLExport::CreateAutoStylePool()
1796 return new SvXMLAutoStylePoolP(*this);
1799 XMLPageExport* SvXMLExport::CreatePageExport()
1801 return new XMLPageExport( *this );
1804 SchXMLExportHelper* SvXMLExport::CreateChartExport()
1806 return new SchXMLExportHelper(*this,*GetAutoStylePool().get());
1809 XMLFontAutoStylePool* SvXMLExport::CreateFontAutoStylePool()
1811 return new XMLFontAutoStylePool( *this );
1814 xmloff::OFormLayerXMLExport* SvXMLExport::CreateFormExport()
1816 return new xmloff::OFormLayerXMLExport(*this);
1819 void SvXMLExport::GetViewSettingsAndViews(uno::Sequence<beans::PropertyValue>& rProps)
1821 GetViewSettings(rProps);
1822 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetModel(), uno::UNO_QUERY);
1823 if(xViewDataSupplier.is())
1825 uno::Reference<container::XIndexAccess> xIndexAccess;
1826 xViewDataSupplier->setViewData( xIndexAccess ); // make sure we get a newly created sequence
1827 xIndexAccess = xViewDataSupplier->getViewData();
1828 sal_Bool bAdd = sal_False;
1829 uno::Any aAny;
1830 if(xIndexAccess.is() && xIndexAccess->hasElements() )
1832 sal_Int32 nCount = xIndexAccess->getCount();
1833 for (sal_Int32 i = 0; i < nCount; i++)
1835 aAny = xIndexAccess->getByIndex(i);
1836 uno::Sequence<beans::PropertyValue> aProps;
1837 if( aAny >>= aProps )
1839 if( aProps.getLength() > 0 )
1841 bAdd = sal_True;
1842 break;
1848 if( bAdd )
1850 sal_Int32 nOldLength(rProps.getLength());
1851 rProps.realloc(nOldLength + 1);
1852 beans::PropertyValue aProp;
1853 aProp.Name = OUString(RTL_CONSTASCII_USTRINGPARAM("Views"));
1854 aProp.Value <<= xIndexAccess;
1855 rProps[nOldLength] = aProp;
1860 void SvXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>&)
1864 void SvXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>&)
1868 sal_Int32 SvXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup >& _out_rSettings )
1870 (void)_out_rSettings;
1871 return 0;
1874 void SvXMLExport::addDataStyle(const sal_Int32 nNumberFormat, sal_Bool /*bTimeFormat*/ )
1876 if(mpNumExport)
1877 mpNumExport->SetUsed(nNumberFormat);
1880 void SvXMLExport::exportDataStyles()
1882 if(mpNumExport)
1883 mpNumExport->Export(sal_False);
1886 void SvXMLExport::exportAutoDataStyles()
1888 if(mpNumExport)
1889 mpNumExport->Export(sal_True);
1891 if (mxFormExport.is())
1892 mxFormExport->exportAutoControlNumberStyles();
1895 OUString SvXMLExport::getDataStyleName(const sal_Int32 nNumberFormat, sal_Bool /*bTimeFormat*/ ) const
1897 OUString sTemp;
1898 if(mpNumExport)
1899 sTemp = mpNumExport->GetStyleName(nNumberFormat);
1900 return sTemp;
1903 void SvXMLExport::exportAnnotationMeta(const uno::Reference<drawing::XShape>&)
1907 sal_Int32 SvXMLExport::dataStyleForceSystemLanguage(sal_Int32 nFormat) const
1909 return ( mpNumExport != NULL )
1910 ? mpNumExport->ForceSystemLanguage( nFormat ) : nFormat;
1914 OUString SvXMLExport::AddEmbeddedGraphicObject( const OUString& rGraphicObjectURL )
1916 OUString sRet( rGraphicObjectURL );
1917 if( 0 == rGraphicObjectURL.compareTo( msGraphicObjectProtocol,
1918 msGraphicObjectProtocol.getLength() ) &&
1919 mxGraphicResolver.is() )
1921 if( (getExportFlags() & EXPORT_EMBEDDED) == 0 )
1922 sRet = mxGraphicResolver->resolveGraphicObjectURL( rGraphicObjectURL );
1923 else
1924 sRet = OUString();
1926 else
1927 sRet = GetRelativeReference( sRet );
1929 return sRet;
1932 sal_Bool SvXMLExport::AddEmbeddedGraphicObjectAsBase64( const OUString& rGraphicObjectURL )
1934 sal_Bool bRet = sal_False;
1936 if( (getExportFlags() & EXPORT_EMBEDDED) != 0 &&
1937 0 == rGraphicObjectURL.compareTo( msGraphicObjectProtocol,
1938 msGraphicObjectProtocol.getLength() ) &&
1939 mxGraphicResolver.is() )
1941 Reference< XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1943 if( xStmResolver.is() )
1945 Reference< XInputStream > xIn( xStmResolver->getInputStream( rGraphicObjectURL ) );
1947 if( xIn.is() )
1949 XMLBase64Export aBase64Exp( *this );
1950 bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
1955 return bRet;
1958 OUString SvXMLExport::AddEmbeddedObject( const OUString& rEmbeddedObjectURL )
1960 OUString sRet;
1961 if( (0 == rEmbeddedObjectURL.compareTo( msEmbeddedObjectProtocol,
1962 msEmbeddedObjectProtocol.getLength() ) ||
1963 0 == rEmbeddedObjectURL.compareTo( msGraphicObjectProtocol,
1964 msGraphicObjectProtocol.getLength() ) ) &&
1965 mxEmbeddedResolver.is() )
1967 sRet =
1968 mxEmbeddedResolver->resolveEmbeddedObjectURL( rEmbeddedObjectURL );
1970 else
1971 sRet = GetRelativeReference( rEmbeddedObjectURL );
1973 return sRet;
1976 sal_Bool SvXMLExport::AddEmbeddedObjectAsBase64( const OUString& rEmbeddedObjectURL )
1978 sal_Bool bRet = sal_False;
1979 if( (0 == rEmbeddedObjectURL.compareTo( msEmbeddedObjectProtocol,
1980 msEmbeddedObjectProtocol.getLength() ) ||
1981 0 == rEmbeddedObjectURL.compareTo( msGraphicObjectProtocol,
1982 msGraphicObjectProtocol.getLength() ) ) &&
1983 mxEmbeddedResolver.is() )
1985 Reference < XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
1986 if( xNA.is() )
1988 Any aAny = xNA->getByName( rEmbeddedObjectURL );
1989 Reference < XInputStream > xIn;
1990 aAny >>= xIn;
1991 if( xIn.is() )
1993 XMLBase64Export aBase64Exp( *this );
1994 bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
1999 return bRet;
2002 OUString SvXMLExport::EncodeStyleName(
2003 const OUString& rName,
2004 sal_Bool *pEncoded ) const
2006 return GetMM100UnitConverter().encodeStyleName( rName, pEncoded );
2009 ProgressBarHelper* SvXMLExport::GetProgressBarHelper()
2011 if (!mpProgressBarHelper)
2013 mpProgressBarHelper = new ProgressBarHelper(mxStatusIndicator, sal_True);
2015 if (mxExportInfo.is())
2017 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
2018 if (xPropertySetInfo.is())
2020 OUString sProgressRange(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSRANGE));
2021 OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
2022 OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
2023 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
2024 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
2025 xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
2026 xPropertySetInfo->hasPropertyByName(sProgressRange))
2028 uno::Any aAny;
2029 sal_Int32 nProgressMax(0);
2030 sal_Int32 nProgressCurrent(0);
2031 sal_Int32 nProgressRange(0);
2032 aAny = mxExportInfo->getPropertyValue(sProgressRange);
2033 if (aAny >>= nProgressRange)
2034 mpProgressBarHelper->SetRange(nProgressRange);
2035 aAny = mxExportInfo->getPropertyValue(sProgressMax);
2036 if (aAny >>= nProgressMax)
2037 mpProgressBarHelper->SetReference(nProgressMax);
2038 aAny = mxExportInfo->getPropertyValue(sProgressCurrent);
2039 if (aAny >>= nProgressCurrent)
2040 mpProgressBarHelper->SetValue(nProgressCurrent);
2042 if (xPropertySetInfo->hasPropertyByName(sRepeat))
2044 uno::Any aAny = mxExportInfo->getPropertyValue(sRepeat);
2045 if (aAny.getValueType() == getBooleanCppuType())
2046 mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
2047 else {
2048 DBG_ERRORFILE("why is it no boolean?");
2054 return mpProgressBarHelper;
2057 XMLEventExport& SvXMLExport::GetEventExport()
2059 if( NULL == mpEventExport)
2061 // create EventExport on demand
2062 mpEventExport = new XMLEventExport(*this, NULL);
2064 // and register standard handlers + names
2065 OUString sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic"));
2066 mpEventExport->AddHandler(sStarBasic, new XMLStarBasicExportHandler());
2067 OUString sScript(RTL_CONSTASCII_USTRINGPARAM("Script"));
2068 mpEventExport->AddHandler(sScript, new XMLScriptExportHandler());
2069 mpEventExport->AddTranslationTable(aStandardEventTable);
2072 return *mpEventExport;
2075 XMLImageMapExport& SvXMLExport::GetImageMapExport()
2077 // image map export, create on-demand
2078 if( NULL == mpImageMapExport )
2080 mpImageMapExport = new XMLImageMapExport(*this);
2083 return *mpImageMapExport;
2086 // XUnoTunnel & co
2087 const uno::Sequence< sal_Int8 > & SvXMLExport::getUnoTunnelId() throw()
2089 static uno::Sequence< sal_Int8 > * pSeq = 0;
2090 if( !pSeq )
2092 Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
2093 if( !pSeq )
2095 static uno::Sequence< sal_Int8 > aSeq( 16 );
2096 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
2097 pSeq = &aSeq;
2100 return *pSeq;
2103 SvXMLExport* SvXMLExport::getImplementation( uno::Reference< uno::XInterface > xInt ) throw()
2105 uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
2106 if( xUT.is() )
2108 return
2109 reinterpret_cast<SvXMLExport*>(
2110 sal::static_int_cast<sal_IntPtr>(
2111 xUT->getSomething( SvXMLExport::getUnoTunnelId())));
2113 else
2114 return NULL;
2117 // XUnoTunnel
2118 sal_Int64 SAL_CALL SvXMLExport::getSomething( const uno::Sequence< sal_Int8 >& rId )
2119 throw( uno::RuntimeException )
2121 if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2122 rId.getConstArray(), 16 ) )
2124 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2126 return 0;
2129 sal_Bool SvXMLExport::ExportEmbeddedOwnObject( Reference< XComponent >& rComp )
2131 OUString sFilterService;
2132 bool bIsChart = false;
2134 Reference < lang::XServiceInfo > xServiceInfo( rComp, UNO_QUERY );
2135 if( xServiceInfo.is() )
2137 const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
2138 while( pEntry->sModelService )
2140 OUString sModelService( pEntry->sModelService,
2141 pEntry->nModelServiceLen,
2142 RTL_TEXTENCODING_ASCII_US );
2143 if( xServiceInfo->supportsService( sModelService ) )
2145 sFilterService = OUString( pEntry->sFilterService,
2146 pEntry->nFilterServiceLen,
2147 RTL_TEXTENCODING_ASCII_US );
2148 bIsChart = sModelService.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( XML_MODEL_SERVICE_CHART ));
2149 break;
2151 pEntry++;
2155 OSL_ENSURE( sFilterService.getLength(), "no export filter for own object" );
2157 if( !sFilterService.getLength() )
2158 return sal_False;
2160 Reference < XDocumentHandler > xHdl =
2161 new XMLEmbeddedObjectExportFilter( mxHandler );
2163 Sequence < Any > aArgs( 1 );
2164 // #144135# the filters for embedded objects in flat format are always
2165 // instantiated as Oasis filters and transformed afterwards. Therefore, all
2166 // special handling that is done if the exportFlags do not contain
2167 // EXPORT_OASIS must be changed to properties being passed in the info
2168 // propertyset
2170 if( ! (getExportFlags() & EXPORT_OASIS) &&
2171 bIsChart )
2173 static ::comphelper::PropertyMapEntry aInfoMap[] =
2175 { RTL_CONSTASCII_STRINGPARAM("ExportTableNumberList"), 0, &::getBooleanCppuType(), PropertyAttribute::MAYBEVOID, 0},
2176 { NULL, 0, 0, NULL, 0, 0 }
2178 Reference< XPropertySet > xInfoProp(
2179 ::comphelper::GenericPropertySet_CreateInstance(
2180 new ::comphelper::PropertySetInfo( aInfoMap )));
2182 if( bIsChart )
2183 xInfoProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ExportTableNumberList")), makeAny( true ));
2185 aArgs.realloc( 2 );
2186 aArgs[1] <<= xInfoProp;
2188 aArgs[0] <<= xHdl;
2190 // #110680#
2191 // Reference< lang::XMultiServiceFactory > xServiceFactory = comphelper::getProcessServiceFactory();
2192 Reference< lang::XMultiServiceFactory > xServiceFactory = getServiceFactory();
2194 Reference< document::XExporter > xExporter(
2195 xServiceFactory->createInstanceWithArguments( sFilterService, aArgs),
2196 UNO_QUERY);
2197 OSL_ENSURE( xExporter.is(),
2198 "can't instantiate export filter component for own object" );
2199 if( !xExporter.is() )
2200 return sal_False;
2202 xExporter->setSourceDocument( rComp );
2204 Reference<XFilter> xFilter( xExporter, UNO_QUERY );
2206 Sequence < PropertyValue > aMediaDesc( 0 );
2207 return xFilter->filter( aMediaDesc );
2210 OUString SvXMLExport::GetRelativeReference(const OUString& rValue)
2212 OUString sValue( rValue );
2213 // #i65474# handling of fragment URLs ("#....") is undefined
2214 // they are stored 'as is'
2215 uno::Reference< uri::XUriReference > xUriRef;
2216 if(sValue.getLength() && sValue.getStr()[0] != '#')
2220 xUriRef = mpImpl->mxUriReferenceFactory->parse( rValue );
2221 if( xUriRef.is() && !xUriRef->isAbsolute() )
2223 //#i61943# relative URLs need special handling
2224 INetURLObject aTemp( mpImpl->msPackageURI );
2225 bool bWasAbsolute = false;
2226 sValue = aTemp.smartRel2Abs(sValue, bWasAbsolute ).GetMainURL(INetURLObject::DECODE_TO_IURI);
2229 catch( uno::Exception& )
2233 OUString sRet = sValue;
2234 if( xUriRef.is() )//no conversion for empty values or for fragments
2236 //conversion for matching schemes only
2237 if( xUriRef->getScheme() == mpImpl->msPackageURIScheme )
2239 sValue = INetURLObject::GetRelURL( msOrigFileName, sValue,
2240 INetURLObject::WAS_ENCODED, INetURLObject::DECODE_TO_IURI, RTL_TEXTENCODING_UTF8, INetURLObject::FSYS_DETECT);
2243 return sValue;
2246 void SvXMLExport::StartElement(sal_uInt16 nPrefix,
2247 enum ::xmloff::token::XMLTokenEnum eName,
2248 sal_Bool bIgnWSOutside )
2250 StartElement(_GetNamespaceMap().GetQNameByKey( nPrefix,
2251 GetXMLToken(eName) ), bIgnWSOutside);
2254 void SvXMLExport::StartElement(const OUString& rName,
2255 sal_Bool bIgnWSOutside )
2257 if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
2261 if( bIgnWSOutside && ((mnExportFlags & EXPORT_PRETTY) == EXPORT_PRETTY))
2262 mxHandler->ignorableWhitespace( msWS );
2263 mxHandler->startElement( rName, GetXAttrList() );
2265 catch ( SAXInvalidCharacterException& e )
2267 Sequence<OUString> aPars(1);
2268 aPars[0] = rName;
2269 SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, NULL );
2271 catch ( SAXException& e )
2273 Sequence<OUString> aPars(1);
2274 aPars[0] = rName;
2275 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2276 aPars, e.Message, NULL );
2279 ClearAttrList();
2280 ++mpImpl->mDepth; // increment nesting depth counter
2283 void SvXMLExport::Characters(const ::rtl::OUString& rChars)
2285 if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
2289 mxHandler->characters(rChars);
2291 catch ( SAXInvalidCharacterException& e )
2293 Sequence<OUString> aPars(1);
2294 aPars[0] = rChars;
2295 SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, NULL );
2297 catch ( SAXException& e )
2299 Sequence<OUString> aPars(1);
2300 aPars[0] = rChars;
2301 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2302 aPars, e.Message, NULL );
2307 void SvXMLExport::EndElement(sal_uInt16 nPrefix,
2308 enum ::xmloff::token::XMLTokenEnum eName,
2309 sal_Bool bIgnWSInside )
2311 EndElement(_GetNamespaceMap().GetQNameByKey( nPrefix, GetXMLToken(eName) ),
2312 bIgnWSInside);
2315 void SvXMLExport::EndElement(const OUString& rName,
2316 sal_Bool bIgnWSInside )
2318 // decrement nesting depth counter & (maybe) restore namespace map
2319 --mpImpl->mDepth;
2320 if (!mpImpl->mNamespaceMaps.empty() &&
2321 (mpImpl->mNamespaceMaps.top().second == mpImpl->mDepth))
2323 delete mpNamespaceMap;
2324 mpNamespaceMap = mpImpl->mNamespaceMaps.top().first;
2325 mpImpl->mNamespaceMaps.pop();
2327 OSL_ENSURE(mpImpl->mNamespaceMaps.empty() ||
2328 (mpImpl->mNamespaceMaps.top().second < mpImpl->mDepth),
2329 "SvXMLExport: NamespaceMaps corrupted");
2331 if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
2335 if( bIgnWSInside && ((mnExportFlags & EXPORT_PRETTY) == EXPORT_PRETTY))
2336 mxHandler->ignorableWhitespace( msWS );
2337 mxHandler->endElement( rName );
2339 catch ( SAXException& e )
2341 Sequence<OUString> aPars(1);
2342 aPars[0] = rName;
2343 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2344 aPars, e.Message, NULL );
2349 void SvXMLExport::IgnorableWhitespace()
2351 if ((mnExportFlags & EXPORT_PRETTY) != EXPORT_PRETTY)
2352 return;
2354 if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
2358 mxHandler->ignorableWhitespace( msWS );
2360 catch ( SAXException& e )
2362 Sequence<OUString> aPars(0);
2363 SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2364 aPars, e.Message, NULL );
2370 void SvXMLExport::SetError(
2371 sal_Int32 nId,
2372 const Sequence<OUString>& rMsgParams,
2373 const OUString& rExceptionMessage,
2374 const Reference<XLocator>& rLocator )
2376 // allow multi-threaded access to the cancel() method
2377 static ::vos::OMutex aMutex;
2378 ::vos::OGuard aGuard(aMutex);
2380 // maintain error flags
2381 if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
2382 mnErrorFlags |= ERROR_ERROR_OCCURED;
2383 if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
2384 mnErrorFlags |= ERROR_WARNING_OCCURED;
2385 if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
2386 mnErrorFlags |= ERROR_DO_NOTHING;
2388 // create error lsit on demand
2389 if ( mpXMLErrors == NULL )
2390 mpXMLErrors = new XMLErrors();
2392 // save error information
2393 mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage, rLocator );
2396 void SvXMLExport::SetError(
2397 sal_Int32 nId,
2398 const Sequence<OUString>& rMsgParams)
2400 OUString sEmpty;
2401 SetError( nId, rMsgParams, sEmpty, NULL );
2405 XMLErrors* SvXMLExport::GetErrors()
2407 return mpXMLErrors;
2410 void SvXMLExport::DisposingModel()
2412 mxModel.clear();
2413 // --> OD 2006-03-13 #i51726#
2414 meModelType = SvtModuleOptions::E_UNKNOWN_FACTORY;;
2415 // <--
2416 mxEventListener.clear();
2419 // #110680#
2420 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > SvXMLExport::getServiceFactory()
2422 // #110680#
2423 return mxServiceFactory;
2426 uno::Reference< uno::XComponentContext >
2427 SvXMLExport::GetComponentContext() const
2429 return mpImpl->mxComponentContext;
2432 ::comphelper::UnoInterfaceToUniqueIdentifierMapper& SvXMLExport::getInterfaceToIdentifierMapper()
2434 return mpImpl->maInterfaceToIdentifierMapper;
2437 // --> OD 2006-09-27 #i69627#
2438 sal_Bool SvXMLExport::writeOutlineStyleAsNormalListStyle() const
2440 return mpImpl->mbOutlineStyleAsNormalListStyle;
2442 // <--
2444 uno::Reference< embed::XStorage > SvXMLExport::GetTargetStorage()
2446 return mpImpl->mxTargetStorage;
2449 /// returns the currently configured default version for odf export
2450 SvtSaveOptions::ODFDefaultVersion SvXMLExport::getDefaultVersion() const
2452 if( mpImpl )
2453 return mpImpl->maSaveOptions.GetODFDefaultVersion();
2455 // fatal error, use current version as default
2456 return SvtSaveOptions::ODFVER_012;
2459 ::rtl::OUString SvXMLExport::GetStreamName() const
2461 return mpImpl->mStreamName;
2464 void
2465 SvXMLExport::AddAttributeXmlId(uno::Reference<uno::XInterface> const & i_xIfc)
2467 // check version >= 1.2
2468 switch (getDefaultVersion()) {
2469 case SvtSaveOptions::ODFVER_011: // fall thru
2470 case SvtSaveOptions::ODFVER_010: return;
2471 default: break;
2473 const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
2474 uno::UNO_QUERY);
2475 //FIXME not yet...
2476 // OSL_ENSURE(xMeta.is(), "xml:id: not XMetadatable");
2477 if ( xMeta.is() )
2479 const beans::StringPair mdref( xMeta->getMetadataReference() );
2480 if ( !mdref.Second.equalsAscii("") )
2482 const ::rtl::OUString streamName( GetStreamName() );
2483 if ( streamName.getLength() )
2485 if ( streamName.equals(mdref.First) )
2487 AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2489 else
2491 OSL_ENSURE(false, "SvXMLExport::AddAttributeXmlId: "
2492 "invalid stream name");
2495 else
2497 // FIXME: this is ugly
2498 // there is no stream name (e.g. XSLT, flat-xml format)!
2499 // but how do we ensure uniqueness in this case?
2500 // a) just omit styles.xml ids -- they are unlikely anyway...
2501 // b) somehow find out whether we are currently exporting styles
2502 // or content, and prefix "s" or "c" => unique
2503 if ( mdref.First.equalsAscii("content.xml") )
2505 AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2507 else
2509 OSL_TRACE("SvXMLExport::AddAttributeXmlId: "
2510 "no stream name given: dropping styles.xml xml:id");
2517 void
2518 SvXMLExport::AddAttributesRDFa(
2519 uno::Reference<text::XTextContent> const & i_xTextContent)
2521 // check version >= 1.2
2522 switch (getDefaultVersion()) {
2523 case SvtSaveOptions::ODFVER_011: // fall thru
2524 case SvtSaveOptions::ODFVER_010: return;
2525 default: break;
2528 const uno::Reference<rdf::XMetadatable> xMeta(
2529 i_xTextContent, uno::UNO_QUERY);
2530 if (!xMeta.is() || !xMeta->getMetadataReference().Second.getLength())
2532 return; // no xml:id => no RDFa
2535 if (!mpImpl->mpRDFaHelper.get())
2537 mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaExportHelper(*this) );
2539 mpImpl->mpRDFaHelper->AddRDFa(xMeta);
2542 // --> OD 2008-11-26 #158694#
2543 sal_Bool SvXMLExport::exportTextNumberElement() const
2545 return mpImpl->mbExportTextNumberElement;
2547 // <--
2549 sal_Bool SvXMLExport::SetNullDateOnUnitConverter()
2551 // if the null date has already been set, don't set it again (performance)
2552 if (!mpImpl->mbNullDateInitialized)
2553 mpImpl->mbNullDateInitialized = GetMM100UnitConverter().setNullDate(GetModel());
2555 return mpImpl->mbNullDateInitialized;
2558 //=============================================================================
2560 void SvXMLElementExport::StartElement( SvXMLExport& rExp,
2561 sal_uInt16 nPrefixKey,
2562 const OUString& rLName,
2563 sal_Bool bIWSOutside )
2565 aName = rExp.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
2566 rExp.StartElement(aName, bIWSOutside);
2569 SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
2570 sal_uInt16 nPrefixKey,
2571 const sal_Char *pLName,
2572 sal_Bool bIWSOutside,
2573 sal_Bool bIWSInside ) :
2574 rExport( rExp ),
2575 bIgnWS( bIWSInside ),
2576 bDoSomething( sal_True )
2578 OUString sLName( OUString::createFromAscii(pLName) );
2579 StartElement( rExp, nPrefixKey, sLName, bIWSOutside );
2582 SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
2583 sal_uInt16 nPrefixKey,
2584 const OUString& rLName,
2585 sal_Bool bIWSOutside,
2586 sal_Bool bIWSInside ) :
2587 rExport( rExp ),
2588 bIgnWS( bIWSInside ),
2589 bDoSomething( sal_True )
2591 StartElement( rExp, nPrefixKey, rLName, bIWSOutside );
2594 SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
2595 sal_uInt16 nPrefixKey,
2596 enum XMLTokenEnum eLName,
2597 sal_Bool bIWSOutside,
2598 sal_Bool bIWSInside ) :
2599 rExport( rExp ),
2600 bIgnWS( bIWSInside ),
2601 bDoSomething( sal_True )
2603 StartElement( rExp, nPrefixKey, GetXMLToken(eLName), bIWSOutside );
2606 SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
2607 sal_Bool bDoSth,
2608 sal_uInt16 nPrefixKey,
2609 const sal_Char *pLName,
2610 sal_Bool bIWSOutside,
2611 sal_Bool bIWSInside ) :
2612 rExport( rExp ),
2613 bIgnWS( bIWSInside ),
2614 bDoSomething( bDoSth )
2616 if( bDoSomething )
2618 OUString sLName( OUString::createFromAscii(pLName) );
2619 StartElement( rExp, nPrefixKey, sLName, bIWSOutside );
2623 SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
2624 sal_Bool bDoSth,
2625 sal_uInt16 nPrefixKey,
2626 const OUString& rLName,
2627 sal_Bool bIWSOutside,
2628 sal_Bool bIWSInside ) :
2629 rExport( rExp ),
2630 bIgnWS( bIWSInside ),
2631 bDoSomething( bDoSth )
2633 if( bDoSomething )
2634 StartElement( rExp, nPrefixKey, rLName, bIWSOutside );
2637 SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
2638 sal_Bool bDoSth,
2639 sal_uInt16 nPrefixKey,
2640 enum XMLTokenEnum eLName,
2641 sal_Bool bIWSOutside,
2642 sal_Bool bIWSInside ) :
2643 rExport( rExp ),
2644 bIgnWS( bIWSInside ),
2645 bDoSomething( bDoSth )
2647 if( bDoSomething )
2648 StartElement( rExport, nPrefixKey, GetXMLToken(eLName), bIWSOutside );
2651 SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
2652 const OUString& rQName,
2653 sal_Bool bIWSOutside,
2654 sal_Bool bIWSInside ) :
2655 rExport( rExp ),
2656 bIgnWS( bIWSInside ),
2657 bDoSomething( sal_True )
2659 aName = rQName;
2660 rExp.StartElement( rQName, bIWSOutside );
2663 SvXMLElementExport::~SvXMLElementExport()
2665 if( bDoSomething )
2667 rExport.EndElement( aName, bIgnWS );