diff options
author | Mohammed Abdul Azeem <azeemmysore@gmail.com> | 2017-10-01 14:11:11 +0530 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2018-03-14 14:12:08 +0100 |
commit | bf46b46a1d734348096936284fb8a76e977936d0 (patch) | |
tree | a76c30897cf1e49491bf26580c823701b6d74778 /xmloff | |
parent | 1b61d0417bf46896ef1f1bd1e1a8209588fc157a (diff) |
Moving XSAXDocumentBuilder2 to use XFastDocumentHandler:
This is used in parsing of meta Contexts across different
modules. This also involved moving to XFastParser for
parsing xml filters in sw, sd, starmath.
Change-Id: Ic663aaac6cb20ee8ce5b97cae87c93220f5a2929
Reviewed-on: https://gerrit.libreoffice.org/42989
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/inc/SchXMLImport.hxx | 3 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLImport.cxx | 41 | ||||
-rw-r--r-- | xmloff/source/chart/contexts.cxx | 44 | ||||
-rw-r--r-- | xmloff/source/chart/contexts.hxx | 17 | ||||
-rw-r--r-- | xmloff/source/core/XMLEmbeddedObjectImportContext.cxx | 3 | ||||
-rw-r--r-- | xmloff/source/core/xmlimp.cxx | 37 | ||||
-rw-r--r-- | xmloff/source/draw/sdxmlimp.cxx | 138 | ||||
-rw-r--r-- | xmloff/source/draw/sdxmlimp_impl.hxx | 11 | ||||
-rw-r--r-- | xmloff/source/meta/MetaImportComponent.cxx | 21 | ||||
-rw-r--r-- | xmloff/source/meta/xmlmetai.cxx | 121 |
10 files changed, 262 insertions, 174 deletions
diff --git a/xmloff/inc/SchXMLImport.hxx b/xmloff/inc/SchXMLImport.hxx index 3248d4ceadbd..5b9db7bdac34 100644 --- a/xmloff/inc/SchXMLImport.hxx +++ b/xmloff/inc/SchXMLImport.hxx @@ -159,6 +159,9 @@ protected: const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override; + virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement, + const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override; + public: SchXMLImport( const css::uno::Reference< css::uno::XComponentContext >& xContext, diff --git a/xmloff/source/chart/SchXMLImport.cxx b/xmloff/source/chart/SchXMLImport.cxx index eab97676edff..c1cdfc91d813 100644 --- a/xmloff/source/chart/SchXMLImport.cxx +++ b/xmloff/source/chart/SchXMLImport.cxx @@ -528,16 +528,7 @@ SvXMLImportContext *SchXMLImport::CreateDocumentContext(sal_uInt16 const nPrefix uno::Reference<document::XDocumentPropertiesSupplier> xDPS( GetModel(), uno::UNO_QUERY); // mst@: right now, this seems to be not supported, so it is untested - if (xDPS.is()) { - pContext = (IsXMLToken(rLocalName, XML_DOCUMENT_META)) - ? new SvXMLMetaDocumentContext(*this, - XML_NAMESPACE_OFFICE, rLocalName, - xDPS->getDocumentProperties()) - // flat OpenDocument file format - : new SchXMLFlatDocContext_Impl( - *maImportHelper.get(), *this, nPrefix, rLocalName, - xDPS->getDocumentProperties()); - } else { + if (!xDPS.is()) { pContext = (IsXMLToken(rLocalName, XML_DOCUMENT_META)) ? SvXMLImport::CreateDocumentContext(nPrefix, rLocalName, xAttrList) : new SchXMLDocContext( *maImportHelper.get(), *this, @@ -550,6 +541,36 @@ SvXMLImportContext *SchXMLImport::CreateDocumentContext(sal_uInt16 const nPrefix return pContext; } +SvXMLImportContext *SchXMLImport::CreateFastContext( sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) +{ + SvXMLImportContext* pContext = nullptr; + + switch (nElement) + { + case XML_ELEMENT( OFFICE, XML_DOCUMENT ): + case XML_ELEMENT( OFFICE, XML_DOCUMENT_META ): + { + uno::Reference<document::XDocumentPropertiesSupplier> xDPS( + GetModel(), uno::UNO_QUERY); + // mst@: right now, this seems to be not supported, so it is untested + if (xDPS.is()) { + pContext = (nElement == XML_ELEMENT( OFFICE, XML_DOCUMENT_META )) + ? new SvXMLMetaDocumentContext(*this, + xDPS->getDocumentProperties()) + // flat OpenDocument file format + : new SchXMLFlatDocContext_Impl( + *maImportHelper.get(), *this, nElement, + xDPS->getDocumentProperties()); + } + } + break; + default: + pContext = new SvXMLImportContext( *this ); + } + return pContext; +} + SvXMLImportContext* SchXMLImport::CreateStylesContext( const OUString& rLocalName, const Reference<xml::sax::XAttributeList>& xAttrList ) diff --git a/xmloff/source/chart/contexts.cxx b/xmloff/source/chart/contexts.cxx index 2ddb5030cb6c..ebba9adaed70 100644 --- a/xmloff/source/chart/contexts.cxx +++ b/xmloff/source/chart/contexts.cxx @@ -77,6 +77,18 @@ SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper& rImpHelper, !IsXMLToken( rLName, XML_DOCUMENT_CONTENT) ), "xmloff.chart", "SchXMLDocContext instantiated with no <office:document> element" ); } +SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, + sal_Int32 nElement ) : + SvXMLImportContext( rImport ), + mrImportHelper( rImpHelper ) +{ + SAL_WARN_IF(( nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT ) && + nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_META ) && + nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_STYLES ) && + nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_CONTENT ) ), "xmloff.chart", "SchXMLDocContext instantiated with no <office:document> element" ); +} + SchXMLDocContext::~SchXMLDocContext() {} @@ -122,31 +134,33 @@ SvXMLImportContextRef SchXMLDocContext::CreateChildContext( return xContext; } +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SchXMLDocContext::createFastChildContext( + sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) +{ + return new SvXMLImportContext( GetImport() ); +} + SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl( SchXMLImportHelper& i_rImpHelper, SchXMLImport& i_rImport, - sal_uInt16 i_nPrefix, const OUString & i_rLName, + sal_Int32 i_nElement, const uno::Reference<document::XDocumentProperties>& i_xDocProps) : - SvXMLImportContext(i_rImport, i_nPrefix, i_rLName), - SchXMLDocContext(i_rImpHelper, i_rImport, i_nPrefix, i_rLName), - SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName, - i_xDocProps) + SvXMLImportContext(i_rImport), + SchXMLDocContext(i_rImpHelper, i_rImport, i_nElement), + SvXMLMetaDocumentContext(i_rImport, i_xDocProps) { } -SvXMLImportContextRef SchXMLFlatDocContext_Impl::CreateChildContext( - sal_uInt16 i_nPrefix, const OUString& i_rLocalName, - const uno::Reference<xml::sax::XAttributeList>& i_xAttrList) +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SchXMLFlatDocContext_Impl::createFastChildContext( + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) { // behave like meta base class iff we encounter office:meta - const SvXMLTokenMap& rTokenMap = - mrImportHelper.GetDocElemTokenMap(); - if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) { - return SvXMLMetaDocumentContext::CreateChildContext( - i_nPrefix, i_rLocalName, i_xAttrList ); + if ( nElement == XML_ELEMENT( OFFICE, XML_META ) ) { + return SvXMLMetaDocumentContext::createFastChildContext( + nElement, xAttrList ); } else { - return SchXMLDocContext::CreateChildContext( - i_nPrefix, i_rLocalName, i_xAttrList ); + return SchXMLDocContext::createFastChildContext( + nElement, xAttrList ); } } diff --git a/xmloff/source/chart/contexts.hxx b/xmloff/source/chart/contexts.hxx index 9820cd3b76e4..c2980d800682 100644 --- a/xmloff/source/chart/contexts.hxx +++ b/xmloff/source/chart/contexts.hxx @@ -47,13 +47,21 @@ public: SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName ); - virtual ~SchXMLDocContext() override; + SchXMLDocContext( + SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, + sal_Int32 nElement ); + + virtual ~SchXMLDocContext() override; virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; }; // context for flat file xml format @@ -64,12 +72,11 @@ public: SchXMLFlatDocContext_Impl( SchXMLImportHelper& i_rImpHelper, SchXMLImport& i_rImport, - sal_uInt16 i_nPrefix, const OUString & i_rLName, + sal_Int32 i_nElement, const css::uno::Reference<css::document::XDocumentProperties>& i_xDocProps); - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 i_nPrefix, const OUString& i_rLocalName, - const css::uno::Reference<css::xml::sax::XAttributeList>& i_xAttrList) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; }; class SchXMLBodyContext : public SvXMLImportContext diff --git a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx index a90ec6b643bc..bfa90235b40b 100644 --- a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx +++ b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx @@ -116,6 +116,9 @@ void XMLEmbeddedObjectImportContext::SetComponent( Reference< XComponent > const if( !xHandler.is() ) return; + if (SvXMLImport *pFastHandler = dynamic_cast<SvXMLImport*>(xHandler.get())) + xHandler.set( new SvXMLLegacyToFastDocHandler( pFastHandler ) ); + try { Reference < XModifiable2 > xModifiable2( rComp, UNO_QUERY_THROW ); diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index b92d5edc64c1..ba656fe41131 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -80,6 +80,7 @@ using namespace ::xmloff::token; css::uno::Reference< css::xml::sax::XFastTokenHandler > SvXMLImport::xTokenHandler( new FastTokenHandler() ); std::unordered_map< sal_Int32, std::pair< OUString, OUString > > SvXMLImport::aNamespaceMap; +std::unordered_map< OUString, OUString, OUStringHash > SvXMLImport::aNamespaceURIPrefixMap; const OUString SvXMLImport::aDefaultNamespace = OUString(""); const OUString SvXMLImport::aNamespaceSeparator = OUString(":"); bool SvXMLImport::bIsNSMapsInitialized = false; @@ -1125,6 +1126,11 @@ void SAL_CALL SvXMLImport::initialize( const uno::Sequence< uno::Any >& aArgumen } } } + + uno::Reference<lang::XInitialization> const xInit(mxParser, uno::UNO_QUERY_THROW); + uno::Sequence<uno::Any> args(1); + args[0] <<= OUString("IgnoreMissingNSDecl"); + xInit->initialize( args ); } // XServiceInfo @@ -2062,14 +2068,35 @@ const OUString SvXMLImport::getNamespacePrefixFromToken( sal_Int32 nToken ) return OUString(); } +const OUString SvXMLImport::getNamespaceURIFromToken( sal_Int32 nToken ) +{ + sal_Int32 nNamespaceToken = ( nToken & NMSP_MASK ) >> NMSP_SHIFT; + auto aIter( aNamespaceMap.find( nNamespaceToken ) ); + if( aIter != aNamespaceMap.end() ) + return (*aIter).second.second; + else + return OUString(); +} + +const OUString SvXMLImport::getNamespacePrefixFromURI( const OUString& rURI ) +{ + auto aIter( aNamespaceURIPrefixMap.find(rURI) ); + if( aIter != aNamespaceURIPrefixMap.end() ) + return (*aIter).second; + else + return OUString(); +} + void SvXMLImport::initializeNamespaceMaps() { auto mapTokenToNamespace = [&]( sal_Int32 nToken, sal_Int32 nPrefix, sal_Int32 nNamespace ) { if ( nToken >= 0 ) { - aNamespaceMap[ nToken + 1 ] = std::make_pair( GetXMLToken( static_cast<XMLTokenEnum>( nPrefix ) ), - GetXMLToken( static_cast<XMLTokenEnum>( nNamespace ) ) ); + const OUString& sNamespace = GetXMLToken( static_cast<XMLTokenEnum>( nNamespace ) ); + const OUString& sPrefix = GetXMLToken( static_cast<XMLTokenEnum>( nPrefix ) ); + aNamespaceMap[ nToken + 1 ] = std::make_pair( sPrefix, sNamespace ); + aNamespaceURIPrefixMap.emplace( sNamespace, sPrefix ); } }; @@ -2180,6 +2207,12 @@ void SvXMLImportFastNamespaceHandler::addNSDeclAttributes( rtl::Reference < comp void SvXMLImportFastNamespaceHandler::registerNamespace( const OUString& rNamespacePrefix, const OUString& rNamespaceURI ) { + // Elements with default namespace parsed by FastParser have namepsace prefix. + // A default namespace needs to be registered with the prefix, to maintan the compatibility. + if ( rNamespacePrefix.isEmpty() ) + m_aNamespaceDefines.push_back( o3tl::make_unique<NamespaceDefine>( + SvXMLImport::getNamespacePrefixFromURI( rNamespaceURI ), rNamespaceURI) ); + m_aNamespaceDefines.push_back( o3tl::make_unique<NamespaceDefine>( rNamespacePrefix, rNamespaceURI) ); } diff --git a/xmloff/source/draw/sdxmlimp.cxx b/xmloff/source/draw/sdxmlimp.cxx index 3d5e91ea814e..2430ff381a13 100644 --- a/xmloff/source/draw/sdxmlimp.cxx +++ b/xmloff/source/draw/sdxmlimp.cxx @@ -90,23 +90,26 @@ protected: SdXMLImport& GetSdImport() { return static_cast<SdXMLImport&>(GetImport()); } public: - SdXMLDocContext_Impl( - SdXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference<xml::sax::XAttributeList>& xAttrList); + SdXMLDocContext_Impl( SdXMLImport& rImport ); virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual void SAL_CALL characters( const OUString& /*aChars*/ ) override {} + + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override {} + + virtual void SAL_CALL endFastElement( sal_Int32 /*nElement*/ ) override {} }; SdXMLDocContext_Impl::SdXMLDocContext_Impl( - SdXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference<xml::sax::XAttributeList>&) -: SvXMLImportContext(rImport, nPrfx, rLName) + SdXMLImport& rImport ) +: SvXMLImportContext(rImport) { } @@ -193,44 +196,65 @@ SvXMLImportContextRef SdXMLDocContext_Impl::CreateChildContext( return xContext; } +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SdXMLDocContext_Impl::createFastChildContext( + sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) +{ + return new SvXMLImportContext( GetImport() ); +} + // context for flat file xml format class SdXMLFlatDocContext_Impl : public SdXMLDocContext_Impl, public SvXMLMetaDocumentContext { public: SdXMLFlatDocContext_Impl( SdXMLImport& i_rImport, - sal_uInt16 i_nPrefix, const OUString & i_rLName, - const uno::Reference<xml::sax::XAttributeList>& i_xAttrList, - const uno::Reference<document::XDocumentProperties>& i_xDocProps); + const uno::Reference<document::XDocumentProperties>& i_xDocProps ); - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 i_nPrefix, const OUString& i_rLocalName, - const uno::Reference<xml::sax::XAttributeList>& i_xAttrList) override; + virtual void SAL_CALL startFastElement( sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override; + + virtual void SAL_CALL characters( const OUString& aChars ) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; }; SdXMLFlatDocContext_Impl::SdXMLFlatDocContext_Impl( SdXMLImport& i_rImport, - sal_uInt16 i_nPrefix, const OUString & i_rLName, - const uno::Reference<xml::sax::XAttributeList>& i_xAttrList, const uno::Reference<document::XDocumentProperties>& i_xDocProps) : - SvXMLImportContext(i_rImport, i_nPrefix, i_rLName), - SdXMLDocContext_Impl(i_rImport, i_nPrefix, i_rLName, i_xAttrList), - SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName, - i_xDocProps) + SvXMLImportContext(i_rImport), + SdXMLDocContext_Impl(i_rImport), + SvXMLMetaDocumentContext(i_rImport, i_xDocProps) +{ +} + +void SAL_CALL SdXMLFlatDocContext_Impl::startFastElement( sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLMetaDocumentContext::startFastElement(nElement, xAttrList); +} + +void SAL_CALL SdXMLFlatDocContext_Impl::endFastElement( sal_Int32 nElement ) +{ + SvXMLMetaDocumentContext::endFastElement(nElement); +} + +void SAL_CALL SdXMLFlatDocContext_Impl::characters( const OUString& rChars ) { + SvXMLMetaDocumentContext::characters(rChars); } -SvXMLImportContextRef SdXMLFlatDocContext_Impl::CreateChildContext( - sal_uInt16 i_nPrefix, const OUString& i_rLocalName, - const uno::Reference<xml::sax::XAttributeList>& i_xAttrList) +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SdXMLFlatDocContext_Impl::createFastChildContext( + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) { // behave like meta base class iff we encounter office:meta - const SvXMLTokenMap& rTokenMap = GetSdImport().GetDocElemTokenMap(); - if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) { - return SvXMLMetaDocumentContext::CreateChildContext( - i_nPrefix, i_rLocalName, i_xAttrList ); + if ( nElement == XML_ELEMENT( OFFICE, XML_META ) ) { + return SvXMLMetaDocumentContext::createFastChildContext( + nElement, xAttrList ); } else { - return SdXMLDocContext_Impl::CreateChildContext( - i_nPrefix, i_rLocalName, i_xAttrList ); + return SdXMLDocContext_Impl::createFastChildContext( + nElement, xAttrList ); } } @@ -584,37 +608,37 @@ const SvXMLTokenMap& SdXMLImport::GetPresentationPlaceholderAttrTokenMap() return *mpPresentationPlaceholderAttrTokenMap; } -SvXMLImportContext *SdXMLImport::CreateDocumentContext(sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference<xml::sax::XAttributeList>& xAttrList) +SvXMLImportContext *SdXMLImport::CreateFastContext( sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) { SvXMLImportContext* pContext = nullptr; - if(XML_NAMESPACE_OFFICE == nPrefix && - ( IsXMLToken( rLocalName, XML_DOCUMENT_STYLES ) || - IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) || - IsXMLToken( rLocalName, XML_DOCUMENT_SETTINGS ) )) + switch (nElement) { - pContext = new SdXMLDocContext_Impl(*this, nPrefix, rLocalName, xAttrList); - } else if ( (XML_NAMESPACE_OFFICE == nPrefix) && - ( IsXMLToken(rLocalName, XML_DOCUMENT_META)) ) { - pContext = CreateMetaContext(rLocalName, xAttrList); - } else if ( (XML_NAMESPACE_OFFICE == nPrefix) && - ( IsXMLToken(rLocalName, XML_DOCUMENT)) ) { - uno::Reference<document::XDocumentPropertiesSupplier> xDPS( - GetModel(), uno::UNO_QUERY_THROW); - // flat OpenDocument file format - pContext = new SdXMLFlatDocContext_Impl( *this, nPrefix, rLocalName, - xAttrList, xDPS->getDocumentProperties()); - } else { - pContext = SvXMLImport::CreateDocumentContext(nPrefix, rLocalName, xAttrList); + case XML_ELEMENT( OFFICE, XML_DOCUMENT_STYLES ): + case XML_ELEMENT( OFFICE, XML_DOCUMENT_CONTENT ): + case XML_ELEMENT( OFFICE, XML_DOCUMENT_SETTINGS ): + pContext = new SdXMLDocContext_Impl(*this); + break; + case XML_ELEMENT( OFFICE, XML_DOCUMENT_META ): + pContext = CreateMetaContext(nElement, xAttrList); + break; + case XML_ELEMENT( OFFICE, XML_DOCUMENT ): + { + uno::Reference<document::XDocumentPropertiesSupplier> xDPS( + GetModel(), uno::UNO_QUERY_THROW); + // flat OpenDocument file format + pContext = new SdXMLFlatDocContext_Impl( *this, xDPS->getDocumentProperties()); + } + break; + default: + pContext = SvXMLImport::CreateFastContext(nElement, xAttrList); } - return pContext; } -SvXMLImportContext *SdXMLImport::CreateMetaContext(const OUString& rLocalName, - const uno::Reference<xml::sax::XAttributeList>&) +SvXMLImportContext *SdXMLImport::CreateMetaContext(const sal_Int32 /*nElement*/, + const uno::Reference<xml::sax::XFastAttributeList>&) { SvXMLImportContext* pContext = nullptr; @@ -624,14 +648,12 @@ SvXMLImportContext *SdXMLImport::CreateMetaContext(const OUString& rLocalName, GetModel(), uno::UNO_QUERY_THROW); uno::Reference<document::XDocumentProperties> const xDocProps( !mbLoadDoc ? nullptr : xDPS->getDocumentProperties()); - pContext = new SvXMLMetaDocumentContext(*this, - XML_NAMESPACE_OFFICE, rLocalName, - xDocProps); + pContext = new SvXMLMetaDocumentContext(*this, xDocProps); } if(!pContext) { - pContext = new SvXMLImportContext(*this, XML_NAMESPACE_OFFICE, rLocalName); + pContext = new SvXMLImportContext(*this); } return pContext; diff --git a/xmloff/source/draw/sdxmlimp_impl.hxx b/xmloff/source/draw/sdxmlimp_impl.hxx index 3900aa02aaf4..7b029895c766 100644 --- a/xmloff/source/draw/sdxmlimp_impl.hxx +++ b/xmloff/source/draw/sdxmlimp_impl.hxx @@ -176,9 +176,10 @@ class SdXMLImport: public SvXMLImport protected: - virtual SvXMLImportContext *CreateDocumentContext(sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList) override; + // This method is called after the namespace map has been updated, but + // before a context for the current element has been pushed. + virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement, + const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override; public: SdXMLImport( @@ -198,8 +199,8 @@ public: // namespace office // NB: in contrast to other CreateFooContexts, this particular one handles // the root element (i.e. office:document-meta) - SvXMLImportContext* CreateMetaContext(const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList); + SvXMLImportContext* CreateMetaContext(const sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList); SvXMLImportContext* CreateScriptContext( const OUString& rLocalName ); SvXMLImportContext* CreateBodyContext(const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList); diff --git a/xmloff/source/meta/MetaImportComponent.cxx b/xmloff/source/meta/MetaImportComponent.cxx index d10d9c8f9bd0..6f5d7c0d1a5f 100644 --- a/xmloff/source/meta/MetaImportComponent.cxx +++ b/xmloff/source/meta/MetaImportComponent.cxx @@ -43,10 +43,8 @@ public: protected: - virtual SvXMLImportContext* CreateDocumentContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement, + const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override; // XImporter virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override; @@ -68,25 +66,22 @@ XMLMetaImportComponent::XMLMetaImportComponent( { } -SvXMLImportContext* XMLMetaImportComponent::CreateDocumentContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference<xml::sax::XAttributeList > & xAttrList ) +SvXMLImportContext *XMLMetaImportComponent::CreateFastContext( sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) { - if ( (XML_NAMESPACE_OFFICE == nPrefix) && - IsXMLToken(rLocalName, XML_DOCUMENT_META) ) + if (nElement == XML_ELEMENT( OFFICE, XML_DOCUMENT_META )) { if (!mxDocProps.is()) { throw uno::RuntimeException( - "XMLMetaImportComponent::CreateContext: setTargetDocument " + "XMLMetaImportComponent::CreateFastContext: setTargetDocument " "has not been called", *this); } return new SvXMLMetaDocumentContext( - *this, nPrefix, rLocalName, mxDocProps); + *this, mxDocProps); } else { - return SvXMLImport::CreateDocumentContext(nPrefix, rLocalName, xAttrList); + return SvXMLImport::CreateFastContext(nElement, xAttrList); } } diff --git a/xmloff/source/meta/xmlmetai.cxx b/xmloff/source/meta/xmlmetai.cxx index 1f9a1b9604e2..10f60b7717dd 100644 --- a/xmloff/source/meta/xmlmetai.cxx +++ b/xmloff/source/meta/xmlmetai.cxx @@ -41,57 +41,66 @@ private: css::uno::Reference< css::xml::dom::XSAXDocumentBuilder2> mxDocBuilder; public: - XMLDocumentBuilderContext(SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, + XMLDocumentBuilderContext(SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList, const css::uno::Reference< css::xml::dom::XSAXDocumentBuilder2>& rDocBuilder); - virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override; + virtual void SAL_CALL characters( const OUString& aChars ) override; - virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override; + virtual void SAL_CALL startFastElement( sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; - virtual void Characters( const OUString& rChars ) override; + virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override; + + virtual void SAL_CALL startUnknownElement( const OUString& Namespace, const OUString& Name, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs ) override; + + virtual void SAL_CALL endUnknownElement( const OUString& Namespace, const OUString& Name ) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; - virtual void EndElement() override; }; XMLDocumentBuilderContext::XMLDocumentBuilderContext(SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const uno::Reference<xml::sax::XAttributeList>&, + sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>&, const uno::Reference<xml::dom::XSAXDocumentBuilder2>& rDocBuilder) : - SvXMLImportContext( rImport, nPrfx, rLName ), + SvXMLImportContext( rImport ), mxDocBuilder(rDocBuilder) { } -SvXMLImportContextRef -XMLDocumentBuilderContext::CreateChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList>& rAttrs) +void SAL_CALL XMLDocumentBuilderContext::startFastElement( sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& xAttribs ) +{ + mxDocBuilder->startFastElement(nElement, xAttribs); +} + +void SAL_CALL XMLDocumentBuilderContext::endFastElement( sal_Int32 nElement ) +{ + mxDocBuilder->endFastElement(nElement); +} + +void SAL_CALL XMLDocumentBuilderContext::startUnknownElement( const OUString& rNamespace, + const OUString& rName, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) { - return new XMLDocumentBuilderContext( - GetImport(), nPrefix, rLocalName, rAttrs, mxDocBuilder); + mxDocBuilder->startUnknownElement(rNamespace, rName, xAttrList); } -void XMLDocumentBuilderContext::StartElement( - const uno::Reference< xml::sax::XAttributeList >& xAttrList ) +void SAL_CALL XMLDocumentBuilderContext::endUnknownElement( const OUString& rNamespace, const OUString& rName ) { - mxDocBuilder->startElement( - GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(), GetLocalName()), - xAttrList); + mxDocBuilder->endUnknownElement(rNamespace, rName); } -void XMLDocumentBuilderContext::Characters( const OUString& rChars ) +void SAL_CALL XMLDocumentBuilderContext::characters( const OUString& rChars ) { mxDocBuilder->characters(rChars); } -void XMLDocumentBuilderContext::EndElement() +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL XMLDocumentBuilderContext::createFastChildContext( + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) { - mxDocBuilder->endElement( - GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(), GetLocalName())); + return new XMLDocumentBuilderContext( GetImport(), nElement, xAttrList, mxDocBuilder ); } static void @@ -150,19 +159,6 @@ lcl_initGenerator(SvXMLImport & rImport, } SvXMLMetaDocumentContext::SvXMLMetaDocumentContext(SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const uno::Reference<document::XDocumentProperties>& xDocProps) : - SvXMLImportContext( rImport, nPrfx, rLName ), - mxDocProps(xDocProps), - mxDocBuilder( - xml::dom::SAXDocumentBuilder::create( - comphelper::getProcessComponentContext())) -{ -// #i103539#: must always read meta.xml for generator, xDocProps unwanted then -// OSL_ENSURE(xDocProps.is(), "SvXMLMetaDocumentContext: no document props"); -} - -SvXMLMetaDocumentContext::SvXMLMetaDocumentContext(SvXMLImport& rImport, const uno::Reference<document::XDocumentProperties>& xDocProps) : SvXMLImportContext( rImport ), mxDocProps(xDocProps), @@ -178,39 +174,18 @@ SvXMLMetaDocumentContext::~SvXMLMetaDocumentContext() { } -SvXMLImportContextRef SvXMLMetaDocumentContext::CreateChildContext( - sal_uInt16 nPrefix, const OUString& rLocalName, - const uno::Reference<xml::sax::XAttributeList>& rAttrs) -{ - if ( (XML_NAMESPACE_OFFICE == nPrefix) && - IsXMLToken(rLocalName, XML_META) ) - { - return new XMLDocumentBuilderContext( - GetImport(), nPrefix, rLocalName, rAttrs, mxDocBuilder); - } - else - { - return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); - } -} - -void SvXMLMetaDocumentContext::StartElement( - const uno::Reference< xml::sax::XAttributeList >& xAttrList ) +void SAL_CALL SvXMLMetaDocumentContext::startFastElement( sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) { mxDocBuilder->startDocument(); // hardcode office:document-meta (necessary in case of flat file ODF) - mxDocBuilder->startElement( - GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(), - GetXMLToken(XML_DOCUMENT_META)), xAttrList); - + mxDocBuilder->startFastElement( ( nElement & NMSP_MASK ) | XML_DOCUMENT_META, xAttrList ); } -void SvXMLMetaDocumentContext::EndElement() +void SAL_CALL SvXMLMetaDocumentContext::endFastElement( sal_Int32 nElement ) { // hardcode office:document-meta (necessary in case of flat file ODF) - mxDocBuilder->endElement( - GetImport().GetNamespaceMap().GetQNameByKey(GetPrefix(), - GetXMLToken(XML_DOCUMENT_META))); + mxDocBuilder->endFastElement( ( nElement & NMSP_MASK ) | XML_DOCUMENT_META ); mxDocBuilder->endDocument(); if (mxDocProps.is()) { @@ -222,6 +197,20 @@ void SvXMLMetaDocumentContext::EndElement() } } +void SAL_CALL SvXMLMetaDocumentContext::characters( const OUString& /*rChars*/ ) +{ +} + +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLMetaDocumentContext::createFastChildContext( + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) +{ + if ( nElement == ( NAMESPACE_TOKEN( XML_NAMESPACE_OFFICE ) | XML_META ) ) + return new XMLDocumentBuilderContext( + GetImport(), nElement, xAttrList, mxDocBuilder); + else + return new SvXMLImportContext( GetImport() ); +} + void SvXMLMetaDocumentContext::setBuildId(OUString const& i_rBuildId, const uno::Reference<beans::XPropertySet>& xImportInfo ) { OUString sBuildId; |