summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2017-12-07 21:27:20 -0500
committerKohei Yoshida <libreoffice@kohei.us>2017-12-18 02:31:24 +0100
commitca1a583e96f832797bf638d0b0a37840d35af5f9 (patch)
treed9088f6286625fcc6ec0f85249845778014d1100
parent152c79ee2be2374334202dc738a8f011e47845c7 (diff)
Remove code duplicates.
Change-Id: I424e5999ef2ec6e71f6b6361ed91079b8d949555 Reviewed-on: https://gerrit.libreoffice.org/46656 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Kohei Yoshida <libreoffice@kohei.us>
-rw-r--r--sc/source/filter/orcus/orcusfiltersimpl.cxx83
1 files changed, 33 insertions, 50 deletions
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 6fc115bdce29..1773caa22330 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -55,6 +55,35 @@ uno::Reference<task::XStatusIndicator> getStatusIndicator(const SfxMedium& rMedi
return xStatusIndicator;
}
+bool loadFileContent(ScDocument& rDoc, SfxMedium& rMedium, orcus::iface::import_filter& filter)
+{
+ SvStream* pStream = rMedium.GetInStream();
+ pStream->Seek(0);
+ static const size_t nReadBuffer = 1024*32;
+ OStringBuffer aBuffer((int(nReadBuffer)));
+ size_t nRead = 0;
+ do
+ {
+ char pData[nReadBuffer];
+ nRead = pStream->ReadBytes(pData, nReadBuffer);
+ aBuffer.append(static_cast<sal_Char*>(pData), nRead);
+ }
+ while (nRead == nReadBuffer);
+
+ try
+ {
+ rDoc.ClearTabs();
+ filter.read_stream(aBuffer.getStr(), aBuffer.getLength());
+ }
+ catch (const std::exception& e)
+ {
+ SAL_WARN("sc", "Unable to load file via orcus filter! " << e.what());
+ return false;
+ }
+
+ return true;
+}
+
}
OString ScOrcusFiltersImpl::toSystemPath(const OUString& rPath)
@@ -88,64 +117,18 @@ bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) co
{
ScOrcusFactory aFactory(rDoc);
aFactory.setStatusIndicator(getStatusIndicator(rMedium));
- SvStream* pStream = rMedium.GetInStream();
- pStream->Seek(0);
- static const size_t nReadBuffer = 1024*32;
- OStringBuffer aBuffer((int(nReadBuffer)));
- size_t nRead = 0;
- do
- {
- char pData[nReadBuffer];
- nRead = pStream->ReadBytes(pData, nReadBuffer);
- aBuffer.append(static_cast<sal_Char*>(pData), nRead);
- }
- while (nRead == nReadBuffer);
-
- try
- {
- rDoc.ClearTabs();
- orcus::orcus_gnumeric filter(&aFactory);
- filter.read_stream(aBuffer.getStr(), aBuffer.getLength());
- }
- catch (const std::exception& e)
- {
- SAL_WARN("sc", "Unable to load gnumeric file! " << e.what());
- return false;
- }
- return true;
+ orcus::orcus_gnumeric filter(&aFactory);
+ return loadFileContent(rDoc, rMedium, filter);
}
bool ScOrcusFiltersImpl::importExcel2003XML(ScDocument& rDoc, SfxMedium& rMedium) const
{
ScOrcusFactory aFactory(rDoc);
aFactory.setStatusIndicator(getStatusIndicator(rMedium));
- SvStream* pStream = rMedium.GetInStream();
- pStream->Seek(0);
- static const size_t nReadBuffer = 1024*32;
- OStringBuffer aBuffer((int(nReadBuffer)));
- size_t nRead = 0;
- do
- {
- char pData[nReadBuffer];
- nRead = pStream->ReadBytes(pData, nReadBuffer);
- aBuffer.append(static_cast<sal_Char*>(pData), nRead);
- }
- while (nRead == nReadBuffer);
-
- try
- {
- rDoc.ClearTabs();
- orcus::orcus_xls_xml filter(&aFactory);
- filter.read_stream(aBuffer.getStr(), aBuffer.getLength());
- }
- catch (const std::exception& e)
- {
- SAL_WARN("sc", "Unable to load Excel 2003 XML file! " << e.what());
- return false;
- }
- return true;
+ orcus::orcus_xls_xml filter(&aFactory);
+ return loadFileContent(rDoc, rMedium, filter);
}
bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const