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