summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2009-12-29 16:11:10 -0500
committerKohei Yoshida <kyoshida@novell.com>2009-12-29 16:11:10 -0500
commit9063977fa27187603aa4c81475e3574535e9f180 (patch)
treee7697e0ca95dd6a77020b5570bf5ac3178bd7922
parent6f9c94e026de8d62c424da7c7fca80996b92c469 (diff)
Store each xls document to control-export.
-rw-r--r--inc/global.hxx4
-rwxr-xr-xrun-test.sh.in2
-rw-r--r--source/global.cxx14
-rw-r--r--source/main.cxx74
4 files changed, 76 insertions, 18 deletions
diff --git a/inc/global.hxx b/inc/global.hxx
index 09212ef..f8aae29 100644
--- a/inc/global.hxx
+++ b/inc/global.hxx
@@ -43,6 +43,10 @@ void error(const ::std::string& msg);
::std::string getEnvVar(const char* name);
+::rtl::OUString toOUString(const ::std::string& rStr);
+
+::com::sun::star::uno::Any toAny(const ::rtl::OUString& rStr);
+
}
#endif
diff --git a/run-test.sh.in b/run-test.sh.in
index 51c13b0..14edb5b 100755
--- a/run-test.sh.in
+++ b/run-test.sh.in
@@ -2,7 +2,7 @@
export LD_LIBRARY_PATH=@OOO_INSTALL_PATH@/program:@OOO_INSTALL_PATH@/ure/lib
source @ROOTDIR@/setenv.sh
-mkdir "$CTRL_XLS_OUT_DIR" || /usr/true
+mkdir "$CTRL_XLS_OUT_DIR" || /bin/true
cd @OOO_INSTALL_PATH@/ure/lib
@ROOTDIR@/test
diff --git a/source/global.cxx b/source/global.cxx
index 3f97efe..8d48520 100644
--- a/source/global.cxx
+++ b/source/global.cxx
@@ -20,6 +20,7 @@ using ::com::sun::star::frame::XDesktop;
using ::com::sun::star::lang::XComponent;;
using ::com::sun::star::lang::XMultiComponentFactory;;
using ::com::sun::star::sheet::XSpreadsheetDocument;
+using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::UNO_QUERY_THROW;
@@ -92,4 +93,17 @@ string getEnvVar(const char* name)
return string(var);
}
+OUString toOUString(const string& rStr)
+{
+ OUString aRet(rStr.c_str(), rStr.size(), RTL_TEXTENCODING_UTF8);
+ return aRet;
+}
+
+Any toAny(const OUString& rStr)
+{
+ Any any;
+ any <<= rStr;
+ return any;
+}
+
}
diff --git a/source/main.cxx b/source/main.cxx
index 34d9369..9ff36ab 100644
--- a/source/main.cxx
+++ b/source/main.cxx
@@ -10,25 +10,33 @@
#include <dirent.h>
#include <sys/stat.h>
+#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/util/XCloseable.hpp>
+#include "rtl/ustrbuf.hxx"
using ::com::sun::star::frame::XDesktop;
+using ::com::sun::star::frame::XStorable;
using ::com::sun::star::lang::DisposedException;
using ::com::sun::star::sheet::XSpreadsheetDocument;
using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::rtl::OUString;
+using ::rtl::OUStringBuffer;
using namespace ::com::sun::star;
using namespace std;
using namespace test;
-bool getImportDocuments(const string& inpath, vector<OUString>& rFilePaths)
+bool getImportDocuments(const OUString& rInPath, vector<OUString>& rFilePaths)
{
+ string inpath = rtl::OUStringToOString(rInPath, RTL_TEXTENCODING_UTF8).getStr();
+
struct stat statbuf;
if (lstat(inpath.c_str(), &statbuf) < 0)
{
@@ -57,9 +65,10 @@ bool getImportDocuments(const string& inpath, vector<OUString>& rFilePaths)
if (aFileName == "." || aFileName == "..")
continue;
- string aFilePath = "file://" + inpath + "/" + aFileName;
- OUString aOUPath(aFilePath.c_str(), aFilePath.size(), RTL_TEXTENCODING_UTF8);
- aFilePaths.push_back(aOUPath);
+ // Only pick up .xls files.
+ ::string::size_type pos = aFileName.find_last_of(".");
+ if (pos != ::string::npos && aFileName.substr(pos) == ".xls")
+ aFilePaths.push_back(toOUString(aFileName));
}
rFilePaths.swap(aFilePaths);
@@ -68,6 +77,13 @@ bool getImportDocuments(const string& inpath, vector<OUString>& rFilePaths)
namespace {
+struct TestParam
+{
+ OUString maInPath;
+ OUString maOutPath;
+ vector<OUString> maInFiles;
+};
+
struct PrintFilePath : public ::std::unary_function<void, OUString>
{
void operator() (const OUString& r) const
@@ -79,20 +95,40 @@ struct PrintFilePath : public ::std::unary_function<void, OUString>
class ProcessFile : public ::std::unary_function<void, OUString>
{
public:
- explicit ProcessFile(const Reference<XDesktop>& xDesktop) :
- mxDesktop(xDesktop) {}
+ explicit ProcessFile(const Reference<XDesktop>& xDesktop, const OUString& rInPath, const OUString& rOutPath) :
+ mxDesktop(xDesktop), maInPath(rInPath), maOutPath(rOutPath) {}
- void operator() (const OUString& r) const
+ void operator() (const OUString& rFile) const
{
- cout << "loading " << rtl::OUStringToOString(r, RTL_TEXTENCODING_UTF8).getStr() << endl;
- Reference<XSpreadsheetDocument> xDoc = loadComponent(mxDesktop, r);
- sleep(2);
+ OUStringBuffer aBuf;
+ aBuf.appendAscii("file://");
+ aBuf.append(maInPath);
+ aBuf.appendAscii("/");
+ aBuf.append(rFile);
+ OUString aInFile = aBuf.makeStringAndClear();
+ cout << "loading " << rtl::OUStringToOString(aInFile, RTL_TEXTENCODING_UTF8).getStr() << endl;
+ Reference<XSpreadsheetDocument> xDoc = loadComponent(mxDesktop, aInFile);
+
+ aBuf.appendAscii("file://");
+ aBuf.append(maOutPath);
+ aBuf.appendAscii("/");
+ aBuf.append(rFile);
+ OUString aOutFile = aBuf.makeStringAndClear();
+ Reference<XStorable> xStorable(xDoc, UNO_QUERY_THROW);
+ cout << "storing to " << rtl::OUStringToOString(aOutFile, RTL_TEXTENCODING_UTF8).getStr() << endl;
+ Sequence<beans::PropertyValue> props(1);
+ props[0].Name = ascii("FilterName");
+ props[0].Value = toAny(ascii("MS Excel 97"));
+ xStorable->storeAsURL(aOutFile, props);
+
Reference<util::XCloseable> xCloseable(xDoc, UNO_QUERY_THROW);
xCloseable->close(true);
}
private:
Reference<XDesktop> mxDesktop;
+ OUString maInPath;
+ OUString maOutPath;
};
}
@@ -101,17 +137,21 @@ int main()
{
try
{
- string aXclImportPath = getEnvVar("CTRL_XLS_IN_DIR");
- string aXclExportPath = getEnvVar("CTRL_XLS_OUT_DIR");
- vector<OUString> aFilePaths;
- if (!getImportDocuments(aXclImportPath, aFilePaths))
+ TestParam aParam;
+
+ aParam.maInPath = toOUString(getEnvVar("CTRL_XLS_IN_DIR"));
+ aParam.maOutPath = toOUString(getEnvVar("CTRL_XLS_OUT_DIR"));
+ if (!getImportDocuments(aParam.maInPath, aParam.maInFiles))
return EXIT_FAILURE;
- cout << "control xls inport directory: " << aXclImportPath << endl;
- for_each(aFilePaths.begin(), aFilePaths.end(), PrintFilePath());
+ cout << "control xls inport directory: "
+ << rtl::OUStringToOString(aParam.maInPath, RTL_TEXTENCODING_UTF8).getStr()
+ << endl;
Reference<XDesktop> xDesktop = bootstrap();
- for_each(aFilePaths.begin(), aFilePaths.end(), ProcessFile(xDesktop));
+ for_each(aParam.maInFiles.begin(), aParam.maInFiles.end(),
+ ProcessFile(xDesktop, aParam.maInPath, aParam.maOutPath));
+
xDesktop->terminate();
}
catch (const DisposedException&)