Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <sal/config.h>
11 :
12 : #include <cassert>
13 : #include <vector>
14 :
15 : #include <com/sun/star/uno/DeploymentException.hpp>
16 : #include <com/sun/star/uno/Any.hxx>
17 : #include <com/sun/star/uno/Reference.hxx>
18 : #include <com/sun/star/uno/XComponentContext.hpp>
19 : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
20 : #include <cppuhelper/bootstrap.hxx>
21 : #include <cppuhelper/component_context.hxx>
22 : #include <rtl/bootstrap.hxx>
23 : #include <rtl/ref.hxx>
24 : #include <rtl/ustring.hxx>
25 :
26 : using rtl::OUString;
27 :
28 : #include "macro_expander.hxx"
29 : #include "paths.hxx"
30 : #include "servicemanager.hxx"
31 : #include "typemanager.hxx"
32 :
33 : namespace {
34 :
35 1038 : rtl::OUString getBootstrapVariable(
36 : rtl::Bootstrap const & bootstrap, rtl::OUString const & name)
37 : {
38 1038 : rtl::OUString v;
39 1038 : if (!bootstrap.getFrom(name, v)) {
40 : throw css::uno::DeploymentException(
41 0 : "Cannot obtain " + name + " from uno ini");
42 : }
43 1038 : return v;
44 : }
45 :
46 : }
47 :
48 : css::uno::Reference< css::uno::XComponentContext >
49 519 : cppu::defaultBootstrap_InitialComponentContext(rtl::OUString const & iniUri)
50 : {
51 519 : rtl::Bootstrap bs(iniUri);
52 519 : if (bs.getHandle() == 0) {
53 : throw css::uno::DeploymentException(
54 0 : "Cannot open uno ini " + iniUri);
55 : }
56 : rtl::Reference< cppuhelper::ServiceManager > smgr(
57 1038 : new cppuhelper::ServiceManager);
58 519 : smgr->init(getBootstrapVariable(bs, "UNO_SERVICES"));
59 1038 : rtl::Reference< cppuhelper::TypeManager > tmgr(new cppuhelper::TypeManager);
60 519 : tmgr->init(getBootstrapVariable(bs, "UNO_TYPES"));
61 1038 : cppu::ContextEntry_Init entry;
62 1038 : std::vector< cppu::ContextEntry_Init > context_values;
63 : context_values.push_back(
64 : cppu::ContextEntry_Init(
65 : "/singletons/com.sun.star.lang.theServiceManager",
66 : css::uno::makeAny(
67 : css::uno::Reference< css::uno::XInterface >(
68 519 : static_cast< cppu::OWeakObject * >(smgr.get()))),
69 519 : false));
70 : context_values.push_back(
71 : cppu::ContextEntry_Init(
72 : "/singletons/com.sun.star.reflection.theTypeDescriptionManager",
73 : css::uno::makeAny(
74 : css::uno::Reference< css::uno::XInterface >(
75 519 : static_cast< cppu::OWeakObject * >(tmgr.get()))),
76 519 : false));
77 : context_values.push_back( //TODO: from services.rdb?
78 : cppu::ContextEntry_Init(
79 : "/singletons/com.sun.star.util.theMacroExpander",
80 : css::uno::makeAny(
81 : cppuhelper::detail::create_bootstrap_macro_expander_factory()),
82 519 : true));
83 519 : smgr->addSingletonContextEntries(&context_values);
84 : context_values.push_back(
85 : cppu::ContextEntry_Init(
86 : "/services/com.sun.star.security.AccessController/mode",
87 519 : css::uno::makeAny(rtl::OUString("off")), false));
88 : context_values.push_back(
89 : cppu::ContextEntry_Init(
90 : "/singletons/com.sun.star.security.theAccessController",
91 : css::uno::makeAny(
92 : rtl::OUString("com.sun.star.security.AccessController")),
93 519 : true));
94 : assert(!context_values.empty());
95 : css::uno::Reference< css::uno::XComponentContext > context(
96 : createComponentContext(
97 1038 : &context_values[0], context_values.size(),
98 1557 : css::uno::Reference< css::uno::XComponentContext >()));
99 519 : smgr->setContext(context);
100 519 : cppu::installTypeDescriptionManager(tmgr.get());
101 1038 : return context;
102 : }
103 :
104 : css::uno::Reference< css::uno::XComponentContext >
105 519 : cppu::defaultBootstrap_InitialComponentContext()
106 : {
107 519 : return defaultBootstrap_InitialComponentContext(getUnoIniUri());
108 : }
109 :
110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|