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

Jaskaran Singh jvsg1303 at gmail.com
Wed Jan 4 17:25:03 UTC 2017


 sc/source/ui/docshell/dataprovider.cxx |   39 +++++++++++++++++++++++++++++++--
 sc/source/ui/inc/dataprovider.hxx      |    3 ++
 2 files changed, 40 insertions(+), 2 deletions(-)

New commits:
commit 2d54ffbf18d461c846535d539d704d45aff059b1
Author: Jaskaran Singh <jvsg1303 at gmail.com>
Date:   Sat Dec 31 23:57:49 2016 +0530

    Enable fetching data from network, not just files available locally
    
    Change-Id: I7bd25fd66130f944bf7f278cf7fcbaae6dbbbc00
    Reviewed-on: https://gerrit.libreoffice.org/32544
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/source/ui/docshell/dataprovider.cxx b/sc/source/ui/docshell/dataprovider.cxx
index 410178e..eb037ed 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();
     }
diff --git a/sc/source/ui/inc/dataprovider.hxx b/sc/source/ui/inc/dataprovider.hxx
index 5a09900..7093ee5 100644
--- a/sc/source/ui/inc/dataprovider.hxx
+++ b/sc/source/ui/inc/dataprovider.hxx
@@ -34,6 +34,9 @@
 
 namespace sc {
 
+/* Fetch Data Stream from local or remote locations */
+SvStream* FetchStreamFromURL(OUString& rUrl);
+
 class DataProvider;
 
 class ExternalDataMapper


More information about the Libreoffice-commits mailing list