[Libreoffice-commits] core.git: xmloff/inc xmloff/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 24 20:30:32 UTC 2020


 xmloff/inc/XMLNumberStylesImport.hxx   |    7 +--
 xmloff/source/draw/XMLNumberStyles.cxx |   26 +++--------
 xmloff/source/draw/ximpstyl.cxx        |   76 ++++++++++++++++-----------------
 3 files changed, 49 insertions(+), 60 deletions(-)

New commits:
commit 24c6ba4b58ce4627d327f59bd5694b54092e8ba5
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sun Aug 23 20:25:45 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Aug 24 22:29:51 2020 +0200

    use fastparser in SdXMLNumberFormatImportContext
    
    Change-Id: I3a63a80363d1c9b41e9ea73e2cc6c78d24bb1bad
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101246
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/xmloff/inc/XMLNumberStylesImport.hxx b/xmloff/inc/XMLNumberStylesImport.hxx
index caddcb7fc106..e342948f05a2 100644
--- a/xmloff/inc/XMLNumberStylesImport.hxx
+++ b/xmloff/inc/XMLNumberStylesImport.hxx
@@ -45,14 +45,13 @@ class SdXMLNumberFormatImportContext final : public SvXMLNumFormatContext
 public:
 
     SdXMLNumberFormatImportContext( SdXMLImport& rImport,
-        sal_uInt16 nPrfx,
-        const OUString& rLocalName,
+        sal_Int32 nElement,
         SvXMLNumImpData* pNewData,  SvXMLStylesTokens nNewType,
-        const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
         SvXMLStylesContext& rStyles);
     virtual ~SdXMLNumberFormatImportContext() override;
 
-    virtual void EndElement() override;
+    virtual void SAL_CALL endFastElement(sal_Int32 nElement) 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/XMLNumberStyles.cxx b/xmloff/source/draw/XMLNumberStyles.cxx
index deb191844cdc..8630752db0fb 100644
--- a/xmloff/source/draw/XMLNumberStyles.cxx
+++ b/xmloff/source/draw/XMLNumberStyles.cxx
@@ -576,29 +576,21 @@ void SdXMLNumberFormatMemberImportContext::Characters( const OUString& rChars )
 }
 
 
-SdXMLNumberFormatImportContext::SdXMLNumberFormatImportContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName, SvXMLNumImpData* pNewData, SvXMLStylesTokens nNewType, const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, SvXMLStylesContext& rStyles)
-:   SvXMLNumFormatContext(rImport, nPrfx, rLocalName, pNewData, nNewType, xAttrList, rStyles),
+SdXMLNumberFormatImportContext::SdXMLNumberFormatImportContext( SdXMLImport& rImport, sal_Int32 nElement, SvXMLNumImpData* pNewData, SvXMLStylesTokens nNewType, const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList, SvXMLStylesContext& rStyles)
+:   SvXMLNumFormatContext(rImport, nElement, pNewData, nNewType, xAttrList, rStyles),
     mbAutomatic( false ),
     mnIndex(0),
     mnKey( -1 )
 {
-    mbTimeStyle = IsXMLToken( rLocalName, XML_TIME_STYLE );
+    mbTimeStyle = (nElement & TOKEN_MASK) == XML_TIME_STYLE;
 
-    const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
-    for(sal_Int16 i=0; i < nAttrCount; i++)
+    for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
     {
-        OUString sAttrName = xAttrList->getNameByIndex( i );
-        OUString aLocalName;
-        sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
-        OUString sValue = xAttrList->getValueByIndex( i );
-
-        if( nPrefix == XML_NAMESPACE_NUMBER )
-        {
-            if( IsXMLToken( aLocalName, XML_AUTOMATIC_ORDER ) )
-            {
+        OUString sValue = aIter.toString();
+        if( aIter.getToken() == XML_ELEMENT(NUMBER, XML_AUTOMATIC_ORDER) )
                 mbAutomatic = IsXMLToken( sValue, XML_TRUE );
-            }
-        }
+        else
+            SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << aIter.toString());
     }
 }
 
@@ -642,7 +634,7 @@ bool SdXMLNumberFormatImportContext::compareStyle( const SdXMLFixedDataStyle* pS
     return true;
 }
 
-void SdXMLNumberFormatImportContext::EndElement()
+void SdXMLNumberFormatImportContext::endFastElement(sal_Int32 )
 {
     SvXMLNumFormatContext::EndElement();
 
diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx
index 82846738b3ab..4d3f25ae173a 100644
--- a/xmloff/source/draw/ximpstyl.cxx
+++ b/xmloff/source/draw/ximpstyl.cxx
@@ -889,22 +889,43 @@ SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext(
     sal_Int32 nElement,
     const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
 {
-    if( nElement == XML_ELEMENT(TABLE, XML_TABLE_TEMPLATE) )
-    {
-        auto pContext = GetImport().GetShapeImport()->GetShapeTableImport()->CreateTableTemplateContext(nElement, xAttrList );
-        if (pContext)
-            return pContext;
-    }
-    else if (nElement == XML_ELEMENT(STYLE, XML_PAGE_LAYOUT))
-    {
-        // style:page-master inside office:styles context
-        return new SdXMLPageMasterContext(GetSdImport(), nElement, xAttrList);
-    }
-    else if (nElement == XML_ELEMENT(STYLE, XML_PRESENTATION_PAGE_LAYOUT))
+    switch (nElement)
     {
-        // style:presentation-page-layout inside office:styles context
-        return new SdXMLPresentationPageLayoutContext(GetSdImport(), nElement, xAttrList);
-    }
+        case XML_ELEMENT(TABLE, XML_TABLE_TEMPLATE):
+        {
+            auto pContext = GetImport().GetShapeImport()->GetShapeTableImport()->CreateTableTemplateContext(nElement, xAttrList );
+            if (pContext)
+                return pContext;
+            break;
+        }
+        case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT):
+            // style:page-master inside office:styles context
+            return new SdXMLPageMasterContext(GetSdImport(), nElement, xAttrList);
+        case XML_ELEMENT(STYLE, XML_PRESENTATION_PAGE_LAYOUT):
+            // style:presentation-page-layout inside office:styles context
+            return new SdXMLPresentationPageLayoutContext(GetSdImport(), nElement, xAttrList);
+        case XML_ELEMENT(NUMBER, XML_DATE_STYLE):
+            // number:date-style or number:time-style
+            return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::DATE_STYLE, xAttrList, *this );
+        case XML_ELEMENT(NUMBER, XML_TIME_STYLE):
+            // number:date-style or number:time-style
+            return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::TIME_STYLE, xAttrList, *this );
+        case XML_ELEMENT(NUMBER, XML_NUMBER_STYLE):
+            return new SvXMLNumFormatContext( GetSdImport(), nElement,
+                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::NUMBER_STYLE, xAttrList, *this );
+        case XML_ELEMENT(NUMBER, XML_CURRENCY_STYLE):
+            return new SvXMLNumFormatContext( GetSdImport(), nElement,
+                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::CURRENCY_STYLE, xAttrList, *this );
+        case XML_ELEMENT(NUMBER, XML_PERCENTAGE_STYLE):
+            return new SvXMLNumFormatContext( GetSdImport(), nElement,
+                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::PERCENTAGE_STYLE, xAttrList, *this );
+        case XML_ELEMENT(NUMBER, XML_BOOLEAN_STYLE):
+            return new SvXMLNumFormatContext( GetSdImport(), nElement,
+                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::BOOLEAN_STYLE, xAttrList, *this );
+        case XML_ELEMENT(NUMBER, XML_TEXT_STYLE):
+            return new SvXMLNumFormatContext( GetSdImport(), nElement,
+                                            mpNumFmtHelper->getData(), SvXMLStylesTokens::TEXT_STYLE, xAttrList, *this );
+     }
 
     // call base class
     return SvXMLStylesContext::CreateStyleChildContext(nElement, xAttrList);
@@ -917,30 +938,7 @@ SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext(
 {
     SvXMLStyleContext* pContext = nullptr;
 
-    if(!pContext)
-    {
-        const SvXMLTokenMap& rTokenMap = mpNumFmtHelper->GetStylesElemTokenMap();
-        SvXMLStylesTokens nToken = static_cast<SvXMLStylesTokens>(rTokenMap.Get( nPrefix, rLocalName ));
-        switch (nToken)
-        {
-            case SvXMLStylesTokens::DATE_STYLE:
-            case SvXMLStylesTokens::TIME_STYLE:
-                // number:date-style or number:time-style
-                pContext = new SdXMLNumberFormatImportContext( GetSdImport(), nPrefix, rLocalName, mpNumFmtHelper->getData(), nToken, xAttrList, *this );
-                break;
-
-            case SvXMLStylesTokens::NUMBER_STYLE:
-            case SvXMLStylesTokens::CURRENCY_STYLE:
-            case SvXMLStylesTokens::PERCENTAGE_STYLE:
-            case SvXMLStylesTokens::BOOLEAN_STYLE:
-            case SvXMLStylesTokens::TEXT_STYLE:
-                pContext = new SvXMLNumFormatContext( GetSdImport(), nPrefix, rLocalName,
-                                                        mpNumFmtHelper->getData(), nToken, xAttrList, *this );
-                break;
-        }
-    }
-
-    if(!pContext && nPrefix == XML_NAMESPACE_PRESENTATION )
+    if(nPrefix == XML_NAMESPACE_PRESENTATION )
     {
         if( IsXMLToken( rLocalName, XML_HEADER_DECL ) ||
             IsXMLToken( rLocalName, XML_FOOTER_DECL ) ||


More information about the Libreoffice-commits mailing list