summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-04-08 21:41:51 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-04-09 13:01:24 -0400
commit6374df20c2a8378209cce21c0e9689e65b8bd9a2 (patch)
treef206455c258484e76d600488d1ad60460acb8f5d /sc
parent50d044d59ac27781932e6f15549f730d693be56e (diff)
Use ucb to load bytes from file URL.
With this, we get file system abstraction for free. Change-Id: Iec988712599f506444cf9c7e3ebbd59d38f083ee
Diffstat (limited to 'sc')
-rw-r--r--sc/Library_scfilt.mk1
-rw-r--r--sc/source/filter/orcus/xmlcontext.cxx34
2 files changed, 30 insertions, 5 deletions
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index a0e407b48a20..5c8c8ef1282a 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -61,6 +61,7 @@ $(eval $(call gb_Library_use_libraries,scfilt,\
svxcore \
tk \
tl \
+ ucbhelper \
utl \
vcl \
i18nlangtag \
diff --git a/sc/source/filter/orcus/xmlcontext.cxx b/sc/source/filter/orcus/xmlcontext.cxx
index 0d7e05ffd068..ab21844983eb 100644
--- a/sc/source/filter/orcus/xmlcontext.cxx
+++ b/sc/source/filter/orcus/xmlcontext.cxx
@@ -14,6 +14,7 @@
#include "svtools/treelistbox.hxx"
#include "svtools/treelistentry.hxx"
+#include "ucbhelper/content.hxx"
#include <orcus/spreadsheet/import_interface.hpp>
#include <orcus/xml_structure_tree.hpp>
@@ -21,7 +22,14 @@
#include <orcus/orcus_xml.hpp>
#include <orcus/global.hpp>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+
#include <string>
+#include <sstream>
+
+#define BUFFER_SIZE 4096
+
+using namespace com::sun::star;
namespace {
@@ -143,6 +151,26 @@ public:
}
};
+void loadContentFromURL(const OUString& rURL, std::string& rStrm)
+{
+ ucbhelper::Content aContent(
+ rURL, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
+ uno::Reference<io::XInputStream> xStrm = aContent.openStream();
+
+ std::ostringstream aStrmBuf;
+ uno::Sequence<sal_Int8> aBytes;
+ size_t nBytesRead = 0;
+ do
+ {
+ nBytesRead = xStrm->readBytes(aBytes, BUFFER_SIZE);
+ const sal_Int8* p = aBytes.getConstArray();
+ aStrmBuf << std::string(p, p + nBytesRead);
+ }
+ while (nBytesRead == BUFFER_SIZE);
+
+ rStrm = aStrmBuf.str();
+}
+
}
ScOrcusXMLContextImpl::ScOrcusXMLContextImpl(ScDocument& rDoc, const OUString& rPath) :
@@ -154,12 +182,8 @@ bool ScOrcusXMLContextImpl::loadXMLStructure(SvTreeListBox& rTreeCtrl, ScOrcusXM
{
rParam.maUserDataStore.clear();
- OString aSysPath = ScOrcusFiltersImpl::toSystemPath(maPath);
- const char* path = aSysPath.getStr();
-
- // TODO: Use our own stream loading call instead of one from orcus.
std::string aStrm;
-// orcus::load_file_content(path, aStrm);
+ loadContentFromURL(maPath, aStrm);
if (aStrm.empty())
return false;