20#ifndef INCLUDED_XMLOFF_XMLIMP_HXX
21#define INCLUDED_XMLOFF_XMLIMP_HXX
32#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
33#include <com/sun/star/xml/sax/XFastParser.hpp>
34#include <com/sun/star/lang/XInitialization.hpp>
35#include <com/sun/star/lang/XServiceInfo.hpp>
36#include <com/sun/star/document/XImporter.hpp>
37#include <com/sun/star/document/XFilter.hpp>
45#include <rtl/ustring.hxx>
46#include <unordered_map>
48#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
66 namespace frame {
class XModel; }
67 namespace io {
class XOutputStream; }
68 namespace rdf {
class XMetadatable; }
71namespace comphelper {
class UnoInterfaceToUniqueIdentifierMapper; }
75 class RDFaImportHelper;
78 class FastTokenHandler;
97#define XML_ELEMENT( prefix, name ) ( NAMESPACE_TOKEN(XML_NAMESPACE_##prefix) | name )
107 return nTmp == nNamespacePrefix;
146 virtual void SAL_CALL
registerNamespace(
const OUString& rNamespacePrefix,
const OUString& rNamespaceURI )
override;
147 virtual OUString SAL_CALL
getNamespaceURI(
const OUString& rNamespacePrefix )
override;
151 css::xml::sax::XDocumentHandler,
152 css::document::XImporter >
163 virtual void SAL_CALL setTargetDocument(
const css::uno::Reference< css::lang::XComponent >& xDoc )
override;
166 virtual void SAL_CALL startDocument()
override;
167 virtual void SAL_CALL endDocument()
override;
168 virtual void SAL_CALL startElement(
const OUString& aName,
169 const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs)
override;
170 virtual void SAL_CALL endElement(
const OUString& aName)
override;
171 virtual void SAL_CALL characters(
const OUString& aChars)
override;
172 virtual void SAL_CALL ignorableWhitespace(
const OUString& aWhitespaces)
override;
173 virtual void SAL_CALL processingInstruction(
const OUString& aTarget,
174 const OUString& aData)
override;
175 virtual void SAL_CALL setDocumentLocator(
const css::uno::Reference< css::xml::sax::XLocator > & xLocator)
override;
179 css::xml::sax::XFastDocumentHandler,
180 css::lang::XServiceInfo,
181 css::lang::XInitialization,
182 css::document::XImporter,
183 css::document::XFilter,
184 css::xml::sax::XFastParser>
189 css::uno::Reference< css::xml::sax::XLocator > mxLocator;
190 css::uno::Reference< css::frame::XModel >
mxModel;
191 css::uno::Reference< css::util::XNumberFormatsSupplier > mxNumberFormatsSupplier;
192 css::uno::Reference< css::document::XGraphicStorageHandler > mxGraphicStorageHandler;
193 css::uno::Reference< css::document::XEmbeddedObjectResolver > mxEmbeddedResolver;
194 css::uno::Reference< css::beans::XPropertySet > mxImportInfo;
206 css::uno::Reference< css::container::XNameContainer > mxGradientHelper;
207 css::uno::Reference< css::container::XNameContainer > mxHatchHelper;
208 css::uno::Reference< css::container::XNameContainer > mxBitmapHelper;
209 css::uno::Reference< css::container::XNameContainer > mxTransGradientHelper;
210 css::uno::Reference< css::container::XNameContainer > mxMarkerHelper;
211 css::uno::Reference< css::container::XNameContainer > mxDashHelper;
212 css::uno::Reference< css::container::XNameContainer > mxNumberStyles;
213 css::uno::Reference< css::lang::XEventListener > mxEventListener;
215 std::unique_ptr<SvXMLImport_Impl> mpImpl;
217 std::optional<SvXMLNamespaceMap> mxNamespaceMap;
218 std::unique_ptr<SvXMLUnitConverter> mpUnitConv;
219 std::stack<SvXMLImportContextRef, std::vector<SvXMLImportContextRef>>
221 std::unique_ptr<SvXMLNumFmtHelper> mpNumImport;
222 std::unique_ptr<ProgressBarHelper> mpProgressBarHelper;
223 std::unique_ptr<XMLEventImportHelper> mpEventImportHelper;
224 std::unique_ptr<XMLErrors> mpXMLErrors;
227 SAL_DLLPRIVATE
void InitCtor_();
230 std::set< OUString > m_embeddedFontUrlsKnown;
231 css::uno::Reference< css::xml::sax::XFastParser > mxParser;
234 css::uno::Reference< css::xml::sax::XFastDocumentHandler > mxFastDocumentHandler;
236 static std::unordered_map< sal_Int32, std::pair< OUString, OUString > > aNamespaceMap;
237 static std::unordered_map< OUString, OUString > aNamespaceURIPrefixMap;
238 static bool bIsNSMapsInitialized;
240 static void initializeNamespaceMaps();
241 void registerNamespaces();
243 static std::optional<SvXMLNamespaceMap> processNSAttributes(
244 std::optional<SvXMLNamespaceMap> & rpNamespaceMap,
245 SvXMLImport *
const pImport,
246 const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList);
253 std::unique_ptr<EmbeddedFontsHelper, o3tl::default_delete<EmbeddedFontsHelper>> mxEmbeddedFontHelper;
256 bool mbIsFormsSupported;
257 bool mbIsTableShapeSupported;
258 bool mbNotifyMacroEventRead;
265 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList );
268 void ClearTextImport() { mxTextImport =
nullptr; }
270 bool HasShapeImport()
const {
return mxShapeImport.is(); }
271 void ClearShapeImport() { mxShapeImport =
nullptr; }
281 bool IsODFVersionConsistent(
const OUString& aODFVersion );
283 const css::uno::Reference< css::document::XEmbeddedObjectResolver >& GetEmbeddedResolver()
const {
return mxEmbeddedResolver; }
284 inline void SetEmbeddedResolver( css::uno::Reference< css::document::XEmbeddedObjectResolver >
const & _xEmbeddedResolver );
286 const css::uno::Reference<css::document::XGraphicStorageHandler> & GetGraphicStorageHandler()
const
288 return mxGraphicStorageHandler;
290 void SetGraphicStorageHandler(css::uno::Reference<css::document::XGraphicStorageHandler>
const & rxGraphicStorageHandler);
292 void CreateNumberFormatsSupplier_();
293 void CreateDataStylesImport_();
301 const css::uno::Reference< css::uno::XComponentContext >& xContext,
302 OUString
const & implementationName,
304 const css::uno::Sequence< OUString > & sSupportedServiceNames = {});
308 virtual ~SvXMLImport() noexcept override;
312 virtual
void SAL_CALL
characters(const OUString& aChars) override;
314 const OUString& aData) override;
318 virtual
void SAL_CALL startFastElement(sal_Int32 Element,
319 const css::
uno::Reference< css::xml::
sax::XFastAttributeList > & Attribs) override;
320 virtual
void SAL_CALL startUnknownElement(const OUString & Namespace,
321 const OUString & Name,
322 const css::
uno::Reference< css::xml::
sax::XFastAttributeList > & Attribs) override;
323 virtual
void SAL_CALL endFastElement(sal_Int32 Element) override;
324 virtual
void SAL_CALL endUnknownElement(const OUString & Namespace,
325 const OUString & Name) override;
326 virtual css::
uno::Reference< css::xml::
sax::XFastContextHandler > SAL_CALL
327 createFastChildContext(sal_Int32 Element,
328 const css::
uno::Reference< css::xml::
sax::XFastAttributeList > & Attribs) override;
329 virtual css::
uno::Reference< css::xml::
sax::XFastContextHandler > SAL_CALL
330 createUnknownChildContext(const OUString & Namespace, const OUString & Name,
331 const css::
uno::Reference< css::xml::
sax::XFastAttributeList > & Attribs) override;
334 virtual
void SAL_CALL parseStream( const css::xml::
sax::InputSource& aInputSource ) override;
335 virtual
void SAL_CALL setFastDocumentHandler( const css::
uno::Reference< css::xml::
sax::XFastDocumentHandler >& Handler ) override;
336 virtual
void SAL_CALL setTokenHandler( const css::
uno::Reference< css::xml::
sax::XFastTokenHandler >& Handler ) override;
337 virtual
void SAL_CALL registerNamespace( const OUString& NamespaceURL, sal_Int32 NamespaceToken ) override;
338 virtual OUString SAL_CALL getNamespaceURL( const OUString& rPrefix ) override;
339 virtual
void SAL_CALL setErrorHandler( const css::
uno::Reference< css::xml::
sax::XErrorHandler >& Handler ) override;
340 virtual
void SAL_CALL setEntityResolver( const css::
uno::Reference< css::xml::
sax::XEntityResolver >& Resolver ) override;
341 virtual
void SAL_CALL setLocale( const css::lang::Locale& rLocale ) override;
342 virtual
void SAL_CALL setNamespaceHandler( const css::
uno::Reference< css::xml::
sax::XFastNamespaceHandler >& Handler) override;
343 virtual
void SAL_CALL setCustomEntityNames( const ::css::
uno::Sequence< ::css::beans::
Pair<::
rtl::OUString, ::
rtl::OUString> >& replacements ) override;
346 virtual
void SAL_CALL
setTargetDocument( const css::
uno::Reference< css::lang::XComponent >& xDoc ) override;
349 virtual
sal_Bool SAL_CALL
filter( const css::
uno::Sequence< css::beans::PropertyValue >& aDescriptor ) override;
350 virtual
void SAL_CALL cancel( ) override;
353 virtual
void SAL_CALL initialize( const css::
uno::Sequence< css::
uno::Any >& aArguments ) override;
356 virtual OUString SAL_CALL getImplementationName( ) final override;
358 virtual css::
uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) final override;
364 virtual
void SetStatistics(const css::
uno::Sequence< css::beans::NamedValue > & i_rStats);
368 bool HasTextImport()
const {
return mxTextImport.is(); }
381 const css::uno::Reference< css::beans::XPropertySet >& getImportInfo()
const {
return mxImportInfo; }
386 static const OUString & getNameFromToken( sal_Int32 nToken );
387 static OUString getPrefixAndNameFromToken( sal_Int32 nToken );
388 static OUString getNamespacePrefixFromToken(sal_Int32 nToken,
const SvXMLNamespaceMap* pMap);
389 static OUString getNamespaceURIFromToken( sal_Int32 nToken );
390 static OUString getNamespacePrefixFromURI(
const OUString& rURI );
391 static sal_Int32 getTokenFromName(std::u16string_view sName);
397 const css::uno::Reference< css::xml::sax::XLocator > & GetLocator()
const {
return mxLocator; }
398 const css::uno::Reference< css::frame::XModel > &
399 GetModel()
const {
return mxModel; }
401 const css::uno::Reference< css::container::XNameContainer > & GetGradientHelper();
402 const css::uno::Reference< css::container::XNameContainer > & GetHatchHelper();
403 const css::uno::Reference< css::container::XNameContainer > & GetBitmapHelper();
404 const css::uno::Reference< css::container::XNameContainer > & GetTransGradientHelper();
405 const css::uno::Reference< css::container::XNameContainer > & GetMarkerHelper();
406 const css::uno::Reference< css::container::XNameContainer > & GetDashHelper();
407 inline css::uno::Reference< css::util::XNumberFormatsSupplier > & GetNumberFormatsSupplier();
408 void SetNumberFormatsSupplier(
const css::uno::Reference< css::util::XNumberFormatsSupplier >& _xNumberFormatSupplier)
410 mxNumberFormatsSupplier = _xNumberFormatSupplier;
413 css::uno::Reference<css::graphic::XGraphic> loadGraphicByURL(OUString
const & rURL);
414 css::uno::Reference<css::graphic::XGraphic> loadGraphicFromBase64(css::uno::Reference<css::io::XOutputStream>
const & rxOutputStream);
416 css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64()
const;
418 bool IsPackageURL( std::u16string_view rURL )
const;
419 OUString ResolveEmbeddedObjectURL(
const OUString& rURL,
420 std::u16string_view rClassId );
421 css::uno::Reference< css::io::XOutputStream >
422 GetStreamForEmbeddedObjectURLFromBase64()
const;
423 OUString ResolveEmbeddedObjectURLFromBase64();
426 css::uno::Reference< css::embed::XStorage >
const &
427 GetSourceStorage()
const;
430 const OUString& rName,
431 const OUString& rDisplayName );
433 const OUString& rName )
const;
437 void AddNumberStyle(sal_Int32 nKey,
const OUString& sName);
439 virtual void SetViewSettings(
const css::uno::Sequence<css::beans::PropertyValue>& aViewProps);
440 virtual void SetConfigurationSettings(
const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps);
441 virtual void SetDocumentSpecificSettings(
const OUString& _rSettingsGroupName,
442 const css::uno::Sequence<css::beans::PropertyValue>& _rSettings);
452 bool IsFormsSupported()
const {
return mbIsFormsSupported; }
453 OUString GetAbsoluteReference(
const OUString& rValue)
const;
458 bool IsTableShapeSupported()
const {
return mbIsTableShapeSupported; }
460 OUString GetODFVersion()
const;
461 bool IsOOoXML()
const;
474 const css::uno::Sequence< OUString > & rMsgParams,
476 const OUString& rExceptionMessage,
478 const css::uno::Reference< css::xml::sax::XLocator> & rLocator );
482 const css::uno::Sequence< OUString> & rMsgParams = {});
484 void SetError( sal_Int32 nId,
const OUString& rMsg1 );
486 virtual void DisposingModel();
490 css::uno::Reference< css::uno::XComponentContext >
const &
491 GetComponentContext()
const;
494 bool IsShapePositionInHoriL2R()
const;
496 bool IsTextDocInOOoFileFormat()
const;
498 OUString GetBaseURL()
const;
499 OUString GetDocumentBase()
const;
502 void SetXmlId(css::uno::Reference<
503 css::uno::XInterface>
const & i_xIfc,
504 OUString
const & i_rXmlId);
507 void AddRDFa(
const css::uno::Reference< css::rdf::XMetadatable>& i_xObject,
508 OUString
const & i_rAbout,
509 OUString
const & i_rProperty,
510 OUString
const & i_rContent,
511 OUString
const & i_rDatatype);
514 SAL_DLLPRIVATE ::xmloff::RDFaImportHelper & GetRDFaImportHelper();
518 virtual void initXForms();
526 bool getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild )
const;
528 static constexpr OUStringLiteral aNamespaceSeparator =
u":";
530 static const sal_uInt16 OOo_1x = 10;
531 static const sal_uInt16 OOo_2x = 20;
532 static const sal_uInt16 OOo_30x = 30;
533 static const sal_uInt16 OOo_31x = 31;
534 static const sal_uInt16 OOo_32x = 32;
535 static const sal_uInt16 OOo_33x = 33;
536 static const sal_uInt16 OOo_34x = 34;
538 static const sal_uInt16 AOO_40x = 40;
544 static const sal_uInt16 AOO_4x = 41;
545 static const sal_uInt16 LO_flag = 0x100;
546 static const sal_uInt16 LO_3x = 30 | LO_flag;
547 static const sal_uInt16 LO_41x = 41 | LO_flag;
548 static const sal_uInt16 LO_42x = 42 | LO_flag;
549 static const sal_uInt16 LO_43x = 43 | LO_flag;
550 static const sal_uInt16 LO_44x = 44 | LO_flag;
551 static const sal_uInt16 LO_5x = 50 | LO_flag;
554 static const sal_uInt16 LO_6x = 60 | LO_flag;
555 static const sal_uInt16 LO_63x = 63 | LO_flag;
556 static const sal_uInt16 LO_7x = 70 | LO_flag;
557 static const sal_uInt16 LO_New = 100 | LO_flag;
562 bool isGeneratorVersionOlderThan(
563 sal_uInt16
const nOOoVersion, sal_uInt16
const nLOVersion);
576 sal_uInt16 getGeneratorVersion()
const;
582 bool embeddedFontAlreadyProcessed(
const OUString& url );
585 bool addEmbeddedFont(
const css::uno::Reference< css::io::XInputStream >& stream,
586 const OUString& fontName, std::u16string_view extra,
587 std::vector< unsigned char >
const & key,
bool eot);
589 virtual void NotifyContainsEmbeddedFont() {}
592 void NotifyMacroEventRead();
594 bool needFixPositionAfterZ()
const;
599 if( !mxTextImport.is() )
600 mxTextImport = CreateTextImport();
607 if( !mxShapeImport.is() )
608 mxShapeImport = CreateShapeImport();
610 return mxShapeImport;
615 if( !mxChartImport.is() )
616 mxChartImport = CreateChartImport();
618 return mxChartImport;
623 if( !mxFormImport.is() )
624 mxFormImport = CreateFormImport();
629inline void SvXMLImport::SetEmbeddedResolver(
630 css::uno::Reference< css::document::XEmbeddedObjectResolver >
const & _xEmbeddedResolver )
632 mxEmbeddedResolver = _xEmbeddedResolver;
635inline void SvXMLImport::SetGraphicStorageHandler(
636 css::uno::Reference<css::document::XGraphicStorageHandler>
const & rxGraphicStorageHandler)
638 mxGraphicStorageHandler = rxGraphicStorageHandler;
641inline css::uno::Reference< css::util::XNumberFormatsSupplier > & SvXMLImport::GetNumberFormatsSupplier()
643 if ( ! mxNumberFormatsSupplier.is() &&
mxModel.is() )
644 CreateNumberFormatsSupplier_();
646 return mxNumberFormatsSupplier;
652 CreateDataStylesImport_();
654 return mpNumImport.get();
css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator
css::uno::Reference< css::frame::XModel2 > mxModel
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.
SvXMLImportFastNamespaceHandler()
std::vector< NamespaceDefine > m_aNamespaceDefines
void addNSDeclAttributes(rtl::Reference< comphelper::AttributeList > const &rAttrList)
virtual OUString SAL_CALL getNamespaceURI(const OUString &rNamespacePrefix) override
virtual void SAL_CALL registerNamespace(const OUString &rNamespacePrefix, const OUString &rNamespaceURI) override
rtl::Reference< sax_fastparser::FastAttributeList > mxFastAttributes
virtual void SAL_CALL endDocument() override
virtual void SAL_CALL processingInstruction(const OUString &aTarget, const OUString &aData) override
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
virtual void SAL_CALL startDocument() override
rtl::Reference< SvXMLImport > mrImport
std::stack< sal_uInt16 > maDefaultNamespaces
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override
virtual void SAL_CALL characters(const OUString &aChars) override
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
The XMLErrors is used to collect all errors and warnings that occur for appropriate processing.
Helps the XMLEventsImportContext.
tDoubleVectorPair cleanup(const css::uno::Sequence< double > &rXValues, const css::uno::Sequence< double > &rYValues, Pred aPred)
class SAL_NO_VTABLE XPropertySet
Handling of tokens in XML:
class SAL_DLLPUBLIC_RTTI SAL_LOPLUGIN_ANNOTATE("crosscast") DocumentSettingsSerializer
NamespaceDefine(OUString sPrefix, OUString sNamespaceURI)
constexpr sal_Int32 NAMESPACE_TOKEN(sal_uInt16 prefixToken)
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
constexpr sal_Int32 NMSP_MASK
constexpr sal_Int32 LAST_NAMESPACE
constexpr sal_Int32 TOKEN_MASK
constexpr size_t NMSP_SHIFT