/src/libreoffice/cppuhelper/source/macro_expander.cxx
Line | Count | Source |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | |
21 | | #include <rtl/bootstrap.hxx> |
22 | | |
23 | | #include <uno/lbnames.h> |
24 | | #include <uno/mapping.hxx> |
25 | | |
26 | | #include <cppuhelper/factory.hxx> |
27 | | #include <compbase2.hxx> |
28 | | #include <cppuhelper/supportsservice.hxx> |
29 | | |
30 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
31 | | #include <com/sun/star/lang/XSingleComponentFactory.hpp> |
32 | | #include <com/sun/star/util/XMacroExpander.hpp> |
33 | | |
34 | | #include "macro_expander.hxx" |
35 | | #include "paths.hxx" |
36 | | |
37 | | constexpr OUString SERVICE_NAME_A = u"com.sun.star.lang.MacroExpander"_ustr; |
38 | | constexpr OUString SERVICE_NAME_B = u"com.sun.star.lang.BootstrapMacroExpander"_ustr; |
39 | | constexpr OUStringLiteral IMPL_NAME = u"com.sun.star.lang.comp.cppuhelper.BootstrapMacroExpander"; |
40 | | |
41 | | using namespace ::com::sun::star; |
42 | | using namespace ::com::sun::star::uno; |
43 | | |
44 | | using rtl::Bootstrap; |
45 | | |
46 | | namespace cppu |
47 | | { |
48 | | |
49 | | static Bootstrap const & get_unorc() |
50 | 0 | { |
51 | 0 | static rtlBootstrapHandle s_bstrap = rtl_bootstrap_args_open(getUnoIniUri().pData); |
52 | 0 | return *reinterpret_cast<Bootstrap const *>(&s_bstrap); |
53 | 0 | } |
54 | | |
55 | | } |
56 | | |
57 | | namespace cppuhelper::detail { |
58 | | |
59 | 0 | OUString expandMacros(OUString const & text) { |
60 | 0 | OUString t(text); |
61 | 0 | rtl_bootstrap_expandMacros_from_handle( |
62 | 0 | cppu::get_unorc().getHandle(), &t.pData); |
63 | 0 | return t; |
64 | 0 | } |
65 | | |
66 | | } |
67 | | |
68 | | namespace |
69 | | { |
70 | | |
71 | | OUString s_impl_name() |
72 | 106 | { |
73 | 106 | return IMPL_NAME; |
74 | 106 | } |
75 | | |
76 | | Sequence< OUString > const & s_get_service_names() |
77 | 106 | { |
78 | 106 | static const Sequence< OUString > IMPL_NAMES { |
79 | 106 | SERVICE_NAME_A, |
80 | 106 | SERVICE_NAME_B |
81 | 106 | }; |
82 | 106 | return IMPL_NAMES; |
83 | 106 | } |
84 | | |
85 | | typedef cppuhelper::WeakComponentImplHelper2< |
86 | | util::XMacroExpander, lang::XServiceInfo > t_uno_impl; |
87 | | |
88 | | class Bootstrap_MacroExpander : public t_uno_impl |
89 | | { |
90 | | public: |
91 | | Bootstrap_MacroExpander() |
92 | 0 | {} |
93 | | |
94 | | // XMacroExpander impl |
95 | | virtual OUString SAL_CALL expandMacros( OUString const & exp ) override; |
96 | | // XServiceInfo impl |
97 | | virtual OUString SAL_CALL getImplementationName() override; |
98 | | virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName ) override; |
99 | | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override; |
100 | | }; |
101 | | |
102 | | |
103 | | // XServiceInfo impl |
104 | | |
105 | | OUString Bootstrap_MacroExpander::getImplementationName() |
106 | 0 | { |
107 | 0 | return s_impl_name(); |
108 | 0 | } |
109 | | |
110 | | sal_Bool Bootstrap_MacroExpander::supportsService( OUString const & serviceName ) |
111 | 0 | { |
112 | 0 | return cppu::supportsService(this, serviceName); |
113 | 0 | } |
114 | | |
115 | | Sequence< OUString > Bootstrap_MacroExpander::getSupportedServiceNames() |
116 | 0 | { |
117 | 0 | return s_get_service_names(); |
118 | 0 | } |
119 | | |
120 | | // XMacroExpander impl |
121 | | |
122 | | OUString Bootstrap_MacroExpander::expandMacros( OUString const & exp ) |
123 | 0 | { |
124 | 0 | return cppuhelper::detail::expandMacros( exp ); |
125 | 0 | } |
126 | | |
127 | | |
128 | | Reference< XInterface > service_create( |
129 | | SAL_UNUSED_PARAMETER Reference< XComponentContext > const & ) |
130 | 0 | { |
131 | 0 | return static_cast< ::cppu::OWeakObject * >( new Bootstrap_MacroExpander ); |
132 | 0 | } |
133 | | |
134 | | } |
135 | | |
136 | | namespace cppuhelper::detail { |
137 | | |
138 | | Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory() |
139 | 106 | { |
140 | 106 | Reference< lang::XSingleComponentFactory > free(::cppu::createSingleComponentFactory( |
141 | 106 | service_create, |
142 | 106 | s_impl_name(), |
143 | 106 | s_get_service_names() )); |
144 | | |
145 | 106 | uno::Environment curr_env(Environment::getCurrent()); |
146 | 106 | uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME); |
147 | | |
148 | 106 | uno::Mapping target2curr(target_env, curr_env); |
149 | | |
150 | 106 | return Reference<lang::XSingleComponentFactory>( |
151 | 106 | static_cast<lang::XSingleComponentFactory *>( |
152 | 106 | target2curr.mapInterface(free.get(), cppu::UnoType<decltype(free)>::get())), |
153 | 106 | SAL_NO_ACQUIRE); |
154 | 106 | } |
155 | | |
156 | | } |
157 | | |
158 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |