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