xref: /aoo42x/main/xmloff/source/core/xmlexp.cxx (revision 1912a402)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 #ifdef PRECOMPILED
28 #include "filt_pch.hxx"
29 #endif
30 #include "unointerfacetouniqueidentifiermapper.hxx"
31 #include <osl/mutex.hxx>
32 #include <rtl/uuid.h>
33 #include <tools/debug.hxx>
34 #include <tools/urlobj.hxx>
35 #include <comphelper/genericpropertyset.hxx>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/io/XInputStream.hpp>
38 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
39 #include <com/sun/star/xml/sax/SAXInvalidCharacterException.hpp>
40 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
41 #include <com/sun/star/uri/UriReferenceFactory.hpp>
42 #include <comphelper/processfactory.hxx>
43 #include <comphelper/configurationhelper.hxx>
44 #include <xmloff/attrlist.hxx>
45 #include <xmloff/nmspmap.hxx>
46 #include <xmloff/xmluconv.hxx>
47 #include "xmloff/xmlnmspe.hxx"
48 #include <xmloff/xmltoken.hxx>
49 #include <xmloff/xmlexp.hxx>
50 #include <xmloff/xmlnumfe.hxx>
51 #include <xmloff/xmlmetae.hxx>
52 #include <xmloff/XMLSettingsExportContext.hxx>
53 #include <xmloff/families.hxx>
54 #include <xmloff/XMLEventExport.hxx>
55 #include "XMLStarBasicExportHandler.hxx"
56 #include "XMLScriptExportHandler.hxx"
57 #include <xmloff/SettingsExportHelper.hxx>
58 #include <com/sun/star/container/XNameAccess.hpp>
59 #include <com/sun/star/container/XIndexContainer.hpp>
60 #include <com/sun/star/document/XEventsSupplier.hpp>
61 #include <com/sun/star/document/XViewDataSupplier.hpp>
62 #include <xmloff/GradientStyle.hxx>
63 #include <xmloff/HatchStyle.hxx>
64 #include <xmloff/ImageStyle.hxx>
65 #include <TransGradientStyle.hxx>
66 #include <xmloff/MarkerStyle.hxx>
67 #include <xmloff/DashStyle.hxx>
68 #include <xmloff/XMLFontAutoStylePool.hxx>
69 #include "XMLImageMapExport.hxx"
70 #include "XMLBase64Export.hxx"
71 #include "xmloff/xmlerror.hxx"
72 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
73 #include <com/sun/star/beans/PropertyAttribute.hpp>
74 #include "xmloff/XMLFilterServiceNames.h"
75 #include "xmloff/XMLEmbeddedObjectExportFilter.hxx"
76 #include "XMLBasicExportFilter.hxx"
77 #include <vos/mutex.hxx>
78 #include <rtl/logfile.hxx>
79 #include <cppuhelper/implbase1.hxx>
80 #include <comphelper/extract.hxx>
81 #include "PropertySetMerger.hxx"
82 
83 #include "svl/urihelper.hxx"
84 #include "xmloff/xformsexport.hxx"
85 
86 #include <unotools/docinfohelper.hxx>
87 #include <unotools/bootstrap.hxx>
88 #include <unotools/configmgr.hxx>
89 #include <tools/inetdef.hxx>
90 #include <com/sun/star/document/XDocumentProperties.hpp>
91 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
92 
93 #include <com/sun/star/rdf/XMetadatable.hpp>
94 #include "RDFaExportHelper.hxx"
95 
96 
97 using ::rtl::OUString;
98 
99 using namespace ::osl;
100 using namespace ::com::sun::star;
101 using namespace ::com::sun::star::uno;
102 using namespace ::com::sun::star::frame;
103 using namespace ::com::sun::star::container;
104 using namespace ::com::sun::star::lang;
105 using namespace ::com::sun::star::document;
106 using namespace ::com::sun::star::beans;
107 using namespace ::com::sun::star::xml::sax;
108 using namespace ::com::sun::star::io;
109 using namespace ::xmloff::token;
110 
111 sal_Char __READONLY_DATA sXML_1_1[] = "1.1";
112 sal_Char __READONLY_DATA sXML_1_2[] = "1.2";
113 
114 const sal_Char *sOpenOfficeOrgProject ="OpenOffice.org_project";
115 
116 // #i115030#: the XSLT is not finished, and not available via HTTP
117 const sal_Char s_grddl_xsl[] = "http://FIXME";
118 
119 #define LOGFILE_AUTHOR "mb93740"
120 
121 #define XML_MODEL_SERVICE_WRITER	"com.sun.star.text.TextDocument"
122 #define XML_MODEL_SERVICE_CALC		"com.sun.star.sheet.SpreadsheetDocument"
123 #define XML_MODEL_SERVICE_DRAW		"com.sun.star.drawing.DrawingDocument"
124 #define XML_MODEL_SERVICE_IMPRESS	"com.sun.star.presentation.PresentationDocument"
125 #define XML_MODEL_SERVICE_MATH		"com.sun.star.formula.FormulaProperties"
126 #define XML_MODEL_SERVICE_CHART		"com.sun.star.chart.ChartDocument"
127 
128 #define XML_USEPRETTYPRINTING       "UsePrettyPrinting"
129 
130 #define C2U(cChar) OUString( RTL_CONSTASCII_USTRINGPARAM(cChar) )
131 
132 struct XMLServiceMapEntry_Impl
133 {
134 	const sal_Char *sModelService;
135 	sal_Int32	   nModelServiceLen;
136 	const sal_Char *sFilterService;
137 	sal_Int32	   nFilterServiceLen;
138 };
139 
140 #define SERVICE_MAP_ENTRY( app ) \
141 	{ XML_MODEL_SERVICE_##app, sizeof(XML_MODEL_SERVICE_##app)-1, \
142 	  XML_EXPORT_FILTER_##app, sizeof(XML_EXPORT_FILTER_##app)-1 }
143 
144 const XMLServiceMapEntry_Impl aServiceMap[] =
145 {
146 	SERVICE_MAP_ENTRY( WRITER ),
147 	SERVICE_MAP_ENTRY( CALC ),
148 	SERVICE_MAP_ENTRY( IMPRESS ),// Impress supports DrawingDocument, too, so
149 	SERVICE_MAP_ENTRY( DRAW ),	 // it must appear before Draw
150 	SERVICE_MAP_ENTRY( MATH ),
151 	SERVICE_MAP_ENTRY( CHART ),
152 	{ 0, 0, 0, 0 }
153 };
154 
155 //==============================================================================
156 
157 class SAL_DLLPRIVATE SettingsExportFacade : public ::xmloff::XMLSettingsExportContext
158 {
159 public:
160     SettingsExportFacade( SvXMLExport& i_rExport )
161         :m_rExport( i_rExport )
162     {
163     }
164 
165     virtual ~SettingsExportFacade()
166     {
167     }
168 
169     virtual void    AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName,
170 				                  const ::rtl::OUString& i_rValue );
171     virtual void    AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName,
172 				                  enum ::xmloff::token::XMLTokenEnum i_eValue );
173 
174     virtual void    StartElement( enum ::xmloff::token::XMLTokenEnum i_eName,
175                                   const sal_Bool i_bIgnoreWhitespace );
176     virtual void    EndElement(   const sal_Bool i_bIgnoreWhitespace );
177 
178     virtual void    Characters( const ::rtl::OUString& i_rCharacters );
179 
180     virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
181                     GetServiceFactory() const;
182 private:
183     SvXMLExport&                    m_rExport;
184     ::std::stack< ::rtl::OUString > m_aElements;
185 };
186 
187 void SettingsExportFacade::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue )
188 {
189     m_rExport.AddAttribute( XML_NAMESPACE_CONFIG, i_eName, i_rValue );
190 }
191 
192 void SettingsExportFacade::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue )
193 {
194     m_rExport.AddAttribute( XML_NAMESPACE_CONFIG, i_eName, i_eValue );
195 }
196 
197 void SettingsExportFacade::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace )
198 {
199     const ::rtl::OUString sElementName( m_rExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_CONFIG, GetXMLToken( i_eName ) ) );
200     m_rExport.StartElement( sElementName, i_bIgnoreWhitespace );
201     m_aElements.push( sElementName );
202 }
203 
204 void SettingsExportFacade::EndElement( const sal_Bool i_bIgnoreWhitespace )
205 {
206     const ::rtl::OUString sElementName( m_aElements.top() );
207     m_rExport.EndElement( sElementName, i_bIgnoreWhitespace );
208     m_aElements.pop();
209 }
210 
211 void SettingsExportFacade::Characters( const ::rtl::OUString& i_rCharacters )
212 {
213     m_rExport.GetDocHandler()->characters( i_rCharacters );
214 }
215 
216 Reference< XMultiServiceFactory > SettingsExportFacade::GetServiceFactory() const
217 {
218     return m_rExport.getServiceFactory();
219 }
220 
221 //==============================================================================
222 
223 class SvXMLExportEventListener : public cppu::WeakImplHelper1<
224 							com::sun::star::lang::XEventListener >
225 {
226 private:
227 	SvXMLExport*	pExport;
228 
229 public:
230 							SvXMLExportEventListener(SvXMLExport* pExport);
231 	virtual					~SvXMLExportEventListener();
232 
233 							// XEventListener
234 	virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException);
235 };
236 
237 SvXMLExportEventListener::SvXMLExportEventListener(SvXMLExport* pTempExport)
238 	: pExport(pTempExport)
239 {
240 }
241 
242 SvXMLExportEventListener::~SvXMLExportEventListener()
243 {
244 }
245 
246 // XEventListener
247 void SAL_CALL SvXMLExportEventListener::disposing( const lang::EventObject& )
248 	throw(uno::RuntimeException)
249 {
250 	if (pExport)
251 	{
252 		pExport->DisposingModel();
253 		pExport = NULL;
254 	}
255 }
256 
257 //==============================================================================
258 
259 class SvXMLExport_Impl
260 {
261 public:
262     SvXMLExport_Impl();
263 
264     ::comphelper::UnoInterfaceToUniqueIdentifierMapper  maInterfaceToIdentifierMapper;
265     uno::Reference< uri::XUriReferenceFactory >         mxUriReferenceFactory;
266     rtl::OUString                                       msPackageURI;
267     rtl::OUString                                       msPackageURIScheme;
268     // --> OD 2006-09-27 #i69627#
269     sal_Bool                                            mbOutlineStyleAsNormalListStyle;
270     // <--
271     // --> PB 2007-07-06 #i146851#
272     sal_Bool                                            mbSaveBackwardCompatibleODF;
273     // <--
274 
275 	uno::Reference< embed::XStorage >					mxTargetStorage;
276 
277 	SvtSaveOptions										maSaveOptions;
278 
279     /// relative path of stream in package, e.g. "someobject/content.xml"
280     ::rtl::OUString mStreamPath;
281 
282     const uno::Reference< uno::XComponentContext > mxComponentContext;
283 
284     /// name of stream in package, e.g., "content.xml"
285     ::rtl::OUString mStreamName;
286 
287     /// stack of backed up namespace maps
288     /// long: depth at which namespace map has been backed up into the stack
289     ::std::stack< ::std::pair< SvXMLNamespaceMap *, long > > mNamespaceMaps;
290     /// counts depth (number of open elements/start tags)
291     long mDepth;
292 
293     ::std::auto_ptr< ::xmloff::RDFaExportHelper> mpRDFaHelper;
294 
295     // --> OD 2008-11-26 #158694#
296     sal_Bool                                            mbExportTextNumberElement;
297     // <--
298     sal_Bool                                            mbNullDateInitialized;
299 
300     void SetSchemeOf( const ::rtl::OUString& rOrigFileName )
301     {
302         sal_Int32 nSep = rOrigFileName.indexOf(':');
303         if( nSep != -1 )
304             msPackageURIScheme = rOrigFileName.copy( 0, nSep );
305     }
306 };
307 
308 SvXMLExport_Impl::SvXMLExport_Impl()
309     // --> OD 2006-09-27 #i69627#
310     : mbOutlineStyleAsNormalListStyle( false )
311     // <--
312     // --> PB 2007-07-06 #i146851#
313         ,mbSaveBackwardCompatibleODF( sal_True )
314     // <--
315         ,mxComponentContext( ::comphelper::getProcessComponentContext() )
316         ,mStreamName()
317         ,mNamespaceMaps()
318         ,mDepth(0)
319         ,mpRDFaHelper() // lazy
320     // --> OD 2008-11-26 #158694#
321         ,mbExportTextNumberElement( sal_False )
322     // <--
323         ,mbNullDateInitialized( sal_False )
324 {
325     OSL_ENSURE(mxComponentContext.is(), "SvXMLExport: no ComponentContext");
326     if (!mxComponentContext.is()) throw uno::RuntimeException();
327     mxUriReferenceFactory = uri::UriReferenceFactory::create(
328         mxComponentContext );
329 }
330 
331 //==============================================================================
332 
333 void SvXMLExport::SetDocHandler( const uno::Reference< xml::sax::XDocumentHandler > &rHandler )
334 {
335 	mxHandler = rHandler;
336 	mxExtHandler = uno::Reference<xml::sax::XExtendedDocumentHandler>( mxHandler, UNO_QUERY );
337 }
338 
339 void SvXMLExport::_InitCtor()
340 {
341     // note: it is not necessary to add XML_NP_XML (it is declared implicitly)
342 	if( (getExportFlags() & ~EXPORT_OASIS) != 0 )
343 	{
344 		mpNamespaceMap->Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE );
345 		mpNamespaceMap->Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
346 	}
347 	if( (getExportFlags() & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS) ) != 0 )
348 	{
349 		mpNamespaceMap->Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
350 	}
351 	if( (getExportFlags() & (EXPORT_META|EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_SETTINGS) ) != 0 )
352 	{
353 		mpNamespaceMap->Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
354 	}
355 	if( (getExportFlags() & EXPORT_SETTINGS) != 0 )
356 	{
357 		mpNamespaceMap->Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG );
358 	}
359 
360 	if( (getExportFlags() & (EXPORT_META|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
361 	{
362 		mpNamespaceMap->Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
363 		mpNamespaceMap->Add( GetXMLToken(XML_NP_META), GetXMLToken(XML_N_META), XML_NAMESPACE_META );
364 	}
365 	if( (getExportFlags() & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_FONTDECLS) ) != 0 )
366 	{
367 		mpNamespaceMap->Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE );
368 	}
369 
370 	// namespaces for documents
371 	if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
372 	{
373 		mpNamespaceMap->Add( GetXMLToken(XML_NP_DC),    GetXMLToken(XML_N_DC),      XML_NAMESPACE_DC );
374 		mpNamespaceMap->Add( GetXMLToken(XML_NP_TEXT),  GetXMLToken(XML_N_TEXT),    XML_NAMESPACE_TEXT );
375 		mpNamespaceMap->Add( GetXMLToken(XML_NP_DRAW),  GetXMLToken(XML_N_DRAW),    XML_NAMESPACE_DRAW );
376 		mpNamespaceMap->Add( GetXMLToken(XML_NP_DR3D),  GetXMLToken(XML_N_DR3D),    XML_NAMESPACE_DR3D );
377 		mpNamespaceMap->Add( GetXMLToken(XML_NP_SVG),   GetXMLToken(XML_N_SVG_COMPAT),  XML_NAMESPACE_SVG );
378 		mpNamespaceMap->Add( GetXMLToken(XML_NP_CHART), GetXMLToken(XML_N_CHART),   XML_NAMESPACE_CHART );
379         mpNamespaceMap->Add( GetXMLToken(XML_NP_RPT),   GetXMLToken(XML_N_RPT),     XML_NAMESPACE_REPORT );
380 		mpNamespaceMap->Add( GetXMLToken(XML_NP_TABLE), GetXMLToken(XML_N_TABLE),   XML_NAMESPACE_TABLE );
381 		mpNamespaceMap->Add( GetXMLToken(XML_NP_NUMBER),GetXMLToken(XML_N_NUMBER),  XML_NAMESPACE_NUMBER );
382 		mpNamespaceMap->Add( GetXMLToken(XML_NP_OOOW),  GetXMLToken(XML_N_OOOW),    XML_NAMESPACE_OOOW );
383 		mpNamespaceMap->Add( GetXMLToken(XML_NP_OOOC),  GetXMLToken(XML_N_OOOC),    XML_NAMESPACE_OOOC );
384 		mpNamespaceMap->Add( GetXMLToken(XML_NP_OF),    GetXMLToken(XML_N_OF),      XML_NAMESPACE_OF );
385 
386         if (getDefaultVersion() > SvtSaveOptions::ODFVER_012)
387         {
388             mpNamespaceMap->Add(
389                 GetXMLToken(XML_NP_TABLE_EXT), GetXMLToken(XML_N_TABLE_EXT), XML_NAMESPACE_TABLE_EXT);
390         }
391 	}
392 	if( (getExportFlags() & (EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
393 	{
394 		mpNamespaceMap->Add( GetXMLToken(XML_NP_MATH), GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH );
395 		mpNamespaceMap->Add( GetXMLToken(XML_NP_FORM), GetXMLToken(XML_N_FORM), XML_NAMESPACE_FORM );
396 	}
397 	if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS) ) != 0 )
398 	{
399 		mpNamespaceMap->Add( GetXMLToken(XML_NP_SCRIPT), GetXMLToken(XML_N_SCRIPT), XML_NAMESPACE_SCRIPT );
400 		mpNamespaceMap->Add( GetXMLToken(XML_NP_DOM), GetXMLToken(XML_N_DOM), XML_NAMESPACE_DOM );
401 	}
402 	if( (getExportFlags() & EXPORT_CONTENT ) != 0 )
403 	{
404 		mpNamespaceMap->Add( GetXMLToken(XML_NP_XFORMS_1_0), GetXMLToken(XML_N_XFORMS_1_0), XML_NAMESPACE_XFORMS );
405 		mpNamespaceMap->Add( GetXMLToken(XML_NP_XSD), GetXMLToken(XML_N_XSD), XML_NAMESPACE_XSD );
406 		mpNamespaceMap->Add( GetXMLToken(XML_NP_XSI), GetXMLToken(XML_N_XSI), XML_NAMESPACE_XSI );
407 		mpNamespaceMap->Add( GetXMLToken(XML_NP_FIELD), GetXMLToken(XML_N_FIELD), XML_NAMESPACE_FIELD );
408 	}
409     // RDFa: needed for content and header/footer styles
410     if( (getExportFlags() & (EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
411     {
412         mpNamespaceMap->Add( GetXMLToken(XML_NP_XHTML),
413             GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
414     }
415     // GRDDL: to convert RDFa and meta.xml to RDF
416     if( (getExportFlags() & (EXPORT_META|EXPORT_STYLES|EXPORT_AUTOSTYLES|EXPORT_MASTERSTYLES|EXPORT_CONTENT) ) != 0 )
417     {
418         mpNamespaceMap->Add( GetXMLToken(XML_NP_GRDDL),
419             GetXMLToken(XML_N_GRDDL), XML_NAMESPACE_GRDDL );
420     }
421 
422 	mxAttrList = (xml::sax::XAttributeList*)mpAttrList;
423 
424 	msPicturesPath = OUString( RTL_CONSTASCII_USTRINGPARAM( "#Pictures/" ) );
425 	msObjectsPath = OUString( RTL_CONSTASCII_USTRINGPARAM( "#./" ) );
426 	msGraphicObjectProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.GraphicObject:" ) );
427 	msEmbeddedObjectProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.EmbeddedObject:" ) );
428 
429 	if (mxModel.is() && !mxEventListener.is())
430 	{
431 		mxEventListener.set( new SvXMLExportEventListener(this));
432 		mxModel->addEventListener(mxEventListener);
433 	}
434 
435     // --> OD 2006-03-10 #i51726# - determine model type
436     _DetermineModelType();
437     // <--
438 
439 	mbEnableExperimentalOdfExport = getenv("ENABLE_EXPERIMENTAL_ODF_EXPORT") != NULL;
440 
441     // --> PB 2007-07-06 #146851# - load mbSaveBackwardCompatibleODF from configuration
442 
443 	// cl: but only if we do export to current oasis format, old openoffice format *must* always be compatible
444 	if( (getExportFlags() & EXPORT_OASIS) != 0 )
445 	{
446 		sal_Bool bTemp = sal_True;
447 		if ( ::comphelper::ConfigurationHelper::readDirectKey(
448 				getServiceFactory(),
449 				C2U("org.openoffice.Office.Common/"), C2U("Save/Document"), C2U("SaveBackwardCompatibleODF"),
450 				::comphelper::ConfigurationHelper::E_READONLY ) >>= bTemp )
451 		{
452 			mpImpl->mbSaveBackwardCompatibleODF = bTemp;
453 		}
454 	}
455     // <--
456 }
457 
458 // --> OD 2006-03-14 #i51726#
459 void SvXMLExport::_DetermineModelType()
460 {
461     meModelType = SvtModuleOptions::E_UNKNOWN_FACTORY;
462 
463     if ( mxModel.is() )
464     {
465         meModelType = SvtModuleOptions::ClassifyFactoryByModel( mxModel );
466     }
467 }
468 // <--
469 
470 // #110680#
471 SvXMLExport::SvXMLExport(
472 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
473 	MapUnit eDfltUnit, const enum XMLTokenEnum eClass, sal_uInt16 nExportFlags )
474 :	mpImpl( new SvXMLExport_Impl ),
475 	// #110680#
476 	mxServiceFactory(xServiceFactory),
477 	mpAttrList( new SvXMLAttributeList ),
478 	mpNamespaceMap( new SvXMLNamespaceMap ),
479 	// #110680#
480 	mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, eDfltUnit, getServiceFactory() ) ),
481 	mpNumExport(0L),
482 	mpProgressBarHelper( NULL ),
483 	mpEventExport( NULL ),
484 	mpImageMapExport( NULL ),
485 	mpXMLErrors( NULL ),
486 	mbExtended( sal_False ),
487 	meClass( eClass ),
488 	mnExportFlags( nExportFlags ),
489 	mnErrorFlags( ERROR_NO ),
490 	msWS( GetXMLToken(XML_WS) ),
491 	mbSaveLinkedSections(sal_True)
492 {
493 	DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
494 	_InitCtor();
495 }
496 
497 // #110680#
498 SvXMLExport::SvXMLExport(
499 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
500 	const OUString &rFileName,
501 	const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
502 	MapUnit eDfltUnit	)
503 :	mpImpl( new SvXMLExport_Impl ),
504 	// #110680#
505 	mxServiceFactory(xServiceFactory),
506 	mxHandler( rHandler ),
507 	mxExtHandler( rHandler, uno::UNO_QUERY ),
508 	mpAttrList( new SvXMLAttributeList ),
509 	msOrigFileName( rFileName ),
510 	mpNamespaceMap( new SvXMLNamespaceMap ),
511 	// #110680#
512 	mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, eDfltUnit, getServiceFactory() ) ),
513 	mpNumExport(0L),
514 	mpProgressBarHelper( NULL ),
515 	mpEventExport( NULL ),
516 	mpImageMapExport( NULL ),
517 	mpXMLErrors( NULL ),
518 	mbExtended( sal_False ),
519 	meClass( XML_TOKEN_INVALID ),
520 	mnExportFlags( 0 ),
521 	mnErrorFlags( ERROR_NO ),
522 	msWS( GetXMLToken(XML_WS) ),
523 	mbSaveLinkedSections(sal_True)
524 {
525     mpImpl->SetSchemeOf( msOrigFileName );
526     DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
527 	_InitCtor();
528 
529 	if (mxNumberFormatsSupplier.is())
530 		mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
531 }
532 
533 // #110680#
534 SvXMLExport::SvXMLExport(
535 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
536 	const OUString &rFileName,
537 	const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
538 	const Reference< XModel >& rModel,
539 	sal_Int16 eDfltUnit	)
540 :	mpImpl( new SvXMLExport_Impl ),
541 	// #110680#
542 	mxServiceFactory(xServiceFactory),
543 	mxModel( rModel ),
544 	mxHandler( rHandler ),
545 	mxExtHandler( rHandler, uno::UNO_QUERY ),
546 	mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
547 	mpAttrList( new SvXMLAttributeList ),
548 	msOrigFileName( rFileName ),
549 	mpNamespaceMap( new SvXMLNamespaceMap ),
550 	// #110680#
551 	// pUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, SvXMLUnitConverter::GetMapUnit(eDfltUnit) ) ),
552 	mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, SvXMLUnitConverter::GetMapUnit(eDfltUnit), getServiceFactory() ) ),
553 	mpNumExport(0L),
554 	mpProgressBarHelper( NULL ),
555 	mpEventExport( NULL ),
556 	mpImageMapExport( NULL ),
557 	mpXMLErrors( NULL ),
558 	mbExtended( sal_False ),
559 	meClass( XML_TOKEN_INVALID ),
560 	mnExportFlags( 0 ),
561 	mnErrorFlags( ERROR_NO ),
562 	msWS( GetXMLToken(XML_WS) ),
563 	mbSaveLinkedSections(sal_True)
564 {
565     mpImpl->SetSchemeOf( msOrigFileName );
566 	DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
567 	_InitCtor();
568 
569 	if (mxNumberFormatsSupplier.is())
570 		mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
571 }
572 
573 // #110680#
574 SvXMLExport::SvXMLExport(
575 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
576 	const OUString &rFileName,
577 	const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
578 	const Reference< XModel >& rModel,
579 	const Reference< document::XGraphicObjectResolver >& rEmbeddedGraphicObjects,
580 	sal_Int16 eDfltUnit	)
581 :	mpImpl( new SvXMLExport_Impl ),
582 	// #110680#
583 	mxServiceFactory(xServiceFactory),
584 	mxModel( rModel ),
585 	mxHandler( rHandler ),
586 	mxExtHandler( rHandler, uno::UNO_QUERY ),
587 	mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
588 	mxGraphicResolver( rEmbeddedGraphicObjects ),
589 	mpAttrList( new SvXMLAttributeList ),
590 	msOrigFileName( rFileName ),
591 	mpNamespaceMap( new SvXMLNamespaceMap ),
592 	// #110680#
593 	mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, SvXMLUnitConverter::GetMapUnit(eDfltUnit), getServiceFactory() ) ),
594 	mpNumExport(0L),
595 	mpProgressBarHelper( NULL ),
596 	mpEventExport( NULL ),
597 	mpImageMapExport( NULL ),
598 	mpXMLErrors( NULL ),
599 	mbExtended( sal_False ),
600 	meClass( XML_TOKEN_INVALID ),
601 	mnExportFlags( 0 ),
602 	mnErrorFlags( ERROR_NO ),
603 	msWS( GetXMLToken(XML_WS) ),
604 	mbSaveLinkedSections(sal_True)
605 {
606     mpImpl->SetSchemeOf( msOrigFileName );
607 	DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
608 	_InitCtor();
609 
610 	if (mxNumberFormatsSupplier.is())
611 		mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
612 }
613 
614 SvXMLExport::~SvXMLExport()
615 {
616 	delete mpXMLErrors;
617 	delete mpImageMapExport;
618     delete mpEventExport;
619 	delete mpNamespaceMap;
620 	delete mpUnitConv;
621 	if (mpProgressBarHelper || mpNumExport)
622 	{
623 		if (mxExportInfo.is())
624 		{
625 			uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
626 			if (xPropertySetInfo.is())
627 			{
628 				if (mpProgressBarHelper)
629 				{
630 					OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
631 					OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
632                     OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
633 					if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
634 						xPropertySetInfo->hasPropertyByName(sProgressCurrent))
635 					{
636 						sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
637 						sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
638 						uno::Any aAny;
639 						aAny <<= nProgressMax;
640 						mxExportInfo->setPropertyValue(sProgressMax, aAny);
641 						aAny <<= nProgressCurrent;
642 						mxExportInfo->setPropertyValue(sProgressCurrent, aAny);
643 					}
644                     if (xPropertySetInfo->hasPropertyByName(sRepeat))
645                         mxExportInfo->setPropertyValue(sRepeat, cppu::bool2any(mpProgressBarHelper->GetRepeat()));
646 				}
647 				if (mpNumExport && (mnExportFlags & (EXPORT_AUTOSTYLES | EXPORT_STYLES)))
648 				{
649 					OUString sWrittenNumberFormats(RTL_CONSTASCII_USTRINGPARAM(XML_WRITTENNUMBERSTYLES));
650 					if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
651 					{
652 						uno::Sequence<sal_Int32> aWasUsed;
653 						mpNumExport->GetWasUsed(aWasUsed);
654 						uno::Any aAny;
655 						aAny <<= aWasUsed;
656 						mxExportInfo->setPropertyValue(sWrittenNumberFormats, aAny);
657 					}
658 				}
659 			}
660 		}
661 		delete mpProgressBarHelper;
662 		delete mpNumExport;
663 	}
664 
665 	xmloff::token::ResetTokens();
666 
667 	if (mxEventListener.is() && mxModel.is())
668 		mxModel->removeEventListener(mxEventListener);
669 
670 	delete mpImpl;
671 }
672 
673 ///////////////////////////////////////////////////////////////////////
674 
675 // XExporter
676 void SAL_CALL SvXMLExport::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
677 	throw(lang::IllegalArgumentException, uno::RuntimeException)
678 {
679 	mxModel = uno::Reference< frame::XModel >::query( xDoc );
680 	if( !mxModel.is() )
681 		throw lang::IllegalArgumentException();
682 	if (mxModel.is() && ! mxEventListener.is())
683 	{
684 		mxEventListener.set( new SvXMLExportEventListener(this));
685 		mxModel->addEventListener(mxEventListener);
686 	}
687 
688 	if(!mxNumberFormatsSupplier.is() )
689 	{
690 		mxNumberFormatsSupplier = mxNumberFormatsSupplier.query( mxModel );
691 		if(mxNumberFormatsSupplier.is() && mxHandler.is())
692 			mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
693 	}
694 	if (mxExportInfo.is())
695 	{
696 		uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
697 		if (xPropertySetInfo.is())
698 		{
699 			OUString sUsePrettyPrinting(RTL_CONSTASCII_USTRINGPARAM(XML_USEPRETTYPRINTING));
700 			if (xPropertySetInfo->hasPropertyByName(sUsePrettyPrinting))
701 			{
702 				uno::Any aAny = mxExportInfo->getPropertyValue(sUsePrettyPrinting);
703 				try
704 				{
705 					if (::cppu::any2bool(aAny))
706 						mnExportFlags |= EXPORT_PRETTY;
707 					else
708 						mnExportFlags &= ~EXPORT_PRETTY;
709 					}
710 				}
711 				catch ( lang::IllegalArgumentException& )
712 				{
713 					DBG_ERRORFILE("why is bUsePrettyPrint not boolean?");
714 				}
715 			}
716 
717             if (mpNumExport && (mnExportFlags & (EXPORT_AUTOSTYLES | EXPORT_STYLES)))
718 			{
719 				OUString sWrittenNumberFormats(RTL_CONSTASCII_USTRINGPARAM(XML_WRITTENNUMBERSTYLES));
720 				if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
721 				{
722 					uno::Any aAny = mxExportInfo->getPropertyValue(sWrittenNumberFormats);
723 					uno::Sequence<sal_Int32> aWasUsed;
724 					if(aAny >>= aWasUsed)
725 						mpNumExport->SetWasUsed(aWasUsed);
726 				}
727 			}
728 		}
729 	}
730 
731     // --> PB 2007-07-06 #i146851#
732     if ( mpImpl->mbSaveBackwardCompatibleODF )
733         mnExportFlags |= EXPORT_SAVEBACKWARDCOMPATIBLE;
734     else
735         mnExportFlags &= ~EXPORT_SAVEBACKWARDCOMPATIBLE;
736     // <--
737 
738 	// namespaces for user defined attributes
739 	Reference< XMultiServiceFactory > xFactory( mxModel,	UNO_QUERY );
740 	if( xFactory.is() )
741 	{
742 		try
743 		{
744 			Reference < XInterface > xIfc =
745 				xFactory->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM(
746 											"com.sun.star.xml.NamespaceMap")) );
747 			if( xIfc.is() )
748 			{
749 				Reference< XNameAccess > xNamespaceMap( xIfc, UNO_QUERY );
750 				if( xNamespaceMap.is() )
751 				{
752 					Sequence< OUString > aPrefixes( xNamespaceMap->getElementNames() );
753 
754 					OUString* pPrefix = aPrefixes.getArray();
755 					const sal_Int32 nCount = aPrefixes.getLength();
756 					sal_Int32 nIndex;
757 					OUString aURL;
758 
759 					for( nIndex = 0; nIndex < nCount; ++nIndex, ++pPrefix )
760 					{
761 						if( xNamespaceMap->getByName( *pPrefix ) >>= aURL )
762 							_GetNamespaceMap().Add( *pPrefix, aURL, XML_NAMESPACE_UNKNOWN );
763 					}
764 				}
765 			}
766 		}
767 		catch( com::sun::star::uno::Exception& )
768 		{
769 		}
770 	}
771 
772     // --> OD 2006-03-10 #i51726# - determine model type
773     _DetermineModelType();
774     // <--
775 }
776 
777 // XInitialize
778 void SAL_CALL SvXMLExport::initialize( const uno::Sequence< uno::Any >& aArguments )
779 	throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
780 {
781     // #93186# we need to queryInterface every single Any with any expected outcome. This variable hold the queryInterface results.
782 
783 	const sal_Int32 nAnyCount = aArguments.getLength();
784 	const uno::Any* pAny = aArguments.getConstArray();
785 
786 	for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
787 	{
788         Reference<XInterface> xValue;
789         *pAny >>= xValue;
790 
791         // status indicator
792         uno::Reference<task::XStatusIndicator> xTmpStatus( xValue, UNO_QUERY );
793         if ( xTmpStatus.is() )
794 			mxStatusIndicator = xTmpStatus;
795 
796         // graphic resolver
797         uno::Reference<document::XGraphicObjectResolver> xTmpGraphic(
798             xValue, UNO_QUERY );
799         if ( xTmpGraphic.is() )
800             mxGraphicResolver = xTmpGraphic;
801 
802         // object resolver
803         uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
804             xValue, UNO_QUERY );
805         if ( xTmpObjectResolver.is() )
806             mxEmbeddedResolver = xTmpObjectResolver;
807 
808         // document handler
809         uno::Reference<xml::sax::XDocumentHandler> xTmpDocHandler(
810             xValue, UNO_QUERY );
811         if( xTmpDocHandler.is() )
812 		{
813 			mxHandler = xTmpDocHandler;
814 			*pAny >>= mxExtHandler;
815 
816 			if (mxNumberFormatsSupplier.is() && mpNumExport == NULL)
817 				mpNumExport = new SvXMLNumFmtExport(*this, mxNumberFormatsSupplier);
818 		}
819 
820         // property set to transport data across
821         uno::Reference<beans::XPropertySet> xTmpPropertySet(
822             xValue, UNO_QUERY );
823         if( xTmpPropertySet.is() )
824 			mxExportInfo = xTmpPropertySet;
825 	}
826 
827 	if( mxExportInfo.is() )
828 	{
829 		uno::Reference< beans::XPropertySetInfo > xPropertySetInfo =
830 			mxExportInfo->getPropertySetInfo();
831 		OUString sPropName(
832 				RTL_CONSTASCII_USTRINGPARAM("BaseURI" ) );
833 		if( xPropertySetInfo->hasPropertyByName(sPropName) )
834 		{
835 			uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
836 			aAny >>= msOrigFileName;
837             mpImpl->msPackageURI = msOrigFileName;
838             mpImpl->SetSchemeOf( msOrigFileName );
839 		}
840 		OUString sRelPath;
841 		sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamRelPath" ) );
842 		if( xPropertySetInfo->hasPropertyByName(sPropName) )
843 		{
844 			uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
845 			aAny >>= sRelPath;
846 		}
847 		OUString sName;
848 		sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamName" ) );
849 		if( xPropertySetInfo->hasPropertyByName(sPropName) )
850 		{
851 			uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
852 			aAny >>= sName;
853 		}
854 		if( msOrigFileName.getLength() && sName.getLength() )
855 		{
856 			INetURLObject aBaseURL( msOrigFileName );
857 			if( sRelPath.getLength() )
858 				aBaseURL.insertName( sRelPath );
859 			aBaseURL.insertName( sName );
860 			msOrigFileName = aBaseURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
861 		}
862         mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
863 
864         // --> OD 2006-09-26 #i69627#
865         const ::rtl::OUString sOutlineStyleAsNormalListStyle(
866                 RTL_CONSTASCII_USTRINGPARAM("OutlineStyleAsNormalListStyle") );
867         if( xPropertySetInfo->hasPropertyByName( sOutlineStyleAsNormalListStyle ) )
868         {
869             uno::Any aAny = mxExportInfo->getPropertyValue( sOutlineStyleAsNormalListStyle );
870             aAny >>= (mpImpl->mbOutlineStyleAsNormalListStyle);
871         }
872         // <--
873 
874 		OUString sTargetStorage( RTL_CONSTASCII_USTRINGPARAM("TargetStorage") );
875 		if( xPropertySetInfo->hasPropertyByName( sTargetStorage ) )
876             mxExportInfo->getPropertyValue( sTargetStorage ) >>= mpImpl->mxTargetStorage;
877 
878         // --> OD 2008-11-26 #158694#
879         const ::rtl::OUString sExportTextNumberElement(
880                 RTL_CONSTASCII_USTRINGPARAM("ExportTextNumberElement") );
881         if( xPropertySetInfo->hasPropertyByName( sExportTextNumberElement ) )
882         {
883             uno::Any aAny = mxExportInfo->getPropertyValue( sExportTextNumberElement );
884             aAny >>= (mpImpl->mbExportTextNumberElement);
885         }
886         // <--
887     }
888 
889 }
890 
891 // XFilter
892 sal_Bool SAL_CALL SvXMLExport::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor ) throw(uno::RuntimeException)
893 {
894     RTL_LOGFILE_CONTEXT_AUTHOR( aLogContext, "xmloff", LOGFILE_AUTHOR,
895                                 "SvXMLExport::filter" );
896 
897     // check for xHandler first... should have been supplied in initialize
898     if( !mxHandler.is() )
899         return sal_False;
900 
901 	try
902 	{
903 		const sal_uInt32 nTest =
904 			EXPORT_META|EXPORT_STYLES|EXPORT_CONTENT|EXPORT_SETTINGS;
905 		if( (mnExportFlags & nTest) == nTest && !msOrigFileName.getLength() )
906 		{
907 			// evaluate descriptor only for flat files and if a base URI
908 			// has not been provided already
909 			const sal_Int32 nPropCount = aDescriptor.getLength();
910 			const beans::PropertyValue* pProps = aDescriptor.getConstArray();
911 
912 			for( sal_Int32 nIndex = 0; nIndex < nPropCount; nIndex++, pProps++ )
913 			{
914 				const OUString& rPropName = pProps->Name;
915 				const Any& rValue = pProps->Value;
916 
917 				if( rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FileName" ) ) )
918 				{
919 					if( !(rValue >>= msOrigFileName ) )
920 						return sal_False;
921 				}
922 				else if (rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FilterName" ) ) )
923 				{
924 					if( !(rValue >>= msFilterName ) )
925 						return sal_False;
926 				}
927 			}
928 		}
929 
930 #ifdef TIMELOG
931         if (GetModel().is())
932         {
933             // print a trace message with the URL
934             ByteString aUrl( (String) GetModel()->getURL(),
935                              RTL_TEXTENCODING_ASCII_US );
936             RTL_LOGFILE_CONTEXT_TRACE1( aLogContext, "%s", aUrl.GetBuffer() );
937 
938             // we also want a trace message with the document class
939             ByteString aClass( (String)GetXMLToken(meClass),
940                                RTL_TEXTENCODING_ASCII_US );
941             RTL_LOGFILE_CONTEXT_TRACE1( aLogContext, "class=\"%s\"",
942                                         aClass.GetBuffer() );
943         }
944 #endif
945 
946 		exportDoc( meClass );
947 	}
948 	catch( uno::Exception e )
949 	{
950 		// We must catch exceptions, because according to the
951 		// API definition export must not throw one!
952         Sequence<OUString> aSeq(0);
953         SetError( XMLERROR_FLAG_ERROR | XMLERROR_FLAG_SEVERE | XMLERROR_API,
954                   aSeq, e.Message, NULL );
955 	}
956 
957     // return true only if no error occurred
958     return (GetErrorFlags() & (ERROR_DO_NOTHING|ERROR_ERROR_OCCURED)) == 0;
959 }
960 
961 void SAL_CALL SvXMLExport::cancel() throw(uno::RuntimeException)
962 {
963     // stop export
964     Sequence<OUString> aEmptySeq;
965     SetError(XMLERROR_CANCEL|XMLERROR_FLAG_SEVERE, aEmptySeq);
966 }
967 
968 ::rtl::OUString SAL_CALL SvXMLExport::getName(  )
969     throw (::com::sun::star::uno::RuntimeException)
970 {
971     return msFilterName;
972 }
973 
974 void SAL_CALL SvXMLExport::setName( const ::rtl::OUString& )
975     throw (::com::sun::star::uno::RuntimeException)
976 {
977     // do nothing, because it is not possible to set the FilterName
978 }
979 
980 
981 // XServiceInfo
982 OUString SAL_CALL SvXMLExport::getImplementationName(  ) throw(uno::RuntimeException)
983 {
984 	OUString aStr;
985 	return aStr;
986 }
987 
988 sal_Bool SAL_CALL SvXMLExport::supportsService( const OUString& rServiceName ) throw(uno::RuntimeException)
989 {
990     return
991         rServiceName.equalsAsciiL(
992             "com.sun.star.document.ExportFilter",
993             sizeof("com.sun.star.document.ExportFilter")-1 ) ||
994         rServiceName.equalsAsciiL(
995             "com.sun.star.xml.XMLExportFilter",
996             sizeof("com.sun.star.xml.XMLExportFilter")-1);
997 }
998 
999 uno::Sequence< OUString > SAL_CALL SvXMLExport::getSupportedServiceNames(  )
1000 	throw(uno::RuntimeException)
1001 {
1002     uno::Sequence<OUString> aSeq(2);
1003     aSeq[0] = OUString(
1004         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ExportFilter"));
1005     aSeq[1] = OUString(
1006         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLExportFilter"));
1007     return aSeq;
1008 }
1009 
1010 ///////////////////////////////////////////////////////////////////////
1011 
1012 ::rtl::OUString
1013 SvXMLExport::EnsureNamespace(::rtl::OUString const & i_rNamespace,
1014     ::rtl::OUString const & i_rPreferredPrefix)
1015 {
1016     ::rtl::OUString sPrefix;
1017     sal_uInt16 nKey( _GetNamespaceMap().GetKeyByName( i_rNamespace ) );
1018     if( XML_NAMESPACE_UNKNOWN == nKey )
1019     {
1020         // There is no prefix for the namespace, so
1021         // we have to generate one and have to add it.
1022         sPrefix = i_rPreferredPrefix;
1023         nKey = _GetNamespaceMap().GetKeyByPrefix( sPrefix );
1024         sal_Int32 n( 0 );
1025         ::rtl::OUStringBuffer buf;
1026         while( nKey != USHRT_MAX )
1027         {
1028             buf.append( i_rPreferredPrefix );
1029             buf.append( ++n );
1030             sPrefix = buf.makeStringAndClear();
1031             nKey = _GetNamespaceMap().GetKeyByPrefix( sPrefix );
1032         }
1033 
1034         if (mpImpl->mNamespaceMaps.empty()
1035             || (mpImpl->mNamespaceMaps.top().second != mpImpl->mDepth))
1036         {
1037             // top was created for lower depth... need a new namespace map!
1038             mpImpl->mNamespaceMaps.push(
1039                 ::std::make_pair(mpNamespaceMap, mpImpl->mDepth) );
1040             mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
1041         }
1042 
1043         // add the namespace to the map and as attribute
1044         mpNamespaceMap->Add( sPrefix, i_rNamespace );
1045         buf.append( GetXMLToken(XML_XMLNS) );
1046         buf.append( sal_Unicode(':') );
1047         buf.append( sPrefix );
1048         AddAttribute( buf.makeStringAndClear(), i_rNamespace );
1049     }
1050     else
1051     {
1052         // If there is a prefix for the namespace, reuse that.
1053         sPrefix = _GetNamespaceMap().GetPrefixByKey( nKey );
1054     }
1055     return sPrefix;
1056 }
1057 
1058 ///////////////////////////////////////////////////////////////////////
1059 
1060 void SvXMLExport::AddAttributeASCII( sal_uInt16 nPrefixKey,
1061 									 const sal_Char *pName,
1062 							  		 const sal_Char *pValue )
1063 {
1064 	OUString sName( OUString::createFromAscii( pName ) );
1065 	OUString sValue( OUString::createFromAscii( pValue ) );
1066 
1067     mpAttrList->AddAttribute(
1068         _GetNamespaceMap().GetQNameByKey( nPrefixKey, sName ), sValue );
1069 }
1070 
1071 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const sal_Char *pName,
1072 							  const OUString& rValue )
1073 {
1074 	OUString sName( OUString::createFromAscii( pName ) );
1075 
1076     mpAttrList->AddAttribute(
1077         _GetNamespaceMap().GetQNameByKey( nPrefixKey, sName ), rValue );
1078 }
1079 
1080 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const OUString& rName,
1081 							  const OUString& rValue )
1082 {
1083     mpAttrList->AddAttribute(
1084         _GetNamespaceMap().GetQNameByKey( nPrefixKey, rName ), rValue );
1085 }
1086 
1087 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
1088                                 enum XMLTokenEnum eName,
1089                                 const OUString& rValue )
1090 {
1091     mpAttrList->AddAttribute(
1092         _GetNamespaceMap().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
1093         rValue );
1094 }
1095 
1096 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
1097                                 enum XMLTokenEnum eName,
1098                                 enum XMLTokenEnum eValue)
1099 {
1100     mpAttrList->AddAttribute(
1101         _GetNamespaceMap().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
1102         GetXMLToken(eValue) );
1103 }
1104 
1105 void SvXMLExport::AddAttribute( const ::rtl::OUString& rQName,
1106                                 const ::rtl::OUString& rValue )
1107 {
1108       mpAttrList->AddAttribute(
1109         rQName,
1110         rValue );
1111 }
1112 
1113 void SvXMLExport::AddAttribute( const ::rtl::OUString& rQName,
1114                                 enum ::xmloff::token::XMLTokenEnum eValue )
1115 {
1116       mpAttrList->AddAttribute(
1117         rQName,
1118         GetXMLToken(eValue) );
1119 }
1120 
1121 void SvXMLExport::AddAttributeList( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1122 {
1123 	if( xAttrList.is())
1124 		mpAttrList->AppendAttributeList( xAttrList );
1125 }
1126 
1127 void SvXMLExport::ClearAttrList()
1128 {
1129 	mpAttrList->Clear();
1130 }
1131 
1132 #ifdef DBG_UTIL
1133 void SvXMLExport::CheckAttrList()
1134 {
1135 	DBG_ASSERT( !mpAttrList->getLength(),
1136 				"XMLExport::CheckAttrList: list is not empty" );
1137 }
1138 #endif
1139 
1140 void SvXMLExport::ImplExportMeta()
1141 {
1142 	CheckAttrList();
1143 
1144     _ExportMeta();
1145 }
1146 
1147 void SvXMLExport::ImplExportSettings()
1148 {
1149 	CheckAttrList();
1150 
1151     ::std::list< SettingsGroup > aSettings;
1152     sal_Int32 nSettingsCount = 0;
1153 
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();
1159 
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();
1165 
1166     // any document specific settings
1167     nSettingsCount += GetDocumentSpecificSettings( aSettings );
1168 
1169 	{
1170 		SvXMLElementExport aElem( *this,
1171 								nSettingsCount != 0,
1172 								XML_NAMESPACE_OFFICE, XML_SETTINGS,
1173 								sal_True, sal_True );
1174 
1175         SettingsExportFacade aSettingsExportContext( *this );
1176 		XMLSettingsExportHelper aSettingsExportHelper( aSettingsExportContext );
1177 
1178         for (   ::std::list< SettingsGroup >::const_iterator settings = aSettings.begin();
1179                 settings != aSettings.end();
1180                 ++settings
1181             )
1182         {
1183             if ( !settings->aSettings.getLength() )
1184                 continue;
1185 
1186 	        OUString sSettingsName( GetXMLToken( settings->eGroupName ) );
1187 	        OUString sQName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOO, sSettingsName );
1188 	        aSettingsExportHelper.exportAllSettings( settings->aSettings, sQName );
1189         }
1190 	}
1191 }
1192 
1193 void SvXMLExport::ImplExportStyles( sal_Bool )
1194 {
1195 	CheckAttrList();
1196 
1197 //	AddAttribute( XML_NAMESPACE_NONE, XML_ID, XML_STYLES_ID );
1198 	{
1199 		// <style:styles>
1200 		SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_STYLES,
1201 								sal_True, sal_True );
1202 
1203 		_ExportStyles( sal_False );
1204 	}
1205 
1206     // transfer style names (+ families) TO other components (if appropriate)
1207     if( ( ( mnExportFlags & EXPORT_CONTENT ) == 0 ) && mxExportInfo.is() )
1208     {
1209         static OUString sStyleNames( RTL_CONSTASCII_USTRINGPARAM("StyleNames") );
1210         static OUString sStyleFamilies( RTL_CONSTASCII_USTRINGPARAM("StyleFamilies") );
1211         uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
1212         if ( xPropertySetInfo->hasPropertyByName( sStyleNames ) && xPropertySetInfo->hasPropertyByName( sStyleFamilies ) )
1213         {
1214             Sequence<sal_Int32> aStyleFamilies;
1215             Sequence<OUString> aStyleNames;
1216             mxAutoStylePool->GetRegisteredNames( aStyleFamilies, aStyleNames );
1217             mxExportInfo->setPropertyValue( sStyleNames, makeAny( aStyleNames ) );
1218             mxExportInfo->setPropertyValue( sStyleFamilies,
1219                                            makeAny( aStyleFamilies ) );
1220         }
1221     }
1222 }
1223 
1224 void SvXMLExport::ImplExportAutoStyles( sal_Bool )
1225 {
1226     // transfer style names (+ families) FROM other components (if appropriate)
1227     OUString sStyleNames( RTL_CONSTASCII_USTRINGPARAM("StyleNames") );
1228     OUString sStyleFamilies( RTL_CONSTASCII_USTRINGPARAM("StyleFamilies") );
1229     if( ( ( mnExportFlags & EXPORT_STYLES ) == 0 )
1230         && mxExportInfo.is()
1231         && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleNames )
1232         && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleFamilies ) )
1233     {
1234         Sequence<sal_Int32> aStyleFamilies;
1235         mxExportInfo->getPropertyValue( sStyleFamilies ) >>= aStyleFamilies;
1236         Sequence<OUString> aStyleNames;
1237         mxExportInfo->getPropertyValue( sStyleNames ) >>= aStyleNames;
1238         mxAutoStylePool->RegisterNames( aStyleFamilies, aStyleNames );
1239     }
1240 
1241 //	AddAttributeASCII( XML_NAMESPACE_NONE, XML_ID, XML_AUTO_STYLES_ID );
1242 	{
1243 		// <style:automatic-styles>
1244 		SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
1245 								  XML_AUTOMATIC_STYLES, sal_True, sal_True );
1246 
1247 #if 0
1248 		AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
1249 		AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, XML_STYLES_HREF );
1250 		AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
1251 		AddAttribute( XML_NAMESPACE_XLINK, XML_ROLE,
1252 				   	  pNamespaceMap->GetQNameByKey( XML_NAMESPACE_OFFICE,
1253                                                GetXMLToken(XML_STYLESHEET)) );
1254 		{
1255 			// <style:use-styles>
1256 			SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
1257 									  XML_USE_STYLES, sal_True, sal_True );
1258 		}
1259 #endif
1260 		_ExportAutoStyles();
1261 	}
1262 }
1263 
1264 void SvXMLExport::ImplExportMasterStyles( sal_Bool )
1265 {
1266 	{
1267 		// <style:master-styles>
1268 		SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_MASTER_STYLES,
1269 								sal_True, sal_True );
1270 
1271 		_ExportMasterStyles();
1272 	}
1273 
1274 #if 0
1275 	AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
1276 	AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, XML_AUTO_STYLES_HREF );
1277 	AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
1278 	AddAttribute( XML_NAMESPACE_XLINK, XML_ROLE,
1279 				  pNamespaceMap->GetQNameByKey( XML_NAMESPACE_OFFICE,
1280                                                 GetXMLToken(XML_STYLESHEET) ) );
1281 	{
1282 		// <style:use-styles>
1283 		SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE,
1284 								  XML_USE_STYLES, sal_True, sal_True );
1285 	}
1286 #endif
1287 }
1288 
1289 void SvXMLExport::ImplExportContent()
1290 {
1291 	CheckAttrList();
1292 
1293 	CheckAttrList();
1294 
1295 	{
1296 		SvXMLElementExport aElemrnt( *this, XML_NAMESPACE_OFFICE, XML_BODY,
1297 								  sal_True, sal_True );
1298 		{
1299 			XMLTokenEnum eClass = meClass;
1300 			if( XML_TEXT_GLOBAL == eClass )
1301 			{
1302 				AddAttribute( XML_NAMESPACE_TEXT, XML_GLOBAL,
1303                       GetXMLToken( XML_TRUE ) );
1304 				eClass = XML_TEXT;
1305 			}
1306 		    // <office:body ...>
1307 		    SetBodyAttributes();
1308 			SvXMLElementExport aElem( *this, meClass != XML_TOKEN_INVALID,
1309 									  XML_NAMESPACE_OFFICE, eClass,
1310 								  	  sal_True, sal_True );
1311 
1312 			_ExportContent();
1313 		}
1314 	}
1315 }
1316 
1317 void SvXMLExport::SetBodyAttributes()
1318 {
1319 }
1320 
1321 static void
1322 lcl_AddGrddl(SvXMLExport & rExport, const sal_Int32 /*nExportMode*/)
1323 {
1324     // check version >= 1.2
1325     switch (rExport.getDefaultVersion()) {
1326         case SvtSaveOptions::ODFVER_011: // fall thru
1327         case SvtSaveOptions::ODFVER_010: return;
1328         default: break;
1329     }
1330 
1331     // #i115030#: disabled
1332 #if 0
1333     if (EXPORT_SETTINGS != nExportMode) // meta, content, styles
1334     {
1335         rExport.AddAttribute( XML_NAMESPACE_GRDDL, XML_TRANSFORMATION,
1336             OUString::createFromAscii(s_grddl_xsl) );
1337     }
1338 #endif
1339 }
1340 
1341 sal_uInt32 SvXMLExport::exportDoc( enum ::xmloff::token::XMLTokenEnum eClass )
1342 {
1343 	bool bOwnGraphicResolver = false;
1344 	bool bOwnEmbeddedResolver = false;
1345 
1346 	if( !mxGraphicResolver.is() || !mxEmbeddedResolver.is() )
1347 	{
1348 		Reference< XMultiServiceFactory > xFactory( mxModel,	UNO_QUERY );
1349 		if( xFactory.is() )
1350 		{
1351 			try
1352 			{
1353 				if( !mxGraphicResolver.is() )
1354 				{
1355 					mxGraphicResolver = Reference< XGraphicObjectResolver >::query(
1356 						xFactory->createInstance(
1357 							OUString(RTL_CONSTASCII_USTRINGPARAM(
1358 								"com.sun.star.document.ExportGraphicObjectResolver"))));
1359 					bOwnGraphicResolver = mxGraphicResolver.is();
1360 				}
1361 
1362 				if( !mxEmbeddedResolver.is() )
1363 				{
1364 					mxEmbeddedResolver = Reference< XEmbeddedObjectResolver >::query(
1365 						xFactory->createInstance(
1366 							OUString(RTL_CONSTASCII_USTRINGPARAM(
1367 								"com.sun.star.document.ExportEmbeddedObjectResolver"))));
1368 					bOwnEmbeddedResolver = mxEmbeddedResolver.is();
1369 				}
1370 			}
1371 			catch( com::sun::star::uno::Exception& )
1372 			{
1373 			}
1374 		}
1375 	}
1376 	if( (getExportFlags() & EXPORT_OASIS) == 0 )
1377 	{
1378 		Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory();
1379 		if( xFactory.is() )
1380 		{
1381 			try
1382 			{
1383 				::comphelper::PropertyMapEntry aInfoMap[] =
1384 				{
1385 					{ "Class", sizeof("Class")-1, 0,
1386 						&::getCppuType((::rtl::OUString*)0),
1387 			  			PropertyAttribute::MAYBEVOID, 0},
1388 					{ NULL, 0, 0, NULL, 0, 0 }
1389 				};
1390 				Reference< XPropertySet > xConvPropSet(
1391 					::comphelper::GenericPropertySet_CreateInstance(
1392 							new ::comphelper::PropertySetInfo( aInfoMap ) ) );
1393 
1394 				Any aAny;
1395 				aAny <<= GetXMLToken( eClass );
1396 				xConvPropSet->setPropertyValue(
1397 						OUString(RTL_CONSTASCII_USTRINGPARAM("Class")), aAny );
1398 
1399 				Reference< XPropertySet > xPropSet =
1400 					mxExportInfo.is()
1401                     ?  PropertySetMerger_CreateInstance( mxExportInfo,
1402                                                          xConvPropSet )
1403                     : xConvPropSet;
1404 
1405                 Sequence<Any> aArgs( 3 );
1406 				aArgs[0] <<= mxHandler;
1407 				aArgs[1] <<= xPropSet;
1408 				aArgs[2] <<= mxModel;
1409 
1410 				// get filter component
1411 				Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
1412 					xFactory->createInstanceWithArguments(
1413 					OUString::createFromAscii("com.sun.star.comp.Oasis2OOoTransformer"),
1414 								aArgs), UNO_QUERY);
1415 				OSL_ENSURE( xTmpDocHandler.is(),
1416 					"can't instantiate OASIS transformer component" );
1417 				if( xTmpDocHandler.is() )
1418 				{
1419 					mxHandler = xTmpDocHandler;
1420 					mxExtHandler = uno::Reference<xml::sax::XExtendedDocumentHandler>( mxHandler, UNO_QUERY );
1421 				}
1422 			}
1423 			catch( com::sun::star::uno::Exception& )
1424 			{
1425 			}
1426 		}
1427 	}
1428 
1429 
1430 	mxHandler->startDocument();
1431 
1432 	// <?xml version="1.0" encoding="UTF-8"?>
1433 //	xHandler->processingInstruction( S2U( sXML_xml ), S2U( sXML_xml_pi ) );
1434 
1435 	// <office:document ...>
1436 	CheckAttrList();
1437 
1438 	// namespace attributes
1439 	// ( The namespace decls should be first attributes in the element;
1440 	//   some faulty XML parsers (JAXP1.1) have a problem with this,
1441 	//   also it's more elegant )
1442 	sal_uInt16 nPos = mpNamespaceMap->GetFirstKey();
1443 	while( USHRT_MAX != nPos )
1444 	{
1445 		mpAttrList->AddAttribute( mpNamespaceMap->GetAttrNameByKey( nPos ),
1446 								  mpNamespaceMap->GetNameByKey( nPos ) );
1447 		nPos = mpNamespaceMap->GetNextKey( nPos );
1448 	}
1449 
1450 
1451 
1452 	// office:version = ...
1453 	if( !mbExtended )
1454     {
1455         const sal_Char* pVersion = 0;
1456         switch( getDefaultVersion() )
1457         {
1458         case SvtSaveOptions::ODFVER_LATEST: pVersion = sXML_1_2; break;
1459         case SvtSaveOptions::ODFVER_012: pVersion = sXML_1_2; break;
1460         case SvtSaveOptions::ODFVER_011: pVersion = sXML_1_1; break;
1461         case SvtSaveOptions::ODFVER_010: break;
1462 
1463         default:
1464             DBG_ERROR("xmloff::SvXMLExport::exportDoc(), unexpected odf default version!");
1465         }
1466 
1467         if( pVersion )
1468 		    AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
1469                               OUString::createFromAscii(pVersion) );
1470     }
1471 
1472 	{
1473 		enum XMLTokenEnum eRootService = XML_TOKEN_INVALID;
1474 		const sal_Int32 nExportMode = mnExportFlags & (EXPORT_META|EXPORT_STYLES|EXPORT_CONTENT|EXPORT_SETTINGS);
1475 
1476         lcl_AddGrddl(*this, nExportMode);
1477 
1478 		if( EXPORT_META == nExportMode )
1479 		{
1480 			// export only meta
1481 			eRootService = XML_DOCUMENT_META;
1482 		}
1483 		else if ( EXPORT_SETTINGS == nExportMode )
1484 		{
1485 			// export only settings
1486 			eRootService = XML_DOCUMENT_SETTINGS;
1487 		}
1488 		else if( EXPORT_STYLES == nExportMode )
1489 		{
1490 			// export only styles
1491 			eRootService = XML_DOCUMENT_STYLES;
1492 		}
1493 		else if( EXPORT_CONTENT == nExportMode )
1494 		{
1495 			// export only content
1496 			eRootService = XML_DOCUMENT_CONTENT;
1497 		}
1498 		else
1499 		{
1500 			// the god'ol one4all element
1501 			eRootService = XML_DOCUMENT;
1502 			// office:mimetype = ... (only for stream containing the content)
1503 			if( eClass != XML_TOKEN_INVALID )
1504 			{
1505 				OUString aTmp( RTL_CONSTASCII_USTRINGPARAM("application/vnd.oasis.opendocument.") );
1506 				aTmp += GetXMLToken( eClass );
1507 				AddAttribute( XML_NAMESPACE_OFFICE, XML_MIMETYPE, aTmp );
1508 			}
1509 		}
1510 
1511 //		if( (getExportFlags() & EXPORT_NODOCTYPE) == 0 &&
1512 //			xExtHandler.is() )
1513 //		{
1514 //			OUStringBuffer aDocType(
1515 //               GetXMLToken(XML_XML_DOCTYPE_PREFIX).getLength() +
1516 //				GetXMLToken(XML_XML_DOCTYPE_SUFFIX).getLength() + 30 );
1517 //
1518 //			aDocType.append( GetXMLToken(XML_XML_DOCTYPE_PREFIX) );
1519 //			aDocType.append( GetNamespaceMap().GetQNameByKey(
1520 //						   XML_NAMESPACE_OFFICE, GetXMLToken(eRootService) ) );
1521 //			aDocType.append( GetXMLToken(XML_XML_DOCTYPE_SUFFIX) );
1522 //			xExtHandler->unknown( aDocType.makeStringAndClear() );
1523 //		}
1524 
1525 		SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, eRootService, sal_True, sal_True );
1526 
1527 		// meta information
1528 		if( mnExportFlags & EXPORT_META )
1529 			ImplExportMeta();
1530 
1531 		// settings
1532 		if( mnExportFlags & EXPORT_SETTINGS )
1533 			ImplExportSettings();
1534 
1535 		// scripts
1536 		if( mnExportFlags & EXPORT_SCRIPTS )
1537 			_ExportScripts();
1538 
1539 		// font declerations
1540 		if( mnExportFlags & EXPORT_FONTDECLS )
1541 			_ExportFontDecls();
1542 
1543 		// styles
1544 		if( mnExportFlags & EXPORT_STYLES )
1545 			ImplExportStyles( sal_False );
1546 
1547 		// autostyles
1548 		if( mnExportFlags & EXPORT_AUTOSTYLES )
1549 			ImplExportAutoStyles( sal_False );
1550 
1551 		// masterstyles
1552 		if( mnExportFlags & EXPORT_MASTERSTYLES )
1553 			ImplExportMasterStyles( sal_False );
1554 
1555 		// contnt
1556 		if( mnExportFlags & EXPORT_CONTENT )
1557 			ImplExportContent();
1558 	}
1559 
1560 
1561 	mxHandler->endDocument();
1562 
1563 	if( bOwnGraphicResolver )
1564 	{
1565 		Reference< XComponent > xComp( mxGraphicResolver, UNO_QUERY );
1566 		xComp->dispose();
1567 	}
1568 
1569 	if( bOwnEmbeddedResolver )
1570 	{
1571 		Reference< XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
1572 		xComp->dispose();
1573 	}
1574 
1575 	return 0;
1576 }
1577 
1578 void SvXMLExport::ResetNamespaceMap()
1579 {
1580     delete mpNamespaceMap;    mpNamespaceMap = new SvXMLNamespaceMap;
1581 }
1582 
1583 void SvXMLExport::_ExportMeta()
1584 {
1585     OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
1586     Reference< XDocumentPropertiesSupplier > xDocPropsSupplier(mxModel,
1587         UNO_QUERY);
1588     if (xDocPropsSupplier.is()) {
1589         Reference<XDocumentProperties> xDocProps(
1590             xDocPropsSupplier->getDocumentProperties());
1591         if (!xDocProps.is()) throw;
1592         // update generator here
1593         xDocProps->setGenerator(generator);
1594         SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, xDocProps);
1595         uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
1596         pMeta->Export();
1597     } else {
1598         // office:meta
1599 		SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_META,
1600 								sal_True, sal_True );
1601         {
1602     // BM: #i60323# export generator even if xInfoProp is empty (which is the
1603     // case for charts). The generator does not depend on xInfoProp
1604             SvXMLElementExport anElem( *this, XML_NAMESPACE_META, XML_GENERATOR,
1605                                       sal_True, sal_True );
1606             Characters(generator);
1607         }
1608     }
1609 }
1610 
1611 void SvXMLExport::_ExportScripts()
1612 {
1613     SvXMLElementExport aElement( *this, XML_NAMESPACE_OFFICE, XML_SCRIPTS, sal_True, sal_True );
1614 
1615     // export Basic macros (only for FlatXML)
1616     if ( mnExportFlags & EXPORT_EMBEDDED )
1617     {
1618         ::rtl::OUString aValue( GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) );
1619         aValue += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":Basic" ) );
1620         AddAttribute( XML_NAMESPACE_SCRIPT, XML_LANGUAGE, aValue );
1621 
1622         SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_SCRIPT, sal_True, sal_True );
1623 
1624         // initialize Basic
1625         if ( mxModel.is() )
1626         {
1627             Reference< beans::XPropertySet > xPSet( mxModel, UNO_QUERY );
1628             if ( xPSet.is() )
1629 	            xPSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) );
1630         }
1631 
1632 	    Reference< document::XExporter > xExporter;
1633 	    Reference< lang::XMultiServiceFactory > xMSF( getServiceFactory() );
1634         if ( xMSF.is() )
1635         {
1636             Reference < XDocumentHandler > xHdl( new XMLBasicExportFilter( mxHandler ) );
1637 	        Sequence < Any > aArgs( 1 );
1638 	        aArgs[0] <<= xHdl;
1639             xExporter.set( xMSF->createInstanceWithArguments(
1640                 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicExporter" ) ), aArgs ),
1641                 UNO_QUERY );
1642         }
1643 
1644         OSL_ENSURE( xExporter.is(),
1645             "SvXMLExport::_ExportScripts: can't instantiate export filter component for Basic macros" );
1646 
1647         if ( xExporter.is() )
1648         {
1649             Reference< XComponent > xComp( mxModel, UNO_QUERY );
1650             xExporter->setSourceDocument( xComp );
1651             Reference< XFilter > xFilter( xExporter, UNO_QUERY );
1652             if ( xFilter.is() )
1653             {
1654                 Sequence < PropertyValue > aMediaDesc( 0 );
1655                 xFilter->filter( aMediaDesc );
1656             }
1657         }
1658     }
1659 
1660 	// export document events
1661 	Reference< document::XEventsSupplier > xEvents( GetModel(), UNO_QUERY );
1662 	GetEventExport().Export( xEvents, sal_True );
1663 }
1664 
1665 void SvXMLExport::_ExportFontDecls()
1666 {
1667 	if( mxFontAutoStylePool.is() )
1668 		mxFontAutoStylePool->exportXML();
1669 }
1670 
1671 void SvXMLExport::_ExportStyles( sal_Bool )
1672 {
1673 	uno::Reference< lang::XMultiServiceFactory > xFact( GetModel(), uno::UNO_QUERY );
1674 	if( xFact.is())
1675 	{
1676 		// export (fill-)gradient-styles
1677 		try
1678 		{
1679 			uno::Reference< container::XNameAccess > xGradient( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GradientTable") ) ), uno::UNO_QUERY );
1680 			if( xGradient.is() )
1681 			{
1682 				XMLGradientStyleExport aGradientStyle( *this );
1683 
1684 				if( xGradient->hasElements() )
1685 				{
1686 					uno::Sequence< OUString > aNamesSeq ( xGradient->getElementNames() );
1687 					sal_Int32 nCount = aNamesSeq.getLength();
1688 					for( sal_Int32 i=0; i<nCount; i++ )
1689 					{
1690 						const OUString& rStrName = aNamesSeq[ i ];
1691 
1692 						try
1693 						{
1694 							uno::Any aValue = xGradient->getByName( rStrName );
1695 
1696 							aGradientStyle.exportXML( rStrName, aValue );
1697 						}
1698 						catch( container::NoSuchElementException& )
1699 						{}
1700 					}
1701 				}
1702 			}
1703 		}
1704 		catch( lang::ServiceNotRegisteredException& )
1705 		{}
1706 
1707 		// export (fill-)hatch-styles
1708 		try
1709 		{
1710 			uno::Reference< container::XNameAccess > xHatch( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.HatchTable") ) ), uno::UNO_QUERY );
1711 			if( xHatch.is() )
1712 			{
1713 				XMLHatchStyleExport aHatchStyle( *this );
1714 
1715 				if( xHatch->hasElements() )
1716 				{
1717 					uno::Sequence< OUString > aNamesSeq ( xHatch->getElementNames() );
1718 					sal_Int32 nCount = aNamesSeq.getLength();
1719 					for( sal_Int32 i=0; i<nCount; i++ )
1720 					{
1721 						const OUString& rStrName = aNamesSeq[ i ];
1722 
1723 						try
1724 						{
1725 							uno::Any aValue = xHatch->getByName( rStrName );
1726 
1727 							aHatchStyle.exportXML( rStrName, aValue );
1728 						}
1729 						catch( container::NoSuchElementException& )
1730 						{}
1731 					}
1732 				}
1733 			}
1734 		}
1735 		catch( lang::ServiceNotRegisteredException& )
1736 		{}
1737 
1738 		// export (fill-)bitmap-styles
1739 		try
1740 		{
1741 			uno::Reference< container::XNameAccess > xBitmap( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.BitmapTable") ) ), uno::UNO_QUERY );
1742 			if( xBitmap.is() )
1743 			{
1744 				XMLImageStyle aImageStyle;
1745 
1746 				if( xBitmap->hasElements() )
1747 				{
1748 					uno::Sequence< OUString > aNamesSeq ( xBitmap->getElementNames() );
1749 					sal_Int32 nCount = aNamesSeq.getLength();
1750 					for( sal_Int32 i=0; i<nCount; i++ )
1751 					{
1752 						const OUString& rStrName = aNamesSeq[ i ];
1753 
1754 						try
1755 						{
1756 							uno::Any aValue = xBitmap->getByName( rStrName );
1757 
1758 							aImageStyle.exportXML( rStrName, aValue, *this );
1759 						}
1760 						catch( container::NoSuchElementException& )
1761 						{}
1762 					}
1763 				}
1764 			}
1765 		}
1766 		catch( lang::ServiceNotRegisteredException& )
1767 		{}
1768 
1769 		// export transparency-gradient -styles
1770 		try
1771 		{
1772 			uno::Reference< container::XNameAccess > xTransGradient( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) ), uno::UNO_QUERY );
1773 			if( xTransGradient.is() )
1774 			{
1775 				XMLTransGradientStyleExport aTransGradientstyle( *this );
1776 
1777 				if( xTransGradient->hasElements() )
1778 				{
1779 					uno::Sequence< OUString > aNamesSeq ( xTransGradient->getElementNames() );
1780 					sal_Int32 nCount = aNamesSeq.getLength();
1781 					for( sal_Int32 i=0; i<nCount; i++ )
1782 					{
1783 						const OUString& rStrName = aNamesSeq[ i ];
1784 
1785 						try
1786 						{
1787 							uno::Any aValue = xTransGradient->getByName( rStrName );
1788 
1789 							aTransGradientstyle.exportXML( rStrName, aValue );
1790 						}
1791 						catch( container::NoSuchElementException& )
1792 						{}
1793 					}
1794 				}
1795 			}
1796 		}
1797 		catch( lang::ServiceNotRegisteredException& )
1798 		{}
1799 
1800 		// export marker-styles
1801 		try
1802 		{
1803 			uno::Reference< container::XNameAccess > xMarker( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.MarkerTable") ) ), uno::UNO_QUERY );
1804 			if( xMarker.is() )
1805 			{
1806 				XMLMarkerStyleExport aMarkerStyle( *this );
1807 
1808 				if( xMarker->hasElements() )
1809 				{
1810 					uno::Sequence< OUString > aNamesSeq ( xMarker->getElementNames() );
1811 					sal_Int32 nCount = aNamesSeq.getLength();
1812 					for( sal_Int32 i=0; i<nCount; i++ )
1813 					{
1814 						const OUString& rStrName = aNamesSeq[ i ];
1815 
1816 						try
1817 						{
1818 							uno::Any aValue = xMarker->getByName( rStrName );
1819 
1820 							aMarkerStyle.exportXML( rStrName, aValue );
1821 						}
1822 						catch( container::NoSuchElementException& )
1823 						{}
1824 					}
1825 				}
1826 			}
1827 		}
1828 		catch( lang::ServiceNotRegisteredException& )
1829 		{}
1830 
1831 		// export dash-styles
1832 		try
1833 		{
1834 			uno::Reference< container::XNameAccess > xDashes( xFact->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DashTable") ) ), uno::UNO_QUERY );
1835 			if( xDashes.is() )
1836 			{
1837 				XMLDashStyleExport aDashStyle( *this );
1838 
1839 				if( xDashes->hasElements() )
1840 				{
1841 					uno::Sequence< OUString > aNamesSeq ( xDashes->getElementNames() );
1842 					sal_Int32 nCount = aNamesSeq.getLength();
1843 					for( sal_Int32 i=0; i<nCount; i++ )
1844 					{
1845 						const OUString& rStrName = aNamesSeq[ i ];
1846 
1847 						try
1848 						{
1849 							uno::Any aValue = xDashes->getByName( rStrName );
1850 
1851 							aDashStyle.exportXML( rStrName, aValue );
1852 						}
1853 						catch( container::NoSuchElementException& )
1854 						{}
1855 					}
1856 				}
1857 			}
1858 		}
1859 		catch( lang::ServiceNotRegisteredException& )
1860 		{}
1861 	}
1862 }
1863 
1864 XMLTextParagraphExport* SvXMLExport::CreateTextParagraphExport()
1865 {
1866 	return new XMLTextParagraphExport( *this, *(GetAutoStylePool().get()) );
1867 }
1868 
1869 XMLShapeExport* SvXMLExport::CreateShapeExport()
1870 {
1871 	return new XMLShapeExport(*this);
1872 }
1873 
1874 SvXMLAutoStylePoolP* SvXMLExport::CreateAutoStylePool()
1875 {
1876 	return new SvXMLAutoStylePoolP(*this);
1877 }
1878 
1879 XMLPageExport* SvXMLExport::CreatePageExport()
1880 {
1881 	return new XMLPageExport( *this );
1882 }
1883 
1884 SchXMLExportHelper* SvXMLExport::CreateChartExport()
1885 {
1886 	return new SchXMLExportHelper(*this,*GetAutoStylePool().get());
1887 }
1888 
1889 XMLFontAutoStylePool* SvXMLExport::CreateFontAutoStylePool()
1890 {
1891 	return new XMLFontAutoStylePool( *this );
1892 }
1893 
1894 xmloff::OFormLayerXMLExport* SvXMLExport::CreateFormExport()
1895 {
1896 	return new xmloff::OFormLayerXMLExport(*this);
1897 }
1898 
1899 void SvXMLExport::GetViewSettingsAndViews(uno::Sequence<beans::PropertyValue>& rProps)
1900 {
1901 	GetViewSettings(rProps);
1902 	uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetModel(), uno::UNO_QUERY);
1903 	if(xViewDataSupplier.is())
1904 	{
1905 		uno::Reference<container::XIndexAccess> xIndexAccess;
1906 		xViewDataSupplier->setViewData( xIndexAccess ); // make sure we get a newly created sequence
1907 		xIndexAccess = xViewDataSupplier->getViewData();
1908 		sal_Bool bAdd = sal_False;
1909 		uno::Any aAny;
1910 		if(xIndexAccess.is() && xIndexAccess->hasElements() )
1911 		{
1912 			sal_Int32 nCount = xIndexAccess->getCount();
1913 			for (sal_Int32 i = 0; i < nCount; i++)
1914 			{
1915 				aAny = xIndexAccess->getByIndex(i);
1916 				uno::Sequence<beans::PropertyValue> aProps;
1917 				if( aAny >>= aProps )
1918 				{
1919 					if( aProps.getLength() > 0 )
1920 					{
1921 						bAdd = sal_True;
1922 						break;
1923 					}
1924 				}
1925 			}
1926 		}
1927 
1928 		if( bAdd )
1929 		{
1930 			sal_Int32 nOldLength(rProps.getLength());
1931 			rProps.realloc(nOldLength + 1);
1932 			beans::PropertyValue aProp;
1933 			aProp.Name = OUString(RTL_CONSTASCII_USTRINGPARAM("Views"));
1934 			aProp.Value <<= xIndexAccess;
1935 			rProps[nOldLength] = aProp;
1936 		}
1937 	}
1938 }
1939 
1940 void SvXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>&)
1941 {
1942 }
1943 
1944 void SvXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>&)
1945 {
1946 }
1947 
1948 sal_Int32 SvXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup >& _out_rSettings )
1949 {
1950     (void)_out_rSettings;
1951     return 0;
1952 }
1953 
1954 void SvXMLExport::addDataStyle(const sal_Int32 nNumberFormat, sal_Bool /*bTimeFormat*/ )
1955 {
1956 	if(mpNumExport)
1957 		mpNumExport->SetUsed(nNumberFormat);
1958 }
1959 
1960 void SvXMLExport::exportDataStyles()
1961 {
1962 	if(mpNumExport)
1963 		mpNumExport->Export(sal_False);
1964 }
1965 
1966 void SvXMLExport::exportAutoDataStyles()
1967 {
1968 	if(mpNumExport)
1969 		mpNumExport->Export(sal_True);
1970 
1971 	if (mxFormExport.is())
1972 		mxFormExport->exportAutoControlNumberStyles();
1973 }
1974 
1975 OUString SvXMLExport::getDataStyleName(const sal_Int32 nNumberFormat, sal_Bool /*bTimeFormat*/ ) const
1976 {
1977 	OUString sTemp;
1978 	if(mpNumExport)
1979 		sTemp = mpNumExport->GetStyleName(nNumberFormat);
1980 	return sTemp;
1981 }
1982 
1983 void SvXMLExport::exportAnnotationMeta(const uno::Reference<drawing::XShape>&)
1984 {
1985 }
1986 
1987 sal_Int32 SvXMLExport::dataStyleForceSystemLanguage(sal_Int32 nFormat) const
1988 {
1989     return ( mpNumExport != NULL )
1990                  ? mpNumExport->ForceSystemLanguage( nFormat ) : nFormat;
1991 }
1992 
1993 
1994 OUString SvXMLExport::AddEmbeddedGraphicObject( const OUString& rGraphicObjectURL )
1995 {
1996 	OUString sRet( rGraphicObjectURL );
1997 	if( 0 == rGraphicObjectURL.compareTo( msGraphicObjectProtocol,
1998                                           msGraphicObjectProtocol.getLength() ) &&
1999         mxGraphicResolver.is() )
2000 	{
2001 		if( (getExportFlags() & EXPORT_EMBEDDED) == 0 )
2002 			sRet = mxGraphicResolver->resolveGraphicObjectURL( rGraphicObjectURL );
2003 		else
2004 			sRet = OUString();
2005 	}
2006 	else
2007 		sRet = GetRelativeReference( sRet );
2008 
2009 	return sRet;
2010 }
2011 
2012 sal_Bool SvXMLExport::AddEmbeddedGraphicObjectAsBase64( const OUString& rGraphicObjectURL )
2013 {
2014     sal_Bool bRet = sal_False;
2015 
2016 	if( (getExportFlags() & EXPORT_EMBEDDED) != 0 &&
2017 		0 == rGraphicObjectURL.compareTo( msGraphicObjectProtocol,
2018                                           msGraphicObjectProtocol.getLength() ) &&
2019 		mxGraphicResolver.is() )
2020 	{
2021         Reference< XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
2022 
2023         if( xStmResolver.is() )
2024         {
2025             Reference< XInputStream > xIn( xStmResolver->getInputStream( rGraphicObjectURL ) );
2026 
2027             if( xIn.is() )
2028             {
2029 				XMLBase64Export aBase64Exp( *this );
2030 				bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
2031             }
2032         }
2033     }
2034 
2035 	return bRet;
2036 }
2037 
2038 OUString SvXMLExport::AddEmbeddedObject( const OUString& rEmbeddedObjectURL )
2039 {
2040 	OUString sRet;
2041 	if( (0 == rEmbeddedObjectURL.compareTo( msEmbeddedObjectProtocol,
2042 				msEmbeddedObjectProtocol.getLength() ) ||
2043 		 0 == rEmbeddedObjectURL.compareTo( msGraphicObjectProtocol,
2044 				msGraphicObjectProtocol.getLength() ) ) &&
2045 		mxEmbeddedResolver.is() )
2046 	{
2047 		sRet =
2048 			mxEmbeddedResolver->resolveEmbeddedObjectURL( rEmbeddedObjectURL );
2049 	}
2050 	else
2051 		sRet = GetRelativeReference( rEmbeddedObjectURL );
2052 
2053 	return sRet;
2054 }
2055 
2056 sal_Bool SvXMLExport::AddEmbeddedObjectAsBase64( const OUString& rEmbeddedObjectURL )
2057 {
2058 	sal_Bool bRet = sal_False;
2059 	if( (0 == rEmbeddedObjectURL.compareTo( msEmbeddedObjectProtocol,
2060 				msEmbeddedObjectProtocol.getLength() ) ||
2061 		 0 == rEmbeddedObjectURL.compareTo( msGraphicObjectProtocol,
2062 				msGraphicObjectProtocol.getLength() ) ) &&
2063 		mxEmbeddedResolver.is() )
2064 	{
2065 		Reference < XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
2066 		if( xNA.is() )
2067 		{
2068 			Any aAny = xNA->getByName( rEmbeddedObjectURL );
2069 			Reference < XInputStream > xIn;
2070 			aAny >>= xIn;
2071 			if( xIn.is() )
2072 			{
2073 				XMLBase64Export aBase64Exp( *this );
2074 				bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
2075 			}
2076 		}
2077 	}
2078 
2079 	return bRet;
2080 }
2081 
2082 OUString SvXMLExport::EncodeStyleName(
2083 		const OUString& rName,
2084 	    sal_Bool *pEncoded ) const
2085 {
2086 	return GetMM100UnitConverter().encodeStyleName( rName, pEncoded );
2087 }
2088 
2089 ProgressBarHelper*	SvXMLExport::GetProgressBarHelper()
2090 {
2091 	if (!mpProgressBarHelper)
2092 	{
2093 		mpProgressBarHelper = new ProgressBarHelper(mxStatusIndicator, sal_True);
2094 
2095 		if (mxExportInfo.is())
2096 		{
2097 			uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
2098 			if (xPropertySetInfo.is())
2099 			{
2100 				OUString sProgressRange(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSRANGE));
2101 				OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
2102 				OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
2103                 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
2104 				if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
2105 					xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
2106 					xPropertySetInfo->hasPropertyByName(sProgressRange))
2107 				{
2108 					uno::Any aAny;
2109 					sal_Int32 nProgressMax(0);
2110 					sal_Int32 nProgressCurrent(0);
2111 					sal_Int32 nProgressRange(0);
2112 					aAny = mxExportInfo->getPropertyValue(sProgressRange);
2113 					if (aAny >>= nProgressRange)
2114 						mpProgressBarHelper->SetRange(nProgressRange);
2115 					aAny = mxExportInfo->getPropertyValue(sProgressMax);
2116 					if (aAny >>= nProgressMax)
2117 						mpProgressBarHelper->SetReference(nProgressMax);
2118 					aAny = mxExportInfo->getPropertyValue(sProgressCurrent);
2119 					if (aAny >>= nProgressCurrent)
2120 						mpProgressBarHelper->SetValue(nProgressCurrent);
2121 				}
2122                 if (xPropertySetInfo->hasPropertyByName(sRepeat))
2123                 {
2124                     uno::Any aAny = mxExportInfo->getPropertyValue(sRepeat);
2125                     if (aAny.getValueType() == getBooleanCppuType())
2126                         mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
2127                     else {
2128                         DBG_ERRORFILE("why is it no boolean?");
2129                     }
2130                 }
2131 			}
2132 		}
2133 	}
2134 	return mpProgressBarHelper;
2135 }
2136 
2137 XMLEventExport& SvXMLExport::GetEventExport()
2138 {
2139 	if( NULL == mpEventExport)
2140 	{
2141 		// create EventExport on demand
2142 		mpEventExport = new XMLEventExport(*this, NULL);
2143 
2144 		// and register standard handlers + names
2145 		OUString sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic"));
2146 		mpEventExport->AddHandler(sStarBasic, new XMLStarBasicExportHandler());
2147 		OUString sScript(RTL_CONSTASCII_USTRINGPARAM("Script"));
2148 		mpEventExport->AddHandler(sScript, new XMLScriptExportHandler());
2149 		mpEventExport->AddTranslationTable(aStandardEventTable);
2150 	}
2151 
2152 	return *mpEventExport;
2153 }
2154 
2155 XMLImageMapExport& SvXMLExport::GetImageMapExport()
2156 {
2157 	// image map export, create on-demand
2158 	if( NULL == mpImageMapExport )
2159 	{
2160 		mpImageMapExport = new XMLImageMapExport(*this);
2161 	}
2162 
2163 	return *mpImageMapExport;
2164 }
2165 
2166 // XUnoTunnel & co
2167 const uno::Sequence< sal_Int8 > & SvXMLExport::getUnoTunnelId() throw()
2168 {
2169 	static uno::Sequence< sal_Int8 > * pSeq = 0;
2170 	if( !pSeq )
2171 	{
2172 		Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
2173 		if( !pSeq )
2174 		{
2175 			static uno::Sequence< sal_Int8 > aSeq( 16 );
2176 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
2177 			pSeq = &aSeq;
2178 		}
2179 	}
2180 	return *pSeq;
2181 }
2182 
2183 SvXMLExport* SvXMLExport::getImplementation( uno::Reference< uno::XInterface > xInt ) throw()
2184 {
2185 	uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
2186 	if( xUT.is() )
2187 	{
2188 		return
2189 			reinterpret_cast<SvXMLExport*>(
2190 				sal::static_int_cast<sal_IntPtr>(
2191 					xUT->getSomething( SvXMLExport::getUnoTunnelId())));
2192 	}
2193 	else
2194 		return NULL;
2195 }
2196 
2197 // XUnoTunnel
2198 sal_Int64 SAL_CALL SvXMLExport::getSomething( const uno::Sequence< sal_Int8 >& rId )
2199 	throw( uno::RuntimeException )
2200 {
2201 	if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2202 														 rId.getConstArray(), 16 ) )
2203 	{
2204 		return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2205 	}
2206 	return 0;
2207 }
2208 
2209 sal_Bool SvXMLExport::ExportEmbeddedOwnObject( Reference< XComponent >& rComp )
2210 {
2211 	OUString sFilterService;
2212     bool bIsChart = false;
2213 
2214     Reference < lang::XServiceInfo > xServiceInfo( rComp, UNO_QUERY );
2215 	if( xServiceInfo.is() )
2216 	{
2217 		const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
2218 		while( pEntry->sModelService )
2219 		{
2220 			OUString sModelService( pEntry->sModelService,
2221 									pEntry->nModelServiceLen,
2222 								   	RTL_TEXTENCODING_ASCII_US );
2223 			if( xServiceInfo->supportsService( sModelService ) )
2224 			{
2225 				sFilterService = OUString( pEntry->sFilterService,
2226 										   pEntry->nFilterServiceLen,
2227 								   		   RTL_TEXTENCODING_ASCII_US );
2228                 bIsChart = sModelService.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( XML_MODEL_SERVICE_CHART ));
2229                 break;
2230 			}
2231 			pEntry++;
2232 		}
2233 	}
2234 
2235 	OSL_ENSURE( sFilterService.getLength(), "no export filter for own object" );
2236 
2237 	if( !sFilterService.getLength() )
2238 		return sal_False;
2239 
2240 	Reference < XDocumentHandler > xHdl =
2241 		new XMLEmbeddedObjectExportFilter( mxHandler );
2242 
2243     Sequence < Any > aArgs( 1 );
2244     // #144135# the filters for embedded objects in flat format are always
2245     // instantiated as Oasis filters and transformed afterwards. Therefore, all
2246     // special handling that is done if the exportFlags do not contain
2247     // EXPORT_OASIS must be changed to properties being passed in the info
2248     // propertyset
2249 
2250 	if( ! (getExportFlags() & EXPORT_OASIS) &&
2251         bIsChart )
2252     {
2253         static ::comphelper::PropertyMapEntry aInfoMap[] =
2254         {
2255             { RTL_CONSTASCII_STRINGPARAM("ExportTableNumberList"), 0, &::getBooleanCppuType(), PropertyAttribute::MAYBEVOID, 0},
2256             { NULL, 0, 0, NULL, 0, 0 }
2257         };
2258         Reference< XPropertySet > xInfoProp(
2259             ::comphelper::GenericPropertySet_CreateInstance(
2260                 new ::comphelper::PropertySetInfo( aInfoMap )));
2261 
2262         if( bIsChart )
2263             xInfoProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ExportTableNumberList")), makeAny( true ));
2264 
2265         aArgs.realloc( 2 );
2266         aArgs[1] <<= xInfoProp;
2267     }
2268 	aArgs[0] <<= xHdl;
2269 
2270 	// #110680#
2271 	// Reference< lang::XMultiServiceFactory > xServiceFactory = comphelper::getProcessServiceFactory();
2272 	Reference< lang::XMultiServiceFactory > xServiceFactory = getServiceFactory();
2273 
2274 	Reference< document::XExporter > xExporter(
2275 		xServiceFactory->createInstanceWithArguments( sFilterService, aArgs),
2276 											   UNO_QUERY);
2277 	OSL_ENSURE( xExporter.is(),
2278 				"can't instantiate export filter component for own object" );
2279 	if( !xExporter.is() )
2280 		return sal_False;
2281 
2282 	xExporter->setSourceDocument( rComp );
2283 
2284 	Reference<XFilter> xFilter( xExporter, UNO_QUERY );
2285 
2286 	Sequence < PropertyValue > aMediaDesc( 0 );
2287 	return xFilter->filter( aMediaDesc );
2288 }
2289 
2290 OUString SvXMLExport::GetRelativeReference(const OUString& rValue)
2291 {
2292     OUString sValue( rValue );
2293     // #i65474# handling of fragment URLs ("#....") is undefined
2294     // they are stored 'as is'
2295     uno::Reference< uri::XUriReference > xUriRef;
2296     if(sValue.getLength() && sValue.getStr()[0] != '#')
2297     {
2298         try
2299         {
2300             xUriRef = mpImpl->mxUriReferenceFactory->parse( rValue );
2301             if( xUriRef.is() && !xUriRef->isAbsolute() )
2302             {
2303                 //#i61943# relative URLs need special handling
2304                 INetURLObject aTemp( mpImpl->msPackageURI );
2305                 bool bWasAbsolute = false;
2306                 sValue = aTemp.smartRel2Abs(sValue, bWasAbsolute ).GetMainURL(INetURLObject::DECODE_TO_IURI);
2307             }
2308         }
2309         catch( uno::Exception& )
2310         {
2311         }
2312     }
2313     OUString sRet = sValue;
2314     if( xUriRef.is() )//no conversion for empty values or for fragments
2315     {
2316         //conversion for matching schemes only
2317         if( xUriRef->getScheme() == mpImpl->msPackageURIScheme )
2318         {
2319             sValue = INetURLObject::GetRelURL( msOrigFileName, sValue,
2320                 INetURLObject::WAS_ENCODED, INetURLObject::DECODE_TO_IURI, RTL_TEXTENCODING_UTF8, INetURLObject::FSYS_DETECT);
2321         }
2322     }
2323     return sValue;
2324 }
2325 
2326 void SvXMLExport::StartElement(sal_uInt16 nPrefix,
2327                         enum ::xmloff::token::XMLTokenEnum eName,
2328 					    sal_Bool bIgnWSOutside )
2329 {
2330 	StartElement(_GetNamespaceMap().GetQNameByKey( nPrefix,
2331         GetXMLToken(eName) ), bIgnWSOutside);
2332 }
2333 
2334 void SvXMLExport::StartElement(const OUString& rName,
2335 					    sal_Bool bIgnWSOutside )
2336 {
2337 	if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
2338 	{
2339 		try
2340 		{
2341 			if( bIgnWSOutside && ((mnExportFlags & EXPORT_PRETTY) == EXPORT_PRETTY))
2342 				mxHandler->ignorableWhitespace( msWS );
2343 			mxHandler->startElement( rName, GetXAttrList() );
2344 		}
2345 		catch ( SAXInvalidCharacterException& e )
2346 		{
2347             Sequence<OUString> aPars(1);
2348             aPars[0] = rName;
2349 			SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, NULL );
2350 		}
2351 		catch ( SAXException& e )
2352 		{
2353             Sequence<OUString> aPars(1);
2354             aPars[0] = rName;
2355             SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2356                       aPars, e.Message, NULL );
2357 		}
2358 	}
2359     ClearAttrList();
2360     ++mpImpl->mDepth; // increment nesting depth counter
2361 }
2362 
2363 void SvXMLExport::Characters(const ::rtl::OUString& rChars)
2364 {
2365 	if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
2366 	{
2367 		try
2368 		{
2369 			mxHandler->characters(rChars);
2370 		}
2371 		catch ( SAXInvalidCharacterException& e )
2372 		{
2373             Sequence<OUString> aPars(1);
2374             aPars[0] = rChars;
2375 			SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, NULL );
2376 		}
2377 		catch ( SAXException& e )
2378 		{
2379             Sequence<OUString> aPars(1);
2380             aPars[0] = rChars;
2381             SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2382                       aPars, e.Message, NULL );
2383 		}
2384 	}
2385 }
2386 
2387 void SvXMLExport::EndElement(sal_uInt16 nPrefix,
2388 						enum ::xmloff::token::XMLTokenEnum eName,
2389 						sal_Bool bIgnWSInside )
2390 {
2391 	EndElement(_GetNamespaceMap().GetQNameByKey( nPrefix, GetXMLToken(eName) ),
2392         bIgnWSInside);
2393 }
2394 
2395 void SvXMLExport::EndElement(const OUString& rName,
2396 						sal_Bool bIgnWSInside )
2397 {
2398     // decrement nesting depth counter & (maybe) restore namespace map
2399     --mpImpl->mDepth;
2400     if (!mpImpl->mNamespaceMaps.empty() &&
2401         (mpImpl->mNamespaceMaps.top().second == mpImpl->mDepth))
2402     {
2403         delete mpNamespaceMap;
2404         mpNamespaceMap = mpImpl->mNamespaceMaps.top().first;
2405         mpImpl->mNamespaceMaps.pop();
2406     }
2407     OSL_ENSURE(mpImpl->mNamespaceMaps.empty() ||
2408         (mpImpl->mNamespaceMaps.top().second < mpImpl->mDepth),
2409         "SvXMLExport: NamespaceMaps corrupted");
2410 
2411 	if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
2412 	{
2413 		try
2414 		{
2415 			if( bIgnWSInside && ((mnExportFlags & EXPORT_PRETTY) == EXPORT_PRETTY))
2416 				mxHandler->ignorableWhitespace( msWS );
2417 			mxHandler->endElement( rName );
2418 		}
2419 		catch ( SAXException& e )
2420 		{
2421             Sequence<OUString> aPars(1);
2422             aPars[0] = rName;
2423             SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2424                       aPars, e.Message, NULL );
2425 		}
2426 	}
2427 }
2428 
2429 void SvXMLExport::IgnorableWhitespace()
2430 {
2431 	if ((mnExportFlags & EXPORT_PRETTY) != EXPORT_PRETTY)
2432 		return;
2433 
2434 	if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
2435 	{
2436 		try
2437 		{
2438 			mxHandler->ignorableWhitespace( msWS );
2439 		}
2440 		catch ( SAXException& e )
2441 		{
2442             Sequence<OUString> aPars(0);
2443             SetError( XMLERROR_SAX|XMLERROR_FLAG_ERROR|XMLERROR_FLAG_SEVERE,
2444                       aPars, e.Message, NULL );
2445 		}
2446 	}
2447 }
2448 
2449 
2450 void SvXMLExport::SetError(
2451     sal_Int32 nId,
2452     const Sequence<OUString>& rMsgParams,
2453     const OUString& rExceptionMessage,
2454     const Reference<XLocator>& rLocator )
2455 {
2456     // allow multi-threaded access to the cancel() method
2457     static ::vos::OMutex aMutex;
2458     ::vos::OGuard aGuard(aMutex);
2459 
2460     // maintain error flags
2461     if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
2462         mnErrorFlags |= ERROR_ERROR_OCCURED;
2463     if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
2464         mnErrorFlags |= ERROR_WARNING_OCCURED;
2465     if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
2466         mnErrorFlags |= ERROR_DO_NOTHING;
2467 
2468     // create error lsit on demand
2469     if ( mpXMLErrors == NULL )
2470         mpXMLErrors = new XMLErrors();
2471 
2472     // save error information
2473     mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage, rLocator );
2474 }
2475 
2476 void SvXMLExport::SetError(
2477     sal_Int32 nId,
2478     const Sequence<OUString>& rMsgParams)
2479 {
2480     OUString sEmpty;
2481     SetError( nId, rMsgParams, sEmpty, NULL );
2482 }
2483 
2484 
2485 XMLErrors* SvXMLExport::GetErrors()
2486 {
2487 	return mpXMLErrors;
2488 }
2489 
2490 void SvXMLExport::DisposingModel()
2491 {
2492 	mxModel.clear();
2493     // --> OD 2006-03-13 #i51726#
2494     meModelType = SvtModuleOptions::E_UNKNOWN_FACTORY;;
2495     // <--
2496 	mxEventListener.clear();
2497 }
2498 
2499 // #110680#
2500 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > SvXMLExport::getServiceFactory()
2501 {
2502 	// #110680#
2503 	return mxServiceFactory;
2504 }
2505 
2506 uno::Reference< uno::XComponentContext >
2507 SvXMLExport::GetComponentContext() const
2508 {
2509     return mpImpl->mxComponentContext;
2510 }
2511 
2512 ::comphelper::UnoInterfaceToUniqueIdentifierMapper& SvXMLExport::getInterfaceToIdentifierMapper()
2513 {
2514 	return mpImpl->maInterfaceToIdentifierMapper;
2515 }
2516 
2517 // --> OD 2006-09-27 #i69627#
2518 sal_Bool SvXMLExport::writeOutlineStyleAsNormalListStyle() const
2519 {
2520     return mpImpl->mbOutlineStyleAsNormalListStyle;
2521 }
2522 // <--
2523 
2524 uno::Reference< embed::XStorage > SvXMLExport::GetTargetStorage()
2525 {
2526 	return mpImpl->mxTargetStorage;
2527 }
2528 
2529 /// returns the currently configured default version for odf export
2530 SvtSaveOptions::ODFDefaultVersion SvXMLExport::getDefaultVersion() const
2531 {
2532 	if( mpImpl )
2533 		return mpImpl->maSaveOptions.GetODFDefaultVersion();
2534 
2535 	// fatal error, use current version as default
2536 	return SvtSaveOptions::ODFVER_012;
2537 }
2538 
2539 ::rtl::OUString SvXMLExport::GetStreamName() const
2540 {
2541     return mpImpl->mStreamName;
2542 }
2543 
2544 void
2545 SvXMLExport::AddAttributeIdLegacy(
2546         sal_uInt16 const nLegacyPrefix, ::rtl::OUString const& rValue)
2547 {
2548     switch (getDefaultVersion()) {
2549         case SvtSaveOptions::ODFVER_011: // fall thru
2550         case SvtSaveOptions::ODFVER_010: break;
2551         default: // ODF 1.2: xml:id
2552             AddAttribute(XML_NAMESPACE_XML, XML_ID, rValue);
2553     }
2554     // in ODF 1.1 this was form:id, anim:id, draw:id, or text:id
2555     // backward compatibility: in ODF 1.2 write _both_ id attrs
2556     AddAttribute(nLegacyPrefix, XML_ID, rValue);
2557     // FIXME: this function simply assumes that rValue is unique
2558 }
2559 
2560 void
2561 SvXMLExport::AddAttributeXmlId(uno::Reference<uno::XInterface> const & i_xIfc)
2562 {
2563     // check version >= 1.2
2564     switch (getDefaultVersion()) {
2565         case SvtSaveOptions::ODFVER_011: // fall thru
2566         case SvtSaveOptions::ODFVER_010: return;
2567         default: break;
2568     }
2569     const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
2570         uno::UNO_QUERY);
2571 //FIXME not yet...
2572 //    OSL_ENSURE(xMeta.is(), "xml:id: not XMetadatable");
2573     if ( xMeta.is() )
2574     {
2575         const beans::StringPair mdref( xMeta->getMetadataReference() );
2576         if ( !mdref.Second.equalsAscii("") )
2577         {
2578             const ::rtl::OUString streamName( GetStreamName() );
2579             if ( streamName.getLength() )
2580             {
2581                 if ( streamName.equals(mdref.First) )
2582                 {
2583                     AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2584                 }
2585                 else
2586                 {
2587                     OSL_ENSURE(false, "SvXMLExport::AddAttributeXmlId: "
2588                          "invalid stream name");
2589                 }
2590             }
2591             else
2592             {
2593                 // FIXME: this is ugly
2594                 // there is no stream name (e.g. XSLT, flat-xml format)!
2595                 // but how do we ensure uniqueness in this case?
2596                 // a) just omit styles.xml ids -- they are unlikely anyway...
2597                 // b) somehow find out whether we are currently exporting styles
2598                 //    or content, and prefix "s" or "c" => unique
2599                 if ( mdref.First.equalsAscii("content.xml") )
2600                 {
2601                     AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2602                 }
2603                 else
2604                 {
2605                     OSL_TRACE("SvXMLExport::AddAttributeXmlId: "
2606                         "no stream name given: dropping styles.xml xml:id");
2607                 }
2608             }
2609         }
2610     }
2611 }
2612 
2613 void
2614 SvXMLExport::AddAttributesRDFa(
2615     uno::Reference<text::XTextContent> const & i_xTextContent)
2616 {
2617     // check version >= 1.2
2618     switch (getDefaultVersion()) {
2619         case SvtSaveOptions::ODFVER_011: // fall thru
2620         case SvtSaveOptions::ODFVER_010: return;
2621         default: break;
2622     }
2623 
2624     const uno::Reference<rdf::XMetadatable> xMeta(
2625         i_xTextContent, uno::UNO_QUERY);
2626     if (!xMeta.is() || !xMeta->getMetadataReference().Second.getLength())
2627     {
2628         return; // no xml:id => no RDFa
2629     }
2630 
2631     if (!mpImpl->mpRDFaHelper.get())
2632     {
2633         mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaExportHelper(*this) );
2634     }
2635     mpImpl->mpRDFaHelper->AddRDFa(xMeta);
2636 }
2637 
2638 sal_Bool SvXMLExport::exportTextNumberElement() const
2639 {
2640     return mpImpl->mbExportTextNumberElement;
2641 }
2642 
2643 sal_Bool SvXMLExport::SetNullDateOnUnitConverter()
2644 {
2645     // if the null date has already been set, don't set it again (performance)
2646     if (!mpImpl->mbNullDateInitialized)
2647         mpImpl->mbNullDateInitialized = GetMM100UnitConverter().setNullDate(GetModel());
2648 
2649     return mpImpl->mbNullDateInitialized;
2650 }
2651 
2652 
2653 //=============================================================================
2654 
2655 
2656 void SvXMLElementExport::StartElement(
2657     const sal_uInt16 nPrefixKey,
2658     const OUString& rLName,
2659     const sal_Bool bIgnoreWhitespaceOutside )
2660 {
2661     maElementName = mrExport.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
2662     mrExport.StartElement(maElementName, bIgnoreWhitespaceOutside);
2663 }
2664 
2665 SvXMLElementExport::SvXMLElementExport(
2666     SvXMLExport& rExp,
2667     sal_uInt16 nPrefixKey,
2668     const sal_Char *pLName,
2669     sal_Bool bIWSOutside,
2670     sal_Bool bIWSInside )
2671     : mrExport( rExp )
2672     , maElementName()
2673     , mbIgnoreWhitespaceInside( bIWSInside )
2674     , mbDoSomething( sal_True )
2675 {
2676     const OUString sLName( OUString::createFromAscii( pLName ) );
2677     StartElement( nPrefixKey, sLName, bIWSOutside );
2678 }
2679 
2680 SvXMLElementExport::SvXMLElementExport(
2681     SvXMLExport& rExp,
2682     sal_uInt16 nPrefixKey,
2683     const OUString& rLName,
2684     sal_Bool bIWSOutside,
2685     sal_Bool bIWSInside )
2686     : mrExport( rExp )
2687     , maElementName()
2688     , mbIgnoreWhitespaceInside( bIWSInside )
2689     , mbDoSomething( sal_True )
2690 {
2691     StartElement( nPrefixKey, rLName, bIWSOutside );
2692 }
2693 
2694 SvXMLElementExport::SvXMLElementExport(
2695     SvXMLExport& rExp,
2696     sal_uInt16 nPrefixKey,
2697     enum XMLTokenEnum eLName,
2698     sal_Bool bIWSOutside,
2699     sal_Bool bIWSInside )
2700     : mrExport( rExp )
2701     , maElementName()
2702     , mbIgnoreWhitespaceInside( bIWSInside )
2703     , mbDoSomething( sal_True )
2704 {
2705     StartElement( nPrefixKey, GetXMLToken(eLName), bIWSOutside );
2706 }
2707 
2708 SvXMLElementExport::SvXMLElementExport(
2709     SvXMLExport& rExp,
2710     sal_Bool bDoSth,
2711     sal_uInt16 nPrefixKey,
2712     const sal_Char *pLName,
2713     sal_Bool bIWSOutside,
2714     sal_Bool bIWSInside )
2715     : mrExport( rExp )
2716     , maElementName()
2717     , mbIgnoreWhitespaceInside( bIWSInside )
2718     , mbDoSomething( bDoSth )
2719 {
2720     if ( mbDoSomething )
2721     {
2722         const OUString sLName( OUString::createFromAscii( pLName ) );
2723         StartElement( nPrefixKey, sLName, bIWSOutside );
2724     }
2725 }
2726 
2727 SvXMLElementExport::SvXMLElementExport(
2728     SvXMLExport& rExp,
2729     sal_Bool bDoSth,
2730     sal_uInt16 nPrefixKey,
2731     const OUString& rLName,
2732     sal_Bool bIWSOutside,
2733     sal_Bool bIWSInside )
2734     : mrExport( rExp )
2735     , maElementName()
2736     , mbIgnoreWhitespaceInside( bIWSInside )
2737     , mbDoSomething( bDoSth )
2738 {
2739     if ( mbDoSomething )
2740         StartElement( nPrefixKey, rLName, bIWSOutside );
2741 }
2742 
2743 SvXMLElementExport::SvXMLElementExport(
2744     SvXMLExport& rExp,
2745     sal_Bool bDoSth,
2746     sal_uInt16 nPrefixKey,
2747     enum XMLTokenEnum eLName,
2748     sal_Bool bIWSOutside,
2749     sal_Bool bIWSInside )
2750     : mrExport( rExp )
2751     , maElementName()
2752     , mbIgnoreWhitespaceInside( bIWSInside )
2753     , mbDoSomething( bDoSth )
2754 {
2755     if ( mbDoSomething )
2756         StartElement( nPrefixKey, GetXMLToken( eLName ), bIWSOutside );
2757 }
2758 
2759 SvXMLElementExport::SvXMLElementExport(
2760     SvXMLExport& rExp,
2761     const OUString& rQName,
2762     sal_Bool bIWSOutside,
2763     sal_Bool bIWSInside )
2764     : mrExport( rExp )
2765     , maElementName()
2766     , mbIgnoreWhitespaceInside( bIWSInside )
2767     , mbDoSomething( sal_True )
2768 {
2769     maElementName = rQName;
2770     rExp.StartElement( rQName, bIWSOutside );
2771 }
2772 
2773 SvXMLElementExport::~SvXMLElementExport()
2774 {
2775     if ( mbDoSomething )
2776     {
2777         mrExport.EndElement( maElementName, mbIgnoreWhitespaceInside );
2778     }
2779 }
2780 
2781