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