summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-08-20 03:34:11 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-08-20 06:38:37 +0200
commit28e4240f81ccc1804ecf4b776290b3553f8d1c61 (patch)
tree1d0ff57066756f34eb2a1f04ee328d286141d67e
parent7a82caa8f7874f44f32c633140b015325454e570 (diff)
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@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r--sc/source/ui/dataprovider/dataprovider.cxx5
-rw-r--r--sc/source/ui/dataprovider/htmldataprovider.cxx31
-rw-r--r--sc/source/ui/dataprovider/htmldataprovider.hxx2
-rw-r--r--sc/source/ui/inc/dataprovider.hxx3
4 files changed, 41 insertions, 0 deletions
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();