1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 #include <string_view>
14 #include <salhelper/thread.hxx>
15 #include <rtl/ustring.hxx>
16 #include <rtl/ref.hxx>
17 #include <osl/mutex.hxx>
18 #include <document.hxx>
20 #include <rtl/strbuf.hxx>
26 #include <orcus/csv_parser.hpp>
33 class DataTransformation
;
34 class ExternalDataSource
;
36 class CSVFetchThread
: public salhelper::Thread
38 ScDocument
& mrDocument
;
41 std::atomic
<bool> mbTerminate
;
43 orcus::csv::parser_config maConfig
;
45 std::vector
<std::shared_ptr
<sc::DataTransformation
>> maDataTransformations
;
47 std::function
<void()> maImportFinishedHdl
;
51 CSVFetchThread(ScDocument
& rDoc
, OUString
, std::function
<void()> aImportFinishedHdl
,
52 std::vector
<std::shared_ptr
<sc::DataTransformation
>>&& mrDataTransformations
);
53 virtual ~CSVFetchThread() override
;
55 void RequestTerminate();
56 bool IsRequestedTerminate();
60 virtual void execute() override
;
64 * Abstract class for all data provider.
71 * If true make the threaded import deterministic for the tests.
74 sc::ExternalDataSource
& mrDataSource
;
77 DataProvider(sc::ExternalDataSource
& rDataSource
);
79 virtual ~DataProvider();
81 virtual void Import() = 0;
83 virtual const OUString
& GetURL() const = 0;
85 static std::unique_ptr
<SvStream
> FetchStreamFromURL(const OUString
&, OStringBuffer
& rBuffer
);
87 void setDeterministic();
90 class CSVDataProvider
: public DataProvider
92 rtl::Reference
<CSVFetchThread
> mxCSVFetchThread
;
93 ScDocument
* mpDocument
;
94 ScDocumentUniquePtr mpDoc
;
99 CSVDataProvider (ScDocument
* pDoc
, sc::ExternalDataSource
& rDataSource
);
100 virtual ~CSVDataProvider() override
;
102 virtual void Import() override
;
104 const OUString
& GetURL() const override
;
105 void ImportFinished();
109 * This class handles the copying of the data from the imported
110 * temporary document to the actual document. Additionally, in the future
111 * we may decide to store data transformations in this class.
113 * In addition this class also handles how to deal with excess data by for example extending the ScDBData or by only showing the first or last entries.
115 * TODO: move the DataProvider::WriteToDoc here
118 class ScDBDataManager
124 ScDBDataManager(OUString aDBName
, ScDocument
* pDoc
);
127 void SetDatabase(const OUString
& rDBName
);
129 ScDBData
* getDBData();
131 void WriteToDoc(ScDocument
& rDoc
);
134 class DataProviderFactory
138 static bool isInternalDataProvider(std::u16string_view rProvider
);
142 static std::shared_ptr
<DataProvider
> getDataProvider(ScDocument
* pDoc
, sc::ExternalDataSource
& rDataSource
);
144 static std::vector
<OUString
> getDataProviders();
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */