From 2863865da44da2e0baa48a9e8d3fc87641fbd6fb Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 9 Mar 2020 10:09:48 +0200 Subject: convert SdXMLGenericPageContext to fastparser Change-Id: I225fcd104252a32715259b85614298d8a2ffd110 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90202 Tested-by: Jenkins Reviewed-by: Noel Grandin --- xmloff/source/core/xmlimp.cxx | 7 ++- xmloff/source/draw/ximpnote.cxx | 66 ------------------------ xmloff/source/draw/ximpnote.hxx | 4 -- xmloff/source/draw/ximppage.cxx | 109 ++++----------------------------------- xmloff/source/draw/ximppage.hxx | 9 ++-- xmloff/source/draw/ximpstyl.cxx | 111 +++++++++++++++++++++------------------- xmloff/source/draw/ximpstyl.hxx | 10 ++-- 7 files changed, 83 insertions(+), 233 deletions(-) diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 0c3000175878..628054dc1fcd 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -2020,7 +2020,12 @@ const OUString & SvXMLImport::getNameFromToken( sal_Int32 nToken ) OUString SvXMLImport::getPrefixAndNameFromToken( sal_Int32 nToken ) { - return getNamespacePrefixFromToken(nToken, nullptr) + ":" + xTokenHandler->getIdentifier( nToken & TOKEN_MASK ); + OUString rv; + sal_Int32 nNamespaceToken = ( nToken & NMSP_MASK ) >> NMSP_SHIFT; + auto aIter( aNamespaceMap.find( nNamespaceToken ) ); + if( aIter != aNamespaceMap.end() ) + rv = (*aIter).second.second + " " + aIter->second.first + ":"; + return rv + xTokenHandler->getIdentifier( nToken & TOKEN_MASK ); } OUString SvXMLImport::getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap* pMap) diff --git a/xmloff/source/draw/ximpnote.cxx b/xmloff/source/draw/ximpnote.cxx index 90d9fe90dd39..8c2aba66fdd5 100644 --- a/xmloff/source/draw/ximpnote.cxx +++ b/xmloff/source/draw/ximpnote.cxx @@ -23,72 +23,6 @@ using namespace ::com::sun::star; using namespace ::xmloff::token; -SdXMLNotesContext::SdXMLNotesContext( SdXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, - uno::Reference< drawing::XShapes > const & rShapes) -: SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes ) -{ - OUString sStyleName, sPageMasterName; - - const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; - for(sal_Int16 i=0; i < nAttrCount; i++) - { - OUString sAttrName = xAttrList->getNameByIndex( i ); - OUString aLocalName; - sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - OUString sValue = xAttrList->getValueByIndex( i ); - const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetMasterPageAttrTokenMap(); - - switch(rAttrTokenMap.Get(nPrefix, aLocalName)) - { - case XML_TOK_MASTERPAGE_PAGE_MASTER_NAME: - { - sPageMasterName = sValue; - break; - } - case XML_TOK_MASTERPAGE_STYLE_NAME: - { - sStyleName = sValue; - break; - } - case XML_TOK_MASTERPAGE_USE_HEADER_NAME: - { - maUseHeaderDeclName = sValue; - break; - } - case XML_TOK_MASTERPAGE_USE_FOOTER_NAME: - { - maUseFooterDeclName = sValue; - break; - } - case XML_TOK_MASTERPAGE_USE_DATE_TIME_NAME: - { - maUseDateTimeDeclName = sValue; - break; - } - - } - } - - SetStyle( sStyleName ); - - // now delete all up-to-now contained shapes from this notes page - uno::Reference< drawing::XShape > xShape; - while(rShapes->getCount()) - { - rShapes->getByIndex(0) >>= xShape; - if(xShape.is()) - rShapes->remove(xShape); - } - - // set page-master? - if(!sPageMasterName.isEmpty()) - { - SetPageMaster( sPageMasterName ); - } -} - SdXMLNotesContext::SdXMLNotesContext( SdXMLImport& rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList, uno::Reference< drawing::XShapes > const & rShapes) diff --git a/xmloff/source/draw/ximpnote.hxx b/xmloff/source/draw/ximpnote.hxx index 3a1e91857b67..c86a39954aba 100644 --- a/xmloff/source/draw/ximpnote.hxx +++ b/xmloff/source/draw/ximpnote.hxx @@ -28,10 +28,6 @@ class SdXMLNotesContext : public SdXMLGenericPageContext { public: - SdXMLNotesContext( SdXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, - css::uno::Reference< css::drawing::XShapes > const & rShapes); SdXMLNotesContext( SdXMLImport& rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList, css::uno::Reference< css::drawing::XShapes > const & rShapes); diff --git a/xmloff/source/draw/ximppage.cxx b/xmloff/source/draw/ximppage.cxx index ad54a1085b1e..e3cd009a4139 100644 --- a/xmloff/source/draw/ximppage.cxx +++ b/xmloff/source/draw/ximppage.cxx @@ -207,30 +207,6 @@ void DrawAnnotationContext::EndElement() } -SdXMLGenericPageContext::SdXMLGenericPageContext( - SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLocalName, - const Reference< xml::sax::XAttributeList>& xAttrList, - Reference< drawing::XShapes > const & rShapes) -: SvXMLImportContext( rImport, nPrfx, rLocalName ) -, mxShapes( rShapes ) -, mxAnnotationAccess( rShapes, UNO_QUERY ) -{ - sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; - - for(sal_Int16 i=0; i < nAttrCount; i++) - { - OUString sAttrName = xAttrList->getNameByIndex( i ); - OUString aLocalName; - sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - if( (nPrefix == XML_NAMESPACE_DRAW) && IsXMLToken( aLocalName, XML_NAV_ORDER ) ) - { - msNavOrder = xAttrList->getValueByIndex( i ); - break; - } - } -} - SdXMLGenericPageContext::SdXMLGenericPageContext( SvXMLImport& rImport, const Reference< xml::sax::XFastAttributeList>& xAttrList, @@ -257,10 +233,7 @@ SdXMLGenericPageContext::~SdXMLGenericPageContext() void SdXMLGenericPageContext::StartElement( const Reference< css::xml::sax::XAttributeList >& ) { - GetImport().GetShapeImport()->pushGroupForPostProcessing( mxShapes ); - - if( GetImport().IsFormsSupported() ) - GetImport().GetFormImport()->startPage( Reference< drawing::XDrawPage >::query( mxShapes ) ); + assert(false); } void SdXMLGenericPageContext::startFastElement( sal_Int32 /*nElement*/, const Reference< css::xml::sax::XFastAttributeList >& ) @@ -271,6 +244,13 @@ void SdXMLGenericPageContext::startFastElement( sal_Int32 /*nElement*/, const Re GetImport().GetFormImport()->startPage( Reference< drawing::XDrawPage >::query( mxShapes ) ); } +css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLGenericPageContext::createFastChildContext( + sal_Int32 /*nElement*/, + const Reference< xml::sax::XFastAttributeList>& /*xAttrList*/ ) +{ + return nullptr; +} + SvXMLImportContextRef SdXMLGenericPageContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< xml::sax::XAttributeList>& xAttrList ) @@ -303,78 +283,7 @@ SvXMLImportContextRef SdXMLGenericPageContext::CreateChildContext( sal_uInt16 nP void SdXMLGenericPageContext::EndElement() { - GetImport().GetShapeImport()->popGroupAndPostProcess(); - - if( GetImport().IsFormsSupported() ) - GetImport().GetFormImport()->endPage(); - - if( !maUseHeaderDeclName.isEmpty() || !maUseFooterDeclName.isEmpty() || !maUseDateTimeDeclName.isEmpty() ) - { - try - { - Reference xSet(mxShapes, uno::UNO_QUERY_THROW ); - Reference< beans::XPropertySetInfo > xInfo( xSet->getPropertySetInfo() ); - - if( !maUseHeaderDeclName.isEmpty() ) - { - const OUString aStrHeaderTextProp( "HeaderText" ); - if( xInfo->hasPropertyByName( aStrHeaderTextProp ) ) - xSet->setPropertyValue( aStrHeaderTextProp, - makeAny( GetSdImport().GetHeaderDecl( maUseHeaderDeclName ) ) ); - } - - if( !maUseFooterDeclName.isEmpty() ) - { - const OUString aStrFooterTextProp( "FooterText" ); - if( xInfo->hasPropertyByName( aStrFooterTextProp ) ) - xSet->setPropertyValue( aStrFooterTextProp, - makeAny( GetSdImport().GetFooterDecl( maUseFooterDeclName ) ) ); - } - - if( !maUseDateTimeDeclName.isEmpty() ) - { - const OUString aStrDateTimeTextProp( "DateTimeText" ); - if( xInfo->hasPropertyByName( aStrDateTimeTextProp ) ) - { - bool bFixed; - OUString aDateTimeFormat; - const OUString aText( GetSdImport().GetDateTimeDecl( maUseDateTimeDeclName, bFixed, aDateTimeFormat ) ); - - xSet->setPropertyValue("IsDateTimeFixed", - makeAny( bFixed ) ); - - if( bFixed ) - { - xSet->setPropertyValue( aStrDateTimeTextProp, makeAny( aText ) ); - } - else if( !aDateTimeFormat.isEmpty() ) - { - const SdXMLStylesContext* pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetStylesContext() ); - if( !pStyles ) - pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetAutoStylesContext() ); - - if( pStyles ) - { - const SdXMLNumberFormatImportContext* pSdNumStyle = - dynamic_cast< const SdXMLNumberFormatImportContext* >( pStyles->FindStyleChildContext( XmlStyleFamily::DATA_STYLE, aDateTimeFormat, true ) ); - - if( pSdNumStyle ) - { - xSet->setPropertyValue("DateTimeFormat", - makeAny( pSdNumStyle->GetDrawKey() ) ); - } - } - } - } - } - } - catch(const uno::Exception&) - { - OSL_FAIL("xmloff::SdXMLGenericPageContext::EndElement(), unexpected exception caught!"); - } - } - - SetNavigationOrder(); + assert(false); } void SdXMLGenericPageContext::endFastElement(sal_Int32 ) diff --git a/xmloff/source/draw/ximppage.hxx b/xmloff/source/draw/ximppage.hxx index 5e9079363200..ba2eef58b8f4 100644 --- a/xmloff/source/draw/ximppage.hxx +++ b/xmloff/source/draw/ximppage.hxx @@ -59,20 +59,19 @@ protected: public: - SdXMLGenericPageContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, - css::uno::Reference< css::drawing::XShapes > const & rShapes); SdXMLGenericPageContext( SvXMLImport& rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList, css::uno::Reference< css::drawing::XShapes > const & rShapes); virtual ~SdXMLGenericPageContext() override; - virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override; + virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) final override; virtual void SAL_CALL startFastElement( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override; - virtual void EndElement() 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 void EndElement() final override; virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; const css::uno::Reference< css::drawing::XShapes >& GetLocalShapesContext() const diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx index 136713271f8d..b093c5e3d90b 100644 --- a/xmloff/source/draw/ximpstyl.cxx +++ b/xmloff/source/draw/ximpstyl.cxx @@ -717,66 +717,63 @@ SdXMLPresentationPlaceholderContext::~SdXMLPresentationPlaceholderContext() SdXMLMasterPageContext::SdXMLMasterPageContext( SdXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList>& xAttrList, + sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList>& xAttrList, uno::Reference< drawing::XShapes > const & rShapes) -: SdXMLGenericPageContext( rImport, nPrfx, rLName, xAttrList, rShapes ) +: SdXMLGenericPageContext( rImport, xAttrList, rShapes ) { - const bool bHandoutMaster = IsXMLToken( rLName, XML_HANDOUT_MASTER ); + const bool bHandoutMaster = (nElement & TOKEN_MASK) == XML_HANDOUT_MASTER; OUString sStyleName, sPageMasterName; - 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 = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - OUString sValue = xAttrList->getValueByIndex( i ); - const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetMasterPageAttrTokenMap(); - - switch(rAttrTokenMap.Get(nPrefix, aLocalName)) + const OUString sValue = aIter.toString(); + switch(aIter.getToken()) { - case XML_TOK_MASTERPAGE_NAME: + case XML_ELEMENT(STYLE, XML_NAME): { msName = sValue; break; } - case XML_TOK_MASTERPAGE_DISPLAY_NAME: + case XML_ELEMENT(STYLE, XML_DISPLAY_NAME): { msDisplayName = sValue; break; } - case XML_TOK_MASTERPAGE_PAGE_MASTER_NAME: + case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME): { sPageMasterName = sValue; break; } - case XML_TOK_MASTERPAGE_STYLE_NAME: + case XML_ELEMENT(DRAW, XML_STYLE_NAME): { sStyleName = sValue; break; } - case XML_TOK_MASTERPAGE_PAGE_LAYOUT_NAME: + case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME): { maPageLayoutName = sValue; break; } - case XML_TOK_MASTERPAGE_USE_HEADER_NAME: + case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME): { maUseHeaderDeclName = sValue; break; } - case XML_TOK_MASTERPAGE_USE_FOOTER_NAME: + case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME): { maUseFooterDeclName = sValue; break; } - case XML_TOK_MASTERPAGE_USE_DATE_TIME_NAME: + case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME): { maUseDateTimeDeclName = sValue; break; } + default: + SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue); } } @@ -812,7 +809,7 @@ SdXMLMasterPageContext::~SdXMLMasterPageContext() { } -void SdXMLMasterPageContext::EndElement() +void SdXMLMasterPageContext::endFastElement(sal_Int32 nElement) { // set styles on master-page if(!msName.isEmpty() && GetSdImport().GetShapeImport()->GetStylesContext()) @@ -822,7 +819,7 @@ void SdXMLMasterPageContext::EndElement() pSdContext->SetMasterPageStyles(*this); } - SdXMLGenericPageContext::EndElement(); + SdXMLGenericPageContext::endFastElement(nElement); GetImport().GetShapeImport()->endPage(GetLocalShapesContext()); } @@ -853,7 +850,22 @@ SvXMLImportContextRef SdXMLMasterPageContext::CreateChildContext( } break; } - case XML_TOK_MASTERPAGE_NOTES: + } + + // call base class + if (!xContext) + xContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList); + + return xContext; +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterPageContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + switch (nElement) + { + case XML_ELEMENT(PRESENTATION, XML_NOTES): { if( GetSdImport().IsImpress() ) { @@ -865,18 +877,13 @@ SvXMLImportContextRef SdXMLMasterPageContext::CreateChildContext( if(xNotesDrawPage.is()) { // presentation:notes inside master-page context - xContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNotesDrawPage); + return new SdXMLNotesContext( GetSdImport(), xAttrList, xNotesDrawPage); } } } } } - - // call base class - if (!xContext) - xContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList); - - return xContext; + return SdXMLGenericPageContext::createFastChildContext(nElement, xAttrList); } SdXMLStylesContext::SdXMLStylesContext( @@ -1388,21 +1395,10 @@ SdXMLMasterStylesContext::SdXMLMasterStylesContext( } css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterStylesContext::createFastChildContext( - sal_Int32 /*nElement*/, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - return nullptr; -} - -SvXMLImportContextRef SdXMLMasterStylesContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList >& xAttrList) -{ - SvXMLImportContextRef xContext; - - if(nPrefix == XML_NAMESPACE_STYLE - && IsXMLToken( rLocalName, XML_MASTER_PAGE ) ) + if( nElement == XML_ELEMENT(STYLE, XML_MASTER_PAGE) ) { // style:masterpage inside office:styles context uno::Reference< drawing::XDrawPage > xNewMasterPage; @@ -1432,15 +1428,14 @@ SvXMLImportContextRef SdXMLMasterStylesContext::CreateChildContext( { const rtl::Reference xLclContext{ new SdXMLMasterPageContext(GetSdImport(), - nPrefix, rLocalName, xAttrList, xNewMasterPage)}; - xContext = xLclContext.get(); + nElement, xAttrList, xNewMasterPage)}; maMasterPageList.push_back(xLclContext); + return xLclContext.get(); } } } } - else if(nPrefix == XML_NAMESPACE_STYLE - && IsXMLToken( rLocalName, XML_HANDOUT_MASTER ) ) + else if( nElement == XML_ELEMENT(STYLE, XML_HANDOUT_MASTER) ) { uno::Reference< presentation::XHandoutMasterSupplier > xHandoutSupp( GetSdImport().GetModel(), uno::UNO_QUERY ); if( xHandoutSupp.is() ) @@ -1448,12 +1443,22 @@ SvXMLImportContextRef SdXMLMasterStylesContext::CreateChildContext( uno::Reference< drawing::XShapes > xHandoutPage = xHandoutSupp->getHandoutMasterPage(); if(xHandoutPage.is() && GetSdImport().GetShapeImport()->GetStylesContext()) { - xContext = new SdXMLMasterPageContext(GetSdImport(), - nPrefix, rLocalName, xAttrList, xHandoutPage); + return new SdXMLMasterPageContext(GetSdImport(), + nElement, xAttrList, xHandoutPage); } } } - else if( (nPrefix == XML_NAMESPACE_DRAW )&& IsXMLToken( rLocalName, XML_LAYER_SET ) ) + return nullptr; +} + +SvXMLImportContextRef SdXMLMasterStylesContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList) +{ + SvXMLImportContextRef xContext; + + if( (nPrefix == XML_NAMESPACE_DRAW) && IsXMLToken( rLocalName, XML_LAYER_SET ) ) { xContext = new SdXMLLayerSetContext( GetImport(), nPrefix, rLocalName, xAttrList ); } diff --git a/xmloff/source/draw/ximpstyl.hxx b/xmloff/source/draw/ximpstyl.hxx index c49be6294dc5..e39ac0a162ec 100644 --- a/xmloff/source/draw/ximpstyl.hxx +++ b/xmloff/source/draw/ximpstyl.hxx @@ -102,17 +102,19 @@ public: SdXMLMasterPageContext( SdXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, css::uno::Reference< css::drawing::XShapes > const & rShapes); virtual ~SdXMLMasterPageContext() 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; - virtual void EndElement() override; + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; const OUString& GetDisplayName() const { return msDisplayName; } -- cgit v1.2.3