LibreOffice Module xmloff (master)  1
xmlimp.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 <optional>
22 
23 #include <tools/diagnose_ex.h>
24 #include <sal/log.hxx>
25 #include <com/sun/star/beans/XPropertySetInfo.hpp>
26 #include <tools/urlobj.hxx>
28 #include <vcl/graph.hxx>
30 #include <xmloff/namespacemap.hxx>
31 #include <xmloff/xmluconv.hxx>
32 #include <xmloff/xmlnamespace.hxx>
33 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlictxt.hxx>
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/xmlnumfi.hxx>
38 #include <XMLEventImportHelper.hxx>
41 #include <StyleMap.hxx>
43 #include <xmloff/xmlerror.hxx>
44 #include <com/sun/star/container/XNameContainer.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
47 #include <com/sun/star/io/XOutputStream.hpp>
48 #include <com/sun/star/util/MeasureUnit.hpp>
49 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
50 #include <com/sun/star/frame/XModel.hpp>
51 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
52 #include <com/sun/star/document/XStorageBasedDocument.hpp>
53 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
54 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
55 #include <com/sun/star/xml/sax/XLocator.hpp>
56 #include <com/sun/star/xml/sax/FastParser.hpp>
57 #include <com/sun/star/xml/sax/SAXException.hpp>
58 #include <com/sun/star/packages/zip/ZipIOException.hpp>
59 #include <comphelper/fileformat.h>
62 #include <cppuhelper/implbase.hxx>
64 #include <comphelper/extract.hxx>
69 #include <unotools/fontcvt.hxx>
70 #include <fasttokenhandler.hxx>
72 
73 #include <com/sun/star/rdf/XMetadatable.hpp>
74 #include <com/sun/star/rdf/XRepositorySupplier.hpp>
75 #include <RDFaImportHelper.hxx>
76 
77 using ::com::sun::star::beans::XPropertySetInfo;
78 
79 using namespace ::com::sun::star;
80 using namespace ::com::sun::star::uno;
81 using namespace ::com::sun::star::util;
82 using namespace ::com::sun::star::io;
83 using namespace ::com::sun::star::container;
84 using namespace ::com::sun::star::document;
85 using namespace ::xmloff::token;
86 
88 std::unordered_map< sal_Int32, std::pair< OUString, OUString > > SvXMLImport::aNamespaceMap;
89 std::unordered_map< OUString, OUString > SvXMLImport::aNamespaceURIPrefixMap;
91 
92 namespace {
93 
94 class SvXMLImportEventListener : public cppu::WeakImplHelper< css::lang::XEventListener >
95 {
96 private:
97  SvXMLImport* pImport;
98 
99 public:
100  explicit SvXMLImportEventListener(SvXMLImport* pImport);
101 
102  // XEventListener
103  virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) override;
104 };
105 
106 }
107 
108 SvXMLImportEventListener::SvXMLImportEventListener(SvXMLImport* pTempImport)
109  : pImport(pTempImport)
110 {
111 }
112 
113 // XEventListener
114 void SAL_CALL SvXMLImportEventListener::disposing( const lang::EventObject& )
115 {
116  if (pImport)
117  {
118  pImport->DisposingModel();
119  pImport = nullptr;
120  }
121 }
122 
123 namespace
124 {
125 
126 OUString
127 getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo)
128 {
129  if (xImportInfo.is())
130  {
131  try
132  {
133  Reference< XPropertySetInfo > const xSetInfo(
134  xImportInfo->getPropertySetInfo());
135  if (xSetInfo.is() && xSetInfo->hasPropertyByName("BuildId"))
136  {
137  OUString aBuildId;
138  xImportInfo->getPropertyValue("BuildId") >>= aBuildId;
139  return aBuildId;
140  }
141  }
142  catch (Exception const&)
143  {
144  DBG_UNHANDLED_EXCEPTION("xmloff.core", "exception getting BuildId");
145  }
146  }
147  return OUString();
148 }
149 
150 class DocumentInfo
151 {
152 private:
153  sal_uInt16 mnGeneratorVersion;
154 
155 public:
156  explicit DocumentInfo( const SvXMLImport& rImport )
157  : mnGeneratorVersion( SvXMLImport::ProductVersionUnknown )
158  {
159  OUString const buildIds(
160  getBuildIdsProperty(rImport.getImportInfo()));
161  if (!buildIds.isEmpty())
162  {
163  sal_Int32 const ix = buildIds.indexOf(';');
164  if (-1 != ix)
165  {
166  OUString const loVersion(buildIds.copy(ix + 1));
167  if (!loVersion.isEmpty())
168  {
169  if ('3' == loVersion[0])
170  {
171  mnGeneratorVersion = SvXMLImport::LO_3x;
172  }
173  else if ('4' == loVersion[0])
174  {
175  if (loVersion.getLength() > 1
176  && (loVersion[1] == '0' || loVersion[1] == '1'))
177  {
178  mnGeneratorVersion = SvXMLImport::LO_41x; // 4.0/4.1
179  }
180  else if (loVersion.getLength() > 1 && '2' == loVersion[1])
181  {
182  mnGeneratorVersion = SvXMLImport::LO_42x; // 4.2
183  }
184  else if (loVersion.getLength() > 1 && '3' == loVersion[1])
185  {
186  mnGeneratorVersion = SvXMLImport::LO_43x; // 4.3
187  }
188  else if (loVersion.getLength() > 1 && '4' == loVersion[1])
189  {
190  mnGeneratorVersion = SvXMLImport::LO_44x; // 4.4
191  }
192  }
193  else if ('5' == loVersion[0])
194  {
195  mnGeneratorVersion = SvXMLImport::LO_5x;
196  }
197  else if ('6' == loVersion[0])
198  {
199  if (loVersion.getLength() > 1
200  && (loVersion[1] == '0' || loVersion[1] == '1'
201  || loVersion[1] == '2'))
202  {
203  mnGeneratorVersion = SvXMLImport::LO_6x; // 6.0/6.1/6.2
204  }
205  else
206  {
207  mnGeneratorVersion = SvXMLImport::LO_63x; // 6.3/6.4
208  }
209  }
210  else if ('7' == loVersion[0])
211  {
212  mnGeneratorVersion = SvXMLImport::LO_7x;
213  }
214  else
215  {
216  SAL_INFO("xmloff.core", "unknown LO version: " << loVersion);
217  }
218  return; // ignore buildIds
219  }
220  }
221  }
222  sal_Int32 nUPD, nBuild;
223  if ( !rImport.getBuildIds( nUPD, nBuild ) )
224  return;
225 
226  if ( nUPD >= 640 && nUPD <= 645 )
227  {
228  mnGeneratorVersion = SvXMLImport::OOo_1x;
229  }
230  else if ( nUPD == 680 )
231  {
232  mnGeneratorVersion = SvXMLImport::OOo_2x;
233  }
234  else if ( nUPD == 300 && nBuild <= 9379 )
235  {
236  mnGeneratorVersion = SvXMLImport::OOo_30x;
237  }
238  else if ( nUPD == 310 )
239  {
240  mnGeneratorVersion = SvXMLImport::OOo_31x;
241  }
242  else if ( nUPD == 320 )
243  {
244  mnGeneratorVersion = SvXMLImport::OOo_32x;
245  }
246  else if ( nUPD == 330 )
247  {
248  mnGeneratorVersion = SvXMLImport::OOo_33x;
249  }
250  else if ( nUPD == 340 )
251  {
252  mnGeneratorVersion = SvXMLImport::OOo_34x;
253  }
254  else if (nUPD == 400 || nUPD == 401)
255  {
256  mnGeneratorVersion = SvXMLImport::AOO_40x;
257  }
258  else if (nUPD >= 410)
259  {
260  // effectively this means "latest", see use
261  // in XMLGraphicsDefaultStyle::SetDefaults()!
262  mnGeneratorVersion = SvXMLImport::AOO_4x;
263  }
264  }
265 
266  sal_uInt16 getGeneratorVersion() const
267  {
268  return mnGeneratorVersion;
269  }
270 };
271 
272 }
273 
275 {
276 public:
279 
284 
286  OUString mStreamName;
287 
288  std::optional<OUString> mxODFVersion;
289 
291 
292  // Boolean, indicating that position attributes
293  // of shapes are given in horizontal left-to-right layout. This is the case
294  // for the OpenOffice.org file format. (#i28749#)
297 
298  const uno::Reference< uno::XComponentContext > mxComponentContext;
300  css::uno::Sequence< OUString > maSupportedServiceNames;
301 
302  uno::Reference< embed::XStorage > mxSourceStorage;
303 
304  std::unique_ptr< xmloff::RDFaImportHelper > mpRDFaHelper;
305 
306  std::unique_ptr< DocumentInfo > mpDocumentInfo;
307 
308  SvXMLImport_Impl( const uno::Reference< uno::XComponentContext >& rxContext,
309  OUString const & theImplementationName,
310  const css::uno::Sequence< OUString > & sSupportedServiceNames = {})
311  : hBatsFontConv( nullptr )
312  , hMathFontConv( nullptr )
313  , mbOwnGraphicResolver( false )
314  , mbOwnEmbeddedResolver( false )
315  , mbIsOOoXML(false)
316  // Convert drawing object positions from OOo file format to OASIS (#i28749#)
317  , mbShapePositionInHoriL2R( false )
318  , mbTextDocInOOoFileFormat( false )
319  , mxComponentContext( rxContext )
320  , implementationName(theImplementationName)
321  , maSupportedServiceNames(sSupportedServiceNames)
322  {
323  SAL_WARN_IF(!mxComponentContext.is(), "xmloff.core", "SvXMLImport: no ComponentContext");
324  if (!mxComponentContext.is()) throw uno::RuntimeException();
325  if (!maSupportedServiceNames.hasElements())
326  maSupportedServiceNames = { "com.sun.star.document.ImportFilter", "com.sun.star.xml.XMLImportFilter" };
327  }
328 
329  sal_uInt16 getGeneratorVersion( const SvXMLImport& rImport )
330  {
331  if (!mpDocumentInfo)
332  {
333  mpDocumentInfo.reset( new DocumentInfo( rImport ) );
334  }
335 
336  return mpDocumentInfo->getGeneratorVersion();
337  }
338 
340 };
341 
343  const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
344 {
345  assert(false);
346  SAL_WARN( "xmloff.core", "CreateFastContext should be overridden, for element " << nElement);
347  return new SvXMLImportContext( *this );
348 }
349 
351 {
353  {
354  // implicit "xml" namespace prefix
366  mxNamespaceMap->Add( "_fo", GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
372  mxNamespaceMap->Add( "_svg", GetXMLToken(XML_N_SVG_COMPAT), XML_NAMESPACE_SVG );
378  mxNamespaceMap->Add( "_xforms", GetXMLToken(XML_N_XFORMS_1_0), XML_NAMESPACE_XFORMS );
388 
390  mxNamespaceMap->Add( "_office_libo",
392  }
393 
394  if (mxNumberFormatsSupplier.is())
395  mpNumImport = std::make_unique<SvXMLNumFmtHelper>(mxNumberFormatsSupplier, GetComponentContext());
396 
397  if (mxModel.is() && !mxEventListener.is())
398  {
399  mxEventListener.set(new SvXMLImportEventListener(this));
400  mxModel->addEventListener(mxEventListener);
401  }
402 }
403 
405  const css::uno::Reference< css::uno::XComponentContext >& xContext,
406  OUString const & implementationName,
407  SvXMLImportFlags nImportFlags,
408  const css::uno::Sequence< OUString > & sSupportedServiceNames )
409 : mpImpl( new SvXMLImport_Impl(xContext, implementationName, sSupportedServiceNames) ),
410  mxNamespaceMap( SvXMLNamespaceMap() ),
411 
412  mpUnitConv( new SvXMLUnitConverter( xContext,
413  util::MeasureUnit::MM_100TH, util::MeasureUnit::MM_100TH,
415 
416  mnImportFlags( nImportFlags ),
417  maNamespaceHandler( new SvXMLImportFastNamespaceHandler() ),
418  mbIsFormsSupported( true ),
419  mbIsTableShapeSupported( false ),
420  mbNotifyMacroEventRead( false )
421 {
422  SAL_WARN_IF( !xContext.is(), "xmloff.core", "got no service manager" );
423  InitCtor_();
424  mxParser = xml::sax::FastParser::create( xContext );
427  if ( !bIsNSMapsInitialized )
428  {
430  bIsNSMapsInitialized = true;
431  }
434 }
435 
436 void SvXMLImport::cleanup() noexcept
437 {
438  if (mxEventListener.is() && mxModel.is())
439  mxModel->removeEventListener(mxEventListener);
440  // clear context stacks first in case of parse error because the context
441  // class dtors are full of application logic
442  while (!maContexts.empty())
443  {
444  if (SvXMLStylesContext* pStylesContext = dynamic_cast<SvXMLStylesContext*>(maContexts.top().get()))
445  pStylesContext->dispose();
446  maContexts.pop();
447  }
448  if( mxTextImport )
449  mxTextImport->dispose();
450  mxTextImport.clear(); // XMLRedlineImportHelper needs model
451  DisposingModel();
452 }
453 
455 {
456  cleanup();
457 }
458 
459 bool SvXMLImport::addEmbeddedFont(const css::uno::Reference< css::io::XInputStream >& stream,
460  const OUString& fontName, const char* extra,
461  std::vector<unsigned char> const & key, bool eot)
462 {
465  return mxEmbeddedFontHelper->addEmbeddedFont(stream, fontName, extra, key, eot);
466 }
467 
468 const css::uno::Sequence<sal_Int8>& SvXMLImport::getUnoTunnelId() noexcept
469 {
470  static const comphelper::UnoIdInit theSvXMLImportUnoTunnelId;
471  return theSvXMLImportUnoTunnelId.getSeq();
472 }
473 
474 // XUnoTunnel
475 sal_Int64 SAL_CALL SvXMLImport::getSomething( const uno::Sequence< sal_Int8 >& rId )
476 {
477  return comphelper::getSomethingImpl(rId, this);
478 }
479 
480 namespace
481 {
482  class setFastDocumentHandlerGuard
483  {
484  private:
485  css::uno::Reference<css::xml::sax::XFastParser> mxParser;
486  public:
487  setFastDocumentHandlerGuard(const css::uno::Reference<css::xml::sax::XFastParser>& Parser,
488  const css::uno::Reference<css::xml::sax::XFastDocumentHandler>& Handler)
489  : mxParser(Parser)
490  {
491  mxParser->setFastDocumentHandler(Handler);
492  }
493  //guarantee restoration of null document handler
494  ~setFastDocumentHandlerGuard()
495  {
496  mxParser->setFastDocumentHandler(nullptr);
497  }
498  };
499 }
500 
501 // XFastParser
502 void SAL_CALL SvXMLImport::parseStream( const xml::sax::InputSource& aInputSource )
503 {
504  setFastDocumentHandlerGuard aDocumentHandlerGuard(mxParser, mxFastDocumentHandler.is() ? mxFastDocumentHandler : this);
505  mxParser->parseStream(aInputSource);
506 }
507 
508 void SAL_CALL SvXMLImport::setFastDocumentHandler( const uno::Reference< xml::sax::XFastDocumentHandler >& Handler )
509 {
510  mxFastDocumentHandler = Handler;
511 }
512 
513 void SAL_CALL SvXMLImport::setTokenHandler( const uno::Reference< xml::sax::XFastTokenHandler >& Handler )
514 {
515  mxParser->setTokenHandler( Handler );
516 }
517 
518 void SAL_CALL SvXMLImport::registerNamespace( const OUString& NamespaceURL, sal_Int32 NamespaceToken )
519 {
520  mxParser->registerNamespace( NamespaceURL, NamespaceToken );
521 }
522 
523 OUString SAL_CALL SvXMLImport::getNamespaceURL( const OUString& rPrefix )
524 {
525  return mxParser->getNamespaceURL( rPrefix );
526 }
527 
528 void SAL_CALL SvXMLImport::setErrorHandler( const uno::Reference< xml::sax::XErrorHandler >& Handler )
529 {
530  mxParser->setErrorHandler( Handler );
531 }
532 
533 void SAL_CALL SvXMLImport::setEntityResolver( const uno::Reference< xml::sax::XEntityResolver >& Resolver )
534 {
535  mxParser->setEntityResolver( Resolver );
536 }
537 
538 void SAL_CALL SvXMLImport::setLocale( const lang::Locale& rLocale )
539 {
540  mxParser->setLocale( rLocale );
541 }
542 
543 void SAL_CALL SvXMLImport::setNamespaceHandler( const uno::Reference< xml::sax::XFastNamespaceHandler >& Handler)
544 {
545  mxParser->setNamespaceHandler( Handler );
546 }
547 
548 void SAL_CALL SvXMLImport::setCustomEntityNames( const ::css::uno::Sequence< ::css::beans::Pair<::rtl::OUString, ::rtl::OUString> >& replacements )
549 {
550  mxParser->setCustomEntityNames( replacements );
551 }
552 
554 {
555  SAL_INFO( "xmloff.core", "{ SvXMLImport::startDocument" );
557  return;
558 
559  Reference< lang::XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
560  if( !xFactory.is() )
561  return;
562 
563  try
564  {
565  if (!mxGraphicStorageHandler.is())
566  {
567  // #99870# Import... instead of Export...
569  xFactory->createInstance("com.sun.star.document.ImportGraphicStorageHandler"),
570  UNO_QUERY);
571  mpImpl->mbOwnGraphicResolver = mxGraphicStorageHandler.is();
572  }
573 
574  if( !mxEmbeddedResolver.is() )
575  {
576  // #99870# Import... instead of Export...
577  mxEmbeddedResolver.set(
578  xFactory->createInstance("com.sun.star.document.ImportEmbeddedObjectResolver"),
579  UNO_QUERY);
580  mpImpl->mbOwnEmbeddedResolver = mxEmbeddedResolver.is();
581  }
582  }
583  catch( css::uno::Exception& )
584  {
585  }
586 }
587 
589 {
590  SAL_INFO( "xmloff.core", "} SvXMLImport::endDocument" );
591  // #i9518# All the stuff that accesses the document has to be done here, not in the dtor,
592  // because the SvXMLImport dtor might not be called until after the document has been closed.
593 
594  GetTextImport()->MapCrossRefHeadingFieldsHorribly();
595 
596  if (mpImpl->mpRDFaHelper)
597  {
598  const uno::Reference<rdf::XRepositorySupplier> xRS(mxModel,
599  uno::UNO_QUERY);
600  if (xRS.is())
601  {
602  mpImpl->mpRDFaHelper->InsertRDFa( xRS );
603  }
604  }
605 
606  mpNumImport.reset();
607  if (mxImportInfo.is())
608  {
609  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
610  if (xPropertySetInfo.is())
611  {
612  if (bool(mpProgressBarHelper))
613  {
614  OUString sProgressMax(XML_PROGRESSMAX);
615  OUString sProgressCurrent(XML_PROGRESSCURRENT);
616  OUString sRepeat(XML_PROGRESSREPEAT);
617  if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
618  xPropertySetInfo->hasPropertyByName(sProgressCurrent))
619  {
620  sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
621  sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
622  mxImportInfo->setPropertyValue(sProgressMax, uno::Any(nProgressMax));
623  mxImportInfo->setPropertyValue(sProgressCurrent, uno::Any(nProgressCurrent));
624  }
625  if (xPropertySetInfo->hasPropertyByName(sRepeat))
626  mxImportInfo->setPropertyValue(sRepeat, css::uno::makeAny(mpProgressBarHelper->GetRepeat()));
627  // pProgressBarHelper is deleted in dtor
628  }
629  OUString sNumberStyles(XML_NUMBERSTYLES);
630  if (mxNumberStyles.is() && xPropertySetInfo->hasPropertyByName(sNumberStyles))
631  {
632  mxImportInfo->setPropertyValue(sNumberStyles, Any(mxNumberStyles));
633  }
634  }
635  }
636 
637  if( mxFontDecls.is() )
638  mxFontDecls->dispose();
639  if( mxStyles.is() )
640  mxStyles->dispose();
641  if( mxAutoStyles.is() )
642  mxAutoStyles->dispose();
643  if( mxMasterStyles.is() )
644  mxMasterStyles->dispose();
645 
646  // possible form-layer related knittings which can only be done when
647  // the whole document exists
648  if ( mxFormImport.is() )
649  mxFormImport->documentDone();
650 
651  // The shape import helper does the z-order sorting in the dtor,
652  // so it must be deleted here, too.
653  mxShapeImport = nullptr;
654 
655  if( mpImpl->mbOwnGraphicResolver )
656  {
658  xComp->dispose();
659  }
660 
661  if( mpImpl->mbOwnEmbeddedResolver )
662  {
664  xComp->dispose();
665  }
666  mpStyleMap.clear();
667 
668  if ( bool( mpXMLErrors ) )
669  {
670  mpXMLErrors->ThrowErrorAsSAXException( XMLERROR_FLAG_SEVERE );
671  }
672 }
673 
674 std::optional<SvXMLNamespaceMap> SvXMLImport::processNSAttributes(
675  std::optional<SvXMLNamespaceMap> & rpNamespaceMap,
676  SvXMLImport *const pImport, // TODO???
677  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
678 {
679  std::optional<SvXMLNamespaceMap> pRewindMap;
680  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
681  for( sal_Int16 i=0; i < nAttrCount; i++ )
682  {
683  const OUString& rAttrName = xAttrList->getNameByIndex( i );
684  if (pImport && rAttrName == "office:version" && !pImport->mpImpl->mxODFVersion)
685  {
686  pImport->mpImpl->mxODFVersion = xAttrList->getValueByIndex( i );
687 
688  // the ODF version in content.xml and manifest.xml must be the same starting from ODF1.2
689  if (pImport->mpImpl->mStreamName == "content.xml"
690  && !pImport->IsODFVersionConsistent(*pImport->mpImpl->mxODFVersion))
691  {
692  throw xml::sax::SAXException("Inconsistent ODF versions in content.xml and manifest.xml!",
693  uno::Reference< uno::XInterface >(),
694  uno::makeAny(
695  packages::zip::ZipIOException("Inconsistent ODF versions in content.xml and manifest.xml!" ) ) );
696  }
697  }
698  else if( ( rAttrName.getLength() >= 5 ) &&
699  ( rAttrName.startsWith( GetXMLToken(XML_XMLNS) ) ) &&
700  ( rAttrName.getLength() == 5 || ':' == rAttrName[5] ) )
701  {
702  if( !pRewindMap )
703  {
704  pRewindMap = std::move(rpNamespaceMap);
705  rpNamespaceMap.emplace(*pRewindMap);
706  }
707  const OUString& rAttrValue = xAttrList->getValueByIndex( i );
708 
709  OUString aPrefix( ( rAttrName.getLength() == 5 )
710  ? OUString()
711  : rAttrName.copy( 6 ) );
712  // Add namespace, but only if it is known.
713  sal_uInt16 nKey = rpNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
714  // If namespace is unknown, try to match a name with similar
715  // TC Id and version
716  if( XML_NAMESPACE_UNKNOWN == nKey )
717  {
718  OUString aTestName( rAttrValue );
719  if( SvXMLNamespaceMap::NormalizeURI( aTestName ) )
720  nKey = rpNamespaceMap->AddIfKnown( aPrefix, aTestName );
721  }
722  // If that namespace is not known, too, add it as unknown
723  if( XML_NAMESPACE_UNKNOWN == nKey )
724  rpNamespaceMap->Add( aPrefix, rAttrValue );
725 
726  }
727  }
728  return pRewindMap;
729 }
730 
731 
732 void SAL_CALL SvXMLImport::characters( const OUString& rChars )
733 {
734  maContexts.top()->characters( rChars );
735 }
736 
737 void SAL_CALL SvXMLImport::processingInstruction( const OUString&,
738  const OUString& )
739 {
740 }
741 
742 void SAL_CALL SvXMLImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& rLocator )
743 {
744  mxLocator = rLocator;
745 }
746 
747 // XFastContextHandler
748 void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element,
749  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
750 {
751  SAL_INFO("xmloff.core", "startFastElement " << SvXMLImport::getNameFromToken( Element ));
752  if ( Attribs.is() && !mpImpl->mxODFVersion)
753  {
754  sax_fastparser::FastAttributeList& rAttribList =
756  auto aIter( rAttribList.find( XML_ELEMENT( OFFICE, XML_VERSION ) ) );
757  if( aIter != rAttribList.end() )
758  {
759  mpImpl->mxODFVersion = aIter.toString();
760 
761  // the ODF version in content.xml and manifest.xml must be the same starting from ODF1.2
762  if ( mpImpl->mStreamName == "content.xml" && !IsODFVersionConsistent( *mpImpl->mxODFVersion ) )
763  {
764  throw xml::sax::SAXException("Inconsistent ODF versions in content.xml and manifest.xml!",
765  uno::Reference< uno::XInterface >(),
766  uno::makeAny(
767  packages::zip::ZipIOException("Inconsistent ODF versions in content.xml and manifest.xml!" ) ) );
768  }
769  }
770  }
771 
772  maNamespaceAttrList->Clear();
773 
774  maNamespaceHandler->addNSDeclAttributes( maNamespaceAttrList );
775  std::optional<SvXMLNamespaceMap> pRewindMap = processNSAttributes(mxNamespaceMap, this, maNamespaceAttrList);
776 
777  SvXMLImportContextRef xContext;
778  const bool bRootContext = maContexts.empty();
779  if (!maContexts.empty())
780  {
781  const SvXMLImportContextRef & pHandler = maContexts.top();
782  SAL_INFO("xmloff.core", "calling createFastChildContext on " << typeid(*pHandler.get()).name());
783  auto tmp = pHandler->createFastChildContext( Element, Attribs );
784  xContext = static_cast<SvXMLImportContext*>(tmp.get());
785  assert((tmp && xContext) || (!tmp && !xContext));
786  }
787  else
788  xContext.set( CreateFastContext( Element, Attribs ) );
789 
790  SAL_INFO_IF(!xContext.is(), "xmloff.core", "No fast context for element " << getNameFromToken(Element));
791  if (bRootContext && !xContext)
792  {
793  OUString aName = getNameFromToken(Element);
795  { aName }, "Root element " + aName + " unknown", Reference<xml::sax::XLocator>() );
796  }
797  if ( !xContext )
798  xContext.set( new SvXMLImportContext( *this ) );
799 
800  // Remember old namespace map.
801  if( pRewindMap )
802  xContext->PutRewindMap(std::move(pRewindMap));
803 
804  // Call a startElement at the new context.
805  xContext->startFastElement( Element, Attribs );
806 
807  // Push context on stack.
808  maContexts.push(xContext);
809 }
810 
811 void SAL_CALL SvXMLImport::startUnknownElement (const OUString & rNamespace, const OUString & rName,
812  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
813 {
814  SAL_INFO("xmloff.core", "startUnknownElement " << rNamespace << " " << rName);
815  SvXMLImportContextRef xContext;
816  const bool bRootContext = maContexts.empty();
817  if (!maContexts.empty())
818  {
819  const SvXMLImportContextRef & pHandler = maContexts.top();
820  SAL_INFO("xmloff.core", "calling createUnknownChildContext on " << typeid(*pHandler.get()).name());
821  auto tmp = pHandler->createUnknownChildContext( rNamespace, rName, Attribs );
822  xContext = static_cast<SvXMLImportContext*>(tmp.get());
823  assert((tmp && xContext) || (!tmp && !xContext));
824  }
825  else
826  xContext.set( CreateFastContext( -1, Attribs ) );
827 
828  SAL_WARN_IF(!xContext.is(), "xmloff.core", "No context for unknown-element " << rNamespace << " " << rName);
829  if (bRootContext && !xContext)
830  {
832  { rName }, "Root element " + rName + " unknown", Reference<xml::sax::XLocator>() );
833  }
834  if (!xContext)
835  {
836  if (!maContexts.empty())
837  // This is pretty weird, but it's what the code did before I simplified it, and some parts of the
838  // code rely on this behaviour e.g. DocumentBuilderContext
839  xContext = maContexts.top();
840  else
841  xContext = new SvXMLImportContext( *this );
842  }
843 
844  xContext->startUnknownElement( rNamespace, rName, Attribs );
845  maContexts.push(xContext);
846 }
847 
848 void SAL_CALL SvXMLImport::endFastElement (sal_Int32 Element)
849 {
850  SAL_INFO("xmloff.core", "endFastElement " << SvXMLImport::getNameFromToken( Element ));
851  if (maContexts.empty())
852  {
853  SAL_WARN("xmloff.core", "SvXMLImport::endFastElement: no context left");
854  assert(false);
855  return;
856  }
857  SvXMLImportContextRef xContext = std::move(maContexts.top());
858  // Get a namespace map to rewind.
859  std::optional<SvXMLNamespaceMap> pRewindMap = xContext->TakeRewindMap();
860  maContexts.pop();
861  xContext->endFastElement( Element );
862  // Rewind a namespace map.
863  if (pRewindMap)
864  mxNamespaceMap = std::move(pRewindMap);
865 }
866 
867 void SAL_CALL SvXMLImport::endUnknownElement (const OUString & rPrefix, const OUString & rLocalName)
868 {
869  SAL_INFO("xmloff.core", "endUnknownElement " << rPrefix << " " << rLocalName);
870  if (maContexts.empty())
871  {
872  SAL_WARN("xmloff.core", "SvXMLImport::endUnknownElement: no context left");
873  assert(false);
874  return;
875  }
876  SvXMLImportContextRef xContext = std::move(maContexts.top());
877  maContexts.pop();
878  xContext->endUnknownElement( rPrefix, rLocalName );
879 }
880 
881 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
883  const uno::Reference< xml::sax::XFastAttributeList > &)
884 {
885  return this;
886 }
887 
888 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
889  SvXMLImport::createUnknownChildContext (const OUString &, const OUString &,
890  const uno::Reference< xml::sax::XFastAttributeList > &)
891 {
892  return this;
893 }
894 
895 void SvXMLImport::SetStatistics(const uno::Sequence< beans::NamedValue> &)
896 {
899 }
900 
901 // XImporter
902 void SAL_CALL SvXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
903 {
904  mxModel.set( xDoc, UNO_QUERY );
905  if( !mxModel.is() )
906  throw lang::IllegalArgumentException();
907 
908  try
909  {
910  uno::Reference<document::XStorageBasedDocument> const xSBDoc(mxModel, uno::UNO_QUERY);
911  uno::Reference<embed::XStorage> const xStor(xSBDoc.is() ? xSBDoc->getDocumentStorage()
912  : nullptr);
913  if (xStor.is())
914  {
915  mpImpl->mbIsOOoXML =
918  }
919  }
920  catch (uno::Exception const&)
921  {
922  DBG_UNHANDLED_EXCEPTION("xmloff.core");
923  }
924  if (!mxEventListener.is())
925  {
926  mxEventListener.set(new SvXMLImportEventListener(this));
927  mxModel->addEventListener(mxEventListener);
928  }
929 
930  SAL_WARN_IF( bool(mpNumImport), "xmloff.core", "number format import already exists." );
931  mpNumImport.reset();
932 }
933 
934 // XFilter
935 sal_Bool SAL_CALL SvXMLImport::filter( const uno::Sequence< beans::PropertyValue >& )
936 {
937  return false;
938 }
939 
940 void SAL_CALL SvXMLImport::cancel( )
941 {
942 }
943 
944 // XInitialize
945 void SAL_CALL SvXMLImport::initialize( const uno::Sequence< uno::Any >& aArguments )
946 {
947  for( const auto& rAny : aArguments )
948  {
949  Reference<XInterface> xValue;
950  rAny >>= xValue;
951 
952  uno::Reference<task::XStatusIndicator> xTmpStatusIndicator(
953  xValue, UNO_QUERY );
954  if( xTmpStatusIndicator.is() )
955  mxStatusIndicator = xTmpStatusIndicator;
956 
957  uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler(xValue, UNO_QUERY);
958  if (xGraphicStorageHandler.is())
959  mxGraphicStorageHandler = xGraphicStorageHandler;
960 
961  uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
962  xValue, UNO_QUERY );
963  if( xTmpObjectResolver.is() )
964  mxEmbeddedResolver = xTmpObjectResolver;
965 
966  uno::Reference<beans::XPropertySet> xTmpPropSet( xValue, UNO_QUERY );
967  if( xTmpPropSet.is() )
968  {
969  mxImportInfo = xTmpPropSet;
970  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
971  if (xPropertySetInfo.is())
972  {
973  OUString sPropName(XML_NUMBERSTYLES);
974  if (xPropertySetInfo->hasPropertyByName(sPropName))
975  {
976  uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
977  aAny >>= mxNumberStyles;
978  }
979 
980  sPropName = "PrivateData";
981  if (xPropertySetInfo->hasPropertyByName(sPropName))
982  {
983  Reference < XInterface > xIfc;
984  uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
985  aAny >>= xIfc;
986 
987  StyleMap *pSMap = comphelper::getFromUnoTunnel<StyleMap>( xIfc );
988  if( pSMap )
989  {
990  mpStyleMap = pSMap;
991  }
992  }
993  OUString sBaseURI;
994  sPropName = "BaseURI";
995  if (xPropertySetInfo->hasPropertyByName(sPropName))
996  {
997  uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
998  aAny >>= sBaseURI;
999  mpImpl->aBaseURL.SetURL( sBaseURI );
1000  mpImpl->aDocBase.SetURL( sBaseURI );
1001  }
1002  OUString sRelPath;
1003  sPropName = "StreamRelPath";
1004  if( xPropertySetInfo->hasPropertyByName(sPropName) )
1005  {
1006  uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1007  aAny >>= sRelPath;
1008  }
1009  OUString sName;
1010  sPropName = "StreamName";
1011  if( xPropertySetInfo->hasPropertyByName(sPropName) )
1012  {
1013  uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1014  aAny >>= sName;
1015  }
1016  if( !sBaseURI.isEmpty() && !sName.isEmpty() )
1017  {
1018  if( !sRelPath.isEmpty() )
1019  mpImpl->aBaseURL.insertName( sRelPath );
1020  mpImpl->aBaseURL.insertName( sName );
1021  }
1022  mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
1023  // Retrieve property <ShapePositionInHoriL2R> (#i28749#)
1024  sPropName = "ShapePositionInHoriL2R";
1025  if( xPropertySetInfo->hasPropertyByName(sPropName) )
1026  {
1027  uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1028  aAny >>= mpImpl->mbShapePositionInHoriL2R;
1029  }
1030  sPropName = "TextDocInOOoFileFormat";
1031  if( xPropertySetInfo->hasPropertyByName(sPropName) )
1032  {
1033  uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1034  aAny >>= mpImpl->mbTextDocInOOoFileFormat;
1035  }
1036 
1037  sPropName = "SourceStorage";
1038  if( xPropertySetInfo->hasPropertyByName(sPropName) )
1039  mxImportInfo->getPropertyValue(sPropName) >>= mpImpl->mxSourceStorage;
1040  }
1041  }
1042  }
1043 
1044  uno::Reference<lang::XInitialization> const xInit(mxParser, uno::UNO_QUERY_THROW);
1045  xInit->initialize( { makeAny(OUString("IgnoreMissingNSDecl")) });
1046 }
1047 
1048 // XServiceInfo
1050 {
1051  return mpImpl->implementationName;
1052 }
1053 
1054 sal_Bool SAL_CALL SvXMLImport::supportsService( const OUString& rServiceName )
1055 {
1056  return cppu::supportsService(this, rServiceName);
1057 }
1058 
1059 uno::Sequence< OUString > SAL_CALL SvXMLImport::getSupportedServiceNames( )
1060 {
1061  return mpImpl->maSupportedServiceNames;
1062 }
1063 
1065 {
1066  return new XMLTextImportHelper( mxModel, *this );
1067 }
1068 
1070 {
1071  return new XMLShapeImportHelper( *this, mxModel );
1072 }
1073 
1075 {
1076  return new SchXMLImportHelper();
1077 }
1078 
1080 {
1081  return new ::xmloff::OFormLayerXMLImport(*this);
1082 }
1083 
1084 
1085 // Get or create fill/line/lineend-style-helper
1086 
1087 
1089 {
1090  if( !mxGradientHelper.is() )
1091  {
1092  if( mxModel.is() )
1093  {
1094  Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1095  if( xServiceFact.is() )
1096  {
1097  try
1098  {
1099  mxGradientHelper.set( xServiceFact->createInstance(
1100  "com.sun.star.drawing.GradientTable" ), UNO_QUERY);
1101  }
1102  catch( lang::ServiceNotRegisteredException& )
1103  {}
1104  }
1105  }
1106  }
1107 
1108  return mxGradientHelper;
1109 }
1110 
1112 {
1113  if( !mxHatchHelper.is() )
1114  {
1115  if( mxModel.is() )
1116  {
1117  Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1118  if( xServiceFact.is() )
1119  {
1120  try
1121  {
1122  mxHatchHelper.set( xServiceFact->createInstance(
1123  "com.sun.star.drawing.HatchTable" ), UNO_QUERY);
1124  }
1125  catch( lang::ServiceNotRegisteredException& )
1126  {}
1127  }
1128  }
1129  }
1130 
1131  return mxHatchHelper;
1132 }
1133 
1135 {
1136  if( !mxBitmapHelper.is() )
1137  {
1138  if( mxModel.is() )
1139  {
1140  Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1141  if( xServiceFact.is() )
1142  {
1143  try
1144  {
1145  mxBitmapHelper.set( xServiceFact->createInstance(
1146  "com.sun.star.drawing.BitmapTable" ), UNO_QUERY);
1147  }
1148  catch( lang::ServiceNotRegisteredException& )
1149  {}
1150  }
1151  }
1152  }
1153 
1154  return mxBitmapHelper;
1155 }
1156 
1158 {
1159  if( !mxTransGradientHelper.is() )
1160  {
1161  if( mxModel.is() )
1162  {
1163  Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1164  if( xServiceFact.is() )
1165  {
1166  try
1167  {
1168  mxTransGradientHelper.set( xServiceFact->createInstance(
1169  "com.sun.star.drawing.TransparencyGradientTable" ), UNO_QUERY);
1170  }
1171  catch( lang::ServiceNotRegisteredException& )
1172  {}
1173  }
1174  }
1175  }
1176 
1177  return mxTransGradientHelper;
1178 }
1179 
1181 {
1182  if( !mxMarkerHelper.is() )
1183  {
1184  if( mxModel.is() )
1185  {
1186  Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1187  if( xServiceFact.is() )
1188  {
1189  try
1190  {
1191  mxMarkerHelper.set( xServiceFact->createInstance( "com.sun.star.drawing.MarkerTable" ), UNO_QUERY);
1192  }
1193  catch( lang::ServiceNotRegisteredException& )
1194  {}
1195  }
1196  }
1197  }
1198 
1199  return mxMarkerHelper;
1200 }
1201 
1203 {
1204  if( !mxDashHelper.is() && mxModel.is() )
1205  {
1206  Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1207  if( xServiceFact.is() )
1208  {
1209  try
1210  {
1211  mxDashHelper.set( xServiceFact->createInstance( "com.sun.star.drawing.DashTable" ), UNO_QUERY);
1212  }
1213  catch( lang::ServiceNotRegisteredException& )
1214  {}
1215  }
1216  }
1217 
1218  return mxDashHelper;
1219 }
1220 
1221 bool SvXMLImport::IsPackageURL( const OUString& rURL ) const
1222 {
1223 
1224  // if, and only if, only parts are imported, then we're in a package
1226  if( (mnImportFlags & nTest) == nTest )
1227  return false;
1228 
1229  // TODO: from this point extract to own static function
1230 
1231  // Some quick tests: Some may rely on the package structure!
1232  sal_Int32 nLen = rURL.getLength();
1233  if( nLen > 0 && '/' == rURL[0] )
1234  // RFC2396 net_path or abs_path
1235  return false;
1236  else if( nLen > 1 && '.' == rURL[0] )
1237  {
1238  if( '.' == rURL[1] )
1239  // ../: We are never going up one level, so we know
1240  // it's not an external URI
1241  return false;
1242  else if( '/' == rURL[1] )
1243  // we are remaining on a level, so it's a package URI
1244  return true;
1245  }
1246 
1247  // Now check for a RFC2396 schema
1248  sal_Int32 nPos = 1;
1249  while( nPos < nLen )
1250  {
1251  switch( rURL[nPos] )
1252  {
1253  case '/':
1254  // a relative path segment
1255  return true;
1256  case ':':
1257  // a schema
1258  return false;
1259  default:
1260  break;
1261  // we don't care about any other characters
1262  }
1263  ++nPos;
1264  }
1265 
1266  return true;
1267 }
1268 
1269 uno::Reference<graphic::XGraphic> SvXMLImport::loadGraphicByURL(OUString const & rURL)
1270 {
1271  uno::Reference<graphic::XGraphic> xGraphic;
1272 
1273  if (mxGraphicStorageHandler.is())
1274  {
1275  if (IsPackageURL(rURL))
1276  {
1277  xGraphic = mxGraphicStorageHandler->loadGraphic(rURL);
1278  }
1279  else
1280  {
1281  OUString const & rAbsoluteURL = GetAbsoluteReference(rURL);
1282  GraphicExternalLink aExternalLink(rAbsoluteURL);
1283  Graphic aGraphic(aExternalLink);
1284  xGraphic = aGraphic.GetXGraphic();
1285  }
1286  }
1287 
1288  return xGraphic;
1289 }
1290 
1291 uno::Reference<graphic::XGraphic> SvXMLImport::loadGraphicFromBase64(uno::Reference<io::XOutputStream> const & rxOutputStream)
1292 {
1293  uno::Reference<graphic::XGraphic> xGraphic;
1294 
1295  if (mxGraphicStorageHandler.is())
1296  {
1297  xGraphic = mxGraphicStorageHandler->loadGraphicFromOutputStream(rxOutputStream);
1298  }
1299 
1300  return xGraphic;
1301 }
1302 
1304 {
1305  Reference< XOutputStream > xOStm;
1306  Reference< document::XBinaryStreamResolver > xStmResolver(mxGraphicStorageHandler, UNO_QUERY);
1307 
1308  if( xStmResolver.is() )
1309  xOStm = xStmResolver->createOutputStream();
1310 
1311  return xOStm;
1312 }
1313 
1315  const OUString& rURL,
1316  std::u16string_view rClassId )
1317 {
1318  OUString sRet;
1319 
1320  if( IsPackageURL( rURL ) )
1321  {
1322  if ( mxEmbeddedResolver.is() )
1323  {
1324  OUString sURL( rURL );
1325  if( !rClassId.empty() )
1326  {
1327  sURL += OUString::Concat("!") + rClassId;
1328  }
1329  sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( sURL );
1330  }
1331  }
1332  else
1333  sRet = GetAbsoluteReference( rURL );
1334 
1335  return sRet;
1336 }
1337 
1339 {
1340  return mpImpl->mxSourceStorage;
1341 }
1342 
1343 Reference < XOutputStream >
1345 {
1346  Reference < XOutputStream > xOLEStream;
1347 
1348  if( mxEmbeddedResolver.is() )
1349  {
1350  Reference< XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
1351  if( xNA.is() )
1352  {
1353  Any aAny = xNA->getByName( "Obj12345678" );
1354  aAny >>= xOLEStream;
1355  }
1356  }
1357 
1358  return xOLEStream;
1359 }
1360 
1362 {
1363  OUString sRet;
1364 
1365  if( mxEmbeddedResolver.is() )
1366  {
1367  sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( "Obj12345678" );
1368  }
1369 
1370  return sRet;
1371 }
1372 
1374  const OUString& rName,
1375  const OUString& rDisplayName )
1376 {
1377  if( !mpStyleMap.is() )
1378  {
1379  mpStyleMap = new StyleMap;
1380  if( mxImportInfo.is() )
1381  {
1382  OUString sPrivateData( "PrivateData" );
1383  Reference< beans::XPropertySetInfo > xPropertySetInfo =
1384  mxImportInfo->getPropertySetInfo();
1385  if( xPropertySetInfo.is() &&
1386  xPropertySetInfo->hasPropertyByName(sPrivateData) )
1387  {
1388  Reference < XInterface > xIfc(
1389  static_cast< XUnoTunnel *>( mpStyleMap.get() ) );
1390  mxImportInfo->setPropertyValue( sPrivateData, Any(xIfc) );
1391  }
1392  }
1393  }
1394 
1395  StyleMap::key_type aKey( nFamily, rName );
1396  StyleMap::value_type aValue( aKey, rDisplayName );
1397  ::std::pair<StyleMap::iterator,bool> aRes( mpStyleMap->insert( aValue ) );
1398  SAL_WARN_IF( !aRes.second,
1399  "xmloff.core",
1400  "duplicate style name of family " << static_cast<int>(nFamily) << ": \"" << rName << "\"");
1401 
1402 }
1403 
1405  const OUString& rName ) const
1406 {
1407  OUString sName( rName );
1408  if( mpStyleMap.is() && !rName.isEmpty() )
1409  {
1410  StyleMap::key_type aKey( nFamily, rName );
1411  StyleMap::const_iterator aIter = mpStyleMap->find( aKey );
1412  if( aIter != mpStyleMap->end() )
1413  sName = (*aIter).second;
1414  }
1415  return sName;
1416 }
1417 
1418 void SvXMLImport::SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>&)
1419 {
1420 }
1421 
1422 void SvXMLImport::SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>&)
1423 {
1424 }
1425 
1426 void SvXMLImport::SetDocumentSpecificSettings(const OUString&, const uno::Sequence<beans::PropertyValue>&)
1427 {
1428 }
1429 
1431 {
1432  if (!mpProgressBarHelper)
1433  {
1434  mpProgressBarHelper = std::make_unique<ProgressBarHelper>(mxStatusIndicator, false);
1435 
1436  if (mxImportInfo.is())
1437  {
1438  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
1439  if (xPropertySetInfo.is())
1440  {
1441  OUString sProgressRange(XML_PROGRESSRANGE);
1442  OUString sProgressMax(XML_PROGRESSMAX);
1443  OUString sProgressCurrent(XML_PROGRESSCURRENT);
1444  OUString sRepeat(XML_PROGRESSREPEAT);
1445  if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
1446  xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
1447  xPropertySetInfo->hasPropertyByName(sProgressRange))
1448  {
1449  uno::Any aAny;
1450  sal_Int32 nProgressMax(0);
1451  sal_Int32 nProgressCurrent(0);
1452  sal_Int32 nProgressRange(0);
1453  aAny = mxImportInfo->getPropertyValue(sProgressRange);
1454  if (aAny >>= nProgressRange)
1455  mpProgressBarHelper->SetRange(nProgressRange);
1456  aAny = mxImportInfo->getPropertyValue(sProgressMax);
1457  if (aAny >>= nProgressMax)
1458  mpProgressBarHelper->SetReference(nProgressMax);
1459  aAny = mxImportInfo->getPropertyValue(sProgressCurrent);
1460  if (aAny >>= nProgressCurrent)
1461  mpProgressBarHelper->SetValue(nProgressCurrent);
1462  }
1463  if (xPropertySetInfo->hasPropertyByName(sRepeat))
1464  {
1465  uno::Any aAny = mxImportInfo->getPropertyValue(sRepeat);
1466  if (aAny.getValueType() == cppu::UnoType<bool>::get())
1467  mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
1468  else {
1469  SAL_WARN( "xmloff.core", "why is it no boolean?" );
1470  }
1471  }
1472  }
1473  }
1474  }
1475  return mpProgressBarHelper.get();
1476 }
1477 
1478 void SvXMLImport::AddNumberStyle(sal_Int32 nKey, const OUString& rName)
1479 {
1480  if (!mxNumberStyles.is())
1482  if (mxNumberStyles.is())
1483  {
1484  try
1485  {
1486  mxNumberStyles->insertByName(rName, Any(nKey));
1487  }
1488  catch ( uno::Exception& )
1489  {
1490  DBG_UNHANDLED_EXCEPTION( "xmloff.core", "Numberformat could not be inserted");
1491  }
1492  }
1493  else {
1494  SAL_WARN( "xmloff.core", "not possible to create NameContainer");
1495  }
1496 }
1497 
1499 {
1500  if (!mpEventImportHelper)
1501  {
1502  // construct event helper and register StarBasic handler and standard
1503  // event tables
1504  mpEventImportHelper = std::make_unique<XMLEventImportHelper>();
1505  const OUString& sStarBasic(GetXMLToken(XML_STARBASIC));
1506  mpEventImportHelper->RegisterFactory(sStarBasic,
1507  std::make_unique<XMLStarBasicContextFactory>());
1508  const OUString& sScript(GetXMLToken(XML_SCRIPT));
1509  mpEventImportHelper->RegisterFactory(sScript,
1510  std::make_unique<XMLScriptContextFactory>());
1511  mpEventImportHelper->AddTranslationTable(aStandardEventTable);
1512 
1513  // register StarBasic event handler with capitalized spelling
1514  mpEventImportHelper->RegisterFactory("StarBasic",
1515  std::make_unique<XMLStarBasicContextFactory>());
1516  }
1517 
1518  return *mpEventImportHelper;
1519 }
1520 
1522 {
1523  if (mxFontDecls.is())
1524  mxFontDecls->dispose();
1525  mxFontDecls = pFontDecls;
1526 }
1527 
1529 {
1530  if (mxStyles.is())
1531  mxStyles->dispose();
1532  mxStyles = pStyles;
1533 }
1534 
1536 {
1537  if (pAutoStyles && mxNumberStyles.is())
1538  {
1539  uno::Reference<xml::sax::XFastAttributeList> xAttrList = new sax_fastparser::FastAttributeList(nullptr);
1540  const uno::Sequence<OUString> aStyleNames = mxNumberStyles->getElementNames();
1541  for (const auto& name : aStyleNames)
1542  {
1543  uno::Any aAny(mxNumberStyles->getByName(name));
1544  sal_Int32 nKey(0);
1545  if (aAny >>= nKey)
1546  {
1547  SvXMLStyleContext* pContext = new SvXMLNumFormatContext(
1548  *this, name, xAttrList, nKey,
1549  GetDataStylesImport()->GetLanguageForKey(nKey), *pAutoStyles);
1550  pAutoStyles->AddStyle(*pContext);
1551  }
1552  }
1553  }
1554  if (mxAutoStyles.is())
1555  mxAutoStyles->dispose();
1556  mxAutoStyles = pAutoStyles;
1557  GetTextImport()->SetAutoStyles( pAutoStyles );
1558  GetShapeImport()->SetAutoStylesContext( pAutoStyles );
1559  GetChartImport()->SetAutoStylesContext( pAutoStyles );
1560  GetFormImport()->setAutoStyleContext( pAutoStyles );
1561 }
1562 
1564 {
1565  if (mxMasterStyles.is())
1566  mxMasterStyles->dispose();
1567  mxMasterStyles = pMasterStyles;
1568 }
1569 
1571 {
1572  return mxFontDecls.get();
1573 }
1574 
1576 {
1577  return mxStyles.get();
1578 }
1579 
1581 {
1582  return mxAutoStyles.get();
1583 }
1584 
1586 {
1587  return mxFontDecls.get();
1588 }
1589 
1591 {
1592  return mxStyles.get();
1593 }
1594 
1596 {
1597  return mxAutoStyles.get();
1598 }
1599 
1600 OUString SvXMLImport::GetAbsoluteReference(const OUString& rValue) const
1601 {
1602  if( rValue.isEmpty() || rValue[0] == '#' )
1603  return rValue;
1604 
1605  INetURLObject aAbsURL;
1606  if( mpImpl->aBaseURL.GetNewAbsURL( rValue, &aAbsURL ) )
1608  else
1609  return rValue;
1610 }
1611 
1612 bool SvXMLImport::IsODFVersionConsistent( const OUString& aODFVersion )
1613 {
1614  // the check returns sal_False only if the storage version could be retrieved
1615  bool bResult = true;
1616 
1617  if ( !aODFVersion.isEmpty() && aODFVersion.compareTo( u"" ODFVER_012_TEXT ) >= 0 )
1618  {
1619  // check the consistency only for the ODF1.2 and later ( according to content.xml )
1620  // manifest.xml might have no version, it should be checked here and the correct version should be set
1621  try
1622  { // don't use getDocumentStorage(), it's temporary and latest version
1623  uno::Reference<embed::XStorage> const xStor(GetSourceStorage());
1624  uno::Reference< beans::XPropertySet > xStorProps( xStor, uno::UNO_QUERY_THROW );
1625 
1626  // the check should be done only for OASIS format
1627  if (!IsOOoXML())
1628  {
1629  bool bRepairPackage = false;
1630  try
1631  {
1632  xStorProps->getPropertyValue( "RepairPackage" )
1633  >>= bRepairPackage;
1634  } catch ( uno::Exception& )
1635  {}
1636 
1637  // check only if not in Repair mode
1638  if ( !bRepairPackage )
1639  {
1640  OUString aStorVersion;
1641  xStorProps->getPropertyValue( "Version" )
1642  >>= aStorVersion;
1643 
1644  // if the storage version is set in manifest.xml, it must be the same as in content.xml
1645  // if not, set it explicitly to be used further ( it will work even for readonly storage )
1646  // This workaround is not nice, but I see no other way to handle it, since there are
1647  // ODF1.2 documents without version in manifest.xml
1648  if ( !aStorVersion.isEmpty() )
1649  bResult = aODFVersion == aStorVersion;
1650  else
1651  xStorProps->setPropertyValue( "Version",
1652  uno::makeAny( aODFVersion ) );
1653 
1654  if ( bResult )
1655  {
1656  bool bInconsistent = false;
1657  xStorProps->getPropertyValue( "IsInconsistent" )
1658  >>= bInconsistent;
1659  bResult = !bInconsistent;
1660  }
1661  }
1662  }
1663  }
1664  catch( uno::Exception& )
1665  {}
1666  }
1667 
1668  return bResult;
1669 }
1670 
1672 {
1673  SAL_WARN_IF( mxNumberFormatsSupplier.is(), "xmloff.core", "number formats supplier already exists!" );
1674  if(mxModel.is())
1676  uno::Reference< util::XNumberFormatsSupplier> (mxModel, uno::UNO_QUERY);
1677 }
1678 
1680 {
1681  SAL_WARN_IF( bool(mpNumImport), "xmloff.core", "data styles import already exists!" );
1682  uno::Reference<util::XNumberFormatsSupplier> xNum =
1684  if ( xNum.is() )
1685  mpNumImport = std::make_unique<SvXMLNumFmtHelper>(xNum, GetComponentContext() );
1686 }
1687 
1689 {
1690  sal_Unicode cNew = c;
1691  if( !mpImpl->hBatsFontConv )
1692  {
1693  mpImpl->hBatsFontConv = CreateFontToSubsFontConverter( u"StarBats",
1694  FontToSubsFontFlags::IMPORT );
1695  SAL_WARN_IF( !mpImpl->hBatsFontConv, "xmloff.core", "Got no symbol font converter" );
1696  }
1697  if( mpImpl->hBatsFontConv )
1698  {
1699  cNew = ConvertFontToSubsFontChar( mpImpl->hBatsFontConv, c );
1700  }
1701 
1702  return cNew;
1703 }
1704 
1706 {
1707  sal_Unicode cNew = c;
1708  if( !mpImpl->hMathFontConv )
1709  {
1710  mpImpl->hMathFontConv = CreateFontToSubsFontConverter( u"StarMath",
1711  FontToSubsFontFlags::IMPORT );
1712  SAL_WARN_IF( !mpImpl->hMathFontConv, "xmloff.core", "Got no symbol font converter" );
1713  }
1714  if( mpImpl->hMathFontConv )
1715  {
1716  cNew = ConvertFontToSubsFontChar( mpImpl->hMathFontConv, c );
1717  }
1718 
1719  return cNew;
1720 }
1721 
1723  sal_Int32 nId,
1724  const Sequence<OUString>& rMsgParams,
1725  const OUString& rExceptionMessage,
1726  const Reference<xml::sax::XLocator>& rLocator )
1727 {
1728  // create error list on demand
1729  if ( !mpXMLErrors )
1730  mpXMLErrors = std::make_unique<XMLErrors>();
1731 
1732  // save error information
1733  // use document locator (if none supplied)
1734  mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage,
1735  rLocator.is() ? rLocator : mxLocator );
1736 }
1737 
1739  sal_Int32 nId,
1740  const Sequence<OUString>& rMsgParams)
1741 {
1742  SetError( nId, rMsgParams, "", nullptr );
1743 }
1744 
1746  sal_Int32 nId,
1747  const OUString& rMsg1)
1748 {
1749  Sequence<OUString> aSeq { rMsg1 };
1750  SetError( nId, aSeq );
1751 }
1752 
1754 {
1755  if( mxFontDecls.is() )
1756  mxFontDecls->dispose();
1757  if( mxStyles.is() )
1758  mxStyles->dispose();
1759  if( mxAutoStyles.is() )
1760  mxAutoStyles->dispose();
1761  if( mxMasterStyles.is() )
1762  mxMasterStyles->dispose();
1763 
1764  mxModel.set(nullptr);
1765  mxEventListener.set(nullptr);
1766 }
1767 
1769 {
1770  return mpImpl->maInterfaceToIdentifierMapper;
1771 }
1772 
1773 uno::Reference< uno::XComponentContext > const &
1775 {
1776  return mpImpl->mxComponentContext;
1777 }
1778 
1779 OUString SvXMLImport::GetBaseURL() const
1780 {
1781  return mpImpl->aBaseURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
1782 }
1783 
1785 {
1786  return mpImpl->aDocBase.GetMainURL( INetURLObject::DecodeMechanism::NONE );
1787 }
1788 
1789 // Convert drawing object positions from OOo file format to OASIS (#i28749#)
1791 {
1792  return mpImpl->mbShapePositionInHoriL2R;
1793 }
1794 
1796 {
1797  return mpImpl->mbTextDocInOOoFileFormat;
1798 }
1799 
1801 {
1802  // dummy method; to be implemented by derived classes supporting XForms
1803 }
1804 
1805 bool SvXMLImport::getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild ) const
1806 {
1807  bool bRet = false;
1808  OUString const aBuildId(getBuildIdsProperty(mxImportInfo));
1809  if (!aBuildId.isEmpty())
1810  {
1811  sal_Int32 nIndex = aBuildId.indexOf('$');
1812  if (nIndex != -1)
1813  {
1814  rUPD = aBuildId.copy( 0, nIndex ).toInt32();
1815  sal_Int32 nIndexEnd = aBuildId.indexOf(';', nIndex);
1816  rBuild = (nIndexEnd == -1)
1817  ? aBuildId.copy(nIndex + 1).toInt32()
1818  : aBuildId.copy(nIndex + 1, nIndexEnd - nIndex - 1).toInt32();
1819  bRet = true;
1820  }
1821  }
1822  return bRet;
1823 }
1824 
1826 {
1827  // --> ORW
1828  return mpImpl->getGeneratorVersion( *this );
1829  // <--
1830 }
1831 
1833  sal_uInt16 const nOOoVersion, sal_uInt16 const nLOVersion)
1834 {
1835  assert( (nLOVersion & LO_flag));
1836  assert(!(nOOoVersion & LO_flag));
1837  const sal_uInt16 nGeneratorVersion(getGeneratorVersion());
1838  return (nGeneratorVersion & LO_flag)
1839  ? nGeneratorVersion < nLOVersion
1840  : nGeneratorVersion < nOOoVersion;
1841 }
1842 
1843 
1845 {
1846  return mpImpl->mxODFVersion ? *mpImpl->mxODFVersion : OUString();
1847 }
1848 
1850 {
1851  return mpImpl->mbIsOOoXML;
1852 }
1853 
1854 // xml:id for RDF metadata
1855 void SvXMLImport::SetXmlId(uno::Reference<uno::XInterface> const & i_xIfc,
1856  OUString const & i_rXmlId)
1857 {
1858  if (i_rXmlId.isEmpty())
1859  return;
1860 
1861  try {
1862  const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
1863  uno::UNO_QUERY);
1864 //FIXME: not yet
1865  if (xMeta.is()) {
1866  const beans::StringPair mdref( mpImpl->mStreamName, i_rXmlId );
1867  try {
1868  xMeta->setMetadataReference(mdref);
1869  } catch (lang::IllegalArgumentException &) {
1870  // probably duplicate; ignore
1871  SAL_INFO("xmloff.core", "SvXMLImport::SetXmlId: cannot set xml:id");
1872  }
1873  }
1874  } catch (uno::Exception &) {
1875  TOOLS_WARN_EXCEPTION("xmloff.core","SvXMLImport::SetXmlId");
1876  }
1877 }
1878 
1881 {
1882  if (!mpImpl->mpRDFaHelper)
1883  {
1884  mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaImportHelper(*this) );
1885  }
1886  return *mpImpl->mpRDFaHelper;
1887 }
1888 
1889 void
1890 SvXMLImport::AddRDFa(const uno::Reference<rdf::XMetadatable>& i_xObject,
1891  OUString const & i_rAbout,
1892  OUString const & i_rProperty,
1893  OUString const & i_rContent,
1894  OUString const & i_rDatatype)
1895 {
1896  // N.B.: we only get called if i_xObject had xhtml:about attribute
1897  // (an empty attribute value is valid)
1899  rRDFaHelper.ParseAndAddRDFa(i_xObject,
1900  i_rAbout, i_rProperty, i_rContent, i_rDatatype);
1901 }
1902 
1904 {
1905  if( embeddedFontUrlsKnown.count( url ) != 0 )
1906  return true;
1907  embeddedFontUrlsKnown.insert( url );
1908  return false;
1909 }
1910 
1911 const OUString & SvXMLImport::getNameFromToken( sal_Int32 nToken )
1912 {
1913  return xTokenHandler->getIdentifier( nToken & TOKEN_MASK );
1914 }
1915 
1916 OUString SvXMLImport::getPrefixAndNameFromToken( sal_Int32 nToken )
1917 {
1918  OUString rv;
1919  sal_Int32 nNamespaceToken = ( nToken & NMSP_MASK ) >> NMSP_SHIFT;
1920  auto aIter( aNamespaceMap.find( nNamespaceToken ) );
1921  if( aIter != aNamespaceMap.end() )
1922  rv = (*aIter).second.second + " " + aIter->second.first + ":";
1923  return rv + xTokenHandler->getIdentifier( nToken & TOKEN_MASK );
1924 }
1925 
1926 OUString SvXMLImport::getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap* pMap)
1927 {
1928  sal_Int32 nNamespaceToken = ( nToken & NMSP_MASK ) >> NMSP_SHIFT;
1929  auto aIter( aNamespaceMap.find( nNamespaceToken ) );
1930  if( aIter != aNamespaceMap.end() )
1931  {
1932  if (pMap)
1933  {
1934  OUString sRet = pMap->GetPrefixByKey(pMap->GetKeyByName((*aIter).second.second));
1935  if (!sRet.isEmpty())
1936  return sRet;
1937  }
1938  return (*aIter).second.first;
1939  }
1940  else
1941  return OUString();
1942 }
1943 
1944 OUString SvXMLImport::getNamespaceURIFromToken( sal_Int32 nToken )
1945 {
1946  sal_Int32 nNamespaceToken = ( nToken & NMSP_MASK ) >> NMSP_SHIFT;
1947  auto aIter( aNamespaceMap.find( nNamespaceToken ) );
1948  if( aIter != aNamespaceMap.end() )
1949  return (*aIter).second.second;
1950  else
1951  return OUString();
1952 }
1953 
1954 OUString SvXMLImport::getNamespacePrefixFromURI( const OUString& rURI )
1955 {
1956  auto aIter( aNamespaceURIPrefixMap.find(rURI) );
1957  if( aIter != aNamespaceURIPrefixMap.end() )
1958  return (*aIter).second;
1959  else
1960  return OUString();
1961 }
1962 
1963 sal_Int32 SvXMLImport::getTokenFromName( const OUString& rName )
1964 {
1965  Sequence< sal_Int8 > aLocalNameSeq( reinterpret_cast<sal_Int8 const *>(
1966  OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr()), rName.getLength() );
1967  return xTokenHandler->getTokenFromUTF8( aLocalNameSeq );
1968 }
1969 
1971 {
1972  auto mapTokenToNamespace = []( sal_Int32 nToken, sal_Int32 nPrefix, sal_Int32 nNamespace )
1973  {
1974  if ( nToken >= 0 )
1975  {
1976  const OUString& sNamespace = GetXMLToken( static_cast<XMLTokenEnum>( nNamespace ) );
1977  const OUString& sPrefix = GetXMLToken( static_cast<XMLTokenEnum>( nPrefix ) );
1978  assert( aNamespaceMap.find(nToken +1) == aNamespaceMap.end() && "cannot map two namespaces to the same token here");
1979  aNamespaceMap[ nToken + 1 ] = std::make_pair( sPrefix, sNamespace );
1980  aNamespaceURIPrefixMap.emplace( sNamespace, sPrefix );
1981  }
1982  };
1983 
1984  mapTokenToNamespace( XML_NAMESPACE_XML, XML_XML, XML_N_XML ); // implicit "xml" namespace prefix
1985  mapTokenToNamespace( XML_NAMESPACE_OFFICE, XML_NP_OFFICE, XML_N_OFFICE );
1986  mapTokenToNamespace( XML_NAMESPACE_OFFICE_SO52, XML_NP_OFFICE, XML_N_OFFICE_OLD );
1987  mapTokenToNamespace( XML_NAMESPACE_OFFICE_OOO, XML_NP_OFFICE, XML_N_OFFICE_OOO );
1988  mapTokenToNamespace( XML_NAMESPACE_STYLE, XML_NP_STYLE, XML_N_STYLE );
1989  mapTokenToNamespace( XML_NAMESPACE_STYLE_SO52, XML_NP_STYLE, XML_N_STYLE_OLD );
1990  mapTokenToNamespace( XML_NAMESPACE_STYLE_OOO, XML_NP_STYLE, XML_N_STYLE_OOO );
1991  mapTokenToNamespace( XML_NAMESPACE_TEXT, XML_NP_TEXT, XML_N_TEXT );
1992  mapTokenToNamespace( XML_NAMESPACE_TEXT_SO52, XML_NP_TEXT, XML_N_TEXT_OLD );
1993  mapTokenToNamespace( XML_NAMESPACE_TEXT_OOO, XML_NP_TEXT, XML_N_TEXT_OOO );
1994  mapTokenToNamespace( XML_NAMESPACE_TABLE, XML_NP_TABLE, XML_N_TABLE );
1995  mapTokenToNamespace( XML_NAMESPACE_TABLE_SO52, XML_NP_TABLE, XML_N_TABLE_OLD );
1996  mapTokenToNamespace( XML_NAMESPACE_TABLE_OOO, XML_NP_TABLE, XML_N_TABLE_OOO );
1997  mapTokenToNamespace( XML_NAMESPACE_DRAW, XML_NP_DRAW, XML_N_DRAW );
1998  mapTokenToNamespace( XML_NAMESPACE_DRAW_SO52, XML_NP_DRAW, XML_N_DRAW_OLD );
1999  mapTokenToNamespace( XML_NAMESPACE_DRAW_OOO, XML_NP_DRAW, XML_N_DRAW_OOO );
2000  mapTokenToNamespace( XML_NAMESPACE_FO, XML_NP_FO, XML_N_FO );
2001  mapTokenToNamespace( XML_NAMESPACE_FO_SO52, XML_NP_FO, XML_N_FO_OLD );
2002  mapTokenToNamespace( XML_NAMESPACE_FO_COMPAT, XML_NP_FO, XML_N_FO_COMPAT );
2003  mapTokenToNamespace( XML_NAMESPACE_XLINK, XML_NP_XLINK, XML_N_XLINK );
2004  mapTokenToNamespace( XML_NAMESPACE_XLINK_SO52, XML_NP_XLINK, XML_N_XLINK_OLD );
2005  mapTokenToNamespace( XML_NAMESPACE_DC, XML_NP_DC, XML_N_DC );
2006  mapTokenToNamespace( XML_NAMESPACE_META, XML_NP_META, XML_N_META );
2007  mapTokenToNamespace( XML_NAMESPACE_META_SO52, XML_NP_META, XML_N_META_OLD );
2008  mapTokenToNamespace( XML_NAMESPACE_META_OOO, XML_NP_META, XML_N_META_OOO );
2009  mapTokenToNamespace( XML_NAMESPACE_NUMBER, XML_NP_NUMBER, XML_N_NUMBER );
2010  mapTokenToNamespace( XML_NAMESPACE_NUMBER_SO52, XML_NP_NUMBER, XML_N_NUMBER_OLD );
2011  mapTokenToNamespace( XML_NAMESPACE_NUMBER_OOO, XML_NP_NUMBER, XML_N_NUMBER_OOO );
2016  mapTokenToNamespace( XML_NAMESPACE_SVG, XML_NP_SVG, XML_N_SVG );
2017  mapTokenToNamespace( XML_NAMESPACE_SVG_COMPAT, XML_NP_SVG, XML_N_SVG_COMPAT );
2018  mapTokenToNamespace( XML_NAMESPACE_CHART, XML_NP_CHART, XML_N_CHART );
2019  mapTokenToNamespace( XML_NAMESPACE_CHART_SO52, XML_NP_CHART, XML_N_CHART_OLD );
2020  mapTokenToNamespace( XML_NAMESPACE_CHART_OOO, XML_NP_CHART, XML_N_CHART_OOO );
2021  mapTokenToNamespace( XML_NAMESPACE_DR3D, XML_NP_DR3D, XML_N_DR3D );
2022  mapTokenToNamespace( XML_NAMESPACE_DR3D_OOO, XML_NP_DR3D, XML_N_DR3D_OOO );
2023  mapTokenToNamespace( XML_NAMESPACE_MATH, XML_NP_MATH, XML_N_MATH );
2025  mapTokenToNamespace( XML_NAMESPACE_FORM, XML_NP_FORM, XML_N_FORM );
2026  mapTokenToNamespace( XML_NAMESPACE_FORM_OOO, XML_NP_FORM, XML_N_FORM_OOO );
2027  mapTokenToNamespace( XML_NAMESPACE_SCRIPT, XML_NP_SCRIPT, XML_N_SCRIPT );
2028  mapTokenToNamespace( XML_NAMESPACE_SCRIPT_OOO, XML_NP_SCRIPT, XML_N_SCRIPT_OOO );
2030  mapTokenToNamespace( XML_NAMESPACE_CONFIG, XML_NP_CONFIG, XML_N_CONFIG );
2031  mapTokenToNamespace( XML_NAMESPACE_CONFIG_OOO, XML_NP_CONFIG, XML_N_CONFIG_OOO );
2032  mapTokenToNamespace( XML_NAMESPACE_OOO, XML_NP_OOO, XML_N_OOO );
2033  mapTokenToNamespace( XML_NAMESPACE_OOOW, XML_NP_OOOW, XML_N_OOOW );
2034  mapTokenToNamespace( XML_NAMESPACE_OOOC, XML_NP_OOOC, XML_N_OOOC );
2035  mapTokenToNamespace( XML_NAMESPACE_DOM, XML_NP_DOM, XML_N_DOM );
2036  mapTokenToNamespace( XML_NAMESPACE_DB, XML_NP_DB, XML_N_DB );
2037  mapTokenToNamespace( XML_NAMESPACE_DB_OASIS, XML_NP_DB, XML_N_DB_OASIS );
2038  mapTokenToNamespace( XML_NAMESPACE_DLG, XML_NP_DLG, XML_N_DLG );
2039  mapTokenToNamespace( XML_NAMESPACE_XFORMS, XML_NP_XFORMS_1_0, XML_N_XFORMS_1_0 );
2040  mapTokenToNamespace( XML_NAMESPACE_XSD, XML_NP_XSD, XML_N_XSD );
2041  mapTokenToNamespace( XML_NAMESPACE_XSI, XML_NP_XSI, XML_N_XSI );
2042  mapTokenToNamespace( XML_NAMESPACE_SMIL, XML_NP_SMIL, XML_N_SMIL );
2043  mapTokenToNamespace( XML_NAMESPACE_SMIL_SO52, XML_NP_SMIL, XML_N_SMIL_OLD );
2044  mapTokenToNamespace( XML_NAMESPACE_SMIL_COMPAT, XML_NP_SMIL, XML_N_SMIL_COMPAT );
2045  mapTokenToNamespace( XML_NAMESPACE_ANIMATION, XML_NP_ANIMATION, XML_N_ANIMATION );
2047  mapTokenToNamespace( XML_NAMESPACE_REPORT, XML_NP_RPT, XML_N_RPT );
2048  mapTokenToNamespace( XML_NAMESPACE_REPORT_OASIS, XML_NP_RPT, XML_N_RPT_OASIS );
2049  mapTokenToNamespace( XML_NAMESPACE_OF, XML_NP_OF, XML_N_OF );
2050  mapTokenToNamespace( XML_NAMESPACE_XHTML, XML_NP_XHTML, XML_N_XHTML );
2051  mapTokenToNamespace( XML_NAMESPACE_GRDDL, XML_NP_GRDDL, XML_N_GRDDL );
2053  mapTokenToNamespace( XML_NAMESPACE_TABLE_EXT, XML_NP_TABLE_EXT, XML_N_TABLE_EXT );
2054  mapTokenToNamespace( XML_NAMESPACE_CHART_EXT, XML_NP_CHART_EXT, XML_N_CHART_EXT );
2055  mapTokenToNamespace( XML_NAMESPACE_DRAW_EXT, XML_NP_DRAW_EXT, XML_N_DRAW_EXT );
2056  mapTokenToNamespace( XML_NAMESPACE_CALC_EXT, XML_NP_CALC_EXT, XML_N_CALC_EXT );
2057  mapTokenToNamespace( XML_NAMESPACE_LO_EXT, XML_NP_LO_EXT, XML_N_LO_EXT );
2058  mapTokenToNamespace( XML_NAMESPACE_CSS3TEXT, XML_NP_CSS3TEXT, XML_N_CSS3TEXT );
2059  mapTokenToNamespace( XML_NAMESPACE_FIELD, XML_NP_FIELD, XML_N_FIELD );
2060  mapTokenToNamespace( XML_NAMESPACE_FORMX, XML_NP_FORMX, XML_N_FORMX );
2061 }
2062 
2064 {
2065  for( auto const &aNamespaceEntry : aNamespaceMap )
2066  {
2067  // aNamespaceMap = { Token : ( NamespacePrefix, NamespaceURI ) }
2068  registerNamespace( aNamespaceEntry.second.second, aNamespaceEntry.first << NMSP_SHIFT );
2069  }
2070 }
2071 
2073 {
2075  return;
2076 
2078 
2079  mbNotifyMacroEventRead = true;
2080 }
2081 
2083 {
2084 }
2085 
2087 {
2088  for(const auto& aNamespaceDefine : m_aNamespaceDefines)
2089  {
2090  const OUString& rPrefix = aNamespaceDefine.m_aPrefix;
2091  const OUString& rNamespaceURI = aNamespaceDefine.m_aNamespaceURI;
2092  OUString sDecl;
2093  if ( rPrefix.isEmpty() )
2094  sDecl = "xmlns";
2095  else
2096  sDecl = "xmlns:" + rPrefix;
2097  rAttrList->AddAttribute( sDecl, "CDATA", rNamespaceURI );
2098  }
2099  m_aNamespaceDefines.clear();
2100 }
2101 
2102 void SvXMLImportFastNamespaceHandler::registerNamespace( const OUString& rNamespacePrefix, const OUString& rNamespaceURI )
2103 {
2104  // Elements with default namespace parsed by FastParser have namespace prefix.
2105  // A default namespace needs to be registered with the prefix, to maintain the compatibility.
2106  if ( rNamespacePrefix.isEmpty() )
2108  SvXMLImport::getNamespacePrefixFromURI( rNamespaceURI ), rNamespaceURI) );
2109 
2111  rNamespacePrefix, rNamespaceURI) );
2112 }
2113 
2114 OUString SvXMLImportFastNamespaceHandler::getNamespaceURI( const OUString&/* rNamespacePrefix */ )
2115 {
2116  return OUString();
2117 }
2118 
2120 : mrImport( rImport ),
2121  mxFastAttributes( new sax_fastparser::FastAttributeList( SvXMLImport::xTokenHandler.get() ) )
2122 {
2123 }
2124 
2125 void SAL_CALL SvXMLLegacyToFastDocHandler::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
2126 {
2127  mrImport->setTargetDocument( xDoc );
2128 }
2129 
2131 {
2132  mrImport->startDocument();
2133 }
2134 
2136 {
2137  mrImport->endDocument();
2138 }
2139 
2140 void SAL_CALL SvXMLLegacyToFastDocHandler::startElement( const OUString& rName,
2141  const uno::Reference< xml::sax::XAttributeList >& xAttrList )
2142 {
2143  sal_uInt16 nDefaultNamespace = XML_NAMESPACE_UNKNOWN;
2144  if (!maDefaultNamespaces.empty())
2145  nDefaultNamespace = maDefaultNamespaces.top();
2146  SvXMLImport::processNSAttributes(mrImport->mxNamespaceMap, mrImport.get(), xAttrList);
2147  OUString aLocalName;
2148  sal_uInt16 nPrefix = mrImport->mxNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
2149  sal_Int32 mnElement = NAMESPACE_TOKEN( nPrefix ) | SvXMLImport::getTokenFromName( aLocalName );
2150  mxFastAttributes->clear();
2151 
2152  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
2153  for( sal_Int16 i=0; i < nAttrCount; i++ )
2154  {
2155  const OUString& rAttrName = xAttrList->getNameByIndex( i );
2156  const OUString& rAttrValue = xAttrList->getValueByIndex( i );
2157  if (rAttrName == "xmlns")
2158  {
2159  sal_uInt16 nNamespaceKey = mrImport->mxNamespaceMap->GetKeyByName(rAttrValue);
2160  if (nNamespaceKey != XML_NAMESPACE_UNKNOWN)
2161  {
2162  nDefaultNamespace = nNamespaceKey;
2163  continue;
2164  }
2165  assert(false && "unknown namespace");
2166  }
2167  else if (rAttrName.indexOf(":") == -1 && nDefaultNamespace != XML_NAMESPACE_UNKNOWN)
2168  {
2169  auto const nToken = SvXMLImport::getTokenFromName(rAttrName);
2171  {
2172  mxFastAttributes->addUnknown(mrImport->mxNamespaceMap->GetNameByKey(nDefaultNamespace),
2173  OUStringToOString(rAttrName, RTL_TEXTENCODING_UTF8),
2174  OUStringToOString(rAttrValue, RTL_TEXTENCODING_UTF8));
2175  }
2176  else
2177  {
2178  sal_Int32 const nAttr = NAMESPACE_TOKEN(nDefaultNamespace) | nToken;
2179  mxFastAttributes->add(nAttr, OUStringToOString(rAttrValue, RTL_TEXTENCODING_UTF8));
2180  }
2181  continue;
2182  }
2183 
2184  OUString aLocalAttrName;
2185  OUString aNamespace;
2186  // don't add unknown namespaces to the map
2187  sal_uInt16 const nAttrPrefix = mrImport->mxNamespaceMap->GetKeyByQName(
2188  rAttrName, nullptr, &aLocalAttrName, &aNamespace, SvXMLNamespaceMap::QNameMode::AttrValue);
2189  if( XML_NAMESPACE_XMLNS == nAttrPrefix )
2190  continue; // ignore
2191  auto const nToken = SvXMLImport::getTokenFromName(aLocalAttrName);
2192  if (XML_NAMESPACE_UNKNOWN == nAttrPrefix || nToken == xmloff::XML_TOKEN_INVALID)
2193  {
2194  mxFastAttributes->addUnknown(aNamespace,
2195  OUStringToOString(rAttrName, RTL_TEXTENCODING_UTF8),
2196  OUStringToOString(rAttrValue, RTL_TEXTENCODING_UTF8));
2197  }
2198  else
2199  {
2200  sal_Int32 const nAttr = NAMESPACE_TOKEN(nAttrPrefix) | nToken;
2201  mxFastAttributes->add(nAttr, OUStringToOString(rAttrValue, RTL_TEXTENCODING_UTF8));
2202  }
2203  }
2204  mrImport->startFastElement( mnElement, mxFastAttributes );
2205  maDefaultNamespaces.push(nDefaultNamespace);
2206 }
2207 
2208 void SAL_CALL SvXMLLegacyToFastDocHandler::endElement( const OUString& rName )
2209 {
2210  OUString aLocalName;
2211  sal_uInt16 nPrefix = mrImport->mxNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
2212  sal_Int32 mnElement = NAMESPACE_TOKEN( nPrefix ) | SvXMLImport::getTokenFromName(aLocalName);
2213  mrImport->endFastElement( mnElement );
2214  maDefaultNamespaces.pop();
2215 }
2216 
2217 void SAL_CALL SvXMLLegacyToFastDocHandler::characters( const OUString& aChars )
2218 {
2219  mrImport->characters( aChars );
2220 }
2221 
2223 {
2224 }
2225 
2226 void SAL_CALL SvXMLLegacyToFastDocHandler::processingInstruction( const OUString& aTarget,
2227  const OUString& aData)
2228 {
2229  mrImport->processingInstruction( aTarget, aData );
2230 }
2231 
2232 void SAL_CALL SvXMLLegacyToFastDocHandler::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& rLocator )
2233 {
2234  mrImport->setDocumentLocator( rLocator );
2235 }
2236 
2237 
2238 
2239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
exports com.sun.star.lib. util
const css::uno::Reference< css::container::XNameContainer > & GetBitmapHelper()
Definition: xmlimp.cxx:1134
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
FontToSubsFontConverter hMathFontConv
Definition: xmlimp.cxx:278
FastAttributeIter find(sal_Int32 nToken) const
constexpr sal_uInt16 XML_NAMESPACE_MATH
constexpr sal_uInt16 XML_NAMESPACE_PRESENTATION_SO52
OUString GetBaseURL() const
Definition: xmlimp.cxx:1779
constexpr sal_uInt16 XML_NAMESPACE_CHART_OOO
static rtl::Reference< xmloff::token::FastTokenHandler > xTokenHandler
Definition: xmlimp.hxx:236
rtl::Reference< SvXMLImport > mrImport
Definition: xmlimp.hxx:155
rtl::Reference< SvXMLStylesContext > mxMasterStyles
Definition: xmlimp.hxx:205
SAL_DLLPRIVATE::xmloff::RDFaImportHelper & GetRDFaImportHelper()
do not dllexport this; only for advanced cases (bookmark-start)
Definition: xmlimp.cxx:1880
virtual void SAL_CALL setErrorHandler(const css::uno::Reference< css::xml::sax::XErrorHandler > &Handler) override
Definition: xmlimp.cxx:528
constexpr sal_uInt16 XML_NAMESPACE_ANIMATION
css::uno::Reference< css::graphic::XGraphic > loadGraphicFromBase64(css::uno::Reference< css::io::XOutputStream > const &rxOutputStream)
Definition: xmlimp.cxx:1291
constexpr sal_uInt16 XML_NAMESPACE_DB_OASIS
sal_Int32 nIndex
OUString implementationName
Definition: xmlimp.cxx:299
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
COMPHELPER_DLLPUBLIC css::uno::Reference< css::container::XNameContainer > NameContainer_createInstance(const css::uno::Type &aType)
virtual void SAL_CALL setFastDocumentHandler(const css::uno::Reference< css::xml::sax::XFastDocumentHandler > &Handler) override
Definition: xmlimp.cxx:508
constexpr sal_uInt16 XML_NAMESPACE_VERSIONS_LIST
void SetStyles(SvXMLStylesContext *pStyles)
Definition: xmlimp.cxx:1528
rtl::Reference< ::xmloff::OFormLayerXMLImport > const & GetFormImport()
Definition: xmlimp.hxx:623
static std::unordered_map< sal_Int32, std::pair< OUString, OUString > > aNamespaceMap
Definition: xmlimp.hxx:237
virtual void SAL_CALL parseStream(const css::xml::sax::InputSource &aInputSource) override
Definition: xmlimp.cxx:502
constexpr sal_uInt16 XML_NAMESPACE_OFFICE_OOO
constexpr sal_uInt16 XML_NAMESPACE_SCRIPT_OOO
constexpr sal_uInt16 XML_NAMESPACE_XFORMS
css::uno::Reference< css::container::XNameContainer > mxTransGradientHelper
Definition: xmlimp.hxx:210
constexpr sal_uInt16 XML_NAMESPACE_CHART
void cleanup() noexcept
Definition: xmlimp.cxx:436
constexpr sal_uInt16 XML_NAMESPACE_DR3D
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
Definition: xmlimp.cxx:848
std::unique_ptr< SvXMLNumFmtHelper > mpNumImport
Definition: xmlimp.hxx:222
rtl::Reference< XMLTextImportHelper > mxTextImport
Definition: xmlimp.hxx:197
void SetRepeat(bool bValue)
constexpr sal_uInt16 XML_NAMESPACE_DRAW_EXT
const css::uno::Reference< css::container::XNameContainer > & GetHatchHelper()
Definition: xmlimp.cxx:1111
SAL_DLLPRIVATE void InitCtor_()
Definition: xmlimp.cxx:350
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:82
constexpr sal_uInt16 XML_NAMESPACE_SCRIPT
constexpr sal_uInt16 XML_NAMESPACE_OOOC
virtual XMLShapeImportHelper * CreateShapeImport()
Definition: xmlimp.cxx:1069
rtl::Reference< XMLFontStylesContext > mxFontDecls
Definition: xmlimp.hxx:202
virtual OUString SAL_CALL getImplementationName() final override
Definition: xmlimp.cxx:1049
virtual void SAL_CALL registerNamespace(const OUString &NamespaceURL, sal_Int32 NamespaceToken) override
Definition: xmlimp.cxx:518
bool mbShapePositionInHoriL2R
Definition: xmlimp.cxx:295
css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator
Definition: xmlimp.hxx:250
static const sal_uInt16 OOo_30x
Definition: xmlimp.hxx:535
#define SAL_INFO_IF(condition, area, stream)
constexpr sal_uInt16 XML_NAMESPACE_FORMX
css::uno::Reference< css::container::XNameContainer > mxNumberStyles
Definition: xmlimp.hxx:213
const css::uno::Reference< css::container::XNameContainer > & GetTransGradientHelper()
Definition: xmlimp.cxx:1157
sal_Unicode ConvStarMathCharToStarSymbol(sal_Unicode c)
Definition: xmlimp.cxx:1705
#define ODFVER_012_TEXT
uno::Reference< embed::XStorage > mxSourceStorage
Definition: xmlimp.cxx:302
constexpr sal_uInt16 XML_NAMESPACE_FO_COMPAT
constexpr sal_uInt16 XML_NAMESPACE_SMIL_SO52
::xmloff::OFormLayerXMLImport * CreateFormImport()
Definition: xmlimp.cxx:1079
constexpr sal_uInt16 XML_NAMESPACE_XLINK
std::unique_ptr< XMLEventImportHelper > mpEventImportHelper
Definition: xmlimp.hxx:224
constexpr sal_uInt16 XML_NAMESPACE_OOO
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) final override
Definition: xmlimp.cxx:1054
std::unique_ptr< ProgressBarHelper > mpProgressBarHelper
Definition: xmlimp.hxx:223
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
css::uno::Reference< css::io::XOutputStream > GetStreamForEmbeddedObjectURLFromBase64() const
Definition: xmlimp.cxx:1344
SvXMLNumFmtHelper * GetDataStylesImport()
Definition: xmlimp.hxx:651
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual XMLTextImportHelper * CreateTextImport()
Definition: xmlimp.cxx:1064
constexpr sal_Int32 NMSP_MASK
Definition: xmlimp.hxx:95
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() final override
Definition: xmlimp.cxx:1059
constexpr sal_uInt16 XML_NAMESPACE_DLG
constexpr sal_uInt16 XML_NAMESPACE_CSS3TEXT
css::uno::Reference< css::graphic::XGraphic > loadGraphicByURL(OUString const &rURL)
Definition: xmlimp.cxx:1269
constexpr sal_uInt16 XML_NAMESPACE_FO_SO52
bool IsShapePositionInHoriL2R() const
Definition: xmlimp.cxx:1790
constexpr sal_uInt16 XML_NAMESPACE_XLINK_SO52
static const sal_uInt16 AOO_40x
Definition: xmlimp.hxx:541
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:599
constexpr sal_uInt16 XML_NAMESPACE_STYLE_OOO
static const sal_uInt16 LO_41x
Definition: xmlimp.hxx:550
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override
Definition: xmlimp.cxx:742
constexpr sal_uInt16 XML_NAMESPACE_ANIMATION_OOO
rtl::Reference< SchXMLImportHelper > const & GetChartImport()
Definition: xmlimp.hxx:615
bool IsOOoXML() const
Definition: xmlimp.cxx:1849
SvXMLImport(const css::uno::Reference< css::uno::XComponentContext > &xContext, OUString const &implementationName, SvXMLImportFlags nImportFlags=SvXMLImportFlags::ALL, const css::uno::Sequence< OUString > &sSupportedServiceNames={})
Definition: xmlimp.cxx:404
constexpr sal_uInt16 XML_NAMESPACE_SMIL_COMPAT
constexpr sal_uInt16 XML_NAMESPACE_DB
constexpr sal_uInt16 XML_NAMESPACE_NUMBER
css::uno::Reference< css::embed::XStorage > const & GetSourceStorage() const
Definition: xmlimp.cxx:1338
constexpr sal_uInt16 XML_NAMESPACE_DOM
OUString GetDocumentBase() const
Definition: xmlimp.cxx:1784
::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper
Definition: xmlimp.cxx:339
void * FontToSubsFontConverter
static const sal_uInt16 LO_43x
Definition: xmlimp.hxx:552
std::set< OUString > embeddedFontUrlsKnown
Definition: xmlimp.hxx:231
static const sal_uInt16 OOo_32x
Definition: xmlimp.hxx:537
constexpr sal_uInt16 XML_NAMESPACE_NUMBER_OOO
css::uno::Reference< css::container::XNameContainer > mxMarkerHelper
Definition: xmlimp.hxx:211
css::uno::Reference< css::container::XNameContainer > mxHatchHelper
Definition: xmlimp.hxx:208
const uno::Reference< uno::XComponentContext > mxComponentContext
Definition: xmlimp.cxx:298
constexpr sal_uInt16 XML_NAMESPACE_CALC_EXT
void SetFontDecls(XMLFontStylesContext *pFontDecls)
Definition: xmlimp.cxx:1521
const sal_uInt16 XML_NAMESPACE_UNKNOWN
constexpr sal_uInt16 XML_NAMESPACE_XSI
const sal_uInt16 XML_NAMESPACE_XMLNS
XmlStyleFamily
Definition: families.hxx:47
bool mbNotifyMacroEventRead
Definition: xmlimp.hxx:259
sal_uInt16 sal_Unicode
static const sal_uInt16 LO_7x
Definition: xmlimp.hxx:559
static OUString getNamespaceURIFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:1944
virtual void SAL_CALL setLocale(const css::lang::Locale &rLocale) override
Definition: xmlimp.cxx:538
std::unique_ptr< XMLErrors > mpXMLErrors
Definition: xmlimp.hxx:225
sal_uInt16 getGeneratorVersion() const
this checks the build ID and returns
Definition: xmlimp.cxx:1825
SvXMLLegacyToFastDocHandler(const rtl::Reference< SvXMLImport > &rImport)
Definition: xmlimp.cxx:2119
constexpr sal_uInt16 XML_NAMESPACE_CHART_SO52
constexpr sal_uInt16 XML_NAMESPACE_OFFICE_SO52
static const sal_uInt16 OOo_2x
Definition: xmlimp.hxx:534
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps)
Definition: xmlimp.cxx:1422
SvXMLImportFlags
Definition: xmlimp.hxx:111
#define XML_PROGRESSRANGE
css::uno::Reference< css::frame::XModel > mxModel
Definition: xmlimp.hxx:191
virtual void SAL_CALL endElement(const OUString &aName) override
Definition: xmlimp.cxx:2208
static const sal_uInt16 LO_flag
Definition: xmlimp.hxx:548
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override
Definition: xmlimp.cxx:2232
std::unique_ptr< xmloff::RDFaImportHelper > mpRDFaHelper
Definition: xmlimp.cxx:304
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId() noexcept
Definition: xmlimp.cxx:468
static const sal_uInt16 OOo_34x
Definition: xmlimp.hxx:539
virtual OUString SAL_CALL getNamespaceURI(const OUString &rNamespacePrefix) override
Definition: xmlimp.cxx:2114
OUString ResolveEmbeddedObjectURL(const OUString &rURL, std::u16string_view rClassId)
Definition: xmlimp.cxx:1314
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr sal_uInt16 XML_NAMESPACE_FORM
::comphelper::UnoInterfaceToUniqueIdentifierMapper & getInterfaceToIdentifierMapper()
Definition: xmlimp.cxx:1768
constexpr OUStringLiteral sStarBasic
SvXMLImport_Impl(const uno::Reference< uno::XComponentContext > &rxContext, OUString const &theImplementationName, const css::uno::Sequence< OUString > &sSupportedServiceNames={})
Definition: xmlimp.cxx:308
XMLEventImportHelper & GetEventImport()
Definition: xmlimp.cxx:1498
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:1916
static const sal_uInt16 OOo_33x
Definition: xmlimp.hxx:538
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
virtual void SAL_CALL setCustomEntityNames(const ::css::uno::Sequence< ::css::beans::Pair<::rtl::OUString,::rtl::OUString > > &replacements) override
Definition: xmlimp.cxx:548
static const sal_uInt16 AOO_4x
Definition: xmlimp.hxx:547
css::uno::Reference< css::xml::sax::XFastDocumentHandler > mxFastDocumentHandler
Definition: xmlimp.hxx:235
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlimp.cxx:945
css::uno::Reference< css::lang::XEventListener > mxEventListener
Definition: xmlimp.hxx:214
FontToSubsFontConverter hBatsFontConv
Definition: xmlimp.cxx:277
constexpr sal_uInt16 XML_NAMESPACE_DRAW
css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64() const
Definition: xmlimp.cxx:1303
#define XML_PROGRESSMAX
static std::unordered_map< OUString, OUString > aNamespaceURIPrefixMap
Definition: xmlimp.hxx:238
const char * sName
constexpr sal_uInt16 XML_NAMESPACE_TABLE_SO52
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps)
Definition: xmlimp.cxx:1418
SvXMLStylesContext * GetStyles()
Definition: xmlimp.cxx:1575
sal_Unicode ConvertFontToSubsFontChar(FontToSubsFontConverter hConverter, sal_Unicode cChar)
virtual void SAL_CALL endUnknownElement(const OUString &Namespace, const OUString &Name) override
Definition: xmlimp.cxx:867
constexpr sal_uInt16 XML_NAMESPACE_BLOCKLIST
const css::uno::Sequence< sal_Int8 > & getSeq() const
static const sal_uInt16 LO_63x
Definition: xmlimp.hxx:558
void AddRDFa(const css::uno::Reference< css::rdf::XMetadatable > &i_xObject, OUString const &i_rAbout, OUString const &i_rProperty, OUString const &i_rContent, OUString const &i_rDatatype)
Add a RDFa statement; parameters are XML attribute values.
Definition: xmlimp.cxx:1890
SvXMLImportFlags mnImportFlags
Definition: xmlimp.hxx:230
constexpr sal_uInt16 XML_NAMESPACE_CONFIG
static void initializeNamespaceMaps()
Definition: xmlimp.cxx:1970
constexpr sal_uInt16 XML_NAMESPACE_META_SO52
constexpr sal_uInt16 XML_NAMESPACE_XML
virtual void SAL_CALL characters(const OUString &aChars) override
Definition: xmlimp.cxx:2217
OUString sPrefix
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlimp.cxx:748
virtual void SAL_CALL processingInstruction(const OUString &aTarget, const OUString &aData) override
Definition: xmlimp.cxx:2226
std::vector< NamespaceDefine > m_aNamespaceDefines
Definition: xmlimp.hxx:139
#define DBG_UNHANDLED_EXCEPTION(...)
constexpr sal_uInt16 XML_NAMESPACE_SVG
#define TOOLS_WARN_EXCEPTION(area, stream)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlimp.cxx:882
constexpr sal_uInt16 XML_NAMESPACE_TABLE_EXT
constexpr sal_uInt16 XML_NAMESPACE_FO
static const sal_uInt16 LO_44x
Definition: xmlimp.hxx:553
int i
bool getBuildIds(sal_Int32 &rUPD, sal_Int32 &rBuild) const
returns the upd and build id (f.e.
Definition: xmlimp.cxx:1805
sal_Unicode ConvStarBatsCharToStarSymbol(sal_Unicode c)
Definition: xmlimp.cxx:1688
static bool NormalizeURI(OUString &rName)
virtual OUString SAL_CALL getNamespaceURL(const OUString &rPrefix) override
Definition: xmlimp.cxx:523
constexpr sal_uInt16 XML_NAMESPACE_TEXT
bool IsPackageURL(const OUString &rURL) const
Definition: xmlimp.cxx:1221
rtl::Reference< SvXMLImportFastNamespaceHandler > maNamespaceHandler
Definition: xmlimp.hxx:233
virtual void SAL_CALL startDocument() override
Definition: xmlimp.cxx:2130
constexpr sal_uInt16 XML_NAMESPACE_CHART_EXT
static sal_Int32 GetXStorageFormat(const css::uno::Reference< css::embed::XStorage > &xStorage)
rtl::Reference< StyleMap > mpStyleMap
Definition: xmlimp.hxx:226
void SetMasterStyles(SvXMLStylesContext *pMasterStyles)
Definition: xmlimp.cxx:1563
rtl::Reference< SvXMLStylesContext > mxAutoStyles
Definition: xmlimp.hxx:204
css::uno::Reference< css::container::XNameContainer > mxGradientHelper
Definition: xmlimp.hxx:207
rtl::Reference< XMLShapeImportHelper > mxShapeImport
Definition: xmlimp.hxx:198
bool IsTextDocInOOoFileFormat() const
Definition: xmlimp.cxx:1795
std::stack< SvXMLImportContextRef, std::vector< SvXMLImportContextRef > > maContexts
Definition: xmlimp.hxx:221
constexpr size_t NMSP_SHIFT
Definition: xmlimp.hxx:93
static const sal_uInt16 OOo_31x
Definition: xmlimp.hxx:536
constexpr sal_uInt16 XML_NAMESPACE_META_OOO
float u
unsigned char sal_Bool
constexpr sal_uInt16 XML_NAMESPACE_TABLE_OOO
friend class SvXMLImportContext
Definition: xmlimp.hxx:187
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlimp.cxx:889
static OUString getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap *pMap)
Definition: xmlimp.cxx:1926
constexpr sal_uInt16 XML_NAMESPACE_GRDDL
ProgressBarHelper * GetProgressBarHelper()
Definition: xmlimp.cxx:1430
constexpr sal_uInt16 XML_NAMESPACE_XHTML
constexpr sal_uInt16 XML_NAMESPACE_XSD
bool mbTextDocInOOoFileFormat
Definition: xmlimp.cxx:296
void CreateDataStylesImport_()
Definition: xmlimp.cxx:1679
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
Definition: xmlimp.cxx:2125
css::uno::Type const & get()
sal_uInt16 getGeneratorVersion(const SvXMLImport &rImport)
Definition: xmlimp.cxx:329
static const sal_uInt16 LO_42x
Definition: xmlimp.hxx:551
virtual void SAL_CALL processingInstruction(const OUString &aTarget, const OUString &aData) override
Definition: xmlimp.cxx:737
constexpr sal_uInt16 XML_NAMESPACE_DC
virtual void SAL_CALL setNamespaceHandler(const css::uno::Reference< css::xml::sax::XFastNamespaceHandler > &Handler) override
Definition: xmlimp.cxx:543
css::uno::Sequence< OUString > maSupportedServiceNames
Definition: xmlimp.cxx:300
FontToSubsFontConverter CreateFontToSubsFontConverter(std::u16string_view rOrgName, FontToSubsFontFlags nFlags)
bool mbOwnGraphicResolver
Definition: xmlimp.cxx:280
std::stack< sal_uInt16 > maDefaultNamespaces
Definition: xmlimp.hxx:157
#define XML_PROGRESSCURRENT
allows you to import a element
constexpr sal_uInt16 XML_NAMESPACE_DR3D_OOO
With this class you can import a element containing its data as element o...
css::uno::Reference< css::beans::XPropertySet > mxImportInfo
Definition: xmlimp.hxx:195
css::uno::Reference< css::container::XNameContainer > mxDashHelper
Definition: xmlimp.hxx:212
constexpr sal_uInt16 XML_NAMESPACE_STYLE_SO52
rtl::Reference< comphelper::AttributeList > maNamespaceAttrList
Definition: xmlimp.hxx:234
Helps the XMLEventsImportContext.
void SetXmlId(css::uno::Reference< css::uno::XInterface > const &i_xIfc, OUString const &i_rXmlId)
set the XmlId attribute of given UNO object (for RDF metadata)
Definition: xmlimp.cxx:1855
static const OUString & getNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:1911
virtual void SAL_CALL startElement(const OUString &aName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
Definition: xmlimp.cxx:2140
static const sal_uInt16 LO_3x
Definition: xmlimp.hxx:549
constexpr sal_uInt16 XML_NAMESPACE_SVG_COMPAT
static OUString getNamespacePrefixFromURI(const OUString &rURI)
Definition: xmlimp.cxx:1954
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
virtual void SAL_CALL startDocument() override
Definition: xmlimp.cxx:553
static const sal_uInt16 LO_6x
: when adding a new value more specific than "6x", grep for all current uses and adapt them!!! ...
Definition: xmlimp.hxx:557
virtual void SAL_CALL cancel() override
Definition: xmlimp.cxx:940
void ParseAndAddRDFa(css::uno::Reference< css::rdf::XMetadatable > const &i_xObject, OUString const &i_rAbout, OUString const &i_rProperty, OUString const &i_rContent, OUString const &i_rDatatype)
Parse and add a RDFa statement; parameters are XML attribute values.
constexpr sal_uInt16 XML_NAMESPACE_PRESENTATION
DefTokenId nToken
static bool bIsNSMapsInitialized
Definition: xmlimp.hxx:239
#define XMLERROR_FLAG_SEVERE
Definition: xmlerror.hxx:37
OUString mStreamName
name of stream in package, e.g., "content.xml"
Definition: xmlimp.cxx:286
virtual void SAL_CALL endDocument() override
Definition: xmlimp.cxx:2135
constexpr sal_uInt16 XML_NAMESPACE_TABLE
virtual void SAL_CALL ignorableWhitespace(const OUString &aWhitespaces) override
Definition: xmlimp.cxx:2222
void CreateNumberFormatsSupplier_()
Definition: xmlimp.cxx:1671
static sal_Int32 getTokenFromName(const OUString &sName)
Definition: xmlimp.cxx:1963
css::uno::Reference< css::uno::XComponentContext > const & GetComponentContext() const
Definition: xmlimp.cxx:1774
OUString GetAbsoluteReference(const OUString &rValue) const
Definition: xmlimp.cxx:1600
OUString GetODFVersion() const
Definition: xmlimp.cxx:1844
bool mbOwnEmbeddedResolver
Definition: xmlimp.cxx:281
OUString GetStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName) const
Definition: xmlimp.cxx:1404
#define SAL_WARN_IF(condition, area, stream)
#define XML_NUMBERSTYLES
Definition: xmlnumfi.hxx:36
void NotifyMacroEventRead()
Definition: xmlimp.cxx:2072
constexpr OUStringLiteral sScript
virtual void SetDocumentSpecificSettings(const OUString &_rSettingsGroupName, const css::uno::Sequence< css::beans::PropertyValue > &_rSettings)
Definition: xmlimp.cxx:1426
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3454
css::uno::Reference< css::xml::sax::XLocator > mxLocator
Definition: xmlimp.hxx:190
constexpr sal_uInt16 XML_NAMESPACE_SMIL
rtl::Reference< SvXMLStylesContext > mxStyles
Definition: xmlimp.hxx:203
constexpr sal_uInt16 XML_NAMESPACE_REPORT
sal_Int64 getSomethingImpl(const css::uno::Sequence< sal_Int8 > &rId, T *pThis, FallbackToGetSomethingOf< Base >={})
constexpr sal_uInt16 XML_NAMESPACE_CONFIG_OOO
#define XML_PROGRESSREPEAT
css::uno::Reference< css::util::XNumberFormatsSupplier > mxNumberFormatsSupplier
Definition: xmlimp.hxx:192
Handling of tokens in XML:
void AddNumberStyle(sal_Int32 nKey, const OUString &sName)
Definition: xmlimp.cxx:1478
#define SAL_INFO(area, stream)
OUString aName
const css::uno::Reference< css::container::XNameContainer > & GetMarkerHelper()
Definition: xmlimp.cxx:1180
virtual SvXMLImportContext * CreateFastContext(sal_Int32 Element, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList)
Definition: xmlimp.cxx:342
virtual void SetStatistics(const css::uno::Sequence< css::beans::NamedValue > &i_rStats)
Definition: xmlimp.cxx:895
static const sal_uInt16 OOo_1x
Definition: xmlimp.hxx:533
OReadImagesDocumentHandler::Image_XML_Namespace nNamespace
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
FastAttributeIter end() const
const char * name
constexpr sal_uInt16 XML_NAMESPACE_TEXT_OOO
std::unique_ptr< SvXMLImport_Impl > mpImpl
Definition: xmlimp.hxx:216
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 import.
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: xmlimp.cxx:475
Sequence< sal_Int8 > aSeq
const css::uno::Reference< css::container::XNameContainer > & GetDashHelper()
Definition: xmlimp.cxx:1202
constexpr sal_uInt16 XML_NAMESPACE_OF
rtl::Reference< ::xmloff::OFormLayerXMLImport > mxFormImport
Definition: xmlimp.hxx:200
std::optional< SvXMLNamespaceMap > mxNamespaceMap
Definition: xmlimp.hxx:218
std::unique_ptr< EmbeddedFontsHelper, o3tl::default_delete< EmbeddedFontsHelper > > mxEmbeddedFontHelper
Definition: xmlimp.hxx:254
constexpr sal_Int32 NAMESPACE_TOKEN(sal_uInt16 prefixToken)
Definition: xmlimp.hxx:99
virtual void initXForms()
Definition: xmlimp.cxx:1800
void SetAutoStyles(SvXMLStylesContext *pAutoStyles)
Definition: xmlimp.cxx:1535
OUString ResolveEmbeddedObjectURLFromBase64()
Definition: xmlimp.cxx:1361
INetURLObject aDocBase
Definition: xmlimp.cxx:283
void AddStyle(SvXMLStyleContext &rNew)
Definition: xmlstyle.cxx:715
constexpr sal_uInt16 XML_NAMESPACE_OFFICE_EXT
void AddStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName, const OUString &rDisplayName)
Definition: xmlimp.cxx:1373
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
sal_uInt16 GetKeyByName(const OUString &rName) const
css::uno::Reference< css::container::XNameContainer > mxBitmapHelper
Definition: xmlimp.hxx:209
ODFSVER_LATEST_EXTENDED
const css::uno::Reference< css::beans::XPropertySet > & getImportInfo() const
Definition: xmlimp.hxx:386
bool IsODFVersionConsistent(const OUString &aODFVersion)
Definition: xmlimp.cxx:1612
static SchXMLImportHelper * CreateChartImport()
Definition: xmlimp.cxx:1074
void SetReference(sal_Int32 nVal)
virtual sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &aDescriptor) override
Definition: xmlimp.cxx:935
constexpr sal_uInt16 XML_NAMESPACE_NUMBER_SO52
constexpr sal_uInt16 XML_NAMESPACE_PRESENTATION_OOO
#define SAL_WARN(area, stream)
Reference< XSingleServiceFactory > xFactory
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
constexpr sal_uInt16 XML_NAMESPACE_DRAW_SO52
constexpr sal_uInt16 XML_NAMESPACE_DRAW_OOO
void registerNamespaces()
Definition: xmlimp.cxx:2063
virtual void DisposingModel()
Definition: xmlimp.cxx:1753
XMLFontStylesContext * GetFontDecls()
Definition: xmlimp.cxx:1570
#define XMLERROR_UNKNOWN_ROOT
Definition: xmlerror.hxx:65
css::uno::Reference< css::document::XEmbeddedObjectResolver > mxEmbeddedResolver
Definition: xmlimp.hxx:194
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
Definition: xmlimp.cxx:902
virtual void SAL_CALL setTokenHandler(const css::uno::Reference< css::xml::sax::XFastTokenHandler > &Handler) override
Definition: xmlimp.cxx:513
bool addEmbeddedFont(const css::uno::Reference< css::io::XInputStream > &stream, const OUString &fontName, const char *extra, std::vector< unsigned char > const &key, bool eot)
Definition: xmlimp.cxx:459
constexpr sal_uInt16 XML_NAMESPACE_META
constexpr sal_uInt16 XML_NAMESPACE_TEXT_SO52
const XMLEventNameTranslation aStandardEventTable[]
a translation table for the events defined in the XEventsSupplier service (implemented in XMLEventExp...
css::uno::Reference< css::document::XGraphicStorageHandler > mxGraphicStorageHandler
Definition: xmlimp.hxx:193
bool isGeneratorVersionOlderThan(sal_uInt16 const nOOoVersion, sal_uInt16 const nLOVersion)
depending on whether the generator version indicates LO, compare against either the given LO or given...
Definition: xmlimp.cxx:1832
COMPHELPER_DLLPUBLIC void notifyMacroEventRead(const css::uno::Reference< css::frame::XModel > &_rxDocument)
const css::uno::Reference< css::container::XNameContainer > & GetGradientHelper()
Definition: xmlimp.cxx:1088
SvXMLStylesContext * GetAutoStyles()
Definition: xmlimp.cxx:1580
constexpr sal_uInt16 XML_NAMESPACE_OOOW
std::unique_ptr< DocumentInfo > mpDocumentInfo
Definition: xmlimp.cxx:306
const OUString & GetPrefixByKey(sal_uInt16 nKey) const
css::uno::Reference< css::util::XNumberFormatsSupplier > & GetNumberFormatsSupplier()
Definition: xmlimp.hxx:643
constexpr sal_uInt16 XML_NAMESPACE_FORM_OOO
constexpr sal_uInt16 XML_NAMESPACE_REPORT_OASIS
static const sal_uInt16 LO_5x
Definition: xmlimp.hxx:554
constexpr sal_uInt16 XML_NAMESPACE_PRESENTATION_OASIS
static std::optional< SvXMLNamespaceMap > processNSAttributes(std::optional< SvXMLNamespaceMap > &rpNamespaceMap, SvXMLImport *const pImport, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
Definition: xmlimp.cxx:674
void addNSDeclAttributes(rtl::Reference< comphelper::AttributeList > const &rAttrList)
Definition: xmlimp.cxx:2086
virtual ~SvXMLImport() noexcept override
Definition: xmlimp.cxx:454
virtual void SAL_CALL characters(const OUString &aChars) override
Definition: xmlimp.cxx:732
constexpr sal_uInt16 XML_NAMESPACE_STYLE
rtl::Reference< sax_fastparser::FastAttributeList > mxFastAttributes
Definition: xmlimp.hxx:156
INetURLObject aBaseURL
Definition: xmlimp.cxx:282
#define SOFFICE_FILEFORMAT_8
sal_uInt16 nPos
virtual void SAL_CALL endDocument() override
Definition: xmlimp.cxx:588
bool any2bool(const css::uno::Any &rAny)
std::optional< OUString > mxODFVersion
Definition: xmlimp.cxx:288
rtl::Reference< XMLShapeImportHelper > const & GetShapeImport()
Definition: xmlimp.hxx:607
virtual void SAL_CALL startUnknownElement(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlimp.cxx:811
virtual void SAL_CALL registerNamespace(const OUString &rNamespacePrefix, const OUString &rNamespaceURI) override
Definition: xmlimp.cxx:2102
constexpr sal_uInt16 XML_NAMESPACE_FIELD
bool embeddedFontAlreadyProcessed(const OUString &url)
Returns true if the embedded font document URL has already been processed.
Definition: xmlimp.cxx:1903
css::uno::Reference< css::xml::sax::XFastParser > mxParser
Definition: xmlimp.hxx:232
virtual void SAL_CALL setEntityResolver(const css::uno::Reference< css::xml::sax::XEntityResolver > &Resolver) override
Definition: xmlimp.cxx:533
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)