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