LCOV - code coverage report
Current view: top level - libreoffice/cppuhelper/source - macro_expander.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 50 84.0 %
Date: 2012-12-27 Functions: 16 19 84.2 %
Legend: Lines: hit not hit

          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             :  * 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/mapping.hxx>
      24             : 
      25             : #include <cppuhelper/factory.hxx>
      26             : #include <cppuhelper/compbase2.hxx>
      27             : #include <cppuhelper/component_context.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : 
      30             : #include <com/sun/star/lang/XServiceInfo.hpp>
      31             : #include <com/sun/star/util/XMacroExpander.hpp>
      32             : #include "com/sun/star/uno/RuntimeException.hpp"
      33             : 
      34             : #include "macro_expander.hxx"
      35             : #include "paths.hxx"
      36             : 
      37             : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
      38             : #define SERVICE_NAME_A "com.sun.star.lang.MacroExpander"
      39             : #define SERVICE_NAME_B "com.sun.star.lang.BootstrapMacroExpander"
      40             : #define IMPL_NAME "com.sun.star.lang.comp.cppuhelper.BootstrapMacroExpander"
      41             : 
      42             : 
      43             : using namespace ::rtl;
      44             : using namespace ::osl;
      45             : using namespace ::com::sun::star;
      46             : using namespace ::com::sun::star::uno;
      47             : 
      48             : namespace cppu
      49             : {
      50             : 
      51        2017 : Bootstrap const & get_unorc() SAL_THROW(())
      52             : {
      53             :     static rtlBootstrapHandle s_bstrap = 0;
      54        2017 :     if (! s_bstrap)
      55             :     {
      56         257 :         OUString iniName(getUnoIniUri());
      57         257 :         rtlBootstrapHandle bstrap = rtl_bootstrap_args_open( iniName.pData );
      58             : 
      59         257 :         ClearableMutexGuard guard( Mutex::getGlobalMutex() );
      60         257 :         if (s_bstrap)
      61             :         {
      62           0 :             guard.clear();
      63           0 :             rtl_bootstrap_args_close( bstrap );
      64             :         }
      65             :         else
      66             :         {
      67         257 :             s_bstrap = bstrap;
      68         257 :         }
      69             :     }
      70        2017 :     return *(Bootstrap const *)&s_bstrap;
      71             : }
      72             : 
      73             : }
      74             : 
      75             : namespace cppuhelper { namespace detail {
      76             : 
      77        2017 : rtl::OUString expandMacros(rtl::OUString const & text) {
      78        2017 :     rtl::OUString t(text);
      79             :     rtl_bootstrap_expandMacros_from_handle(
      80        2017 :         cppu::get_unorc().getHandle(), &t.pData);
      81        2017 :     return t;
      82             : }
      83             : 
      84             : } }
      85             : 
      86             : namespace
      87             : {
      88             : 
      89         257 : class ImplNames
      90             : {
      91             : private:
      92             :     Sequence<OUString> m_aNames;
      93             : public:
      94         257 :     ImplNames() : m_aNames(2)
      95             :     {
      96         257 :         m_aNames[0] = OUSTR(SERVICE_NAME_A);
      97         257 :         m_aNames[1] = OUSTR(SERVICE_NAME_B);
      98         257 :     }
      99         259 :     const Sequence<OUString>& getNames() const { return m_aNames; }
     100             : };
     101             : 
     102             : class theImplNames : public rtl::Static<ImplNames, theImplNames> {};
     103             : 
     104         259 : inline OUString s_impl_name()
     105             : {
     106         259 :     return OUSTR(IMPL_NAME);
     107             : }
     108             : 
     109         259 : inline Sequence< OUString > const & s_get_service_names()
     110             : {
     111         259 :     return theImplNames::get().getNames();
     112             : }
     113             : 
     114             : typedef ::cppu::WeakComponentImplHelper2<
     115             :     util::XMacroExpander, lang::XServiceInfo > t_uno_impl;
     116             : 
     117          29 : struct mutex_holder
     118             : {
     119             :     Mutex m_mutex;
     120             : };
     121             : 
     122             : class Bootstrap_MacroExpander : public mutex_holder, public t_uno_impl
     123             : {
     124             : protected:
     125             :     virtual void SAL_CALL disposing();
     126             : 
     127             : public:
     128          18 :     inline Bootstrap_MacroExpander() SAL_THROW(())
     129          18 :         : t_uno_impl( m_mutex )
     130          18 :         {}
     131             :     virtual ~Bootstrap_MacroExpander()
     132             :         SAL_THROW(());
     133             : 
     134             :     // XMacroExpander impl
     135             :     virtual OUString SAL_CALL expandMacros( OUString const & exp )
     136             :         throw (lang::IllegalArgumentException);
     137             :     // XServiceInfo impl
     138             :     virtual OUString SAL_CALL getImplementationName()
     139             :         throw (RuntimeException);
     140             :     virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName )
     141             :         throw (RuntimeException);
     142             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
     143             :         throw (RuntimeException);
     144             : };
     145             : 
     146             : //__________________________________________________________________________________________________
     147          18 : void Bootstrap_MacroExpander::disposing()
     148          18 : {}
     149             : //__________________________________________________________________________________________________
     150          22 : Bootstrap_MacroExpander::~Bootstrap_MacroExpander() SAL_THROW(())
     151          22 : {}
     152             : 
     153             : // XServiceInfo impl
     154             : //__________________________________________________________________________________________________
     155           0 : OUString Bootstrap_MacroExpander::getImplementationName()
     156             :     throw (RuntimeException)
     157             : {
     158           0 :     return s_impl_name();
     159             : }
     160             : //__________________________________________________________________________________________________
     161           0 : sal_Bool Bootstrap_MacroExpander::supportsService( OUString const & serviceName )
     162             :     throw (RuntimeException)
     163             : {
     164           0 :     return cppu::supportsService(this, serviceName);
     165             : }
     166             : //__________________________________________________________________________________________________
     167           0 : Sequence< OUString > Bootstrap_MacroExpander::getSupportedServiceNames()
     168             :     throw (RuntimeException)
     169             : {
     170           0 :     return s_get_service_names();
     171             : }
     172             : 
     173             : // XMacroExpander impl
     174             : //__________________________________________________________________________________________________
     175         163 : OUString Bootstrap_MacroExpander::expandMacros( OUString const & exp )
     176             :     throw (lang::IllegalArgumentException)
     177             : {
     178         163 :     return cppuhelper::detail::expandMacros( exp );
     179             : }
     180             : 
     181             : //==================================================================================================
     182          18 : Reference< XInterface > SAL_CALL service_create(
     183             :     SAL_UNUSED_PARAMETER Reference< XComponentContext > const & )
     184             :     SAL_THROW( (RuntimeException) )
     185             : {
     186          18 :     return static_cast< ::cppu::OWeakObject * >( new Bootstrap_MacroExpander );
     187             : }
     188             : 
     189             : }
     190             : 
     191             : namespace cppuhelper { namespace detail {
     192             : 
     193         259 : Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory() SAL_THROW(())
     194             : {
     195             :     Reference< lang::XSingleComponentFactory > free(::cppu::createSingleComponentFactory(
     196             :                                                         service_create,
     197             :                                                         s_impl_name(),
     198         259 :                                                         s_get_service_names() ));
     199             : 
     200         259 :     uno::Environment curr_env(Environment::getCurrent());
     201         259 :     uno::Environment target_env(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV))));
     202             : 
     203         259 :     uno::Mapping target2curr(target_env, curr_env);
     204             : 
     205             :     return Reference<lang::XSingleComponentFactory>(
     206             :         reinterpret_cast<lang::XSingleComponentFactory *>(
     207         259 :             target2curr.mapInterface(free.get(), ::getCppuType(&free))),
     208         259 :         SAL_NO_ACQUIRE);
     209             : }
     210             : 
     211             : } }
     212             : 
     213             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10