Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <rtl/bootstrap.hxx>
31 : :
32 : : #include <uno/mapping.hxx>
33 : :
34 : : #include <cppuhelper/factory.hxx>
35 : : #include <cppuhelper/compbase2.hxx>
36 : : #include <cppuhelper/component_context.hxx>
37 : :
38 : : #include <com/sun/star/lang/XServiceInfo.hpp>
39 : : #include <com/sun/star/util/XMacroExpander.hpp>
40 : : #include "com/sun/star/uno/RuntimeException.hpp"
41 : :
42 : : #include "macro_expander.hxx"
43 : : #include "paths.hxx"
44 : :
45 : : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
46 : : #define SERVICE_NAME_A "com.sun.star.lang.MacroExpander"
47 : : #define SERVICE_NAME_B "com.sun.star.lang.BootstrapMacroExpander"
48 : : #define IMPL_NAME "com.sun.star.lang.comp.cppuhelper.BootstrapMacroExpander"
49 : :
50 : :
51 : : using namespace ::rtl;
52 : : using namespace ::osl;
53 : : using namespace ::com::sun::star;
54 : : using namespace ::com::sun::star::uno;
55 : :
56 : : namespace cppu
57 : : {
58 : :
59 : 52854 : Bootstrap const & get_unorc() SAL_THROW(())
60 : : {
61 : : static rtlBootstrapHandle s_bstrap = 0;
62 [ + + ]: 52854 : if (! s_bstrap)
63 : : {
64 [ + - ]: 843 : OUString iniName(getUnoIniUri());
65 : 843 : rtlBootstrapHandle bstrap = rtl_bootstrap_args_open( iniName.pData );
66 : :
67 [ + - ][ + - ]: 843 : ClearableMutexGuard guard( Mutex::getGlobalMutex() );
68 [ - + ]: 843 : if (s_bstrap)
69 : : {
70 [ # # ]: 0 : guard.clear();
71 : 0 : rtl_bootstrap_args_close( bstrap );
72 : : }
73 : : else
74 : : {
75 : 843 : s_bstrap = bstrap;
76 [ + - ]: 843 : }
77 : : }
78 : 52854 : return *(Bootstrap const *)&s_bstrap;
79 : : }
80 : :
81 : : }
82 : :
83 : : namespace cppuhelper { namespace detail {
84 : :
85 : 52854 : rtl::OUString expandMacros(rtl::OUString const & text) {
86 : 52854 : rtl::OUString t(text);
87 : : rtl_bootstrap_expandMacros_from_handle(
88 [ + - ]: 52854 : cppu::get_unorc().getHandle(), &t.pData);
89 : 52854 : return t;
90 : : }
91 : :
92 : : } }
93 : :
94 : : namespace
95 : : {
96 : :
97 : 742 : class ImplNames
98 : : {
99 : : private:
100 : : Sequence<OUString> m_aNames;
101 : : public:
102 : 742 : ImplNames() : m_aNames(2)
103 : : {
104 [ + - ][ + - ]: 742 : m_aNames[0] = OUSTR(SERVICE_NAME_A);
105 [ + - ][ + - ]: 742 : m_aNames[1] = OUSTR(SERVICE_NAME_B);
106 : 742 : }
107 : 756 : const Sequence<OUString>& getNames() const { return m_aNames; }
108 : : };
109 : :
110 : : class theImplNames : public rtl::Static<ImplNames, theImplNames> {};
111 : :
112 : 756 : inline OUString s_impl_name()
113 : : {
114 : 756 : return OUSTR(IMPL_NAME);
115 : : }
116 : :
117 : 756 : inline Sequence< OUString > const & s_get_service_names()
118 : : {
119 : 756 : return theImplNames::get().getNames();
120 : : }
121 : :
122 : : typedef ::cppu::WeakComponentImplHelper2<
123 : : util::XMacroExpander, lang::XServiceInfo > t_uno_impl;
124 : :
125 : 522 : struct mutex_holder
126 : : {
127 : : Mutex m_mutex;
128 : : };
129 : :
130 : : class Bootstrap_MacroExpander : public mutex_holder, public t_uno_impl
131 : : {
132 : : protected:
133 : : virtual void SAL_CALL disposing();
134 : :
135 : : public:
136 : 269 : inline Bootstrap_MacroExpander() SAL_THROW(())
137 : 269 : : t_uno_impl( m_mutex )
138 : 269 : {}
139 : : virtual ~Bootstrap_MacroExpander()
140 : : SAL_THROW(());
141 : :
142 : : // XMacroExpander impl
143 : : virtual OUString SAL_CALL expandMacros( OUString const & exp )
144 : : throw (lang::IllegalArgumentException);
145 : : // XServiceInfo impl
146 : : virtual OUString SAL_CALL getImplementationName()
147 : : throw (RuntimeException);
148 : : virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName )
149 : : throw (RuntimeException);
150 : : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
151 : : throw (RuntimeException);
152 : : };
153 : :
154 : : //__________________________________________________________________________________________________
155 : 269 : void Bootstrap_MacroExpander::disposing()
156 : 269 : {}
157 : : //__________________________________________________________________________________________________
158 [ + - ]: 253 : Bootstrap_MacroExpander::~Bootstrap_MacroExpander() SAL_THROW(())
159 [ - + ]: 506 : {}
160 : :
161 : : // XServiceInfo impl
162 : : //__________________________________________________________________________________________________
163 : 0 : OUString Bootstrap_MacroExpander::getImplementationName()
164 : : throw (RuntimeException)
165 : : {
166 : 0 : return s_impl_name();
167 : : }
168 : : //__________________________________________________________________________________________________
169 : 0 : sal_Bool Bootstrap_MacroExpander::supportsService( OUString const & serviceName )
170 : : throw (RuntimeException)
171 : : {
172 : 0 : Sequence< OUString > const & service_names = s_get_service_names();
173 : 0 : OUString const * p = service_names.getConstArray();
174 [ # # ]: 0 : for ( sal_Int32 nPos = service_names.getLength(); nPos--; )
175 : : {
176 [ # # ]: 0 : if (p[ nPos ].equals( serviceName ))
177 : 0 : return sal_True;
178 : : }
179 : 0 : return sal_False;
180 : : }
181 : : //__________________________________________________________________________________________________
182 : 0 : Sequence< OUString > Bootstrap_MacroExpander::getSupportedServiceNames()
183 : : throw (RuntimeException)
184 : : {
185 : 0 : return s_get_service_names();
186 : : }
187 : :
188 : : // XMacroExpander impl
189 : : //__________________________________________________________________________________________________
190 : 31907 : OUString Bootstrap_MacroExpander::expandMacros( OUString const & exp )
191 : : throw (lang::IllegalArgumentException)
192 : : {
193 : 31907 : return cppuhelper::detail::expandMacros( exp );
194 : : }
195 : :
196 : : //==================================================================================================
197 : 269 : Reference< XInterface > SAL_CALL service_create(
198 : : SAL_UNUSED_PARAMETER Reference< XComponentContext > const & )
199 : : SAL_THROW( (RuntimeException) )
200 : : {
201 [ + - ]: 269 : return static_cast< ::cppu::OWeakObject * >( new Bootstrap_MacroExpander );
202 : : }
203 : :
204 : : }
205 : :
206 : : namespace cppuhelper { namespace detail {
207 : :
208 : 756 : Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory() SAL_THROW(())
209 : : {
210 : : Reference< lang::XSingleComponentFactory > free(::cppu::createSingleComponentFactory(
211 : : service_create,
212 : : s_impl_name(),
213 [ + - ][ + - ]: 756 : s_get_service_names() ));
[ + - ]
214 : :
215 [ + - ][ + - ]: 756 : uno::Environment curr_env(Environment::getCurrent());
216 [ + - ]: 756 : uno::Environment target_env(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV))));
217 : :
218 : 756 : uno::Mapping target2curr(target_env, curr_env);
219 : :
220 : : return Reference<lang::XSingleComponentFactory>(
221 : : reinterpret_cast<lang::XSingleComponentFactory *>(
222 [ + - ][ + - ]: 756 : target2curr.mapInterface(free.get(), ::getCppuType(&free))),
[ + - ]
223 [ + - ][ + - ]: 756 : SAL_NO_ACQUIRE);
[ + - ][ + - ]
224 : : }
225 : :
226 : : } }
227 : :
228 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|