diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-27 13:05:14 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-27 20:48:36 +0200 |
commit | c995359be1b768d9848ebbeac57765e217f5acff (patch) | |
tree | bb4223767b5dc293dde9942972cf310024cde9bc | |
parent | 2730ae520da2c47ac1cabaa3ddcc43359aae5875 (diff) |
use fastparser in CreateHeaderFooterContext
Change-Id: Ic0a4e4911bb56fd9731e0e9d3850387b1f26b1d5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101474
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/xmloff/XMLTextMasterPageContext.hxx | 12 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLTableHeaderFooterContext.cxx | 100 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLTableHeaderFooterContext.hxx | 20 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlstyli.cxx | 7 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlstyli.hxx | 5 | ||||
-rw-r--r-- | xmloff/inc/XMLTextHeaderFooterContext.hxx | 8 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextHeaderFooterContext.cxx | 9 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextMasterPageContext.cxx | 44 |
8 files changed, 94 insertions, 111 deletions
diff --git a/include/xmloff/XMLTextMasterPageContext.hxx b/include/xmloff/XMLTextMasterPageContext.hxx index ad58d69eb269..3d2bd7302f68 100644 --- a/include/xmloff/XMLTextMasterPageContext.hxx +++ b/include/xmloff/XMLTextMasterPageContext.hxx @@ -60,15 +60,13 @@ public: virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) 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 >& AttrList ) override; virtual SvXMLImportContext *CreateHeaderFooterContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, const bool bFooter, const bool bLeft, const bool bFirst ); diff --git a/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx b/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx index e62dec99205c..1e04f85cbf53 100644 --- a/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx +++ b/sc/source/filter/xml/XMLTableHeaderFooterContext.cxx @@ -26,6 +26,7 @@ #include "XMLTableHeaderFooterContext.hxx" #include <xmloff/xmltoken.hxx> #include <comphelper/extract.hxx> +#include <sal/log.hxx> #include <unonames.hxx> @@ -37,13 +38,12 @@ using namespace ::com::sun::star::beans; using namespace xmloff::token; -XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, +XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_Int32 /*nElement*/, const uno::Reference< - xml::sax::XAttributeList > & xAttrList, + xml::sax::XFastAttributeList > & xAttrList, const Reference < XPropertySet > & rPageStylePropSet, bool bFooter, bool bLeft ) : - SvXMLImportContext( rImport, nPrfx, rLName ), + SvXMLImportContext( rImport ), xPropSet( rPageStylePropSet ), bContainsLeft(false), bContainsRight(false), @@ -54,20 +54,12 @@ XMLTableHeaderFooterContext::XMLTableHeaderFooterContext( SvXMLImport& rImport, OUString sContentLeft( bFooter ? OUString(SC_UNO_PAGE_LEFTFTRCONT) : OUString(SC_UNO_PAGE_LEFTHDRCONT) ); OUString sShareContent( bFooter ? OUString(SC_UNO_PAGE_FTRSHARED) : OUString(SC_UNO_PAGE_HDRSHARED) ); bool bDisplay( true ); - sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0); - for( sal_Int16 i=0; i < nAttrCount; ++i ) + for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) ) { - const OUString& rAttrName(xAttrList->getNameByIndex( i )); - OUString aLName; - sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLName )); - const OUString& rValue(xAttrList->getValueByIndex( i )); - - // TODO: use a map here - if( XML_NAMESPACE_STYLE == nPrefix ) - { - if( IsXMLToken(aLName, XML_DISPLAY ) ) - bDisplay = IsXMLToken(rValue, XML_TRUE); - } + if( aIter.getToken() == XML_ELEMENT(STYLE, XML_DISPLAY) ) + bDisplay = IsXMLToken(aIter.toString(), XML_TRUE); + else + SAL_WARN("sc", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << aIter.toString()); } if( bLeft ) { @@ -103,6 +95,39 @@ XMLTableHeaderFooterContext::~XMLTableHeaderFooterContext() { } +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableHeaderFooterContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) +{ + if (xHeaderFooterContent.is()) + { + uno::Reference < text::XText > xText; + switch (nElement) + { + case XML_ELEMENT(STYLE, XML_REGION_LEFT): + xText.set(xHeaderFooterContent->getLeftText()); + bContainsLeft = true; + break; + case XML_ELEMENT(STYLE, XML_REGION_CENTER): + xText.set(xHeaderFooterContent->getCenterText()); + bContainsCenter = true; + break; + case XML_ELEMENT(STYLE, XML_REGION_RIGHT): + xText.set(xHeaderFooterContent->getRightText()); + bContainsRight = true; + break; + default: break; + } + if (xText.is()) + { + xText->setString(""); + uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor()); + return new XMLHeaderFooterRegionContext( GetImport(), xTempTextCursor); + } + } + return nullptr; +} + SvXMLImportContextRef XMLTableHeaderFooterContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, @@ -131,43 +156,11 @@ SvXMLImportContextRef XMLTableHeaderFooterContext::CreateChildContext( rLocalName, xAttrList); } - else - { - if (nPrefix == XML_NAMESPACE_STYLE) - { - if (xHeaderFooterContent.is()) - { - uno::Reference < text::XText > xText; - if (IsXMLToken(rLocalName, XML_REGION_LEFT )) - { - xText.set(xHeaderFooterContent->getLeftText()); - bContainsLeft = true; - } - else if (IsXMLToken(rLocalName, XML_REGION_CENTER )) - { - xText.set(xHeaderFooterContent->getCenterText()); - bContainsCenter = true; - } - else if (IsXMLToken(rLocalName, XML_REGION_RIGHT )) - { - xText.set(xHeaderFooterContent->getRightText()); - bContainsRight = true; - } - if (xText.is()) - { - xText->setString(""); - //SvXMLImport aSvXMLImport( GetImport() ); - uno::Reference < text::XTextCursor > xTempTextCursor(xText->createTextCursor()); - pContext = new XMLHeaderFooterRegionContext( GetImport(), nPrefix, rLocalName, xTempTextCursor); - } - } - } - } return pContext; } -void XMLTableHeaderFooterContext::EndElement() +void XMLTableHeaderFooterContext::endFastElement(sal_Int32 ) { if( GetImport().GetTextImport()->GetCursor().is() ) { @@ -196,10 +189,9 @@ void XMLTableHeaderFooterContext::EndElement() } -XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, +XMLHeaderFooterRegionContext::XMLHeaderFooterRegionContext( SvXMLImport& rImport, uno::Reference< text::XTextCursor >& xCursor ) : - SvXMLImportContext( rImport, nPrfx, rLName ), + SvXMLImportContext( rImport ), xTextCursor ( xCursor ) { xOldTextCursor.set(GetImport().GetTextImport()->GetCursor()); @@ -230,7 +222,7 @@ SvXMLImportContextRef XMLHeaderFooterRegionContext::CreateChildContext( return pContext; } -void XMLHeaderFooterRegionContext::EndElement() +void XMLHeaderFooterRegionContext::endFastElement(sal_Int32 ) { if( GetImport().GetTextImport()->GetCursor().is() ) { diff --git a/sc/source/filter/xml/XMLTableHeaderFooterContext.hxx b/sc/source/filter/xml/XMLTableHeaderFooterContext.hxx index a8021d55f00c..f9088ebe8f38 100644 --- a/sc/source/filter/xml/XMLTableHeaderFooterContext.hxx +++ b/sc/source/filter/xml/XMLTableHeaderFooterContext.hxx @@ -43,9 +43,8 @@ class XMLTableHeaderFooterContext: public SvXMLImportContext public: - XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + XMLTableHeaderFooterContext( SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, const css::uno::Reference< css::beans::XPropertySet > & rPageStylePropSet, bool bFooter, bool bLft ); @@ -56,7 +55,13 @@ public: const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; - virtual void EndElement() 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 void SAL_CALL endFastElement(sal_Int32 nElement) override; }; class XMLHeaderFooterRegionContext: public SvXMLImportContext @@ -67,8 +72,7 @@ private: public: - XMLHeaderFooterRegionContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, + XMLHeaderFooterRegionContext( SvXMLImport& rImport, css::uno::Reference< css::text::XTextCursor >& xCursor ); virtual ~XMLHeaderFooterRegionContext() override; @@ -78,7 +82,9 @@ public: const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; - virtual void EndElement() override; + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {} + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; }; #endif diff --git a/sc/source/filter/xml/xmlstyli.cxx b/sc/source/filter/xml/xmlstyli.cxx index 80f9a207537e..9569fa52e417 100644 --- a/sc/source/filter/xml/xmlstyli.cxx +++ b/sc/source/filter/xml/xmlstyli.cxx @@ -955,9 +955,8 @@ ScMasterPageContext::~ScMasterPageContext() } SvXMLImportContext *ScMasterPageContext::CreateHeaderFooterContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, const bool bFooter, const bool bLeft, const bool /*bFirst*/ ) @@ -972,7 +971,7 @@ SvXMLImportContext *ScMasterPageContext::CreateHeaderFooterContext( if (!xPropSet.is()) xPropSet.set(GetStyle(), UNO_QUERY ); return new XMLTableHeaderFooterContext( GetImport(), - nPrefix, rLocalName, + nElement, xAttrList, xPropSet, bFooter, bLeft ); diff --git a/sc/source/filter/xml/xmlstyli.hxx b/sc/source/filter/xml/xmlstyli.hxx index 29010ad2b507..0bbcefb18a0b 100644 --- a/sc/source/filter/xml/xmlstyli.hxx +++ b/sc/source/filter/xml/xmlstyli.hxx @@ -200,9 +200,8 @@ public: virtual ~ScMasterPageContext() override; virtual SvXMLImportContext *CreateHeaderFooterContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, const bool bFooter, const bool bLeft, const bool bFirst ) override; diff --git a/xmloff/inc/XMLTextHeaderFooterContext.hxx b/xmloff/inc/XMLTextHeaderFooterContext.hxx index 2a251b8fd37e..86ac28b1f558 100644 --- a/xmloff/inc/XMLTextHeaderFooterContext.hxx +++ b/xmloff/inc/XMLTextHeaderFooterContext.hxx @@ -44,9 +44,7 @@ class XMLTextHeaderFooterContext final : public SvXMLImportContext public: - XMLTextHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + XMLTextHeaderFooterContext( SvXMLImport& rImport, const css::uno::Reference< css::beans::XPropertySet > & rPageStylePropSet, bool bFooter, bool bLft, bool bFrst ); @@ -57,7 +55,9 @@ public: const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; - virtual void EndElement() override; + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {} + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; }; diff --git a/xmloff/source/text/XMLTextHeaderFooterContext.cxx b/xmloff/source/text/XMLTextHeaderFooterContext.cxx index 38dc32dd1e46..5437cb508f71 100644 --- a/xmloff/source/text/XMLTextHeaderFooterContext.cxx +++ b/xmloff/source/text/XMLTextHeaderFooterContext.cxx @@ -32,13 +32,10 @@ using namespace ::com::sun::star::text; using namespace ::com::sun::star::beans; -XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< - xml::sax::XAttributeList > &, +XMLTextHeaderFooterContext::XMLTextHeaderFooterContext( SvXMLImport& rImport, const Reference < XPropertySet > & rPageStylePropSet, bool bFooter, bool bLft, bool bFrst ) : - SvXMLImportContext( rImport, nPrfx, rLName ), + SvXMLImportContext( rImport ), xPropSet( rPageStylePropSet ), sOn( bFooter ? OUString("FooterIsOn") : OUString("HeaderIsOn") ), sShareContent( bFooter ? OUString("FooterIsShared") : OUString("HeaderIsShared") ), @@ -176,7 +173,7 @@ SvXMLImportContextRef XMLTextHeaderFooterContext::CreateChildContext( return pContext; } -void XMLTextHeaderFooterContext::EndElement() +void XMLTextHeaderFooterContext::endFastElement(sal_Int32 ) { if( xOldTextCursor.is() ) { diff --git a/xmloff/source/text/XMLTextMasterPageContext.cxx b/xmloff/source/text/XMLTextMasterPageContext.cxx index c5b98ea4cc34..ff005f65c5ab 100644 --- a/xmloff/source/text/XMLTextMasterPageContext.cxx +++ b/xmloff/source/text/XMLTextMasterPageContext.cxx @@ -178,46 +178,44 @@ XMLTextMasterPageContext::~XMLTextMasterPageContext() { } -SvXMLImportContextRef XMLTextMasterPageContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const Reference< XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextMasterPageContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { SvXMLImportContextRef xContext; - const SvXMLTokenMap& rTokenMap = - GetImport().GetTextImport()->GetTextMasterPageElemTokenMap(); - bool bInsert = false, bFooter = false, bLeft = false, bFirst = false; - switch( rTokenMap.Get( nPrefix, rLocalName ) ) + switch( nElement ) { - case XML_TOK_TEXT_MP_HEADER: + case XML_ELEMENT(STYLE, XML_HEADER): if( bInsertHeader && !bHeaderInserted ) { bInsert = true; bHeaderInserted = true; } break; - case XML_TOK_TEXT_MP_FOOTER: + case XML_ELEMENT(STYLE, XML_FOOTER): if( bInsertFooter && !bFooterInserted ) { bInsert = bFooter = true; bFooterInserted = true; } break; - case XML_TOK_TEXT_MP_HEADER_LEFT: + case XML_ELEMENT(STYLE, XML_HEADER_LEFT): if( bInsertHeaderLeft && bHeaderInserted ) bInsert = bLeft = true; break; - case XML_TOK_TEXT_MP_FOOTER_LEFT: + case XML_ELEMENT(STYLE, XML_FOOTER_LEFT): if( bInsertFooterLeft && bFooterInserted ) bInsert = bFooter = bLeft = true; break; - case XML_TOK_TEXT_MP_HEADER_FIRST: + case XML_ELEMENT(LO_EXT, XML_HEADER_FIRST): + case XML_ELEMENT(STYLE, XML_HEADER_FIRST): if( bInsertHeaderFirst && bHeaderInserted ) bInsert = bFirst = true; break; - case XML_TOK_TEXT_MP_FOOTER_FIRST: + case XML_ELEMENT(LO_EXT, XML_FOOTER_FIRST): + case XML_ELEMENT(STYLE, XML_FOOTER_FIRST): if( bInsertFooterFirst && bFooterInserted ) bInsert = bFooter = bFirst = true; break; @@ -225,28 +223,22 @@ SvXMLImportContextRef XMLTextMasterPageContext::CreateChildContext( if( bInsert && xStyle.is() ) { - xContext = CreateHeaderFooterContext( nPrefix, rLocalName, - xAttrList, - bFooter, bLeft, bFirst ); + xContext = CreateHeaderFooterContext( nElement, xAttrList, + bFooter, bLeft, bFirst ); } - return xContext; + return xContext.get(); } SvXMLImportContext *XMLTextMasterPageContext::CreateHeaderFooterContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*xAttrList*/, const bool bFooter, const bool bLeft, const bool bFirst ) { Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); - return new XMLTextHeaderFooterContext( GetImport(), - nPrefix, rLocalName, - xAttrList, - xPropSet, - bFooter, bLeft, bFirst ); + return new XMLTextHeaderFooterContext( GetImport(), xPropSet, bFooter, bLeft, bFirst ); } void XMLTextMasterPageContext::Finish( bool bOverwrite ) |