LibreOffice Module sc (master) 1
xmldataprovider.cxx
Go to the documentation of this file.
1/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#include "xmldataprovider.hxx"
12#include <salhelper/thread.hxx>
13#include <filter.hxx>
14#include <document.hxx>
15#include <datamapper.hxx>
16#include <utility>
17#include <vcl/svapp.hxx>
18#include <orcusfilters.hxx>
19
20using namespace com::sun::star;
21
22namespace sc
23{
25{
27 OUString maURL;
28 OUString maID;
30 std::unique_ptr<ScOrcusXMLContext> mpXMLContext;
31 const std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
32 std::function<void()> maImportFinishedHdl;
33
34public:
35 XMLFetchThread(ScDocument& rDoc, const OUString&, const ScOrcusImportXMLParam& rParam,
36 const OUString& rID, std::function<void()> aImportFinishedHdl,
37 std::vector<std::shared_ptr<sc::DataTransformation>>&& rTransformations);
38 virtual void execute() override;
39};
40
42 ScDocument& rDoc, const OUString& rURL, const ScOrcusImportXMLParam& rParam,
43 const OUString& rID, std::function<void()> aImportFinishedHdl,
44 std::vector<std::shared_ptr<sc::DataTransformation>>&& rTransformations)
45 : salhelper::Thread("XML Fetch Thread")
46 , mrDocument(rDoc)
47 , maURL(rURL)
48 , maID(rID)
49 , maParam(rParam)
50 , maDataTransformations(std::move(rTransformations))
51 , maImportFinishedHdl(std::move(aImportFinishedHdl))
52{
53}
54
56{
58 if (!pOrcus)
59 return;
60
62 if (!mpXMLContext)
63 return;
64
65 if (!maID.isEmpty())
66 {
68 aRangeLink.maPos = ScAddress(0, 0, 0);
69 aRangeLink.maFieldPaths.push_back(OUStringToOString(maID, RTL_TEXTENCODING_UTF8));
70 maParam.maRangeLinks.clear();
71 maParam.maRangeLinks.push_back(aRangeLink);
72 }
73 // Do the import.
74 mpXMLContext->importXML(maParam);
75
76 for (auto& itr : maDataTransformations)
77 {
78 itr->Transform(mrDocument);
79 }
80
81 SolarMutexGuard aGuard;
83}
84
86 : DataProvider(rDataSource)
87 , mpDocument(pDoc)
88{
89}
90
92{
93 if (mxXMLFetchThread.is())
94 {
95 SolarMutexReleaser aReleaser;
96 mxXMLFetchThread->join();
97 }
98}
99
101{
102 // already importing data
103 if (mpDoc)
104 return;
105
106 mpDoc.reset(new ScDocument(SCDOCMODE_CLIP));
107 mpDoc->ResetClip(mpDocument, SCTAB(0));
110 std::bind(&XMLDataProvider::ImportFinished, this),
111 std::vector(mrDataSource.getDataTransformation()));
112 mxXMLFetchThread->launch();
113
114 if (mbDeterministic)
115 {
116 SolarMutexReleaser aReleaser;
117 mxXMLFetchThread->join();
118 }
119}
120
122
123const OUString& XMLDataProvider::GetURL() const { return mrDataSource.getURL(); }
124}
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ScOrcusFilters * GetOrcusFilters()=0
static SC_DLLPUBLIC ScFormatFilterPlugin & Get()
Definition: impex.cxx:2672
Collection of orcus filter wrappers.
virtual std::unique_ptr< ScOrcusXMLContext > createXMLContext(ScDocument &rDoc, const OUString &rPath) const =0
Create a context for XML file.
Abstract class for all data provider.
bool mbDeterministic
If true make the threaded import deterministic for the tests.
sc::ExternalDataSource & mrDataSource
const ScOrcusImportXMLParam & getXMLImportParam() const
const OUString & getID() const
const std::vector< std::shared_ptr< sc::DataTransformation > > & getDataTransformation() const
const OUString & getURL() const
ScDBDataManager * getDBManager()
void WriteToDoc(ScDocument &rDoc)
virtual ~XMLDataProvider() override
rtl::Reference< XMLFetchThread > mxXMLFetchThread
XMLDataProvider(ScDocument *pDoc, sc::ExternalDataSource &rDataSource)
virtual const OUString & GetURL() const override
ScDocumentUniquePtr mpDoc
virtual void Import() override
std::function< void()> maImportFinishedHdl
XMLFetchThread(ScDocument &rDoc, const OUString &, const ScOrcusImportXMLParam &rParam, const OUString &rID, std::function< void()> aImportFinishedHdl, std::vector< std::shared_ptr< sc::DataTransformation > > &&rTransformations)
const std::vector< std::shared_ptr< sc::DataTransformation > > maDataTransformations
virtual void execute() override
std::unique_ptr< ScOrcusXMLContext > mpXMLContext
ScDocument & mrDocument
ScOrcusImportXMLParam maParam
@ SCDOCMODE_CLIP
Definition: document.hxx:256
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
CAUTION! The following defines must be in the same namespace as the respective type.
const URL maURL
std::vector< RangeLink > maRangeLinks
Definition: orcusxml.hxx:76
sal_Int16 SCTAB
Definition: types.hxx:22