1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <rtl/bootstrap.hxx>
23 #include <uno/lbnames.h>
24 #include <uno/mapping.hxx>
26 #include <cppuhelper/factory.hxx>
27 #include <cppuhelper/compbase.hxx>
28 #include <cppuhelper/supportsservice.hxx>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
32 #include <com/sun/star/util/XMacroExpander.hpp>
34 #include "macro_expander.hxx"
37 #define SERVICE_NAME_A "com.sun.star.lang.MacroExpander"
38 #define SERVICE_NAME_B "com.sun.star.lang.BootstrapMacroExpander"
39 #define IMPL_NAME "com.sun.star.lang.comp.cppuhelper.BootstrapMacroExpander"
41 using namespace ::osl
;
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::uno
;
50 static Bootstrap
const & get_unorc()
52 static rtlBootstrapHandle s_bstrap
= rtl_bootstrap_args_open(getUnoIniUri().pData
);
53 return *reinterpret_cast<Bootstrap
const *>(&s_bstrap
);
58 namespace cppuhelper::detail
{
60 OUString
expandMacros(OUString
const & text
) {
62 rtl_bootstrap_expandMacros_from_handle(
63 cppu::get_unorc().getHandle(), &t
.pData
);
75 Sequence
<OUString
> m_aNames
;
77 ImplNames() : m_aNames(2)
79 m_aNames
[0] = SERVICE_NAME_A
;
80 m_aNames
[1] = SERVICE_NAME_B
;
82 const Sequence
<OUString
>& getNames() const { return m_aNames
; }
85 class theImplNames
: public rtl::Static
<ImplNames
, theImplNames
> {};
87 OUString
s_impl_name()
92 Sequence
< OUString
> const & s_get_service_names()
94 return theImplNames::get().getNames();
97 typedef cppu::WeakComponentImplHelper
<
98 util::XMacroExpander
, lang::XServiceInfo
> t_uno_impl
;
105 class Bootstrap_MacroExpander
: public mutex_holder
, public t_uno_impl
108 virtual void SAL_CALL
disposing() override
;
111 Bootstrap_MacroExpander()
112 : t_uno_impl( m_mutex
)
115 // XMacroExpander impl
116 virtual OUString SAL_CALL
expandMacros( OUString
const & exp
) override
;
118 virtual OUString SAL_CALL
getImplementationName() override
;
119 virtual sal_Bool SAL_CALL
supportsService( OUString
const & serviceName
) override
;
120 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
124 void Bootstrap_MacroExpander::disposing()
129 OUString
Bootstrap_MacroExpander::getImplementationName()
131 return s_impl_name();
134 sal_Bool
Bootstrap_MacroExpander::supportsService( OUString
const & serviceName
)
136 return cppu::supportsService(this, serviceName
);
139 Sequence
< OUString
> Bootstrap_MacroExpander::getSupportedServiceNames()
141 return s_get_service_names();
144 // XMacroExpander impl
146 OUString
Bootstrap_MacroExpander::expandMacros( OUString
const & exp
)
148 return cppuhelper::detail::expandMacros( exp
);
152 Reference
< XInterface
> service_create(
153 SAL_UNUSED_PARAMETER Reference
< XComponentContext
> const & )
155 return static_cast< ::cppu::OWeakObject
* >( new Bootstrap_MacroExpander
);
160 namespace cppuhelper::detail
{
162 Reference
< lang::XSingleComponentFactory
> create_bootstrap_macro_expander_factory()
164 Reference
< lang::XSingleComponentFactory
> free(::cppu::createSingleComponentFactory(
167 s_get_service_names() ));
169 uno::Environment
curr_env(Environment::getCurrent());
170 uno::Environment
target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME
);
172 uno::Mapping
target2curr(target_env
, curr_env
);
174 return Reference
<lang::XSingleComponentFactory
>(
175 static_cast<lang::XSingleComponentFactory
*>(
176 target2curr
.mapInterface(free
.get(), cppu::UnoType
<decltype(free
)>::get())),
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */