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