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