diff options
author | Jaskaran Singh <jvsg1303@gmail.com> | 2016-12-31 23:57:49 +0530 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-01-04 17:24:41 +0000 |
commit | 2d54ffbf18d461c846535d539d704d45aff059b1 (patch) | |
tree | faecb2497040b1c3557793bc2a6fc5f7551d43b1 /sc/source/ui/docshell | |
parent | 0fa23d9b499411407c1a0fed41e91f24d59d2ac0 (diff) |
Enable fetching data from network, not just files available locally
Change-Id: I7bd25fd66130f944bf7f278cf7fcbaae6dbbbc00
Reviewed-on: https://gerrit.libreoffice.org/32544
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/source/ui/docshell')
-rw-r--r-- | sc/source/ui/docshell/dataprovider.cxx | 39 |
1 files changed, 37 insertions, 2 deletions
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 <dataprovider.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess3.hpp> +#include <com/sun/star/ucb/SimpleFileAccess.hpp> +#include <com/sun/star/io/XInputStream.hpp> #include "officecfg/Office/Calc.hxx" #include <stringutil.hxx> +#include <rtl/strbuf.hxx> #if defined(_WIN32) #if !defined __ORCUS_STATIC_LIB // avoid -Werror,-Wunused-macros @@ -17,8 +21,40 @@ #endif #include <orcus/csv_parser.hpp> +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(); } |