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