xmloff/source/draw/sdxmlimp.cxx | 47 +++++++++------------- xmloff/source/draw/ximpbody.cxx | 24 ++++++++--- xmloff/source/draw/ximpbody.hxx | 8 +++ xmloff/source/draw/ximpshow.cxx | 85 +++++++++++++++++++++------------------- xmloff/source/draw/ximpshow.hxx | 11 ++--- 5 files changed, 97 insertions(+), 78 deletions(-)
New commits: commit 24b0ef899e10e03743cf01f737f1c07167f391ec Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Jan 21 10:54:17 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Jan 21 11:09:29 2020 +0100 Use FastParser in SdXMLBodyContext Change-Id: I1070ca2351f7bfb2e0c10ba6e876ebcf2cae0ce0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87118 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/xmloff/source/draw/sdxmlimp.cxx b/xmloff/source/draw/sdxmlimp.cxx index dfb4bf267ea8..fcf2a179d0f3 100644 --- a/xmloff/source/draw/sdxmlimp.cxx +++ b/xmloff/source/draw/sdxmlimp.cxx @@ -56,31 +56,27 @@ class SdXMLBodyContext_Impl : public SvXMLImportContext public: - SdXMLBodyContext_Impl( SdXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ); + SdXMLBodyContext_Impl( SdXMLImport& rImport ); - virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) override; + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {} + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; }; } -SdXMLBodyContext_Impl::SdXMLBodyContext_Impl( SdXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & ) : - SvXMLImportContext( rImport, nPrfx, rLName ) +SdXMLBodyContext_Impl::SdXMLBodyContext_Impl( SdXMLImport& rImport ) : + SvXMLImportContext( rImport ) { } -SvXMLImportContextRef SdXMLBodyContext_Impl::CreateChildContext( - sal_uInt16 /*nPrefix*/, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) +css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLBodyContext_Impl::createFastChildContext( + sal_Int32 /*nElement*/, + const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) { - SvXMLImportContext* pContext = new SdXMLBodyContext(GetSdImport(), rLocalName); - return pContext; + return new SdXMLBodyContext(GetSdImport()); } namespace { @@ -164,16 +160,6 @@ SvXMLImportContextRef SdXMLDocContext_Impl::CreateChildContext( SAL_INFO("xmloff.draw", "XML_TOK_DOC_META: should not have come here, maybe document is invalid?"); break; } - case XML_TOK_DOC_BODY: - { - if( GetImport().getImportFlags() & SvXMLImportFlags::CONTENT ) - { - // office:body inside office:document - xContext = new SdXMLBodyContext_Impl(GetSdImport(),nPrefix, - rLocalName, xAttrList); - } - break; - } } return xContext; @@ -202,6 +188,15 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SdXMLDocContext_Impl::c } break; } + case XML_ELEMENT(OFFICE, XML_BODY): + { + if( GetImport().getImportFlags() & SvXMLImportFlags::CONTENT ) + { + // office:body inside office:document + return new SdXMLBodyContext_Impl(GetSdImport()); + } + break; + } } return nullptr; } diff --git a/xmloff/source/draw/ximpbody.cxx b/xmloff/source/draw/ximpbody.cxx index d6ff5ee2033e..f99346709dbe 100644 --- a/xmloff/source/draw/ximpbody.cxx +++ b/xmloff/source/draw/ximpbody.cxx @@ -37,6 +37,7 @@ #include <sal/log.hxx> using namespace ::com::sun::star; +using namespace ::xmloff::token; SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, @@ -277,9 +278,8 @@ void SdXMLDrawPageContext::EndElement() } } -SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport, - const OUString& rLocalName ) -: SvXMLImportContext( rImport, XML_NAMESPACE_OFFICE, rLocalName ) +SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport ) +: SvXMLImportContext( rImport ) { } @@ -287,6 +287,20 @@ SdXMLBodyContext::~SdXMLBodyContext() { } +css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLBodyContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + switch (nElement) + { + case XML_ELEMENT(PRESENTATION, XML_SETTINGS): + { + return new SdXMLShowsContext( GetSdImport(), xAttrList ); + } + } + return nullptr; +} + SvXMLImportContextRef SdXMLBodyContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, @@ -340,10 +354,6 @@ SvXMLImportContextRef SdXMLBodyContext::CreateChildContext( } break; } - case XML_TOK_BODY_SETTINGS: - { - xContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList ); - } } return xContext; diff --git a/xmloff/source/draw/ximpbody.hxx b/xmloff/source/draw/ximpbody.hxx index a23826462a78..9c527d823961 100644 --- a/xmloff/source/draw/ximpbody.hxx +++ b/xmloff/source/draw/ximpbody.hxx @@ -55,9 +55,15 @@ class SdXMLBodyContext : public SvXMLImportContext SdXMLImport& GetSdImport() { return static_cast<SdXMLImport&>(GetImport()); } public: - SdXMLBodyContext( SdXMLImport& rImport, const OUString& rLocalName ); + SdXMLBodyContext( SdXMLImport& rImport ); virtual ~SdXMLBodyContext() override; + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {} + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override; diff --git a/xmloff/source/draw/ximpshow.cxx b/xmloff/source/draw/ximpshow.cxx index 42d3589d17b1..a971bda8b535 100644 --- a/xmloff/source/draw/ximpshow.cxx +++ b/xmloff/source/draw/ximpshow.cxx @@ -58,8 +58,8 @@ public: }; -SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList ) -: SvXMLImportContext(rImport, nPrfx, rLocalName), +SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, const Reference< XFastAttributeList >& xAttrList ) +: SvXMLImportContext(rImport), mpImpl(new ShowsImpImpl ) { @@ -88,28 +88,27 @@ SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, c bIsMouseVisible = false; // read attributes - const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; - for(sal_Int16 i=0; i < nAttrCount; i++) + sax_fastparser::FastAttributeList *pAttribList = + sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList ); + for (auto &aIter : *pAttribList) { - OUString sAttrName = xAttrList->getNameByIndex( i ); - OUString aLocalName; - sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - OUString sValue = xAttrList->getValueByIndex( i ); + OUString sValue = aIter.toString(); - switch( nPrefix ) + switch( aIter.getToken() ) { - case XML_NAMESPACE_PRESENTATION: - if( IsXMLToken( aLocalName, XML_START_PAGE ) ) + case XML_ELEMENT(PRESENTATION, XML_START_PAGE): { mpImpl->mxPresProps->setPropertyValue("FirstPage", Any(sValue) ); bAll = false; + break; } - else if( IsXMLToken( aLocalName, XML_SHOW ) ) + case XML_ELEMENT(PRESENTATION, XML_SHOW): { mpImpl->maCustomShowName = sValue; bAll = false; + break; } - else if( IsXMLToken( aLocalName, XML_PAUSE ) ) + case XML_ELEMENT(PRESENTATION, XML_PAUSE): { Duration aDuration; if (!::sax::Converter::convertDuration(aDuration, sValue)) @@ -118,55 +117,66 @@ SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, c const sal_Int32 nMS = (aDuration.Hours * 60 + aDuration.Minutes) * 60 + aDuration.Seconds; mpImpl->mxPresProps->setPropertyValue("Pause", Any(nMS) ); + break; } - else if( IsXMLToken( aLocalName, XML_ANIMATIONS ) ) + case XML_ELEMENT(PRESENTATION, XML_ANIMATIONS): { aAny <<= IsXMLToken( sValue, XML_ENABLED ); mpImpl->mxPresProps->setPropertyValue("AllowAnimations", aAny ); + break; } - else if( IsXMLToken( aLocalName, XML_STAY_ON_TOP ) ) + case XML_ELEMENT(PRESENTATION, XML_STAY_ON_TOP): { aAny <<= IsXMLToken( sValue, XML_TRUE ); mpImpl->mxPresProps->setPropertyValue("IsAlwaysOnTop", aAny ); + break; } - else if( IsXMLToken( aLocalName, XML_FORCE_MANUAL ) ) + case XML_ELEMENT(PRESENTATION, XML_FORCE_MANUAL): { aAny <<= IsXMLToken( sValue, XML_TRUE ); mpImpl->mxPresProps->setPropertyValue("IsAutomatic", aAny ); + break; } - else if( IsXMLToken( aLocalName, XML_ENDLESS ) ) + case XML_ELEMENT(PRESENTATION, XML_ENDLESS): { aAny <<= IsXMLToken( sValue, XML_TRUE ); mpImpl->mxPresProps->setPropertyValue("IsEndless", aAny ); + break; } - else if( IsXMLToken( aLocalName, XML_FULL_SCREEN ) ) + case XML_ELEMENT(PRESENTATION, XML_FULL_SCREEN): { aAny <<= IsXMLToken( sValue, XML_TRUE ); mpImpl->mxPresProps->setPropertyValue("IsFullScreen", aAny ); + break; } - else if( IsXMLToken( aLocalName, XML_MOUSE_VISIBLE ) ) + case XML_ELEMENT(PRESENTATION, XML_MOUSE_VISIBLE): { bIsMouseVisible = IsXMLToken( sValue, XML_TRUE ); + break; } - else if( IsXMLToken( aLocalName, XML_START_WITH_NAVIGATOR ) ) + case XML_ELEMENT(PRESENTATION, XML_START_WITH_NAVIGATOR): { aAny <<= IsXMLToken( sValue, XML_TRUE ); mpImpl->mxPresProps->setPropertyValue("StartWithNavigator", aAny ); + break; } - else if( IsXMLToken( aLocalName, XML_MOUSE_AS_PEN ) ) + case XML_ELEMENT(PRESENTATION, XML_MOUSE_AS_PEN): { aAny <<= IsXMLToken( sValue, XML_TRUE ); mpImpl->mxPresProps->setPropertyValue("UsePen", aAny ); + break; } - else if( IsXMLToken( aLocalName, XML_TRANSITION_ON_CLICK ) ) + case XML_ELEMENT(PRESENTATION, XML_TRANSITION_ON_CLICK): { aAny <<= IsXMLToken( sValue, XML_ENABLED ); mpImpl->mxPresProps->setPropertyValue("IsTransitionOnClick", aAny ); + break; } - else if( IsXMLToken( aLocalName, XML_SHOW_LOGO ) ) + case XML_ELEMENT(PRESENTATION, XML_SHOW_LOGO): { aAny <<= IsXMLToken( sValue, XML_TRUE ); mpImpl->mxPresProps->setPropertyValue("IsShowLogo", aAny ); + break; } } } @@ -185,33 +195,30 @@ SdXMLShowsContext::~SdXMLShowsContext() } } -SvXMLImportContextRef SdXMLShowsContext::CreateChildContext( sal_uInt16 p_nPrefix, const OUString& rLocalName, const Reference< XAttributeList>& xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLShowsContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - if( mpImpl && p_nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_SHOW ) ) + if( nElement == XML_ELEMENT(PRESENTATION, XML_SHOW) ) { OUString aName; OUString aPages; // read attributes - const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; - for(sal_Int16 i=0; i < nAttrCount; i++) + sax_fastparser::FastAttributeList *pAttribList = + sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList ); + for (auto &aIter : *pAttribList) { - OUString sAttrName = xAttrList->getNameByIndex( i ); - OUString aLocalName; - sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - OUString sValue = xAttrList->getValueByIndex( i ); + OUString sValue = aIter.toString(); - switch( nPrefix ) + switch( aIter.getToken() ) { - case XML_NAMESPACE_PRESENTATION: - if( IsXMLToken( aLocalName, XML_NAME ) ) - { + case XML_ELEMENT(PRESENTATION, XML_NAME): aName = sValue; - } - else if( IsXMLToken( aLocalName, XML_PAGES ) ) - { + break; + case XML_ELEMENT(PRESENTATION, XML_PAGES): aPages = sValue; - } + break; } } diff --git a/xmloff/source/draw/ximpshow.hxx b/xmloff/source/draw/ximpshow.hxx index 3764b5922879..b7c4b3b492d8 100644 --- a/xmloff/source/draw/ximpshow.hxx +++ b/xmloff/source/draw/ximpshow.hxx @@ -35,13 +35,14 @@ class SdXMLShowsContext : public SvXMLImportContext public: SdXMLShowsContext( SdXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList); + const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList); virtual ~SdXMLShowsContext() override; - virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, - 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 >& ) override {} + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; }; #endif // INCLUDED_XMLOFF_SOURCE_DRAW_XIMPSHOW_HXX _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits