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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun Jan 19 17:37:13 UTC 2020


 xmloff/source/text/XMLSectionSourceImportContext.cxx |   52 +++++++++++++------
 xmloff/source/text/XMLSectionSourceImportContext.hxx |    6 +-
 2 files changed, 40 insertions(+), 18 deletions(-)

New commits:
commit 55f224ff57cf16057e0493ee4f9b8a14132d7ec1
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sun Jan 19 12:08:09 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Jan 19 18:36:34 2020 +0100

    tdf#129883 Section links are lost on save and reload
    
    Revert "convert XMLSectionSourceImportContext to FastParser APIs"
    This reverts commit ccdcc25a085299bda45bc5ea4b3594e856f2d315.
    
    THis was one of my earliest fastparser attempts before I properly
    understood the weirde workings of the SvImportXML stuff.
    
    Change-Id: I729467cb513740d36c0483eb6f8c84ffa4cab578
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87038
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/xmloff/source/text/XMLSectionSourceImportContext.cxx b/xmloff/source/text/XMLSectionSourceImportContext.cxx
index 82e01979ab0c..2ae4e671f7c0 100644
--- a/xmloff/source/text/XMLSectionSourceImportContext.cxx
+++ b/xmloff/source/text/XMLSectionSourceImportContext.cxx
@@ -32,7 +32,6 @@
 using ::com::sun::star::beans::XPropertySet;
 using ::com::sun::star::uno::Reference;
 using ::com::sun::star::xml::sax::XAttributeList;
-using ::com::sun::star::xml::sax::XFastAttributeList;
 
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::text;
@@ -53,31 +52,54 @@ XMLSectionSourceImportContext::~XMLSectionSourceImportContext()
 {
 }
 
+namespace {
+enum XMLSectionSourceToken
+{
+    XML_TOK_SECTION_XLINK_HREF,
+    XML_TOK_SECTION_TEXT_FILTER_NAME,
+    XML_TOK_SECTION_TEXT_SECTION_NAME
+};
+
+}
+
+static const SvXMLTokenMapEntry aSectionSourceTokenMap[] =
+{
+    { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_SECTION_XLINK_HREF },
+    { XML_NAMESPACE_TEXT, XML_FILTER_NAME, XML_TOK_SECTION_TEXT_FILTER_NAME },
+    { XML_NAMESPACE_TEXT, XML_SECTION_NAME,
+                                        XML_TOK_SECTION_TEXT_SECTION_NAME },
+    XML_TOKEN_MAP_END
+};
+
 
-void XMLSectionSourceImportContext::startFastElement(sal_Int32 /*nElement*/,
-    const Reference<XFastAttributeList> & xAttrList)
+void XMLSectionSourceImportContext::StartElement(
+    const Reference<XAttributeList> & xAttrList)
 {
+    static const SvXMLTokenMap aTokenMap(aSectionSourceTokenMap);
     OUString sURL;
     OUString sFilterName;
     OUString sSectionName;
 
-    sax_fastparser::FastAttributeList *pAttribList =
-            sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
-
-    for (auto &aIter : *pAttribList)
+    sal_Int16 nLength = xAttrList->getLength();
+    for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
     {
-        switch (aIter.getToken())
+        OUString sLocalName;
+        sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
+            GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
+                              &sLocalName );
+
+        switch (aTokenMap.Get(nPrefix, sLocalName))
         {
-            case XML_ELEMENT(XLINK, XML_HREF):
-                sURL = aIter.toString();
+            case XML_TOK_SECTION_XLINK_HREF:
+                sURL = xAttrList->getValueByIndex(nAttr);
                 break;
 
-            case XML_ELEMENT(TEXT, XML_FILTER_NAME):
-                sFilterName = aIter.toString();
+            case XML_TOK_SECTION_TEXT_FILTER_NAME:
+                sFilterName = xAttrList->getValueByIndex(nAttr);
                 break;
 
-            case XML_ELEMENT(TEXT, XML_SECTION_NAME):
-                sSectionName = aIter.toString();
+            case XML_TOK_SECTION_TEXT_SECTION_NAME:
+                sSectionName = xAttrList->getValueByIndex(nAttr);
                 break;
 
             default:
@@ -105,7 +127,7 @@ void XMLSectionSourceImportContext::startFastElement(sal_Int32 /*nElement*/,
     }
 }
 
-void XMLSectionSourceImportContext::endFastElement(sal_Int32 /*nElement*/)
+void XMLSectionSourceImportContext::EndElement()
 {
     // this space intentionally left blank.
 }
diff --git a/xmloff/source/text/XMLSectionSourceImportContext.hxx b/xmloff/source/text/XMLSectionSourceImportContext.hxx
index 838375ff7e78..865e9753ff6f 100644
--- a/xmloff/source/text/XMLSectionSourceImportContext.hxx
+++ b/xmloff/source/text/XMLSectionSourceImportContext.hxx
@@ -45,10 +45,10 @@ public:
 
 protected:
 
-    virtual void SAL_CALL startFastElement(sal_Int32 nElement,
-        const css::uno::Reference<css::xml::sax::XFastAttributeList> & xAttrList) override;
+    virtual void StartElement(
+        const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList) override;
 
-    virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+    virtual void EndElement() override;
 };
 
 #endif


More information about the Libreoffice-commits mailing list