diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2020-08-19 20:23:26 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-20 09:38:13 +0200 |
commit | 7b83a28f1eb7d0687d07cfaaf8cfaaf9a8eea8c1 (patch) | |
tree | 8148aa5f8453b3391984831367c2f67edb8e5b88 | |
parent | bf529f8dff2482eba190b512ff93f16bcab7af26 (diff) |
use fastparser in SdXMLHeaderFooterDeclContext
actually, it can do both fast and slow parser paths for now, because
it is used in a place fast-parser doesn't reach yet.
Which means that I had to make SvXMLStyleContext also
capable of handling both fast and slow parser paths.
Change-Id: I24fd5bfb6603e93a5f752365c246ce47dabea8bf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101017
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/xmloff/xmlstyle.hxx | 9 | ||||
-rw-r--r-- | xmloff/source/draw/ximpbody.cxx | 27 | ||||
-rw-r--r-- | xmloff/source/draw/ximpbody.hxx | 4 | ||||
-rw-r--r-- | xmloff/source/draw/ximpstyl.cxx | 56 | ||||
-rw-r--r-- | xmloff/source/draw/ximpstyl.hxx | 8 | ||||
-rw-r--r-- | xmloff/source/style/xmlstyle.cxx | 32 |
6 files changed, 112 insertions, 24 deletions
diff --git a/include/xmloff/xmlstyle.hxx b/include/xmloff/xmlstyle.hxx index 017b2c56af47..6ddf51d8872a 100644 --- a/include/xmloff/xmlstyle.hxx +++ b/include/xmloff/xmlstyle.hxx @@ -98,11 +98,20 @@ public: XmlStyleFamily nFamily=XmlStyleFamily::DATA_STYLE, bool bDefaultStyle = false ); + // Fast-parser constructor + SvXMLStyleContext( SvXMLImport& rImport, + XmlStyleFamily nFamily=XmlStyleFamily::DATA_STYLE, + bool bDefaultStyle = false ); + virtual ~SvXMLStyleContext() 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 >& ) override; + const OUString& GetName() const { return maName; } const OUString& GetDisplayName() const { return maDisplayName.getLength() ? maDisplayName : maName; } const OUString& GetAutoName() const { return maAutoName; } diff --git a/xmloff/source/draw/ximpbody.cxx b/xmloff/source/draw/ximpbody.cxx index 87acc84f18d6..7e7325018cba 100644 --- a/xmloff/source/draw/ximpbody.cxx +++ b/xmloff/source/draw/ximpbody.cxx @@ -331,30 +331,17 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLBodyContext::crea } break; } - } - return nullptr; -} - -SvXMLImportContextRef SdXMLBodyContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList>& xAttrList ) -{ - SvXMLImportContextRef xContext; - const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap(); - - switch(rTokenMap.Get(nPrefix, rLocalName)) - { - case XML_TOK_BODY_HEADER_DECL: - case XML_TOK_BODY_FOOTER_DECL: - case XML_TOK_BODY_DATE_TIME_DECL: + case XML_ELEMENT(PRESENTATION, XML_HEADER_DECL): + case XML_ELEMENT(PRESENTATION, XML_FOOTER_DECL): + case XML_ELEMENT(PRESENTATION, XML_DATE_TIME_DECL): { - xContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList ); + return new SdXMLHeaderFooterDeclContext( GetImport(), xAttrList ); break; } + default: + assert(false); } - - return xContext; + return nullptr; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/draw/ximpbody.hxx b/xmloff/source/draw/ximpbody.hxx index ac77bf5479aa..714c8f8ec07d 100644 --- a/xmloff/source/draw/ximpbody.hxx +++ b/xmloff/source/draw/ximpbody.hxx @@ -58,10 +58,6 @@ public: 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; }; #endif // INCLUDED_XMLOFF_SOURCE_DRAW_XIMPBODY_HXX diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx index 6952d6b68562..51058a1f36d1 100644 --- a/xmloff/source/draw/ximpstyl.cxx +++ b/xmloff/source/draw/ximpstyl.cxx @@ -1512,11 +1512,62 @@ SdXMLHeaderFooterDeclContext::SdXMLHeaderFooterDeclContext(SvXMLImport& rImport, } } +SdXMLHeaderFooterDeclContext::SdXMLHeaderFooterDeclContext(SvXMLImport& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) + : SvXMLStyleContext( rImport ) + , mbFixed(false) +{ + for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) + { + OUString sValue = aIter.toString(); + if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_NAME) ) + { + maStrName = sValue; + } + else if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_SOURCE) ) + { + mbFixed = IsXMLToken( sValue, XML_FIXED ); + } + else if( aIter.getToken() == XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME) ) + { + maStrDateTimeFormat = sValue; + } + else + { + SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << aIter.toString()); + assert(false); + } + } +} + bool SdXMLHeaderFooterDeclContext::IsTransient() const { return true; } +void SdXMLHeaderFooterDeclContext::endFastElement(sal_Int32 nToken) +{ + SdXMLImport& rImport = dynamic_cast<SdXMLImport&>(GetImport()); + auto nElement = nToken & TOKEN_MASK; + if( nElement == XML_HEADER_DECL ) + { + rImport.AddHeaderDecl( maStrName, maStrText ); + } + else if( nElement == XML_FOOTER_DECL ) + { + rImport.AddFooterDecl( maStrName, maStrText ); + } + else if( nElement == XML_DATE_TIME_DECL ) + { + rImport.AddDateTimeDecl( maStrName, maStrText, mbFixed, maStrDateTimeFormat ); + } + else + { + SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nToken)); + assert(false); + } +} + void SdXMLHeaderFooterDeclContext::EndElement() { SdXMLImport& rImport = dynamic_cast<SdXMLImport&>(GetImport()); @@ -1539,4 +1590,9 @@ void SdXMLHeaderFooterDeclContext::Characters( const OUString& rChars ) maStrText += rChars; } +void SdXMLHeaderFooterDeclContext::characters( const OUString& rChars ) +{ + maStrText += rChars; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/draw/ximpstyl.hxx b/xmloff/source/draw/ximpstyl.hxx index 9c1f21e28c23..68927899d2d7 100644 --- a/xmloff/source/draw/ximpstyl.hxx +++ b/xmloff/source/draw/ximpstyl.hxx @@ -247,13 +247,21 @@ public: class SdXMLHeaderFooterDeclContext : public SvXMLStyleContext { public: + // Can be called in either fast- or slow-parser mode SdXMLHeaderFooterDeclContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ); + SdXMLHeaderFooterDeclContext( SvXMLImport& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ); virtual bool IsTransient() const override; virtual void EndElement() override; virtual void Characters( const OUString& rChars ) 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 ) override; + virtual void SAL_CALL characters( const OUString& rChars ) override; private: OUString maStrName; diff --git a/xmloff/source/style/xmlstyle.cxx b/xmloff/source/style/xmlstyle.cxx index 8644d016e186..3c458b55a43e 100644 --- a/xmloff/source/style/xmlstyle.cxx +++ b/xmloff/source/style/xmlstyle.cxx @@ -164,6 +164,19 @@ SvXMLStyleContext::SvXMLStyleContext( { } +// fast-parser constructor +SvXMLStyleContext::SvXMLStyleContext( + SvXMLImport& rImp, + XmlStyleFamily nFam, bool bDefault ) : + SvXMLImportContext( rImp ), + mbHidden( false ), + mnFamily( nFam ), + mbValid( true ), + mbNew( true ), + mbDefaultStyle( bDefault ) +{ +} + SvXMLStyleContext::~SvXMLStyleContext() { } @@ -182,6 +195,25 @@ void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttribute } } +void SvXMLStyleContext::startFastElement( + sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + // Fall back from fastparser to slowparser code + for( auto &it : sax_fastparser::castToFastAttributeList( xAttrList ) ) + { + sal_Int32 nToken = it.getToken(); + const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &GetImport().GetNamespaceMap()); + OUString sAttrName = SvXMLImport::getNameFromToken( nToken ); + if ( !rAttrNamespacePrefix.isEmpty() ) + sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName; + OUString aLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + SetAttribute( nPrefix, aLocalName, it.toString() ); + } +} + void SvXMLStyleContext::SetDefaults() { } |