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

Markus Mohrhard markus.mohrhard at googlemail.com
Sun Aug 20 04:40:36 UTC 2017


 sc/source/ui/dataprovider/dataprovider.cxx     |    5 ++++
 sc/source/ui/dataprovider/htmldataprovider.cxx |   31 +++++++++++++++++++++++++
 sc/source/ui/dataprovider/htmldataprovider.hxx |    2 +
 sc/source/ui/inc/dataprovider.hxx              |    3 ++
 4 files changed, 41 insertions(+)

New commits:
commit 28e4240f81ccc1804ecf4b776290b3553f8d1c61
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 20 03:34:11 2017 +0200

    external data: add a way to get the available data sourcesfor a provider
    
    Change-Id: I1620537ee004c5acbc85db05dce2b8e3b84bb565
    Reviewed-on: https://gerrit.libreoffice.org/41345
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/source/ui/dataprovider/dataprovider.cxx b/sc/source/ui/dataprovider/dataprovider.cxx
index 01cd501a7dde..57b22ce7d4d7 100644
--- a/sc/source/ui/dataprovider/dataprovider.cxx
+++ b/sc/source/ui/dataprovider/dataprovider.cxx
@@ -170,6 +170,11 @@ void DataProvider::setDeterministic()
     mbDeterministic = true;
 }
 
+std::map<OUString, OUString> DataProvider::getDataSourcesForURL(const OUString& /*rURL*/)
+{
+    return std::map<OUString, OUString>();
+}
+
 DataProvider::~DataProvider()
 {
 }
diff --git a/sc/source/ui/dataprovider/htmldataprovider.cxx b/sc/source/ui/dataprovider/htmldataprovider.cxx
index 9ea070782ae4..090d6d73721f 100644
--- a/sc/source/ui/dataprovider/htmldataprovider.cxx
+++ b/sc/source/ui/dataprovider/htmldataprovider.cxx
@@ -249,6 +249,37 @@ void HTMLDataProvider::Import()
     }
 }
 
+std::map<OUString, OUString> HTMLDataProvider::getDataSourcesForURL(const OUString& /*rURL*/)
+{
+    std::map<OUString, OUString> aMap;
+
+    OStringBuffer aBuffer(64000);
+    std::unique_ptr<SvStream> pStream = DataProvider::FetchStreamFromURL(maURL, aBuffer);
+
+    if (aBuffer.isEmpty())
+        return std::map<OUString, OUString>();
+
+    htmlDocPtr pHtmlPtr = htmlParseDoc(reinterpret_cast<xmlChar*>(const_cast<char*>(aBuffer.getStr())), nullptr);
+
+    xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pHtmlPtr);
+    xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST("//table"), pXmlXpathCtx);
+    xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval;
+
+    for (int i = 0; i < pXmlNodes->nodeNr; ++i)
+    {
+        xmlChar* pVal = xmlGetProp(pXmlNodes->nodeTab[i], BAD_CAST("id"));
+
+        if (pVal)
+        {
+            OUString aID = OStringToOUString(toString(pVal), RTL_TEXTENCODING_UTF8);
+            aMap.insert(std::pair<OUString, OUString>(aID, "//table[@id=\""+ aID + "\""));
+            xmlFree(pVal);
+        }
+    }
+
+    return aMap;
+}
+
 IMPL_LINK_NOARG(HTMLDataProvider, ImportFinishedHdl, Timer*, void)
 {
     mpDBDataManager->WriteToDoc(*mpDoc);
diff --git a/sc/source/ui/dataprovider/htmldataprovider.hxx b/sc/source/ui/dataprovider/htmldataprovider.hxx
index 36f3a95ece1c..95bf9e0b3d36 100644
--- a/sc/source/ui/dataprovider/htmldataprovider.hxx
+++ b/sc/source/ui/dataprovider/htmldataprovider.hxx
@@ -39,6 +39,8 @@ public:
 
     virtual const OUString& GetURL() const override;
 
+    virtual std::map<OUString, OUString> getDataSourcesForURL(const OUString& rURL) override;
+
     DECL_LINK( ImportFinishedHdl, Timer*, void );
 };
 
diff --git a/sc/source/ui/inc/dataprovider.hxx b/sc/source/ui/inc/dataprovider.hxx
index 474eff87a427..df70c4099d2c 100644
--- a/sc/source/ui/inc/dataprovider.hxx
+++ b/sc/source/ui/inc/dataprovider.hxx
@@ -29,6 +29,7 @@
 
 #include <queue>
 #include <vector>
+#include <map>
 
 #include "officecfg/Office/Calc.hxx"
 
@@ -96,6 +97,8 @@ public:
 
     virtual const OUString& GetURL() const = 0;
 
+    virtual std::map<OUString, OUString> getDataSourcesForURL(const OUString& rURL);
+
     static std::unique_ptr<SvStream> FetchStreamFromURL(const OUString&, OStringBuffer& rBuffer);
 
     void setDeterministic();


More information about the Libreoffice-commits mailing list