11 #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
12 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
13 #include <com/sun/star/io/XInputStream.hpp>
15 #include <rtl/strbuf.hxx>
32 std::unique_ptr<SvStream> DataProvider::FetchStreamFromURL(
const OUString& rURL, OStringBuffer& rBuffer)
38 uno::Reference< io::XInputStream >
xStream = xFileAccess->openFileRead( rURL );
40 const sal_Int32 BUF_LEN = 8000;
41 uno::Sequence< sal_Int8 > buffer( BUF_LEN );
44 while ( ( nRead = xStream->readBytes( buffer, BUF_LEN ) ) == BUF_LEN )
46 rBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
51 rBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
54 xStream->closeInput();
56 SvStream* pStream =
new SvMemoryStream(const_cast<char*>(rBuffer.getStr()), rBuffer.getLength(), StreamMode::READ);
57 return std::unique_ptr<SvStream>(pStream);
66 ExternalDataSource::ExternalDataSource(
const OUString& rURL,
69 , maProvider(rProvider)
171 const std::shared_ptr<sc::DataTransformation>& mpDataTransformation)
206 mbDeterministic(
false),
207 mrDataSource(rDataSource)
224 bool bShrunk =
false;
229 rDoc.
ShrinkToUsedDataArea(bShrunk, 0, nStartCol, nStartRow, nEndCol, nEndRow,
false,
true,
true);
230 ScRange aClipRange(nStartCol, nStartRow, 0, nEndCol, nEndRow, 0);
278 const OUString& rDataProvider = rDataSource.
getProvider();
282 if (rDataProvider ==
"org.libreoffice.calc.csv")
283 return std::make_shared<CSVDataProvider>(pDoc, rDataSource);
284 else if (rDataProvider ==
"org.libreoffice.calc.html")
285 return std::make_shared<HTMLDataProvider>(pDoc, rDataSource);
286 else if (rDataProvider ==
"org.libreoffice.calc.xml")
287 return std::make_shared<XMLDataProvider>(pDoc, rDataSource);
288 else if (rDataProvider ==
"org.libreoffice.calc.sql")
289 return std::make_shared<SQLDataProvider>(pDoc, rDataSource);
293 SAL_WARN(
"sc",
"no external data provider supported yet");
294 return std::shared_ptr<DataProvider>();
297 return std::shared_ptr<DataProvider>();
302 std::vector<OUString> aDataProviders;
303 aDataProviders.emplace_back(
"org.libreoffice.calc.csv");
304 aDataProviders.emplace_back(
"org.libreoffice.calc.html");
305 aDataProviders.emplace_back(
"org.libreoffice.calc.xml");
306 aDataProviders.emplace_back(
"org.libreoffice.calc.sql");
308 return aDataProviders;
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
static bool isInternalDataProvider(std::u16string_view rProvider)
static std::vector< OUString > getDataProviders()
ScDBDataManager(const OUString &rDBName, ScDocument *pDoc)
bool mbDeterministic
If true make the threaded import deterministic for the tests.
void AddDataTransformation(const std::shared_ptr< sc::DataTransformation > &mpDataTransformation)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
SC_DLLPUBLIC void CopyFromClip(const ScRange &rDestRange, const ScMarkData &rMark, InsertDeleteFlags nInsFlag, ScDocument *pRefUndoDoc, ScDocument *pClipDoc, bool bResetCut=true, bool bAsLink=false, bool bIncludeFiltered=true, bool bSkipEmptyCells=false, const ScRangeList *pDestRanges=nullptr)
Paste data from a clipboard document into this document.
void setProvider(const OUString &rProvider)
This class handles the copying of the data from the imported temporary document to the actual documen...
std::shared_ptr< DataProvider > mpDataProvider
SC_DLLPUBLIC SCROW MaxRow() const
OUString maProvider
The data provider is a unique identifier that will allow to identify and instantiate the required dat...
bool ShrinkToUsedDataArea(bool &o_bShrunk, SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow, bool bColumnsOnly, bool bStickyTopRow=false, bool bStickyLeftCol=false, ScDataAreaExtras *pDataAreaExtras=nullptr) const
Shrink a range to only include used data area.
void setID(const OUString &rID)
void WriteToDoc(ScDocument &rDoc)
void SetClipArea(const ScRange &rArea, bool bCut=false)
SC_DLLPUBLIC SCCOL MaxCol() const
const std::vector< ExternalDataSource > & getDataSources() const
static std::shared_ptr< DataProvider > getDataProvider(ScDocument *pDoc, sc::ExternalDataSource &rDataSource)
std::vector< ExternalDataSource > maDataSources
void SelectTable(SCTAB nTab, bool bNew)
OUString getDBName() const
static SC_DLLPUBLIC const CharClass & getCharClass()
CAUTION! The following defines must be in the same namespace as the respective type.
ScSheetLimits & GetSheetLimits() const
const OUString & getURL() const
void SetDatabase(const OUString &rDBName)
void refresh(ScDocument *pDoc, bool bDeterministic=false)
const OUString & GetName() const
ExternalDataMapper(ScDocument &rDoc)
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
std::vector< std::shared_ptr< sc::DataTransformation > > maDataTransformations
const OUString & getProvider() const
ScDBData * findByUpperName(const OUString &rName)
ScDBDataManager * getDBManager()
const ScOrcusImportXMLParam & getXMLImportParam() const
void insertDataSource(const ExternalDataSource &rSource)
DataProvider(sc::ExternalDataSource &rDataSource)
OUString maID
The ID allows the same data provider to support different data streams.
void setURL(const OUString &rURL)
OUString maURL
The URL for the external data provider.
static double getUpdateFrequency()
Reference< XComponentContext > getProcessComponentContext()
void setXMLImportParam(const ScOrcusImportXMLParam &rParam)
SfxObjectShell * GetDocumentShell() const
#define SAL_WARN(area, stream)
const std::vector< std::shared_ptr< sc::DataTransformation > > & getDataTransformation() const
const OUString & getID() const
void setDBData(const OUString &rDBName)
std::shared_ptr< ScDBDataManager > mpDBDataManager
ScOrcusImportXMLParam maParam
bool m_bDetectedRangeSegmentation false