1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#include "global.hxx"
#include "cppuhelper/bootstrap.hxx"
#include "rtl/ustring.hxx"
#include "rtl/textenc.h"
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/frame/XDesktop.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <cstdlib>
#include <cstring>
#include <iostream>
using ::com::sun::star::beans::PropertyValue;
using ::com::sun::star::frame::XComponentLoader;
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;
using ::com::sun::star::uno::XComponentContext;
using ::rtl::OUString;
using namespace ::std;
namespace test {
GeneralException::GeneralException(const string& msg) : maMsg(msg) {}
GeneralException::~GeneralException() throw() {}
const char* GeneralException::what() const throw()
{
return maMsg.c_str();
}
OUString ascii(const sal_Char* str)
{
return ::rtl::OUString::intern(str, ::std::strlen(str), RTL_TEXTENCODING_ASCII_US);
}
Reference<XDesktop> bootstrap()
{
Reference<XSpreadsheetDocument> xSpDoc;
Reference<XComponentContext> xCC = ::cppu::bootstrap();
Reference<XMultiComponentFactory> xFactory = xCC->getServiceManager();
Reference<XDesktop> xDesktop(xFactory->createInstanceWithContext(
ascii("com.sun.star.frame.Desktop"), xCC), UNO_QUERY_THROW);
return xDesktop;
}
Reference<XSpreadsheetDocument> loadComponent(const Reference<XDesktop>& xDesktop, const OUString& rPath)
{
Reference<XSpreadsheetDocument> xSpDoc;
Reference<XComponentLoader> xLoader(xDesktop, UNO_QUERY_THROW);
Sequence<PropertyValue> args;
Reference<XComponent> xComponent = xLoader->loadComponentFromURL(
rPath, ascii("_default"), 0, args);
if (!xComponent.is())
{
error("component failed to load");
return xSpDoc;
}
xSpDoc.set(xComponent, UNO_QUERY_THROW);
return xSpDoc;
}
void info(const string& msg)
{
cout << "info: " << msg << endl;
}
void error(const string& msg)
{
cerr << "error: " << msg << endl;
}
string getEnvVar(const char* name)
{
char* var = getenv(name);
if (!var)
throw GeneralException(string("failed to get environment variable ") + 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;
}
}
|