LibreOffice Module xmloff (master)  1
xmlexp.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <memory>
21 #include <sal/config.h>
22 #include <sal/log.hxx>
23 
24 #include <stack>
25 
26 #include <officecfg/Office/Common.hxx>
28 #include <osl/mutex.hxx>
29 #include <tools/urlobj.hxx>
30 #include <vcl/graph.hxx>
32 #include <com/sun/star/container/XNameAccess.hpp>
33 #include <com/sun/star/io/XInputStream.hpp>
34 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
35 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
36 #include <com/sun/star/xml/sax/SAXInvalidCharacterException.hpp>
37 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
38 #include <com/sun/star/uri/UriReferenceFactory.hpp>
39 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
40 #include <com/sun/star/util/MeasureUnit.hpp>
44 #include <xmloff/attrlist.hxx>
45 #include <xmloff/nmspmap.hxx>
46 #include <xmloff/xmluconv.hxx>
47 #include <xmloff/xmlnmspe.hxx>
48 #include <xmloff/xmltoken.hxx>
49 #include <xmloff/xmlexp.hxx>
50 #include <xmloff/xmlnumfe.hxx>
51 #include <xmloff/xmlmetae.hxx>
58 #include <com/sun/star/document/XEventsSupplier.hpp>
59 #include <com/sun/star/document/XViewDataSupplier.hpp>
60 #include <com/sun/star/frame/XModel.hpp>
61 #include <xmloff/GradientStyle.hxx>
62 #include <xmloff/HatchStyle.hxx>
63 #include <xmloff/ImageStyle.hxx>
64 #include <TransGradientStyle.hxx>
65 #include <xmloff/MarkerStyle.hxx>
66 #include <xmloff/DashStyle.hxx>
68 #include <XMLImageMapExport.hxx>
69 #include <XMLBase64Export.hxx>
70 #include <xmloff/xmlerror.hxx>
71 #include <com/sun/star/style/XStyle.hpp>
72 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
73 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
74 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
75 #include <com/sun/star/beans/PropertyAttribute.hpp>
78 #include <XMLBasicExportFilter.hxx>
79 #include <cppuhelper/exc_hlp.hxx>
80 #include <cppuhelper/implbase.hxx>
82 #include <comphelper/extract.hxx>
83 #include <PropertySetMerger.hxx>
84 
86 #include <com/sun/star/document/XDocumentProperties.hpp>
87 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
88 #include <com/sun/star/document/XMLOasisBasicExporter.hpp>
89 #include <com/sun/star/embed/XEncryptionProtectedSource2.hpp>
90 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
91 #include <com/sun/star/rdf/XMetadatable.hpp>
92 #include <RDFaExportHelper.hxx>
93 
94 #include <comphelper/xmltools.hxx>
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 char const sXML_1_2[] = "1.2";
110 
111 #define XML_MODEL_SERVICE_WRITER "com.sun.star.text.TextDocument"
112 #define XML_MODEL_SERVICE_CALC "com.sun.star.sheet.SpreadsheetDocument"
113 #define XML_MODEL_SERVICE_DRAW "com.sun.star.drawing.DrawingDocument"
114 #define XML_MODEL_SERVICE_IMPRESS "com.sun.star.presentation.PresentationDocument"
115 #define XML_MODEL_SERVICE_MATH "com.sun.star.formula.FormulaProperties"
116 #define XML_MODEL_SERVICE_CHART "com.sun.star.chart.ChartDocument"
117 
118 #define XML_USEPRETTYPRINTING "UsePrettyPrinting"
119 
120 #define XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE "vnd.sun.star.GraphicObject:"
121 #define XML_EMBEDDEDOBJECT_URL_BASE "vnd.sun.star.EmbeddedObject:"
122 
123 namespace {
124 
125 struct XMLServiceMapEntry_Impl
126 {
127  const char *sModelService;
128  sal_Int32 nModelServiceLen;
129  const char *sFilterService;
130  sal_Int32 nFilterServiceLen;
131 };
132 
133 }
134 
135 #define SERVICE_MAP_ENTRY( app ) \
136  { XML_MODEL_SERVICE_##app, sizeof(XML_MODEL_SERVICE_##app)-1, \
137  XML_EXPORT_FILTER_##app, sizeof(XML_EXPORT_FILTER_##app)-1 }
138 
139 const XMLServiceMapEntry_Impl aServiceMap[] =
140 {
143  SERVICE_MAP_ENTRY( IMPRESS ),// Impress supports DrawingDocument, too, so
144  SERVICE_MAP_ENTRY( DRAW ), // it must appear before Draw
147  { nullptr, 0, nullptr, 0 }
148 };
149 
150 namespace {
151 
152 class SettingsExportFacade : public ::xmloff::XMLSettingsExportContext
153 {
154 public:
155  explicit SettingsExportFacade( SvXMLExport& i_rExport )
156  :m_rExport( i_rExport )
157  {
158  }
159 
160  virtual ~SettingsExportFacade()
161  {
162  }
163 
164  virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName,
165  const OUString& i_rValue ) override;
166  virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName,
167  enum ::xmloff::token::XMLTokenEnum i_eValue ) override;
168 
169  virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName ) override;
170  virtual void EndElement( const bool i_bIgnoreWhitespace ) override;
171 
172  virtual void Characters( const OUString& i_rCharacters ) override;
173 
174  virtual css::uno::Reference< css::uno::XComponentContext >
175  GetComponentContext() const override;
176 private:
177  SvXMLExport& m_rExport;
178  ::std::stack< OUString > m_aElements;
179 };
180 
181 }
182 
183 void SettingsExportFacade::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const OUString& i_rValue )
184 {
185  m_rExport.AddAttribute( XML_NAMESPACE_CONFIG, i_eName, i_rValue );
186 }
187 
188 void SettingsExportFacade::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue )
189 {
190  m_rExport.AddAttribute( XML_NAMESPACE_CONFIG, i_eName, i_eValue );
191 }
192 
193 void SettingsExportFacade::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName )
194 {
195  const OUString sElementName( m_rExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_CONFIG, GetXMLToken( i_eName ) ) );
196  m_rExport.StartElement( sElementName, true/*i_bIgnoreWhitespace*/ );
197  m_aElements.push( sElementName );
198 }
199 
200 void SettingsExportFacade::EndElement( const bool i_bIgnoreWhitespace )
201 {
202  const OUString sElementName( m_aElements.top() );
203  m_rExport.EndElement( sElementName, i_bIgnoreWhitespace );
204  m_aElements.pop();
205 }
206 
207 void SettingsExportFacade::Characters( const OUString& i_rCharacters )
208 {
209  m_rExport.GetDocHandler()->characters( i_rCharacters );
210 }
211 
212 Reference< XComponentContext > SettingsExportFacade::GetComponentContext() const
213 {
214  return m_rExport.getComponentContext();
215 }
216 
217 namespace {
218 
219 class SvXMLExportEventListener : public cppu::WeakImplHelper<
220  css::lang::XEventListener >
221 {
222 private:
223  SvXMLExport* pExport;
224 
225 public:
226  explicit SvXMLExportEventListener(SvXMLExport* pExport);
227 
228  // XEventListener
229  virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) override;
230 };
231 
232 }
233 
234 SvXMLExportEventListener::SvXMLExportEventListener(SvXMLExport* pTempExport)
235  : pExport(pTempExport)
236 {
237 }
238 
239 // XEventListener
240 void SAL_CALL SvXMLExportEventListener::disposing( const lang::EventObject& )
241 {
242  if (pExport)
243  {
244  pExport->DisposingModel();
245  pExport = nullptr;
246  }
247 }
248 
250 {
251 public:
253 
255  uno::Reference< uri::XUriReferenceFactory > mxUriReferenceFactory;
256  OUString msPackageURI;
258  // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
261 
262  uno::Reference< embed::XStorage > mxTargetStorage;
263 
265 
267  OUString mStreamName;
268 
269  OUString maSrcShellID;
270  OUString maDestShellID;
271 
274  ::std::stack< ::std::pair< std::unique_ptr<SvXMLNamespaceMap>, long > > mNamespaceMaps;
276  long mDepth;
277 
278  ::std::unique_ptr< ::xmloff::RDFaExportHelper> mpRDFaHelper;
279 
282 
283  void SetSchemeOf( const OUString& rOrigFileName )
284  {
285  sal_Int32 nSep = rOrigFileName.indexOf(':');
286  if( nSep != -1 )
287  msPackageURIScheme = rOrigFileName.copy( 0, nSep );
288  }
289 };
290 
292 : mxUriReferenceFactory( uri::UriReferenceFactory::create(comphelper::getProcessComponentContext()) ),
293  // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
294  mbOutlineStyleAsNormalListStyle( false ),
295  mbSaveBackwardCompatibleODF( true ),
296  mDepth( 0 ),
297  mbExportTextNumberElement( false ),
298  mbNullDateInitialized( false )
299 {
300 }
301 
302 void SvXMLExport::SetDocHandler( const uno::Reference< xml::sax::XDocumentHandler > &rHandler )
303 {
304  mxHandler = rHandler;
305  mxExtHandler.set( mxHandler, UNO_QUERY );
306 }
307 
309 {
310  // note: it is not necessary to add XML_NP_XML (it is declared implicitly)
312  {
315  }
317  {
319  }
321  {
323  }
325  {
327  }
328 
330  {
333  }
335  {
337  }
338 
339  // namespaces for documents
341  {
354 
356  {
357  mpNamespaceMap->Add(
359  mpNamespaceMap->Add(
361  mpNamespaceMap->Add(
363  mpNamespaceMap->Add(
367  }
368  }
370  {
373  }
375  {
378  }
380  {
385  }
386 
387  // RDFa: needed for content and header/footer styles
389  {
392  }
393  // GRDDL: to convert RDFa and meta.xml to RDF
395  {
398  }
399  // CSS Text Level 3 for distributed text justification.
401  {
402  mpNamespaceMap->Add(
404  }
405 
406  if (mxModel.is() && !mxEventListener.is())
407  {
408  mxEventListener.set( new SvXMLExportEventListener(this));
409  mxModel->addEventListener(mxEventListener);
410  }
411 
412  // Determine model type (#i51726#)
414 
415  // cl: but only if we do export to current oasis format, old openoffice format *must* always be compatible
417  {
418  mpImpl->mbSaveBackwardCompatibleODF =
419  officecfg::Office::Common::Save::Document::
420  SaveBackwardCompatibleODF::get( comphelper::getProcessComponentContext() );
421  }
422 }
423 
424 // Shapes in Writer cannot be named via context menu (#i51726#)
426 {
428 
429  if ( mxModel.is() )
430  {
432  }
433 }
434 
436  sal_Int16 const eDefaultMeasureUnit /*css::util::MeasureUnit*/,
437  const uno::Reference< uno::XComponentContext >& xContext,
438  OUString const & implementationName,
439  const enum XMLTokenEnum eClass, SvXMLExportFlags nExportFlags )
440 : mpImpl( new SvXMLExport_Impl ),
441  m_xContext(xContext), m_implementationName(implementationName),
442  mxAttrList( new SvXMLAttributeList ),
443  mpNamespaceMap( new SvXMLNamespaceMap ),
444  maUnitConv( xContext, util::MeasureUnit::MM_100TH, eDefaultMeasureUnit ),
445  meClass( eClass ),
446  mnExportFlags( nExportFlags ),
447  mnErrorFlags( SvXMLErrorFlags::NO ),
448  msWS( GetXMLToken(XML_WS) ),
449  mbSaveLinkedSections(true),
450  mbAutoStylesCollected(false)
451 {
452  SAL_WARN_IF( !xContext.is(), "xmloff.core", "got no service manager" );
453  InitCtor_();
454 }
455 
457  const css::uno::Reference< css::uno::XComponentContext >& xContext,
458  OUString const & implementationName,
459  const OUString &rFileName,
460  sal_Int16 const eDefaultMeasureUnit /*css::util::MeasureUnit*/,
461  const uno::Reference< xml::sax::XDocumentHandler > & rHandler)
462 : mpImpl( new SvXMLExport_Impl ),
463  m_xContext(xContext), m_implementationName(implementationName),
464  mxHandler( rHandler ),
465  mxExtHandler( rHandler, uno::UNO_QUERY ),
466  mxAttrList( new SvXMLAttributeList ),
467  msOrigFileName( rFileName ),
468  mpNamespaceMap( new SvXMLNamespaceMap ),
469  maUnitConv( xContext, util::MeasureUnit::MM_100TH, eDefaultMeasureUnit ),
471  mnExportFlags( SvXMLExportFlags::NONE ),
472  mnErrorFlags( SvXMLErrorFlags::NO ),
473  msWS( GetXMLToken(XML_WS) ),
474  mbSaveLinkedSections(true),
475  mbAutoStylesCollected(false)
476 {
477  SAL_WARN_IF( !xContext.is(), "xmloff.core", "got no service manager" );
478  mpImpl->SetSchemeOf( msOrigFileName );
479  InitCtor_();
480 
481  if (mxNumberFormatsSupplier.is())
483 }
484 
486  const css::uno::Reference< css::uno::XComponentContext >& xContext,
487  OUString const & implementationName,
488  const OUString &rFileName,
489  const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
490  const Reference< XModel >& rModel,
491  FieldUnit const eDefaultFieldUnit,
492  SvXMLExportFlags nExportFlag)
493 : mpImpl( new SvXMLExport_Impl ),
494  m_xContext(xContext), m_implementationName(implementationName),
495  mxModel( rModel ),
496  mxHandler( rHandler ),
497  mxExtHandler( rHandler, uno::UNO_QUERY ),
498  mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
499  mxAttrList( new SvXMLAttributeList ),
500  msOrigFileName( rFileName ),
501  mpNamespaceMap( new SvXMLNamespaceMap ),
502  maUnitConv( xContext,
503  util::MeasureUnit::MM_100TH,
504  SvXMLUnitConverter::GetMeasureUnit(eDefaultFieldUnit) ),
506  mnExportFlags( nExportFlag ),
507  mnErrorFlags( SvXMLErrorFlags::NO ),
508  msWS( GetXMLToken(XML_WS) ),
509  mbSaveLinkedSections(true),
510  mbAutoStylesCollected(false)
511 {
512  SAL_WARN_IF(!xContext.is(), "xmloff.core", "got no service manager" );
513  mpImpl->SetSchemeOf( msOrigFileName );
514  InitCtor_();
515 
516  if (mxNumberFormatsSupplier.is())
518 }
519 
521 {
522  mpXMLErrors.reset();
523  mpImageMapExport.reset();
524  mpEventExport.reset();
525  mpNamespaceMap.reset();
527  {
528  if (mxExportInfo.is())
529  {
530  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
531  if (xPropertySetInfo.is())
532  {
534  {
535  OUString sProgressMax(XML_PROGRESSMAX);
536  OUString sProgressCurrent(XML_PROGRESSCURRENT);
537  OUString sRepeat(XML_PROGRESSREPEAT);
538  if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
539  xPropertySetInfo->hasPropertyByName(sProgressCurrent))
540  {
541  sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
542  sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
543  mxExportInfo->setPropertyValue(sProgressMax, uno::Any(nProgressMax));
544  mxExportInfo->setPropertyValue(sProgressCurrent, uno::Any(nProgressCurrent));
545  }
546  if (xPropertySetInfo->hasPropertyByName(sRepeat))
547  mxExportInfo->setPropertyValue(sRepeat, css::uno::makeAny(mpProgressBarHelper->GetRepeat()));
548  }
550  {
551  OUString sWrittenNumberFormats(XML_WRITTENNUMBERSTYLES);
552  if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
553  {
554  mxExportInfo->setPropertyValue(sWrittenNumberFormats, Any(mpNumExport->GetWasUsed()));
555  }
556  }
557  }
558  }
559  mpProgressBarHelper.reset();
560  mpNumExport.reset();
561  }
562 
563  if (mxEventListener.is() && mxModel.is())
564  mxModel->removeEventListener(mxEventListener);
565 }
566 
567 // XExporter
568 void SAL_CALL SvXMLExport::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
569 {
570  mxModel.set( xDoc, UNO_QUERY );
571  if( !mxModel.is() )
572  throw lang::IllegalArgumentException();
573  if (mxModel.is() && ! mxEventListener.is())
574  {
575  mxEventListener.set( new SvXMLExportEventListener(this));
576  mxModel->addEventListener(mxEventListener);
577  }
578 
579  if(!mxNumberFormatsSupplier.is() )
580  {
581  mxNumberFormatsSupplier.set(mxModel, css::uno::UNO_QUERY);
582  if(mxNumberFormatsSupplier.is() && mxHandler.is())
584  }
585  if (mxExportInfo.is())
586  {
587  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
588  if (xPropertySetInfo.is())
589  {
590  OUString sUsePrettyPrinting(XML_USEPRETTYPRINTING);
591  if (xPropertySetInfo->hasPropertyByName(sUsePrettyPrinting))
592  {
593  uno::Any aAny = mxExportInfo->getPropertyValue(sUsePrettyPrinting);
594  if (::cppu::any2bool(aAny))
596  else
598  }
599 
601  {
602  OUString sWrittenNumberFormats(XML_WRITTENNUMBERSTYLES);
603  if (xPropertySetInfo->hasPropertyByName(sWrittenNumberFormats))
604  {
605  uno::Any aAny = mxExportInfo->getPropertyValue(sWrittenNumberFormats);
606  uno::Sequence<sal_Int32> aWasUsed;
607  if(aAny >>= aWasUsed)
608  mpNumExport->SetWasUsed(aWasUsed);
609  }
610  }
611  }
612  }
613 
614  if ( mpImpl->mbSaveBackwardCompatibleODF )
616  else
618 
619  // namespaces for user defined attributes
620  Reference< XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
621  if( xFactory.is() )
622  {
623  try
624  {
626  xFactory->createInstance("com.sun.star.xml.NamespaceMap");
627  if( xIfc.is() )
628  {
629  Reference< XNameAccess > xNamespaceMap( xIfc, UNO_QUERY );
630  if( xNamespaceMap.is() )
631  {
632  const Sequence< OUString > aPrefixes( xNamespaceMap->getElementNames() );
633  for( OUString const & prefix : aPrefixes )
634  {
635  OUString aURL;
636  if( xNamespaceMap->getByName( prefix ) >>= aURL )
637  GetNamespaceMap_().Add( prefix, aURL );
638  }
639  }
640  }
641  }
642  catch(const css::uno::Exception&)
643  {
644  }
645  }
646 
647  // Determine model type (#i51726#)
649 }
650 
651 // XInitialize
652 void SAL_CALL SvXMLExport::initialize( const uno::Sequence< uno::Any >& aArguments )
653 {
654  // #93186# we need to queryInterface every single Any with any expected outcome. This variable hold the queryInterface results.
655 
656  for( const auto& rAny : aArguments )
657  {
658  Reference<XInterface> xValue;
659  rAny >>= xValue;
660 
661  // status indicator
662  uno::Reference<task::XStatusIndicator> xTmpStatus( xValue, UNO_QUERY );
663  if ( xTmpStatus.is() )
664  mxStatusIndicator = xTmpStatus;
665 
666  // graphic storage handler
667  uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler(xValue, UNO_QUERY);
668  if (xGraphicStorageHandler.is())
669  mxGraphicStorageHandler = xGraphicStorageHandler;
670 
671  // object resolver
672  uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
673  xValue, UNO_QUERY );
674  if ( xTmpObjectResolver.is() )
675  mxEmbeddedResolver = xTmpObjectResolver;
676 
677  // document handler
678  uno::Reference<xml::sax::XDocumentHandler> xTmpDocHandler(
679  xValue, UNO_QUERY );
680  if( xTmpDocHandler.is() )
681  {
682  mxHandler = xTmpDocHandler;
683  rAny >>= mxExtHandler;
684 
685  if (mxNumberFormatsSupplier.is() && mpNumExport == nullptr)
687  }
688 
689  // property set to transport data across
690  uno::Reference<beans::XPropertySet> xTmpPropertySet(
691  xValue, UNO_QUERY );
692  if( xTmpPropertySet.is() )
693  mxExportInfo = xTmpPropertySet;
694  }
695 
696  if( !mxExportInfo.is() )
697  return;
698 
699  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo =
700  mxExportInfo->getPropertySetInfo();
701  OUString sPropName(
702  "BaseURI" );
703  if( xPropertySetInfo->hasPropertyByName(sPropName) )
704  {
705  uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
706  aAny >>= msOrigFileName;
707  mpImpl->msPackageURI = msOrigFileName;
708  mpImpl->SetSchemeOf( msOrigFileName );
709  }
710  OUString sRelPath;
711  sPropName = "StreamRelPath";
712  if( xPropertySetInfo->hasPropertyByName(sPropName) )
713  {
714  uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
715  aAny >>= sRelPath;
716  }
717  OUString sName;
718  sPropName = "StreamName";
719  if( xPropertySetInfo->hasPropertyByName(sPropName) )
720  {
721  uno::Any aAny = mxExportInfo->getPropertyValue(sPropName);
722  aAny >>= sName;
723  }
724  if( !msOrigFileName.isEmpty() && !sName.isEmpty() )
725  {
726  INetURLObject aBaseURL( msOrigFileName );
727  if( !sRelPath.isEmpty() )
728  aBaseURL.insertName( sRelPath );
729  aBaseURL.insertName( sName );
731  }
732  mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
733 
734  // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
735  const OUString sOutlineStyleAsNormalListStyle(
736  "OutlineStyleAsNormalListStyle" );
737  if( xPropertySetInfo->hasPropertyByName( sOutlineStyleAsNormalListStyle ) )
738  {
739  uno::Any aAny = mxExportInfo->getPropertyValue( sOutlineStyleAsNormalListStyle );
740  aAny >>= mpImpl->mbOutlineStyleAsNormalListStyle;
741  }
742 
743  OUString sTargetStorage( "TargetStorage" );
744  if( xPropertySetInfo->hasPropertyByName( sTargetStorage ) )
745  mxExportInfo->getPropertyValue( sTargetStorage ) >>= mpImpl->mxTargetStorage;
746 
747  const OUString sExportTextNumberElement(
748  "ExportTextNumberElement" );
749  if( xPropertySetInfo->hasPropertyByName( sExportTextNumberElement ) )
750  {
751  uno::Any aAny = mxExportInfo->getPropertyValue( sExportTextNumberElement );
752  aAny >>= mpImpl->mbExportTextNumberElement;
753  }
754 }
755 
756 // XFilter
757 sal_Bool SAL_CALL SvXMLExport::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
758 {
759  // check for xHandler first... should have been supplied in initialize
760  if( !mxHandler.is() )
761  return false;
762 
763  try
764  {
765  const SvXMLExportFlags nTest =
767  if( (mnExportFlags & nTest) == nTest && msOrigFileName.isEmpty() )
768  {
769  // evaluate descriptor only for flat files and if a base URI
770  // has not been provided already
771 
772  for( const auto& rProp : aDescriptor )
773  {
774  const OUString& rPropName = rProp.Name;
775  const Any& rValue = rProp.Value;
776 
777  if ( rPropName == "FileName" )
778  {
779  if( !(rValue >>= msOrigFileName ) )
780  return false;
781  }
782  else if ( rPropName == "FilterName" )
783  {
784  if( !(rValue >>= msFilterName ) )
785  return false;
786  }
787  }
788  }
789 
790  for( const auto& rProp : aDescriptor )
791  {
792  const OUString& rPropName = rProp.Name;
793  const Any& rValue = rProp.Value;
794 
795  if (rPropName == "SourceShellID")
796  {
797  if (!(rValue >>= mpImpl->maSrcShellID))
798  return false;
799  }
800  else if (rPropName == "DestinationShellID")
801  {
802  if (!(rValue >>= mpImpl->maDestShellID))
803  return false;
804  }
805  else if( rPropName == "ImageFilter")
806  {
807  if (!(rValue >>= msImgFilterName))
808  return false;
809  }
810  }
811 
812 
813  exportDoc( meClass );
814  }
815  catch(const uno::Exception& e)
816  {
817  // We must catch exceptions, because according to the
818  // API definition export must not throw one!
819  css::uno::Any ex(cppu::getCaughtException());
820  OUString sMessage( ex.getValueTypeName() + ": \"" + e.Message + "\"");
821  if (e.Context.is())
822  {
823  const char* pContext = typeid(*e.Context).name();
824  sMessage += " (context: " + OUString::createFromAscii(pContext) + " )";
825  }
827  Sequence<OUString>(), sMessage, nullptr );
828  }
829 
830  // return true only if no error occurred
832 }
833 
834 void SAL_CALL SvXMLExport::cancel()
835 {
836  // stop export
837  Sequence<OUString> aEmptySeq;
839 }
840 
841 OUString SAL_CALL SvXMLExport::getName( )
842 {
843  return msFilterName;
844 }
845 
846 void SAL_CALL SvXMLExport::setName( const OUString& )
847 {
848  // do nothing, because it is not possible to set the FilterName
849 }
850 
851 // XServiceInfo
853 {
854  return m_implementationName;
855 }
856 
857 sal_Bool SAL_CALL SvXMLExport::supportsService( const OUString& rServiceName )
858 {
859  return cppu::supportsService(this, rServiceName);
860 }
861 
862 uno::Sequence< OUString > SAL_CALL SvXMLExport::getSupportedServiceNames( )
863 {
864  return { "com.sun.star.document.ExportFilter", "com.sun.star.xml.XMLExportFilter" };
865 }
866 
867 OUString
868 SvXMLExport::EnsureNamespace(OUString const & i_rNamespace)
869 {
870  OUString const aPreferredPrefix("gen");
871  OUString sPrefix;
872  sal_uInt16 nKey( GetNamespaceMap_().GetKeyByName( i_rNamespace ) );
873  if( XML_NAMESPACE_UNKNOWN == nKey )
874  {
875  // There is no prefix for the namespace, so
876  // we have to generate one and have to add it.
877  sPrefix = aPreferredPrefix;
878  nKey = GetNamespaceMap_().GetKeyByPrefix( sPrefix );
879  sal_Int32 n( 0 );
880  OUStringBuffer buf;
881  while( nKey != USHRT_MAX )
882  {
883  buf.append( aPreferredPrefix );
884  buf.append( ++n );
885  sPrefix = buf.makeStringAndClear();
886  nKey = GetNamespaceMap_().GetKeyByPrefix( sPrefix );
887  }
888 
889  if (mpImpl->mNamespaceMaps.empty()
890  || (mpImpl->mNamespaceMaps.top().second != mpImpl->mDepth))
891  {
892  // top was created for lower depth... need a new namespace map!
893  auto pNew = new SvXMLNamespaceMap( *mpNamespaceMap );
894  mpImpl->mNamespaceMaps.push(
895  ::std::make_pair(std::move(mpNamespaceMap), mpImpl->mDepth) );
896  mpNamespaceMap.reset( pNew );
897  }
898 
899  // add the namespace to the map and as attribute
900  mpNamespaceMap->Add( sPrefix, i_rNamespace );
901  buf.append( GetXMLToken(XML_XMLNS) );
902  buf.append( ':' );
903  buf.append( sPrefix );
904  AddAttribute( buf.makeStringAndClear(), i_rNamespace );
905  }
906  else
907  {
908  // If there is a prefix for the namespace, reuse that.
909  sPrefix = GetNamespaceMap_().GetPrefixByKey( nKey );
910  }
911  return sPrefix;
912 }
913 
914 void SvXMLExport::AddAttributeASCII( sal_uInt16 nPrefixKey,
915  const char *pName,
916  const char *pValue )
917 {
918  OUString sName( OUString::createFromAscii( pName ) );
919  OUString sValue( OUString::createFromAscii( pValue ) );
920 
921  mxAttrList->AddAttribute(
922  GetNamespaceMap_().GetQNameByKey( nPrefixKey, sName ), sValue );
923 }
924 
925 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const char *pName,
926  const OUString& rValue )
927 {
928  OUString sName( OUString::createFromAscii( pName ) );
929 
930  mxAttrList->AddAttribute(
931  GetNamespaceMap_().GetQNameByKey( nPrefixKey, sName ), rValue );
932 }
933 
934 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey, const OUString& rName,
935  const OUString& rValue )
936 {
937  mxAttrList->AddAttribute(
938  GetNamespaceMap_().GetQNameByKey( nPrefixKey, rName ), rValue );
939 }
940 
941 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
942  enum XMLTokenEnum eName,
943  const OUString& rValue )
944 {
945  mxAttrList->AddAttribute(
946  GetNamespaceMap_().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
947  rValue );
948 }
949 
950 void SvXMLExport::AddAttribute( sal_uInt16 nPrefixKey,
951  enum XMLTokenEnum eName,
952  enum XMLTokenEnum eValue)
953 {
954  mxAttrList->AddAttribute(
955  GetNamespaceMap_().GetQNameByKey( nPrefixKey, GetXMLToken(eName) ),
956  GetXMLToken(eValue) );
957 }
958 
959 void SvXMLExport::AddAttribute( const OUString& rQName,
960  const OUString& rValue )
961 {
962  mxAttrList->AddAttribute(
963  rQName,
964  rValue );
965 }
966 
967 void SvXMLExport::AddAttribute( const OUString& rQName,
969 {
970  mxAttrList->AddAttribute(
971  rQName,
972  GetXMLToken(eValue) );
973 }
974 
975 void SvXMLExport::AddLanguageTagAttributes( sal_uInt16 nPrefix, sal_uInt16 nPrefixRfc,
976  const css::lang::Locale& rLocale, bool bWriteEmpty )
977 {
978  if (rLocale.Variant.isEmpty())
979  {
980  // Per convention The BCP 47 string is always stored in Variant, if
981  // that is empty we have a plain language-country combination, no need
982  // to convert to LanguageTag first. Also catches the case of empty
983  // locale denoting system locale.
984  xmloff::token::XMLTokenEnum eLanguage, eCountry;
985  eLanguage = XML_LANGUAGE;
986  eCountry = XML_COUNTRY;
987  if (bWriteEmpty || !rLocale.Language.isEmpty())
988  AddAttribute( nPrefix, eLanguage, rLocale.Language);
989  if (bWriteEmpty || !rLocale.Country.isEmpty())
990  AddAttribute( nPrefix, eCountry, rLocale.Country);
991  }
992  else
993  {
994  LanguageTag aLanguageTag( rLocale);
995  AddLanguageTagAttributes( nPrefix, nPrefixRfc, aLanguageTag, bWriteEmpty);
996  }
997 }
998 
999 void SvXMLExport::AddLanguageTagAttributes( sal_uInt16 nPrefix, sal_uInt16 nPrefixRfc,
1000  const LanguageTag& rLanguageTag, bool bWriteEmpty )
1001 {
1002  if (rLanguageTag.isIsoODF())
1003  {
1004  if (bWriteEmpty || !rLanguageTag.isSystemLocale())
1005  {
1006  AddAttribute( nPrefix, XML_LANGUAGE, rLanguageTag.getLanguage());
1007  if (rLanguageTag.hasScript() && getDefaultVersion() >= SvtSaveOptions::ODFVER_012)
1008  AddAttribute( nPrefix, XML_SCRIPT, rLanguageTag.getScript());
1009  if (bWriteEmpty || !rLanguageTag.getCountry().isEmpty())
1010  AddAttribute( nPrefix, XML_COUNTRY, rLanguageTag.getCountry());
1011  }
1012  }
1013  else
1014  {
1016  AddAttribute( nPrefixRfc, XML_RFC_LANGUAGE_TAG, rLanguageTag.getBcp47());
1017  // Also in case of non-pure-ISO tag store best matching fo: attributes
1018  // for consumers not handling *:rfc-language-tag, ensuring that only
1019  // valid ISO codes are stored. Here the bWriteEmpty parameter has no
1020  // meaning.
1021  OUString aLanguage, aScript, aCountry;
1022  rLanguageTag.getIsoLanguageScriptCountry( aLanguage, aScript, aCountry);
1023  if (!aLanguage.isEmpty())
1024  {
1025  AddAttribute( nPrefix, XML_LANGUAGE, aLanguage);
1026  if (!aScript.isEmpty() && getDefaultVersion() >= SvtSaveOptions::ODFVER_012)
1027  AddAttribute( nPrefix, XML_SCRIPT, aScript);
1028  if (!aCountry.isEmpty())
1029  AddAttribute( nPrefix, XML_COUNTRY, aCountry);
1030  }
1031  }
1032 }
1033 
1034 void SvXMLExport::AddAttributeList( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
1035 {
1036  if( xAttrList.is())
1037  mxAttrList->AppendAttributeList( xAttrList );
1038 }
1039 
1041 {
1042  mxAttrList->Clear();
1043 }
1044 
1045 #ifdef DBG_UTIL
1047 {
1048  SAL_WARN_IF( mxAttrList->getLength(), "xmloff.core", "XMLExport::CheckAttrList: list is not empty" );
1049 }
1050 #endif
1051 
1053 {
1054  CheckAttrList();
1055 
1056  ExportMeta_();
1057 }
1058 
1060 {
1061  CheckAttrList();
1062 
1063  ::std::vector< SettingsGroup > aSettings;
1064  sal_Int32 nSettingsCount = 0;
1065 
1066  // view settings
1067  uno::Sequence< beans::PropertyValue > aViewSettings;
1068  GetViewSettingsAndViews( aViewSettings );
1069  aSettings.emplace_back( XML_VIEW_SETTINGS, aViewSettings );
1070  nSettingsCount += aViewSettings.getLength();
1071 
1072  // configuration settings
1073  uno::Sequence<beans::PropertyValue> aConfigSettings;
1074  GetConfigurationSettings( aConfigSettings );
1075  aSettings.emplace_back( XML_CONFIGURATION_SETTINGS, aConfigSettings );
1076  nSettingsCount += aConfigSettings.getLength();
1077 
1078  // any document specific settings
1079  nSettingsCount += GetDocumentSpecificSettings( aSettings );
1080 
1081  {
1082  SvXMLElementExport aElem( *this,
1083  nSettingsCount != 0,
1085  true, true );
1086 
1087  SettingsExportFacade aSettingsExportContext( *this );
1088  XMLSettingsExportHelper aSettingsExportHelper( aSettingsExportContext );
1089 
1090  for (auto const& settings : aSettings)
1091  {
1092  if ( !settings.aSettings.hasElements() )
1093  continue;
1094 
1095  const OUString& sSettingsName( GetXMLToken( settings.eGroupName ) );
1096  OUString sQName = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOO, sSettingsName );
1097  aSettingsExportHelper.exportAllSettings( settings.aSettings, sQName );
1098  }
1099  }
1100 }
1101 
1103 {
1104  CheckAttrList();
1105 
1106  {
1107  // <style:styles>
1109  true, true );
1110 
1111  ExportStyles_( false );
1112  }
1113 
1114  // transfer style names (+ families) TO other components (if appropriate)
1115  if( ( !( mnExportFlags & SvXMLExportFlags::CONTENT ) ) && mxExportInfo.is() )
1116  {
1117  static OUString sStyleNames( "StyleNames" );
1118  static OUString sStyleFamilies( "StyleFamilies" );
1119  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
1120  if ( xPropertySetInfo->hasPropertyByName( sStyleNames ) && xPropertySetInfo->hasPropertyByName( sStyleFamilies ) )
1121  {
1122  Sequence<sal_Int32> aStyleFamilies;
1123  Sequence<OUString> aStyleNames;
1124  mxAutoStylePool->GetRegisteredNames( aStyleFamilies, aStyleNames );
1125  mxExportInfo->setPropertyValue( sStyleNames, makeAny( aStyleNames ) );
1126  mxExportInfo->setPropertyValue( sStyleFamilies,
1127  makeAny( aStyleFamilies ) );
1128  }
1129  }
1130 }
1131 
1133 {
1134  // transfer style names (+ families) FROM other components (if appropriate)
1135  OUString sStyleNames( "StyleNames" );
1136  OUString sStyleFamilies( "StyleFamilies" );
1138  && mxExportInfo.is()
1139  && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleNames )
1140  && mxExportInfo->getPropertySetInfo()->hasPropertyByName( sStyleFamilies ) )
1141  {
1142  Sequence<sal_Int32> aStyleFamilies;
1143  mxExportInfo->getPropertyValue( sStyleFamilies ) >>= aStyleFamilies;
1144  Sequence<OUString> aStyleNames;
1145  mxExportInfo->getPropertyValue( sStyleNames ) >>= aStyleNames;
1146  mxAutoStylePool->RegisterNames( aStyleFamilies, aStyleNames );
1147  }
1148 
1149  {
1150  // <style:automatic-styles>
1152  XML_AUTOMATIC_STYLES, true, true );
1153 
1155  }
1156 }
1157 
1159 {
1160  // <style:master-styles>
1162  true, true );
1163 
1165 }
1166 
1168 {
1169  CheckAttrList();
1170 
1171  CheckAttrList();
1172 
1173  {
1175  true, true );
1176  {
1177  XMLTokenEnum eClass = meClass;
1178  if( XML_TEXT_GLOBAL == eClass )
1179  {
1181  GetXMLToken( XML_TRUE ) );
1182  eClass = XML_TEXT;
1183  }
1184  if ( XML_GRAPHICS == eClass )
1185  eClass = XML_DRAWING;
1186  // <office:body ...>
1188  SvXMLElementExport aElem( *this, meClass != XML_TOKEN_INVALID,
1189  XML_NAMESPACE_OFFICE, eClass,
1190  true, true );
1191 
1192  ExportContent_();
1193  }
1194  }
1195 }
1196 
1198 {
1199 }
1200 
1201 static void
1202 lcl_AddGrddl(SvXMLExport const & rExport, const SvXMLExportFlags /*nExportMode*/)
1203 {
1204  // check version >= 1.2
1205  switch (rExport.getDefaultVersion()) {
1206  case SvtSaveOptions::ODFVER_011: // fall through
1207  case SvtSaveOptions::ODFVER_010: return;
1208  default: break;
1209  }
1210 
1211  // #i115030#: disabled, the XSLT is not finished, and not available via HTTP
1212 #if 0
1213  if (SvXMLExportFlags::SETTINGS != nExportMode) // meta, content, styles
1214  {
1216  OUString("http://FIXME") );
1217  }
1218 #endif
1219 }
1220 
1222 {
1223  uno::Reference< embed::XEncryptionProtectedSource2 > xEncr(mpImpl->mxTargetStorage, uno::UNO_QUERY);
1224 
1225  if (xEncr.is() && xEncr->hasEncryptionData() && mxExtHandler.is())
1226  {
1227  mxExtHandler->comment(OStringToOUString(comphelper::xml::makeXMLChaff(), RTL_TEXTENCODING_ASCII_US));
1228  }
1229 }
1230 
1232 {
1233  bool bOwnGraphicResolver = false;
1234  bool bOwnEmbeddedResolver = false;
1235 
1236  if (!mxGraphicStorageHandler.is() || !mxEmbeddedResolver.is())
1237  {
1238  Reference< XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
1239  if( xFactory.is() )
1240  {
1241  try
1242  {
1243  if (!mxGraphicStorageHandler.is())
1244  {
1245  mxGraphicStorageHandler.set(xFactory->createInstance( "com.sun.star.document.ExportGraphicStorageHandler"), UNO_QUERY);
1246  bOwnGraphicResolver = mxGraphicStorageHandler.is();
1247  }
1248 
1249  if( !mxEmbeddedResolver.is() )
1250  {
1251  mxEmbeddedResolver.set(
1252  xFactory->createInstance( "com.sun.star.document.ExportEmbeddedObjectResolver" ), UNO_QUERY);
1253  bOwnEmbeddedResolver = mxEmbeddedResolver.is();
1254  }
1255  }
1256  catch(const css::uno::Exception&)
1257  {
1258  }
1259  }
1260  }
1262  {
1263  try
1264  {
1265  static ::comphelper::PropertyMapEntry const aInfoMap[] =
1266  {
1267  { OUString("Class"), 0,
1269  PropertyAttribute::MAYBEVOID, 0},
1270  { OUString(), 0, css::uno::Type(), 0, 0 }
1271  };
1272  Reference< XPropertySet > xConvPropSet(
1274  new ::comphelper::PropertySetInfo( aInfoMap ) ) );
1275 
1276  xConvPropSet->setPropertyValue( "Class", Any(GetXMLToken( eClass )) );
1277 
1278  Reference< XPropertySet > xPropSet =
1279  mxExportInfo.is()
1281  xConvPropSet )
1282  : xConvPropSet;
1283 
1284  Sequence<Any> aArgs( 3 );
1285  aArgs[0] <<= mxHandler;
1286  aArgs[1] <<= xPropSet;
1287  aArgs[2] <<= mxModel;
1288 
1289  // get filter component
1291  m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.Oasis2OOoTransformer", aArgs, m_xContext),
1292  UNO_QUERY);
1293  SAL_WARN_IF(!xTmpDocHandler.is(), "xmloff.core", "can't instantiate OASIS transformer component" );
1294  if( xTmpDocHandler.is() )
1295  {
1296  mxHandler = xTmpDocHandler;
1297  mxExtHandler.set( mxHandler, UNO_QUERY );
1298  }
1299  }
1300  catch(const css::uno::Exception&)
1301  {
1302  }
1303  }
1304 
1305  mxHandler->startDocument();
1306 
1308 
1309  // <office:document ...>
1310  CheckAttrList();
1311 
1312  // namespace attributes
1313  // ( The namespace decls should be first attributes in the element;
1314  // some faulty XML parsers (JAXP1.1) have a problem with this,
1315  // also it's more elegant )
1316  sal_uInt16 nPos = mpNamespaceMap->GetFirstKey();
1317  while( USHRT_MAX != nPos )
1318  {
1319  mxAttrList->AddAttribute( mpNamespaceMap->GetAttrNameByKey( nPos ),
1320  mpNamespaceMap->GetNameByKey( nPos ) );
1321  nPos = mpNamespaceMap->GetNextKey( nPos );
1322  }
1323 
1324  // office:version = ...
1325  const char* pVersion = nullptr;
1326  switch (getDefaultVersion())
1327  {
1328  case SvtSaveOptions::ODFVER_LATEST: pVersion = sXML_1_2; break;
1329  case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = sXML_1_2; break;
1330  case SvtSaveOptions::ODFVER_012: pVersion = sXML_1_2; break;
1331  case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break;
1332  case SvtSaveOptions::ODFVER_010: break;
1333 
1334  default:
1335  SAL_WARN("xmloff.core", "xmloff::SvXMLExport::exportDoc(), unexpected odf default version!");
1336  }
1337 
1338  if (pVersion)
1339  {
1341  OUString::createFromAscii(pVersion) );
1342  }
1343 
1344  {
1345  enum XMLTokenEnum eRootService = XML_TOKEN_INVALID;
1347 
1348  lcl_AddGrddl(*this, nExportMode);
1349 
1350  if( SvXMLExportFlags::META == nExportMode )
1351  {
1352  // export only meta
1353  eRootService = XML_DOCUMENT_META;
1354  }
1355  else if ( SvXMLExportFlags::SETTINGS == nExportMode )
1356  {
1357  // export only settings
1358  eRootService = XML_DOCUMENT_SETTINGS;
1359  }
1360  else if( SvXMLExportFlags::STYLES == nExportMode )
1361  {
1362  // export only styles
1363  eRootService = XML_DOCUMENT_STYLES;
1364  }
1365  else if( SvXMLExportFlags::CONTENT == nExportMode )
1366  {
1367  // export only content
1368  eRootService = XML_DOCUMENT_CONTENT;
1369  }
1370  else
1371  {
1372  // the god'ol one4all element
1373  eRootService = XML_DOCUMENT;
1374  // office:mimetype = ... (only for stream containing the content)
1375  if( eClass != XML_TOKEN_INVALID )
1376  {
1377  OUString aTmp = "application/vnd.oasis.opendocument." + GetXMLToken( eClass );
1379  }
1380  }
1381 
1382  SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, eRootService, true, true );
1383 
1384  // meta information
1386  ImplExportMeta();
1387 
1388  // settings
1391 
1392  // scripts
1394  ExportScripts_();
1395 
1396  // font declarations
1398  ExportFontDecls_();
1399 
1400  // styles
1402  ImplExportStyles();
1403 
1404  // autostyles
1407 
1408  // masterstyles
1411 
1412  // content
1415  }
1416 
1417  mxHandler->endDocument();
1418 
1419  if( bOwnGraphicResolver )
1420  {
1421  uno::Reference<XComponent> xComp(mxGraphicStorageHandler, UNO_QUERY);
1422  xComp->dispose();
1423  }
1424 
1425  if( bOwnEmbeddedResolver )
1426  {
1427  Reference< XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
1428  xComp->dispose();
1429  }
1430 
1431  return ERRCODE_NONE;
1432 }
1433 
1435 {
1436  mpNamespaceMap.reset( new SvXMLNamespaceMap );
1437 }
1438 
1439 OUString const & SvXMLExport::GetSourceShellID() const
1440 {
1441  return mpImpl->maSrcShellID;
1442 }
1443 
1444 OUString const & SvXMLExport::GetDestinationShellID() const
1445 {
1446  return mpImpl->maDestShellID;
1447 }
1448 
1450 {
1451  OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
1452  Reference< XDocumentPropertiesSupplier > xDocPropsSupplier(mxModel,
1453  UNO_QUERY);
1454  if (xDocPropsSupplier.is()) {
1455  Reference<XDocumentProperties> xDocProps(
1456  xDocPropsSupplier->getDocumentProperties());
1457  if (!xDocProps.is()) throw;
1458  // update generator here
1459  xDocProps->setGenerator(generator);
1460  rtl::Reference<SvXMLMetaExport> pMeta = new SvXMLMetaExport(*this, xDocProps);
1461  pMeta->Export();
1462  } else {
1463  // office:meta
1465  true, true );
1466  {
1467  // BM: #i60323# export generator even if xInfoProp is empty (which is the
1468  // case for charts). The generator does not depend on xInfoProp
1470  true, true );
1471  Characters(generator);
1472  }
1473  }
1474 }
1475 
1477 {
1478  SvXMLElementExport aElement( *this, XML_NAMESPACE_OFFICE, XML_SCRIPTS, true, true );
1479 
1480  // export Basic macros (only for FlatXML)
1482  {
1483  OUString aValue( GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) + ":Basic" );
1485 
1486  SvXMLElementExport aElem( *this, XML_NAMESPACE_OFFICE, XML_SCRIPT, true, true );
1487 
1488  // initialize Basic
1489  if ( mxModel.is() )
1490  {
1491  Reference< beans::XPropertySet > xPSet( mxModel, UNO_QUERY );
1492  if ( xPSet.is() )
1493  xPSet->getPropertyValue("BasicLibraries");
1494  }
1495 
1496  Reference < XDocumentHandler > xHdl( new XMLBasicExportFilter( mxHandler ) );
1497  Reference< document::XXMLBasicExporter > xExporter = document::XMLOasisBasicExporter::createWithHandler( m_xContext, xHdl );
1498 
1499  xExporter->setSourceDocument( mxModel );
1500  Sequence< PropertyValue > aMediaDesc( 0 );
1501  xExporter->filter( aMediaDesc );
1502  }
1503 
1504  // export document events
1505  Reference< document::XEventsSupplier > xEvents( GetModel(), UNO_QUERY );
1506  GetEventExport().Export( xEvents );
1507 }
1508 
1510 {
1511  if( mxFontAutoStylePool.is() )
1512  mxFontAutoStylePool->exportXML();
1513 }
1514 
1516 {
1517  uno::Reference< lang::XMultiServiceFactory > xFact( GetModel(), uno::UNO_QUERY );
1518  if( xFact.is())
1519  {
1520  // export (fill-)gradient-styles
1521  try
1522  {
1523  uno::Reference< container::XNameAccess > xGradient( xFact->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
1524  if( xGradient.is() )
1525  {
1526  XMLGradientStyleExport aGradientStyle( *this );
1527 
1528  if( xGradient->hasElements() )
1529  {
1530  const uno::Sequence< OUString > aNamesSeq ( xGradient->getElementNames() );
1531  for( const OUString& rStrName : aNamesSeq )
1532  {
1533  try
1534  {
1535  uno::Any aValue = xGradient->getByName( rStrName );
1536 
1537  aGradientStyle.exportXML( rStrName, aValue );
1538  }
1539  catch(const container::NoSuchElementException&)
1540  {
1541  }
1542  }
1543  }
1544  }
1545  }
1546  catch(const lang::ServiceNotRegisteredException&)
1547  {
1548  }
1549 
1550  // export (fill-)hatch-styles
1551  try
1552  {
1553  uno::Reference< container::XNameAccess > xHatch( xFact->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
1554  if( xHatch.is() )
1555  {
1556  XMLHatchStyleExport aHatchStyle( *this );
1557 
1558  if( xHatch->hasElements() )
1559  {
1560  const uno::Sequence< OUString > aNamesSeq ( xHatch->getElementNames() );
1561  for( const OUString& rStrName : aNamesSeq )
1562  {
1563  try
1564  {
1565  uno::Any aValue = xHatch->getByName( rStrName );
1566 
1567  aHatchStyle.exportXML( rStrName, aValue );
1568  }
1569  catch(const container::NoSuchElementException&)
1570  {}
1571  }
1572  }
1573  }
1574  }
1575  catch(const lang::ServiceNotRegisteredException&)
1576  {
1577  }
1578 
1579  // export (fill-)bitmap-styles
1580  try
1581  {
1582  uno::Reference< container::XNameAccess > xBitmap( xFact->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
1583  if( xBitmap.is() )
1584  {
1585  if( xBitmap->hasElements() )
1586  {
1587  const uno::Sequence< OUString > aNamesSeq ( xBitmap->getElementNames() );
1588  for( const OUString& rStrName : aNamesSeq )
1589  {
1590  try
1591  {
1592  uno::Any aValue = xBitmap->getByName( rStrName );
1593 
1594  XMLImageStyle::exportXML( rStrName, aValue, *this );
1595  }
1596  catch(const container::NoSuchElementException&)
1597  {
1598  }
1599  }
1600  }
1601  }
1602  }
1603  catch(const lang::ServiceNotRegisteredException&)
1604  {
1605  }
1606 
1607  // export transparency-gradient -styles
1608  try
1609  {
1610  uno::Reference< container::XNameAccess > xTransGradient( xFact->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
1611  if( xTransGradient.is() )
1612  {
1613  XMLTransGradientStyleExport aTransGradientstyle( *this );
1614 
1615  if( xTransGradient->hasElements() )
1616  {
1617  const uno::Sequence< OUString > aNamesSeq ( xTransGradient->getElementNames() );
1618  for( const OUString& rStrName : aNamesSeq )
1619  {
1620  try
1621  {
1622  uno::Any aValue = xTransGradient->getByName( rStrName );
1623 
1624  aTransGradientstyle.exportXML( rStrName, aValue );
1625  }
1626  catch(const container::NoSuchElementException&)
1627  {
1628  }
1629  }
1630  }
1631  }
1632  }
1633  catch(const lang::ServiceNotRegisteredException&)
1634  {
1635  }
1636 
1637  // export marker-styles
1638  try
1639  {
1640  uno::Reference< container::XNameAccess > xMarker( xFact->createInstance("com.sun.star.drawing.MarkerTable"), uno::UNO_QUERY );
1641  if( xMarker.is() )
1642  {
1643  XMLMarkerStyleExport aMarkerStyle( *this );
1644 
1645  if( xMarker->hasElements() )
1646  {
1647  const uno::Sequence< OUString > aNamesSeq ( xMarker->getElementNames() );
1648  for( const OUString& rStrName : aNamesSeq )
1649  {
1650  try
1651  {
1652  uno::Any aValue = xMarker->getByName( rStrName );
1653 
1654  aMarkerStyle.exportXML( rStrName, aValue );
1655  }
1656  catch(const container::NoSuchElementException&)
1657  {
1658  }
1659  }
1660  }
1661  }
1662  }
1663  catch(const lang::ServiceNotRegisteredException&)
1664  {
1665  }
1666 
1667  // export dash-styles
1668  try
1669  {
1670  uno::Reference< container::XNameAccess > xDashes( xFact->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
1671  if( xDashes.is() )
1672  {
1673  XMLDashStyleExport aDashStyle( *this );
1674 
1675  if( xDashes->hasElements() )
1676  {
1677  const uno::Sequence< OUString > aNamesSeq ( xDashes->getElementNames() );
1678  for( const OUString& rStrName : aNamesSeq )
1679  {
1680  try
1681  {
1682  uno::Any aValue = xDashes->getByName( rStrName );
1683 
1684  aDashStyle.exportXML( rStrName, aValue );
1685  }
1686  catch(const container::NoSuchElementException&)
1687  {
1688  }
1689  }
1690  }
1691  }
1692  }
1693  catch(const lang::ServiceNotRegisteredException&)
1694  {
1695  }
1696  }
1697 }
1698 
1700 {
1701  return new XMLTextParagraphExport( *this, *GetAutoStylePool() );
1702 }
1703 
1705 {
1706  return new XMLShapeExport(*this);
1707 }
1708 
1710 {
1711  return new SvXMLAutoStylePoolP(*this);
1712 }
1713 
1715 {
1716 }
1717 
1719 {
1720  return new XMLPageExport( *this );
1721 }
1722 
1724 {
1725  return new SchXMLExportHelper(*this, *GetAutoStylePool());
1726 }
1727 
1729 {
1730  return new XMLFontAutoStylePool( *this );
1731 }
1732 
1734 {
1735  return new xmloff::OFormLayerXMLExport(*this);
1736 }
1737 
1738 void SvXMLExport::GetViewSettingsAndViews(uno::Sequence<beans::PropertyValue>& rProps)
1739 {
1740  GetViewSettings(rProps);
1741  uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetModel(), uno::UNO_QUERY);
1742  if(xViewDataSupplier.is())
1743  {
1744  uno::Reference<container::XIndexAccess> xIndexAccess;
1745  xViewDataSupplier->setViewData( xIndexAccess ); // make sure we get a newly created sequence
1746  xIndexAccess = xViewDataSupplier->getViewData();
1747  bool bAdd = false;
1748  uno::Any aAny;
1749  if(xIndexAccess.is() && xIndexAccess->hasElements() )
1750  {
1751  sal_Int32 nCount = xIndexAccess->getCount();
1752  for (sal_Int32 i = 0; i < nCount; i++)
1753  {
1754  aAny = xIndexAccess->getByIndex(i);
1755  uno::Sequence<beans::PropertyValue> aProps;
1756  if( aAny >>= aProps )
1757  {
1758  if( aProps.hasElements() )
1759  {
1760  bAdd = true;
1761  break;
1762  }
1763  }
1764  }
1765  }
1766 
1767  if( bAdd )
1768  {
1769  sal_Int32 nOldLength(rProps.getLength());
1770  rProps.realloc(nOldLength + 1);
1771  beans::PropertyValue aProp;
1772  aProp.Name = "Views";
1773  aProp.Value <<= xIndexAccess;
1774  rProps[nOldLength] = aProp;
1775  }
1776  }
1777 }
1778 
1779 void SvXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>&)
1780 {
1781 }
1782 
1783 void SvXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>&)
1784 {
1785 }
1786 
1787 sal_Int32 SvXMLExport::GetDocumentSpecificSettings( ::std::vector< SettingsGroup >& )
1788 {
1789  return 0;
1790 }
1791 
1792 void SvXMLExport::collectDataStyles(bool bFromUsedStyles)
1793 {
1794  Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(GetModel(), uno::UNO_QUERY);
1795  if (!xStyleFamiliesSupplier.is())
1796  return;
1797 
1798  Reference<container::XNameAccess> xStylesFamilies(xStyleFamiliesSupplier->getStyleFamilies());
1799  if (!xStylesFamilies.is())
1800  return;
1801 
1802  Reference<container::XIndexAccess> xCellStyles(xStylesFamilies->getByName("CellStyles"), uno::UNO_QUERY);
1803  if (!xCellStyles.is())
1804  return;
1805 
1806  sal_Int32 nCount(xCellStyles->getCount());
1807  for (sal_Int32 i = 0; i < nCount; ++i)
1808  {
1809  Reference<style::XStyle> xStyle(xCellStyles->getByIndex(i), uno::UNO_QUERY);
1810  if (bFromUsedStyles && !xStyle->isInUse())
1811  continue;
1812 
1813  Reference<beans::XPropertySet> xCellProperties(xStyle, uno::UNO_QUERY);
1814  if (xCellProperties.is())
1815  {
1816  sal_Int32 nNumberFormat = 0;
1817  if (xCellProperties->getPropertyValue("NumberFormat") >>= nNumberFormat)
1818  addDataStyle(nNumberFormat);
1819  }
1820  }
1821 }
1822 
1823 void SvXMLExport::addDataStyle(const sal_Int32 nNumberFormat, bool /*bTimeFormat*/ )
1824 {
1825  if(mpNumExport)
1826  mpNumExport->SetUsed(nNumberFormat);
1827 }
1828 
1830 {
1831  if(mpNumExport)
1832  mpNumExport->Export(false);
1833 }
1834 
1836 {
1837  if(mpNumExport)
1838  mpNumExport->Export(true);
1839 
1840  if (mxFormExport.is())
1841  mxFormExport->exportAutoControlNumberStyles();
1842 }
1843 
1844 OUString SvXMLExport::getDataStyleName(const sal_Int32 nNumberFormat, bool /*bTimeFormat*/ ) const
1845 {
1846  OUString sTemp;
1847  if(mpNumExport)
1848  sTemp = mpNumExport->GetStyleName(nNumberFormat);
1849  return sTemp;
1850 }
1851 
1852 void SvXMLExport::exportAnnotationMeta(const uno::Reference<drawing::XShape>&)
1853 {
1854 }
1855 
1856 sal_Int32 SvXMLExport::dataStyleForceSystemLanguage(sal_Int32 nFormat) const
1857 {
1858  return ( mpNumExport != nullptr )
1859  ? mpNumExport->ForceSystemLanguage( nFormat ) : nFormat;
1860 }
1861 
1862 OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic, OUString & rOutMimeType, OUString const & rRequestedName)
1863 {
1864  OUString sURL;
1865 
1866  Graphic aGraphic(rxGraphic);
1867  OUString aOriginURL = aGraphic.getOriginURL();
1868 
1869  if (!aOriginURL.isEmpty())
1870  {
1871  sURL = GetRelativeReference(aOriginURL);
1872  }
1873  else
1874  {
1875  if (mxGraphicStorageHandler.is())
1876  {
1878  sURL = mxGraphicStorageHandler->saveGraphicByName(rxGraphic, rOutMimeType, rRequestedName);
1879  }
1880  }
1881  return sURL;
1882 }
1883 
1884 bool SvXMLExport::GetGraphicMimeTypeFromStream(uno::Reference<graphic::XGraphic> const & rxGraphic, OUString & rOutMimeType)
1885 {
1886  if (mxGraphicStorageHandler.is())
1887  {
1888  Reference<XInputStream> xInputStream(mxGraphicStorageHandler->createInputStream(rxGraphic));
1889  if (xInputStream.is())
1890  {
1892  return true;
1893  }
1894  }
1895 
1896  return false;
1897 }
1898 
1899 bool SvXMLExport::AddEmbeddedXGraphicAsBase64(uno::Reference<graphic::XGraphic> const & rxGraphic)
1900 {
1903  {
1904  Reference<XInputStream> xInputStream(mxGraphicStorageHandler->createInputStream(rxGraphic));
1905  if (xInputStream.is())
1906  {
1907  Graphic aGraphic(rxGraphic);
1908  if (aGraphic.getOriginURL().isEmpty()) // don't add the base64 if the origin URL is set (image is from an external URL)
1909  {
1910  XMLBase64Export aBase64Exp(*this);
1911  return aBase64Exp.exportOfficeBinaryDataElement(xInputStream);
1912  }
1913  }
1914  }
1915 
1916  return false;
1917 }
1918 
1919 OUString SvXMLExport::AddEmbeddedObject( const OUString& rEmbeddedObjectURL )
1920 {
1921  OUString sRet;
1922  bool bSupportedURL = rEmbeddedObjectURL.startsWith(XML_EMBEDDEDOBJECT_URL_BASE) ||
1923  rEmbeddedObjectURL.startsWith(XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE);
1924  if (bSupportedURL && mxEmbeddedResolver.is())
1925  {
1926  sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL(rEmbeddedObjectURL);
1927  }
1928  else
1929  sRet = GetRelativeReference( rEmbeddedObjectURL );
1930 
1931  return sRet;
1932 }
1933 
1934 bool SvXMLExport::AddEmbeddedObjectAsBase64( const OUString& rEmbeddedObjectURL )
1935 {
1936  bool bRet = false;
1937  bool bSupportedURL = rEmbeddedObjectURL.startsWith(XML_EMBEDDEDOBJECT_URL_BASE) ||
1938  rEmbeddedObjectURL.startsWith(XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE);
1939  if (bSupportedURL && mxEmbeddedResolver.is())
1940  {
1941  Reference < XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
1942  if( xNA.is() )
1943  {
1944  Any aAny = xNA->getByName( rEmbeddedObjectURL );
1946  aAny >>= xIn;
1947  if( xIn.is() )
1948  {
1949  XMLBase64Export aBase64Exp( *this );
1950  bRet = aBase64Exp.exportOfficeBinaryDataElement( xIn );
1951  }
1952  }
1953  }
1954 
1955  return bRet;
1956 }
1957 
1959  const OUString& rName,
1960  bool *pEncoded ) const
1961 {
1962  return GetMM100UnitConverter().encodeStyleName( rName, pEncoded );
1963 }
1964 
1966 {
1967  if (!mpProgressBarHelper)
1968  {
1970 
1971  if (mxExportInfo.is())
1972  {
1973  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxExportInfo->getPropertySetInfo();
1974  if (xPropertySetInfo.is())
1975  {
1976  OUString sProgressRange(XML_PROGRESSRANGE);
1977  OUString sProgressMax(XML_PROGRESSMAX);
1978  OUString sProgressCurrent(XML_PROGRESSCURRENT);
1979  OUString sRepeat(XML_PROGRESSREPEAT);
1980  if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
1981  xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
1982  xPropertySetInfo->hasPropertyByName(sProgressRange))
1983  {
1984  uno::Any aAny;
1985  sal_Int32 nProgressMax(0);
1986  sal_Int32 nProgressCurrent(0);
1987  sal_Int32 nProgressRange(0);
1988  aAny = mxExportInfo->getPropertyValue(sProgressRange);
1989  if (aAny >>= nProgressRange)
1990  mpProgressBarHelper->SetRange(nProgressRange);
1991  aAny = mxExportInfo->getPropertyValue(sProgressMax);
1992  if (aAny >>= nProgressMax)
1993  mpProgressBarHelper->SetReference(nProgressMax);
1994  aAny = mxExportInfo->getPropertyValue(sProgressCurrent);
1995  if (aAny >>= nProgressCurrent)
1996  mpProgressBarHelper->SetValue(nProgressCurrent);
1997  }
1998  if (xPropertySetInfo->hasPropertyByName(sRepeat))
1999  {
2000  uno::Any aAny = mxExportInfo->getPropertyValue(sRepeat);
2001  if (aAny.getValueType() == cppu::UnoType<bool>::get())
2002  mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
2003  else {
2004  SAL_WARN("xmloff.core", "why is it no boolean?" );
2005  }
2006  }
2007  }
2008  }
2009  }
2010  return mpProgressBarHelper.get();
2011 }
2012 
2014 {
2015  if( nullptr == mpEventExport)
2016  {
2017  // create EventExport on demand
2018  mpEventExport.reset( new XMLEventExport(*this) );
2019 
2020  // and register standard handlers + names
2021  mpEventExport->AddHandler("StarBasic", std::make_unique<XMLStarBasicExportHandler>());
2022  mpEventExport->AddHandler("Script", std::make_unique<XMLScriptExportHandler>());
2023  mpEventExport->AddTranslationTable(aStandardEventTable);
2024  }
2025 
2026  return *mpEventExport;
2027 }
2028 
2030 {
2031  // image map export, create on-demand
2032  if( nullptr == mpImageMapExport )
2033  {
2034  mpImageMapExport.reset( new XMLImageMapExport(*this) );
2035  }
2036 
2037  return *mpImageMapExport;
2038 }
2039 
2040 // XUnoTunnel & co
2042 
2043 void SvXMLExport::ExportEmbeddedOwnObject( Reference< XComponent > const & rComp )
2044 {
2045  OUString sFilterService;
2046 
2047  Reference < lang::XServiceInfo > xServiceInfo( rComp, UNO_QUERY );
2048  if( xServiceInfo.is() )
2049  {
2050  const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
2051  while( pEntry->sModelService )
2052  {
2053  OUString sModelService( pEntry->sModelService,
2054  pEntry->nModelServiceLen,
2055  RTL_TEXTENCODING_ASCII_US );
2056  if( xServiceInfo->supportsService( sModelService ) )
2057  {
2058  sFilterService = OUString( pEntry->sFilterService,
2059  pEntry->nFilterServiceLen,
2060  RTL_TEXTENCODING_ASCII_US );
2061  break;
2062  }
2063  pEntry++;
2064  }
2065  }
2066 
2067  SAL_WARN_IF( !sFilterService.getLength(), "xmloff.core", "no export filter for own object" );
2068 
2069  if( sFilterService.isEmpty() )
2070  return;
2071 
2072  Reference < XDocumentHandler > xHdl =
2074 
2075  Sequence < Any > aArgs( 1 );
2076  aArgs[0] <<= xHdl;
2077 
2078  Reference< document::XExporter > xExporter(
2079  m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(sFilterService, aArgs, m_xContext),
2080  UNO_QUERY);
2081  SAL_WARN_IF( !xExporter.is(), "xmloff.core", "can't instantiate export filter component for own object" );
2082  if( !xExporter.is() )
2083  return;
2084 
2085  xExporter->setSourceDocument( rComp );
2086 
2087  Reference<XFilter> xFilter( xExporter, UNO_QUERY );
2088 
2089  Sequence < PropertyValue > aMediaDesc( 0 );
2090  xFilter->filter( aMediaDesc );
2091 }
2092 
2093 OUString SvXMLExport::GetRelativeReference(const OUString& rValue)
2094 {
2095  OUString sValue( rValue );
2096  // #i65474# handling of fragment URLs ("#...") is undefined
2097  // they are stored 'as is'
2098  uno::Reference< uri::XUriReference > xUriRef;
2099  if(!sValue.isEmpty() && sValue[0] != '#')
2100  {
2101  try
2102  {
2103  xUriRef = mpImpl->mxUriReferenceFactory->parse( rValue );
2104  if( xUriRef.is() && !xUriRef->isAbsolute() )
2105  {
2106  //#i61943# relative URLs need special handling
2107  INetURLObject aTemp( mpImpl->msPackageURI );
2108  bool bWasAbsolute = false;
2109  sValue = aTemp.smartRel2Abs(sValue, bWasAbsolute ).GetMainURL(INetURLObject::DecodeMechanism::ToIUri);
2110  }
2111  }
2112  catch(const uno::Exception&)
2113  {
2114  }
2115  }
2116  if( xUriRef.is() )//no conversion for empty values or for fragments
2117  {
2118  //conversion for matching schemes only
2119  if( xUriRef->getScheme() == mpImpl->msPackageURIScheme )
2120  {
2121  sValue = INetURLObject::GetRelURL( msOrigFileName, sValue );
2122  }
2123  }
2124  return sValue;
2125 }
2126 
2127 void SvXMLExport::StartElement(sal_uInt16 nPrefix,
2129  bool bIgnWSOutside )
2130 {
2131  StartElement(GetNamespaceMap_().GetQNameByKey( nPrefix,
2132  GetXMLToken(eName) ), bIgnWSOutside);
2133 }
2134 
2135 void SvXMLExport::StartElement(const OUString& rName,
2136  bool bIgnWSOutside )
2137 {
2138  if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2139  {
2140  try
2141  {
2142  if( bIgnWSOutside && ((mnExportFlags & SvXMLExportFlags::PRETTY) == SvXMLExportFlags::PRETTY))
2143  mxHandler->ignorableWhitespace( msWS );
2144  mxHandler->startElement( rName, GetXAttrList() );
2145  }
2146  catch (const SAXInvalidCharacterException& e)
2147  {
2148  Sequence<OUString> aPars { rName };
2149  SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, nullptr );
2150  }
2151  catch (const SAXException& e)
2152  {
2153  Sequence<OUString> aPars { rName };
2155  aPars, e.Message, nullptr );
2156  }
2157  }
2158  ClearAttrList();
2159  ++mpImpl->mDepth; // increment nesting depth counter
2160 }
2161 
2162 void SvXMLExport::Characters(const OUString& rChars)
2163 {
2164  if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2165  {
2166  try
2167  {
2168  mxHandler->characters(rChars);
2169  }
2170  catch (const SAXInvalidCharacterException& e)
2171  {
2172  Sequence<OUString> aPars { rChars };
2173  SetError( XMLERROR_SAX|XMLERROR_FLAG_WARNING, aPars, e.Message, nullptr );
2174  }
2175  catch (const SAXException& e)
2176  {
2177  Sequence<OUString> aPars { rChars };
2179  aPars, e.Message, nullptr );
2180  }
2181  }
2182 }
2183 
2184 void SvXMLExport::EndElement(sal_uInt16 nPrefix,
2186  bool bIgnWSInside )
2187 {
2188  EndElement(GetNamespaceMap_().GetQNameByKey( nPrefix, GetXMLToken(eName) ),
2189  bIgnWSInside);
2190 }
2191 
2192 void SvXMLExport::EndElement(const OUString& rName,
2193  bool bIgnWSInside )
2194 {
2195  // decrement nesting depth counter & (maybe) restore namespace map
2196  --mpImpl->mDepth;
2197  if (!mpImpl->mNamespaceMaps.empty() &&
2198  (mpImpl->mNamespaceMaps.top().second == mpImpl->mDepth))
2199  {
2200  mpNamespaceMap = std::move(mpImpl->mNamespaceMaps.top().first);
2201  mpImpl->mNamespaceMaps.pop();
2202  }
2203  SAL_WARN_IF(!mpImpl->mNamespaceMaps.empty() &&
2204  (mpImpl->mNamespaceMaps.top().second >= mpImpl->mDepth), "xmloff.core", "SvXMLExport: NamespaceMaps corrupted");
2205 
2206  if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2207  {
2208  try
2209  {
2210  if( bIgnWSInside && ((mnExportFlags & SvXMLExportFlags::PRETTY) == SvXMLExportFlags::PRETTY))
2211  mxHandler->ignorableWhitespace( msWS );
2212  mxHandler->endElement( rName );
2213  }
2214  catch (const SAXException& e)
2215  {
2216  Sequence<OUString> aPars { rName };
2218  aPars, e.Message, nullptr );
2219  }
2220  }
2221 }
2222 
2224 {
2225  if ((mnExportFlags & SvXMLExportFlags::PRETTY) != SvXMLExportFlags::PRETTY)
2226  return;
2227 
2228  if ((mnErrorFlags & SvXMLErrorFlags::DO_NOTHING) != SvXMLErrorFlags::DO_NOTHING)
2229  {
2230  try
2231  {
2232  mxHandler->ignorableWhitespace( msWS );
2233  }
2234  catch (const SAXException& e)
2235  {
2236  Sequence<OUString> aPars(0);
2238  aPars, e.Message, nullptr );
2239  }
2240  }
2241 }
2242 
2244  sal_Int32 nId,
2245  const Sequence<OUString>& rMsgParams,
2246  const OUString& rExceptionMessage,
2247  const Reference<XLocator>& rLocator )
2248 {
2249  // allow multi-threaded access to the cancel() method
2250  static osl::Mutex aMutex;
2251  osl::MutexGuard aGuard(aMutex);
2252 
2253  // maintain error flags
2254  if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
2256  if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
2258  if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
2260 
2261  // create error list on demand
2262  if ( mpXMLErrors == nullptr )
2263  mpXMLErrors.reset( new XMLErrors() );
2264 
2265  // save error information
2266  mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage, rLocator );
2267 }
2268 
2270  sal_Int32 nId,
2271  const Sequence<OUString>& rMsgParams)
2272 {
2273  SetError( nId, rMsgParams, "", nullptr );
2274 }
2275 
2277 {
2278  mxModel.clear();
2279  // Shapes in Writer cannot be named via context menu (#i51726#)
2281  mxEventListener.clear();
2282 }
2283 
2284 
2286 {
2287  return mpImpl->maInterfaceToIdentifierMapper;
2288 }
2289 
2290 // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
2292 {
2293  return mpImpl->mbOutlineStyleAsNormalListStyle;
2294 }
2295 
2296 uno::Reference< embed::XStorage > const & SvXMLExport::GetTargetStorage() const
2297 {
2298  return mpImpl->mxTargetStorage;
2299 }
2300 
2303 {
2304  if( mpImpl )
2305  return mpImpl->maSaveOptions.GetODFDefaultVersion();
2306 
2307  // fatal error, use current version as default
2309 }
2310 
2312 {
2313  if( mpImpl )
2314  return mpImpl->maSaveOptions.GetODFSaneDefaultVersion();
2315 
2316  // fatal error, use current version as default
2318 }
2319 
2320 void
2322  sal_uInt16 const nLegacyPrefix, OUString const& rValue)
2323 {
2324  switch (getDefaultVersion()) {
2325  case SvtSaveOptions::ODFVER_011: // fall through
2326  case SvtSaveOptions::ODFVER_010: break;
2327  default: // ODF 1.2: xml:id
2329  }
2330  // in ODF 1.1 this was form:id, anim:id, draw:id, or text:id
2331  // backward compatibility: in ODF 1.2 write _both_ id attrs
2332  AddAttribute(nLegacyPrefix, XML_ID, rValue);
2333  // FIXME: this function simply assumes that rValue is unique
2334 }
2335 
2336 void
2337 SvXMLExport::AddAttributeXmlId(uno::Reference<uno::XInterface> const & i_xIfc)
2338 {
2339  // check version >= 1.2
2340  switch (getDefaultVersion()) {
2341  case SvtSaveOptions::ODFVER_011: // fall through
2342  case SvtSaveOptions::ODFVER_010: return;
2343  default: break;
2344  }
2345  const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
2346  uno::UNO_QUERY);
2347 //FIXME not yet...
2348  if ( xMeta.is() )
2349  {
2350  const beans::StringPair mdref( xMeta->getMetadataReference() );
2351  if ( !mdref.Second.isEmpty() )
2352  {
2353  const OUString streamName = mpImpl->mStreamName;
2354  if ( !streamName.isEmpty() )
2355  {
2356  if ( streamName == mdref.First )
2357  {
2358  AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2359  }
2360  else
2361  {
2362  SAL_WARN("xmloff.core","SvXMLExport::AddAttributeXmlId: invalid stream name");
2363  }
2364  }
2365  else
2366  {
2367  // FIXME: this is ugly
2368  // there is no stream name (e.g. XSLT, flat-xml format)!
2369  // but how do we ensure uniqueness in this case?
2370  // a) just omit styles.xml ids -- they are unlikely anyway...
2371  // b) somehow find out whether we are currently exporting styles
2372  // or content, and prefix "s" or "c" => unique
2373  if ( mdref.First == "content.xml" )
2374  {
2375  AddAttribute( XML_NAMESPACE_XML, XML_ID, mdref.Second );
2376  }
2377  else
2378  {
2379  SAL_INFO("xmloff.core", "SvXMLExport::AddAttributeXmlId: no stream name given: dropping styles.xml xml:id");
2380  }
2381  }
2382  }
2383  }
2384 }
2385 
2386 void
2388  uno::Reference<text::XTextContent> const & i_xTextContent)
2389 {
2390  // check version >= 1.2
2391  switch (getDefaultVersion()) {
2392  case SvtSaveOptions::ODFVER_011: // fall through
2393  case SvtSaveOptions::ODFVER_010: return;
2394  default: break;
2395  }
2396 
2397  const uno::Reference<rdf::XMetadatable> xMeta(
2398  i_xTextContent, uno::UNO_QUERY);
2399  if (!xMeta.is() || xMeta->getMetadataReference().Second.isEmpty())
2400  {
2401  return; // no xml:id => no RDFa
2402  }
2403 
2404  if (!mpImpl->mpRDFaHelper)
2405  {
2406  mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaExportHelper(*this) );
2407  }
2408  mpImpl->mpRDFaHelper->AddRDFa(xMeta);
2409 }
2410 
2412 {
2413  return mpImpl->mbExportTextNumberElement;
2414 }
2415 
2417 {
2418  // if the null date has already been set, don't set it again (performance)
2419  if (!mpImpl->mbNullDateInitialized)
2420  mpImpl->mbNullDateInitialized = GetMM100UnitConverter().setNullDate(GetModel());
2421 
2422  return mpImpl->mbNullDateInitialized;
2423 }
2424 
2425 OUString const & SvXMLExport::GetImageFilterName() const
2426 {
2427  return msImgFilterName;
2428 }
2429 
2431  const sal_uInt16 nPrefixKey,
2432  const OUString& rLName,
2433  const bool bIgnoreWhitespaceOutside )
2434 {
2435  maElementName = mrExport.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
2436  mrExport.StartElement(maElementName, bIgnoreWhitespaceOutside);
2437 }
2438 
2440  SvXMLExport& rExp,
2441  sal_uInt16 nPrefixKey,
2442  const char *pLName,
2443  bool bIWSOutside,
2444  bool bIWSInside )
2445  : mrExport( rExp )
2446  , maElementName()
2447  , mbIgnoreWhitespaceInside( bIWSInside )
2448  , mbDoSomething( true )
2449 {
2450  const OUString sLName( OUString::createFromAscii( pLName ) );
2451  StartElement( nPrefixKey, sLName, bIWSOutside );
2452 }
2453 
2455  SvXMLExport& rExp,
2456  sal_uInt16 nPrefixKey,
2457  const OUString& rLName,
2458  bool bIWSOutside,
2459  bool bIWSInside )
2460  : mrExport( rExp )
2461  , maElementName()
2462  , mbIgnoreWhitespaceInside( bIWSInside )
2463  , mbDoSomething( true )
2464 {
2465  StartElement( nPrefixKey, rLName, bIWSOutside );
2466 }
2467 
2469  SvXMLExport& rExp,
2470  sal_uInt16 nPrefixKey,
2471  enum XMLTokenEnum eLName,
2472  bool bIWSOutside,
2473  bool bIWSInside )
2474  : mrExport( rExp )
2475  , maElementName()
2476  , mbIgnoreWhitespaceInside( bIWSInside )
2477  , mbDoSomething( true )
2478 {
2479  StartElement( nPrefixKey, GetXMLToken(eLName), bIWSOutside );
2480 }
2481 
2483  SvXMLExport& rExp,
2484  bool bDoSth,
2485  sal_uInt16 nPrefixKey,
2486  enum XMLTokenEnum eLName,
2487  bool bIWSOutside,
2488  bool bIWSInside )
2489  : mrExport( rExp )
2490  , maElementName()
2491  , mbIgnoreWhitespaceInside( bIWSInside )
2492  , mbDoSomething( bDoSth )
2493 {
2494  if ( mbDoSomething )
2495  StartElement( nPrefixKey, GetXMLToken( eLName ), bIWSOutside );
2496 }
2497 
2499  SvXMLExport& rExp,
2500  const OUString& rQName,
2501  bool bIWSOutside,
2502  bool bIWSInside )
2503  : mrExport( rExp )
2504  , maElementName()
2505  , mbIgnoreWhitespaceInside( bIWSInside )
2506  , mbDoSomething( true )
2507 {
2508  maElementName = rQName;
2509  rExp.StartElement( rQName, bIWSOutside );
2510 }
2511 
2513 {
2514  if ( mbDoSomething )
2515  {
2517  }
2518 }
2519 
2520 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::embed::XStorage > const & GetTargetStorage() const
Definition: xmlexp.cxx:2296
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
Definition: xmlnmspe.hxx:74
#define XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE
Definition: xmlexp.cxx:120
SvXMLExportFlags mnExportFlags
Definition: xmlexp.hxx:157
constexpr sal_uInt16 XML_NAMESPACE_CSS3TEXT
Definition: xmlnmspe.hxx:120
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:29
sal_uInt16 GetKeyByPrefix(const OUString &rPrefix) const
Definition: nmspmap.cxx:144
virtual OUString SAL_CALL getImplementationName() final override
Definition: xmlexp.cxx:852
URL aURL
FieldUnit
OUString sMessage
OUString maElementName
Definition: xmlexp.hxx:638
#define XML_WRITTENNUMBERSTYLES
Definition: xmlnumfe.hxx:35
::comphelper::UnoInterfaceToUniqueIdentifierMapper & getInterfaceToIdentifierMapper()
Definition: xmlexp.cxx:2285
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:77
::std::unique_ptr< ::xmloff::RDFaExportHelper > mpRDFaHelper
Definition: xmlexp.cxx:278
virtual void DisposingModel()
Definition: xmlexp.cxx:2276
virtual void exportAutoDataStyles()
Definition: xmlexp.cxx:1835
#define XML_USEPRETTYPRINTING
Definition: xmlexp.cxx:118
OUString msPackageURI
Definition: xmlexp.cxx:256
void addChaffWhenEncryptedStorage()
Definition: xmlexp.cxx:1221
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlexp.hxx:395
static EFactory ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel > &xModel)
constexpr sal_uInt16 XML_NAMESPACE_XHTML
Definition: xmlnmspe.hxx:63
void CheckAttrList()
Definition: xmlexp.cxx:1046
SvXMLExportFlags
Definition: xmlexp.hxx:89
constexpr sal_uInt16 XML_NAMESPACE_CHART
Definition: xmlnmspe.hxx:40
css::uno::Reference< css::beans::XPropertySet > mxExportInfo
Definition: xmlexp.hxx:130
The XMLErrors is used to collect all errors and warnings that occur for appropriate processing...
Definition: xmlerror.hxx:102
virtual SvXMLAutoStylePoolP * CreateAutoStylePool()
Definition: xmlexp.cxx:1709
virtual void SAL_CALL setSourceDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
Definition: xmlexp.cxx:568
sal_Int64 n
const OUString & getBcp47(bool bResolveSystem=true) const
void AddAttributesRDFa(css::uno::Reference< css::text::XTextContent > const &i_xTextContent)
add RDFa attributes for a metadatable text content
Definition: xmlexp.cxx:2387
OUString EnsureNamespace(OUString const &i_rNamespace)
ensures that the given namespace is in scope at the next started element.
Definition: xmlexp.cxx:868
css::uno::Reference< css::document::XGraphicStorageHandler > mxGraphicStorageHandler
Definition: xmlexp.hxx:127
constexpr sal_uInt16 XML_NAMESPACE_OF
Definition: xmlnmspe.hxx:62
bool exportTextNumberElement() const
Definition: xmlexp.cxx:2411
SvXMLExport & mrExport
Definition: xmlexp.hxx:637
OUString getScript() const
css::uno::Reference< css::xml::sax::XAttributeList > GetXAttrList()
Definition: xmlexp.hxx:382
css::uno::Reference< css::frame::XModel2 > mxModel
virtual XMLTextParagraphExport * CreateTextParagraphExport()
Definition: xmlexp.cxx:1699
virtual css::uno::Reference< css::uno::XComponentContext > GetComponentContext() const =0
OUString msPackageURIScheme
Definition: xmlexp.cxx:257
static OUString GetRelURL(OUString const &rTheBaseURIRef, OUString const &rTheAbsURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
void GetViewSettingsAndViews(css::uno::Sequence< css::beans::PropertyValue > &rProps)
Definition: xmlexp.cxx:1738
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:30
bool AddEmbeddedObjectAsBase64(const OUString &rEmbeddedObjectURL)
Definition: xmlexp.cxx:1934
CALC
std::unique_ptr< SvXMLNamespaceMap > mpNamespaceMap
Definition: xmlexp.hxx:138
constexpr sal_uInt16 XML_NAMESPACE_DC
Definition: xmlnmspe.hxx:35
OString makeXMLChaff()
OUString msFilterName
Definition: xmlexp.hxx:136
css::uno::Reference< css::document::XEmbeddedObjectResolver > mxEmbeddedResolver
Definition: xmlexp.hxx:128
virtual ErrCode exportDoc(enum::xmloff::token::XMLTokenEnum eClass=::xmloff::token::XML_TOKEN_INVALID)
Definition: xmlexp.cxx:1231
constexpr sal_uInt16 XML_NAMESPACE_CONFIG
Definition: xmlnmspe.hxx:47
const sal_uInt16 XML_NAMESPACE_UNKNOWN
Definition: nmspmap.hxx:38
void SAL_DLLPRIVATE AddAttributeIdLegacy(sal_uInt16 const nLegacyPrefix, OUString const &rValue)
add xml:id and legacy namespace id
Definition: xmlexp.cxx:2321
void getIsoLanguageScriptCountry(OUString &rLanguage, OUString &rScript, OUString &rCountry) const
virtual void ExportStyles_(bool bUsed)
Override this method to export the content of .
Definition: xmlexp.cxx:1515
SAL_DLLPRIVATE void ImplExportAutoStyles()
Definition: xmlexp.cxx:1132
SAL_DLLPRIVATE void DetermineModelType_()
Definition: xmlexp.cxx:425
NONE
#define XMLERROR_API
Definition: xmlerror.hxx:71
constexpr sal_uInt16 XML_NAMESPACE_XSD
Definition: xmlnmspe.hxx:56
uno::Reference< embed::XStorage > mxTargetStorage
Definition: xmlexp.cxx:262
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
virtual void SetBodyAttributes()
Definition: xmlexp.cxx:1197
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlexp.hxx:415
rtl::Reference< xmloff::OFormLayerXMLExport > mxFormExport
Definition: xmlexp.hxx:149
virtual void SAL_CALL cancel() override
Definition: xmlexp.cxx:834
virtual void exportAnnotationMeta(const css::uno::Reference< css::drawing::XShape > &xShape)
Definition: xmlexp.cxx:1852
virtual void EndElement(const bool i_bIgnoreWhitespace)=0
#define SERVICE_MAP_ENTRY(app)
Definition: xmlexp.cxx:135
ProgressBarHelper * GetProgressBarHelper()
Definition: xmlexp.cxx:1965
SchXMLExportHelper * CreateChartExport()
Definition: xmlexp.cxx:1723
constexpr sal_uInt16 XML_NAMESPACE_MATH
Definition: xmlnmspe.hxx:42
#define XML_PROGRESSRANGE
OUString getLanguage() const
SvXMLExport(sal_Int16 const eDefaultMeasureUnit, const css::uno::Reference< css::uno::XComponentContext > &xContext, OUString const &implementationName, const enum::xmloff::token::XMLTokenEnum eClass, SvXMLExportFlags nExportFlag)
Any SAL_CALL getCaughtException()
bool mbNullDateInitialized
Definition: xmlexp.cxx:281
void AddLanguageTagAttributes(sal_uInt16 nPrefix, sal_uInt16 nPrefixRfc, const css::lang::Locale &rLocale, bool bWriteEmpty)
Add language tag attributes, deciding which are necessary.
Definition: xmlexp.cxx:975
DRAW
xmloff::OFormLayerXMLExport * CreateFormExport()
Definition: xmlexp.cxx:1733
TStyleElements m_aElements
int nCount
virtual void GetViewSettings(css::uno::Sequence< css::beans::PropertyValue > &aProps)
Definition: xmlexp.cxx:1779
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:925
const bool mbIgnoreWhitespaceInside
Definition: xmlexp.hxx:639
css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator
Definition: xmlexp.hxx:129
Mutex aMutex
void StartElement(sal_uInt16 nPrefix, enum::xmloff::token::XMLTokenEnum eName, bool bIgnWSOutside)
Definition: xmlexp.cxx:2127
enum::xmloff::token::XMLTokenEnum meClass
Definition: xmlexp.hxx:154
constexpr sal_uInt16 XML_NAMESPACE_GRDDL
Definition: xmlnmspe.hxx:64
static OUString GetGeneratorString()
bool insertName(OUString const &rTheName, bool bAppendFinalSlash=false, sal_Int32 nIndex=LAST_SEGMENT, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
OUString GetRelativeReference(const OUString &rValue)
Definition: xmlexp.cxx:2093
virtual OUString getDataStyleName(const sal_Int32 nNumberFormat, bool bTimeFormat=false) const
Definition: xmlexp.cxx:1844
SvtSaveOptions::ODFDefaultVersion getDefaultVersion() const
returns the currently configured default version for odf export
Definition: xmlexp.cxx:2302
Reference< deployment::XPackageRegistry > create(Reference< deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, Reference< XComponentContext > const &xComponentContext)
::std::stack< ::std::pair< std::unique_ptr< SvXMLNamespaceMap >, long > > mNamespaceMaps
stack of backed up namespace maps long: depth at which namespace map has been backed up into the stac...
Definition: xmlexp.cxx:274
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlexp.cxx:652
OUString AddEmbeddedXGraphic(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic, OUString &rOutMimeType, OUString const &rRequestedName=OUString())
Definition: xmlexp.cxx:1862
#define XML_PROGRESSMAX
const char * sName
static void lcl_AddGrddl(SvXMLExport const &rExport, const SvXMLExportFlags)
Definition: xmlexp.cxx:1202
#define XMLERROR_FLAG_WARNING
Definition: xmlerror.hxx:35
void SetError(sal_Int32 nId, const css::uno::Sequence< OUString > &rMsgParams, const OUString &rExceptionMessage, const css::uno::Reference< css::xml::sax::XLocator > &rLocator)
Record an error condition that occurred during export.
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:47
constexpr sal_uInt16 XML_NAMESPACE_FORMX
Definition: xmlnmspe.hxx:121
constexpr sal_uInt16 XML_NAMESPACE_NUMBER
Definition: xmlnmspe.hxx:37
void SetSchemeOf(const OUString &rOrigFileName)
Definition: xmlexp.cxx:283
std::unique_ptr< SvXMLNumFmtExport > mpNumExport
Definition: xmlexp.hxx:140
OUString const & GetDestinationShellID() const
Definition: xmlexp.cxx:1444
rtl::Reference< XMLFontAutoStylePool > mxFontAutoStylePool
Definition: xmlexp.hxx:148
std::unique_ptr< ProgressBarHelper > mpProgressBarHelper
Definition: xmlexp.hxx:141
virtual OUString SAL_CALL getName() override
Definition: xmlexp.cxx:841
constexpr sal_uInt16 XML_NAMESPACE_DRAW
Definition: xmlnmspe.hxx:32
constexpr sal_uInt16 XML_NAMESPACE_XML
Definition: xmlnmspe.hxx:60
bool GetGraphicMimeTypeFromStream(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic, OUString &rOutMimeType)
Definition: xmlexp.cxx:1884
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
returns the deterministic version for odf export
Definition: xmlexp.cxx:2311
OUString sPrefix
UNO3_GETIMPLEMENTATION_IMPL(SvXMLExport)
bool SetNullDateOnUnitConverter()
set null date from model to unit converter, if not already done
Definition: xmlexp.cxx:2416
SAL_DLLPRIVATE void ImplExportSettings()
Definition: xmlexp.cxx:1059
WRITER
sal_uInt16 char * pName
constexpr sal_uInt16 XML_NAMESPACE_XFORMS
Definition: xmlnmspe.hxx:55
void AddAttributeASCII(sal_uInt16 nPrefix, const char *pName, const char *pValue)
Definition: xmlexp.cxx:914
SAL_DLLPRIVATE void ImplExportStyles()
Definition: xmlexp.cxx:1102
virtual void Characters(const OUString &i_rCharacters)=0
const XMLServiceMapEntry_Impl aServiceMap[]
Definition: xmlexp.cxx:139
SvtSaveOptions maSaveOptions
Definition: xmlexp.cxx:264
int i
XMLEventExport & GetEventExport()
get Event export, with handlers for script types "None" and "StarBasic" already registered; other han...
Definition: xmlexp.cxx:2013
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) final override
Definition: xmlexp.cxx:857
RequestPriorityClass meClass
css::uno::Reference< css::xml::sax::XDocumentHandler > mxHandler
Definition: xmlexp.hxx:124
const OUString msWS
Definition: xmlexp.hxx:160
MATH
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
export meta data from an XDocumentProperties instance.
Definition: xmlmetae.hxx:50
OUString m_implementationName
Definition: xmlexp.hxx:121
static OUString GetMimeTypeForImageStream(const css::uno::Reference< css::io::XInputStream > &xInputStream)
bool mbSaveBackwardCompatibleODF
Definition: xmlexp.cxx:260
virtual XMLPageExport * CreatePageExport()
Definition: xmlexp.cxx:1718
unsigned char sal_Bool
virtual XMLFontAutoStylePool * CreateFontAutoStylePool()
Definition: xmlexp.cxx:1728
Object Value
constexpr sal_uInt16 XML_NAMESPACE_REPORT
Definition: xmlnmspe.hxx:61
std::unique_ptr< SvXMLExport_Impl > mpImpl
Definition: xmlexp.hxx:118
constexpr sal_uInt16 XML_NAMESPACE_OOO
Definition: xmlnmspe.hxx:48
bool setNullDate(const css::uno::Reference< css::frame::XModel > &xModel)
get the Null Date of the XModel and set it to the UnitConverter
Definition: xmluconv.cxx:304
OUString AddEmbeddedObject(const OUString &rEmbeddedObjectURL)
Definition: xmlexp.cxx:1919
std::unique_ptr< XMLImageMapExport > mpImageMapExport
Definition: xmlexp.hxx:151
virtual void ExportContent_()=0
Override this method to export the content of .
With this class you can export a element containing its data as element o...
XMLImageMapExport & GetImageMapExport()
get the export for image maps
Definition: xmlexp.cxx:2029
css::uno::Type const & get()
void exportAllSettings(const css::uno::Sequence< css::beans::PropertyValue > &aProps, const OUString &rName) const
OUString getOriginURL() const
virtual void ExportScripts_()
Override this method to export the content of .
Definition: xmlexp.cxx:1476
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
Definition: nmspmap.cxx:187
virtual ~SvXMLExport() override
Definition: xmlexp.cxx:520
virtual void ExportMeta_()
Override this method to export the content of .
Definition: xmlexp.cxx:1449
OUString maSrcShellID
Definition: xmlexp.cxx:269
const uno::Reference< uno::XComponentContext > m_xContext
constexpr sal_uInt16 XML_NAMESPACE_FORM
Definition: xmlnmspe.hxx:43
#define XML_PROGRESSCURRENT
void SetDocHandler(const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler)
Definition: xmlexp.cxx:302
const SvXMLNamespaceMap & GetNamespaceMap() const
Definition: xmlexp.hxx:392
SAL_DLLPRIVATE void ImplExportContent()
Definition: xmlexp.cxx:1167
constexpr sal_uInt16 XML_NAMESPACE_OOOW
Definition: xmlnmspe.hxx:49
virtual void exportDataStyles()
Definition: xmlexp.cxx:1829
rtl::Reference< FragmentHandler > mxHandler
virtual void ExportAutoStyles_()=0
Override this method to export the contents of .
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString maDestShellID
Definition: xmlexp.cxx:270
OUString EncodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmlexp.cxx:1958
constexpr sal_uInt16 XML_NAMESPACE_XLINK
Definition: xmlnmspe.hxx:34
OUString msImgFilterName
Definition: xmlexp.hxx:137
Reference< XPropertySet > PropertySetMerger_CreateInstance(const Reference< XPropertySet > &rPropSet1, const Reference< XPropertySet > &rPropSet2)
SAL_DLLPRIVATE void InitCtor_()
Definition: xmlexp.cxx:308
virtual void SAL_CALL setName(const OUString &aName) override
Definition: xmlexp.cxx:846
constexpr sal_uInt16 XML_NAMESPACE_DR3D
Definition: xmlnmspe.hxx:41
bool isIsoODF() const
constexpr sal_uInt16 XML_NAMESPACE_FO
Definition: xmlnmspe.hxx:33
void IgnorableWhitespace()
Definition: xmlexp.cxx:2223
SAL_DLLPRIVATE void ImplExportMasterStyles()
Definition: xmlexp.cxx:1158
void ClearAttrList()
Definition: xmlexp.cxx:1040
#define XMLERROR_FLAG_SEVERE
Definition: xmlerror.hxx:37
virtual sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &aDescriptor) override
Definition: xmlexp.cxx:757
OUString const & GetImageFilterName() const
Get clamped mimetype for image export (empty if none)
Definition: xmlexp.cxx:2425
SvtModuleOptions::EFactory meModelType
Definition: xmlexp.hxx:163
constexpr sal_uInt16 XML_NAMESPACE_OOOC
Definition: xmlnmspe.hxx:50
void EndElement(sal_uInt16 nPrefix, enum::xmloff::token::XMLTokenEnum eName, bool bIgnWSInside)
Definition: xmlexp.cxx:2184
virtual sal_Int32 GetDocumentSpecificSettings(::std::vector< SettingsGroup > &_out_rSettings)
returns the current document settings
Definition: xmlexp.cxx:1787
std::unique_ptr< XMLErrors > mpXMLErrors
Definition: xmlexp.hxx:152
SvXMLNamespaceMap & GetNamespaceMap_()
Definition: xmlexp.hxx:181
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
SAL_DLLPRIVATE void StartElement(const sal_uInt16 nPrefix, const OUString &rName, const bool bIgnoreWhitespaceOutside)
Definition: xmlexp.cxx:2430
long mDepth
counts depth (number of open elements/start tags)
Definition: xmlexp.cxx:276
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3360
rtl::Reference< SvXMLAutoStylePoolP > const & GetAutoStylePool()
Definition: xmlexp.hxx:577
virtual XMLShapeExport * CreateShapeExport()
Definition: xmlexp.cxx:1704
char const sXML_1_2[]
Definition: xmlexp.cxx:109
#define XML_PROGRESSREPEAT
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
constexpr sal_uInt16 XML_NAMESPACE_TABLE
Definition: xmlnmspe.hxx:31
OUString const & GetSourceShellID() const
Definition: xmlexp.cxx:1439
#define SAL_INFO(area, stream)
void Characters(const OUString &rChars)
Definition: xmlexp.cxx:2162
rtl::Reference< SvXMLAutoStylePoolP > mxAutoStylePool
Definition: xmlexp.hxx:145
#define XMLERROR_FLAG_ERROR
Definition: xmlerror.hxx:36
bool mbOutlineStyleAsNormalListStyle
Definition: xmlexp.cxx:259
constexpr sal_uInt16 XML_NAMESPACE_XSI
Definition: xmlnmspe.hxx:57
provides functionality for exporting a complete form layer.
css::uno::Reference< css::lang::XEventListener > mxEventListener
Definition: xmlexp.hxx:131
void ResetNamespaceMap()
Definition: xmlexp.cxx:1434
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
Definition: nmspmap.cxx:103
css::uno::Reference< css::frame::XModel > mxModel
Definition: xmlexp.hxx:123
uno::Reference< uri::XUriReferenceFactory > mxUriReferenceFactory
Definition: xmlexp.cxx:255
Export instances of EventsSupplier services.
Reference< XComponentContext > getProcessComponentContext()
const char * name
constexpr sal_uInt16 XML_NAMESPACE_DRAW_EXT
Definition: xmlnmspe.hxx:72
IMPRESS
virtual void ExportMasterStyles_()=0
Override this method to export the contents of .
constexpr sal_uInt16 XML_NAMESPACE_META
Definition: xmlnmspe.hxx:36
sal_Int32 dataStyleForceSystemLanguage(sal_Int32 nFormat) const
Definition: xmlexp.cxx:1856
virtual void GetConfigurationSettings(css::uno::Sequence< css::beans::PropertyValue > &aProps)
Definition: xmlexp.cxx:1783
#define XMLERROR_CANCEL
Definition: xmlerror.hxx:74
constexpr sal_uInt16 XML_NAMESPACE_TABLE_EXT
Definition: xmlnmspe.hxx:70
OUString encodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmluconv.cxx:738
SvXMLErrorFlags mnErrorFlags
Definition: xmlexp.hxx:158
virtual void AddAttribute(enum::xmloff::token::XMLTokenEnum i_eName, const OUString &i_rValue)=0
bool AddEmbeddedXGraphicAsBase64(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic)
Definition: xmlexp.cxx:1899
#define SAL_WARN(area, stream)
void AddAttributeList(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
Definition: xmlexp.cxx:1034
Reference< XSingleServiceFactory > xFactory
css::uno::Reference< css::util::XNumberFormatsSupplier > mxNumberFormatsSupplier
Definition: xmlexp.hxx:126
OUString maElementName
css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > mxExtHandler
Definition: xmlexp.hxx:125
void collectDataStyles(bool bFromUsedStyles)
Definition: xmlexp.cxx:1792
bool mbExportTextNumberElement
Definition: xmlexp.cxx:280
constexpr sal_uInt16 XML_NAMESPACE_CALC_EXT
Definition: xmlnmspe.hxx:73
::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper
Definition: xmlexp.cxx:254
SvXMLElementExport(SvXMLExport &rExp, sal_uInt16 nPrefix, const char *pName, bool bIgnWSOutside, bool bIgnWSInside)
Definition: xmlexp.cxx:2439
#define XMLERROR_SAX
Definition: xmlerror.hxx:52
void AddAttributeXmlId(css::uno::Reference< css::uno::XInterface > const &i_xIfc)
add xml:id attribute (for RDF metadata)
Definition: xmlexp.cxx:2337
const XMLEventNameTranslation aStandardEventTable[]
a translation table for the events defined in the XEventsSupplier service (implemented in XMLEventExp...
OUString mStreamName
name of stream in package, e.g., "content.xml"
Definition: xmlexp.cxx:267
virtual void StartElement(enum::xmloff::token::XMLTokenEnum i_eName)=0
bool exportOfficeBinaryDataElement(const css::uno::Reference< css::io::XInputStream > &rIn)
SAL_DLLPRIVATE void ImplExportMeta()
Definition: xmlexp.cxx:1052
Export an ImageMap as defined by service com.sun.star.image.ImageMap to XML.
INetURLObject smartRel2Abs(OUString const &rTheRelURIRef, bool &rWasAbsolute, bool bIgnoreFragment=false, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, bool bRelativeNonURIs=false, FSysStyle eStyle=FSysStyle::Detect) const
void exportXML(const OUString &rStrName, const css::uno::Any &rValue)
constexpr sal_uInt16 XML_NAMESPACE_FIELD
Definition: xmlnmspe.hxx:119
virtual void addDataStyle(const sal_Int32 nNumberFormat, bool bTimeFormat=false)
Definition: xmlexp.cxx:1823
constexpr sal_uInt16 XML_NAMESPACE_SCRIPT
Definition: xmlnmspe.hxx:44
css::uno::Any const SvXMLExport & rExport
Definition: ImageStyle.hxx:38
#define XML_EMBEDDEDOBJECT_URL_BASE
Definition: xmlexp.cxx:121
bool hasScript() const
constexpr sal_uInt16 XML_NAMESPACE_SVG
Definition: xmlnmspe.hxx:39
const OUString & GetPrefixByKey(sal_uInt16 nKey) const
Definition: nmspmap.cxx:162
SvXMLExportFlags getExportFlags() const
Definition: xmlexp.hxx:477
std::unique_ptr< XMLEventExport > mpEventExport
Definition: xmlexp.hxx:150
constexpr sal_uInt16 XML_NAMESPACE_DOM
Definition: xmlnmspe.hxx:51
virtual void ExportFontDecls_()
Override this method to export the font declarations The default implementation will export the conte...
Definition: xmlexp.cxx:1509
bool writeOutlineStyleAsNormalListStyle() const
Definition: xmlexp.cxx:2291
sal_uInt16 nPos
void ExportEmbeddedOwnObject(css::uno::Reference< css::lang::XComponent > const &rComp)
Definition: xmlexp.cxx:2043
SvXMLErrorFlags
Definition: xmlerror.hxx:78
bool any2bool(const css::uno::Any &rAny)
bool isSystemLocale() const
const bool mbDoSomething
Definition: xmlexp.hxx:640
OUString getCountry() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() final override
Definition: xmlexp.cxx:862
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
Definition: xmlnmspe.hxx:28
rtl::Reference< SvXMLAttributeList > mxAttrList
Definition: xmlexp.hxx:133
virtual void collectAutoStyles()
Definition: xmlexp.cxx:1714
void Export(css::uno::Reference< css::document::XEventsSupplier > const &xAccess, bool bUseWhitespace=true)
export the events (calls EventExport::Export(Reference) )
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: xmlexp.hxx:120
OUString msOrigFileName
Definition: xmlexp.hxx:135
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)