From 2d54ffbf18d461c846535d539d704d45aff059b1 Mon Sep 17 00:00:00 2001 From: Jaskaran Singh Date: Sat, 31 Dec 2016 23:57:49 +0530 Subject: Enable fetching data from network, not just files available locally Change-Id: I7bd25fd66130f944bf7f278cf7fcbaae6dbbbc00 Reviewed-on: https://gerrit.libreoffice.org/32544 Tested-by: Jenkins Reviewed-by: Markus Mohrhard --- sc/source/ui/docshell/dataprovider.cxx | 39 ++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'sc/source/ui/docshell') diff --git a/sc/source/ui/docshell/dataprovider.cxx b/sc/source/ui/docshell/dataprovider.cxx index 410178e80678..eb037edcd1b2 100644 --- a/sc/source/ui/docshell/dataprovider.cxx +++ b/sc/source/ui/docshell/dataprovider.cxx @@ -7,8 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include +#include +#include +#include #include "officecfg/Office/Calc.hxx" #include +#include #if defined(_WIN32) #if !defined __ORCUS_STATIC_LIB // avoid -Werror,-Wunused-macros @@ -17,8 +21,40 @@ #endif #include +using namespace com::sun::star; + namespace sc { +SvStream* FetchStreamFromURL (OUString& rURL) +{ + uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY ); + + uno::Reference< io::XInputStream > xStream; + xStream = xFileAccess->openFileRead( rURL ); + + const sal_Int32 BUF_LEN = 8000; + uno::Sequence< sal_Int8 > buffer( BUF_LEN ); + OStringBuffer aBuffer( 64000 ); + + sal_Int32 nRead = 0; + while ( ( nRead = xStream->readBytes( buffer, BUF_LEN ) ) == BUF_LEN ) + { + aBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead ); + } + + if ( nRead > 0 ) + { + aBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead ); + } + + xStream->closeInput(); + + SvStream* pStream = new SvStream; + pStream->WriteCharPtr(aBuffer.getStr()); + + return pStream; +} + ExternalDataMapper::ExternalDataMapper(ScDocShell* pDocShell, const OUString& rURL, const OUString& rName, SCTAB nTab, SCCOL nCol1,SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool& bSuccess): maRange (ScRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab)), @@ -175,8 +211,7 @@ void CSVDataProvider::StartImport() if (!mxCSVFetchThread.is()) { - SvStream *pStream = nullptr; - pStream = new SvFileStream(maURL, StreamMode::READ); + SvStream* pStream = FetchStreamFromURL(maURL); mxCSVFetchThread = new CSVFetchThread(pStream, mrRange.aEnd.Col() - mrRange.aStart.Col() + 1); mxCSVFetchThread->launch(); } -- cgit