LibreOffice Module cppuhelper (master) 1
macro_expander.cxx
Go to the documentation of this file.
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
27#include <compbase2.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
37constexpr OUStringLiteral SERVICE_NAME_A = u"com.sun.star.lang.MacroExpander";
38constexpr OUStringLiteral SERVICE_NAME_B = u"com.sun.star.lang.BootstrapMacroExpander";
39constexpr OUStringLiteral IMPL_NAME = u"com.sun.star.lang.comp.cppuhelper.BootstrapMacroExpander";
40
41using namespace ::osl;
42using namespace ::com::sun::star;
43using namespace ::com::sun::star::uno;
44
45using rtl::Bootstrap;
46
47namespace cppu
48{
49
50static Bootstrap const & get_unorc()
51{
52 static rtlBootstrapHandle s_bstrap = rtl_bootstrap_args_open(getUnoIniUri().pData);
53 return *reinterpret_cast<Bootstrap const *>(&s_bstrap);
54}
55
56}
57
58namespace cppuhelper::detail {
59
60OUString expandMacros(OUString const & text) {
61 OUString t(text);
62 rtl_bootstrap_expandMacros_from_handle(
63 cppu::get_unorc().getHandle(), &t.pData);
64 return t;
65}
66
67}
68
69namespace
70{
71
72OUString s_impl_name()
73{
74 return IMPL_NAME;
75}
76
77Sequence< OUString > const & s_get_service_names()
78{
79 static const Sequence< OUString > IMPL_NAMES {
82 };
83 return IMPL_NAMES;
84}
85
87 util::XMacroExpander, lang::XServiceInfo > t_uno_impl;
88
89class Bootstrap_MacroExpander : public t_uno_impl
90{
91public:
92 Bootstrap_MacroExpander()
93 {}
94
95 // XMacroExpander impl
96 virtual OUString SAL_CALL expandMacros( OUString const & exp ) override;
97 // XServiceInfo impl
98 virtual OUString SAL_CALL getImplementationName() override;
99 virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName ) override;
100 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
101};
102
103
104// XServiceInfo impl
105
106OUString Bootstrap_MacroExpander::getImplementationName()
107{
108 return s_impl_name();
109}
110
111sal_Bool Bootstrap_MacroExpander::supportsService( OUString const & serviceName )
112{
113 return cppu::supportsService(this, serviceName);
114}
115
116Sequence< OUString > Bootstrap_MacroExpander::getSupportedServiceNames()
117{
118 return s_get_service_names();
119}
120
121// XMacroExpander impl
122
123OUString Bootstrap_MacroExpander::expandMacros( OUString const & exp )
124{
126}
127
128
129Reference< XInterface > service_create(
130 SAL_UNUSED_PARAMETER Reference< XComponentContext > const & )
131{
132 return static_cast< ::cppu::OWeakObject * >( new Bootstrap_MacroExpander );
133}
134
135}
136
137namespace cppuhelper::detail {
138
139Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory()
140{
141 Reference< lang::XSingleComponentFactory > free(::cppu::createSingleComponentFactory(
142 service_create,
143 s_impl_name(),
144 s_get_service_names() ));
145
146 uno::Environment curr_env(Environment::getCurrent());
147 uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
148
149 uno::Mapping target2curr(target_env, curr_env);
150
151 return Reference<lang::XSingleComponentFactory>(
152 static_cast<lang::XSingleComponentFactory *>(
153 target2curr.mapInterface(free.get(), cppu::UnoType<decltype(free)>::get())),
154 SAL_NO_ACQUIRE);
155}
156
157}
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
Base class to implement a UNO object supporting weak references, i.e.
Definition: weak.hxx:48
float u
constexpr OUStringLiteral IMPL_NAME
constexpr OUStringLiteral SERVICE_NAME_A
constexpr OUStringLiteral SERVICE_NAME_B
std::unique_ptr< sal_Int32[]> pData
def text(shape, orig_st)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
css::uno::Reference< css::uno::XInterface >(SAL_CALL *ComponentFactoryFunc)(css CPPUHELPER_DLLPUBLIC css::uno::Reference< css::lang::XSingleComponentFactory > SAL_CALL createSingleComponentFactory(ComponentFactoryFunc fptr, ::rtl::OUString const &rImplementationName, css::uno::Sequence< ::rtl::OUString > const &rServiceNames, rtl_ModuleCount *pModCount=NULL)
Function pointer declaration.
Definition: factory.hxx:146
OUString getUnoIniUri()
Definition: paths.cxx:55
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
A helper for implementations of com.sun.star.lang.XServiceInfo.
static Bootstrap const & get_unorc()
Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory()
OUString expandMacros(OUString const &text)
Helper function to expand macros based on the unorc/uno.ini.
const rtl::Bootstrap * Bootstrap()
unsigned char sal_Bool