2010-10-14 08:30:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-12-05 11:46:50 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2002-06-14 12:20:20 +00:00
|
|
|
|
2006-09-16 11:41:36 +00:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
#include <rtl/bootstrap.hxx>
|
|
|
|
|
2013-12-16 16:45:46 +01:00
|
|
|
#include <uno/lbnames.h>
|
2007-05-09 12:25:36 +00:00
|
|
|
#include <uno/mapping.hxx>
|
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
#include <cppuhelper/factory.hxx>
|
2016-12-07 08:59:42 +01:00
|
|
|
#include <cppuhelper/compbase.hxx>
|
2002-09-05 15:13:52 +00:00
|
|
|
#include <cppuhelper/component_context.hxx>
|
2012-09-14 19:27:00 +02:00
|
|
|
#include <cppuhelper/supportsservice.hxx>
|
2002-06-14 12:20:20 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
|
|
|
#include <com/sun/star/util/XMacroExpander.hpp>
|
2014-06-04 16:23:19 +02:00
|
|
|
#include <com/sun/star/uno/RuntimeException.hpp>
|
2002-06-14 12:20:20 +00:00
|
|
|
|
2007-10-15 10:53:06 +00:00
|
|
|
#include "macro_expander.hxx"
|
2012-04-20 22:46:42 +02:00
|
|
|
#include "paths.hxx"
|
2007-10-15 10:53:06 +00:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
#define SERVICE_NAME_A "com.sun.star.lang.MacroExpander"
|
|
|
|
#define SERVICE_NAME_B "com.sun.star.lang.BootstrapMacroExpander"
|
|
|
|
#define IMPL_NAME "com.sun.star.lang.comp.cppuhelper.BootstrapMacroExpander"
|
|
|
|
|
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
|
2013-08-19 11:49:57 +02:00
|
|
|
using rtl::Bootstrap;
|
|
|
|
using rtl::OUString;
|
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
namespace cppu
|
|
|
|
{
|
2012-04-20 22:46:42 +02:00
|
|
|
|
2014-06-05 08:08:06 +02:00
|
|
|
Bootstrap const & get_unorc()
|
2012-04-20 22:46:42 +02:00
|
|
|
{
|
2015-11-10 10:13:11 +01:00
|
|
|
static rtlBootstrapHandle s_bstrap = nullptr;
|
2012-04-20 22:46:42 +02:00
|
|
|
if (! s_bstrap)
|
|
|
|
{
|
|
|
|
OUString iniName(getUnoIniUri());
|
|
|
|
rtlBootstrapHandle bstrap = rtl_bootstrap_args_open( iniName.pData );
|
|
|
|
|
|
|
|
ClearableMutexGuard guard( Mutex::getGlobalMutex() );
|
|
|
|
if (s_bstrap)
|
|
|
|
{
|
|
|
|
guard.clear();
|
|
|
|
rtl_bootstrap_args_close( bstrap );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_bstrap = bstrap;
|
|
|
|
}
|
|
|
|
}
|
2015-03-28 19:00:21 +01:00
|
|
|
return *reinterpret_cast<Bootstrap const *>(&s_bstrap);
|
2012-04-20 22:46:42 +02:00
|
|
|
}
|
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
}
|
|
|
|
|
2007-10-15 10:53:06 +00:00
|
|
|
namespace cppuhelper { namespace detail {
|
|
|
|
|
|
|
|
rtl::OUString expandMacros(rtl::OUString const & text) {
|
|
|
|
rtl::OUString t(text);
|
|
|
|
rtl_bootstrap_expandMacros_from_handle(
|
|
|
|
cppu::get_unorc().getHandle(), &t.pData);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
namespace
|
|
|
|
{
|
2011-04-02 17:20:24 +01:00
|
|
|
|
|
|
|
class ImplNames
|
2002-06-14 12:20:20 +00:00
|
|
|
{
|
2011-04-02 17:20:24 +01:00
|
|
|
private:
|
|
|
|
Sequence<OUString> m_aNames;
|
|
|
|
public:
|
|
|
|
ImplNames() : m_aNames(2)
|
2002-06-14 12:20:20 +00:00
|
|
|
{
|
2013-01-30 11:44:23 +01:00
|
|
|
m_aNames[0] = SERVICE_NAME_A;
|
|
|
|
m_aNames[1] = SERVICE_NAME_B;
|
2002-06-14 12:20:20 +00:00
|
|
|
}
|
2011-04-02 17:20:24 +01:00
|
|
|
const Sequence<OUString>& getNames() const { return m_aNames; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class theImplNames : public rtl::Static<ImplNames, theImplNames> {};
|
|
|
|
|
|
|
|
inline OUString s_impl_name()
|
|
|
|
{
|
2013-01-30 11:44:23 +01:00
|
|
|
return OUString(IMPL_NAME);
|
2011-04-02 17:20:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Sequence< OUString > const & s_get_service_names()
|
|
|
|
{
|
|
|
|
return theImplNames::get().getNames();
|
2002-06-14 12:20:20 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 08:59:42 +01:00
|
|
|
typedef cppu::WeakComponentImplHelper<
|
2007-10-15 10:53:06 +00:00
|
|
|
util::XMacroExpander, lang::XServiceInfo > t_uno_impl;
|
2002-06-14 12:20:20 +00:00
|
|
|
|
|
|
|
struct mutex_holder
|
|
|
|
{
|
|
|
|
Mutex m_mutex;
|
|
|
|
};
|
2011-04-02 17:20:24 +01:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
class Bootstrap_MacroExpander : public mutex_holder, public t_uno_impl
|
|
|
|
{
|
|
|
|
protected:
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void SAL_CALL disposing() override;
|
2002-06-14 12:20:20 +00:00
|
|
|
|
|
|
|
public:
|
2014-06-05 08:08:06 +02:00
|
|
|
inline Bootstrap_MacroExpander()
|
2007-10-15 10:53:06 +00:00
|
|
|
: t_uno_impl( m_mutex )
|
2002-06-14 12:20:20 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
// XMacroExpander impl
|
|
|
|
virtual OUString SAL_CALL expandMacros( OUString const & exp )
|
2015-10-12 16:04:04 +02:00
|
|
|
throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception) override;
|
2002-06-14 12:20:20 +00:00
|
|
|
// XServiceInfo impl
|
|
|
|
virtual OUString SAL_CALL getImplementationName()
|
2015-10-12 16:04:04 +02:00
|
|
|
throw (RuntimeException, std::exception) override;
|
2002-06-14 12:20:20 +00:00
|
|
|
virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName )
|
2015-10-12 16:04:04 +02:00
|
|
|
throw (RuntimeException, std::exception) override;
|
2002-06-14 12:20:20 +00:00
|
|
|
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames()
|
2015-10-12 16:04:04 +02:00
|
|
|
throw (RuntimeException, std::exception) override;
|
2002-06-14 12:20:20 +00:00
|
|
|
};
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
void Bootstrap_MacroExpander::disposing()
|
2007-10-15 10:53:06 +00:00
|
|
|
{}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
// XServiceInfo impl
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
OUString Bootstrap_MacroExpander::getImplementationName()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw (RuntimeException, std::exception)
|
2002-06-14 12:20:20 +00:00
|
|
|
{
|
2004-06-25 16:38:00 +00:00
|
|
|
return s_impl_name();
|
2002-06-14 12:20:20 +00:00
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
sal_Bool Bootstrap_MacroExpander::supportsService( OUString const & serviceName )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw (RuntimeException, std::exception)
|
2002-06-14 12:20:20 +00:00
|
|
|
{
|
2012-09-14 19:27:00 +02:00
|
|
|
return cppu::supportsService(this, serviceName);
|
2002-06-14 12:20:20 +00:00
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
Sequence< OUString > Bootstrap_MacroExpander::getSupportedServiceNames()
|
2014-02-25 21:31:58 +01:00
|
|
|
throw (RuntimeException, std::exception)
|
2002-06-14 12:20:20 +00:00
|
|
|
{
|
|
|
|
return s_get_service_names();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XMacroExpander impl
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
OUString Bootstrap_MacroExpander::expandMacros( OUString const & exp )
|
2014-05-24 15:33:17 +01:00
|
|
|
throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
|
2002-06-14 12:20:20 +00:00
|
|
|
{
|
2007-10-15 10:53:06 +00:00
|
|
|
return cppuhelper::detail::expandMacros( exp );
|
2002-06-14 12:20:20 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 18:02:27 +01:00
|
|
|
|
2002-06-14 12:20:20 +00:00
|
|
|
Reference< XInterface > SAL_CALL service_create(
|
2012-01-21 15:21:16 +01:00
|
|
|
SAL_UNUSED_PARAMETER Reference< XComponentContext > const & )
|
2002-06-14 12:20:20 +00:00
|
|
|
{
|
2012-01-21 15:21:16 +01:00
|
|
|
return static_cast< ::cppu::OWeakObject * >( new Bootstrap_MacroExpander );
|
2002-06-14 12:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-18 15:59:58 +02:00
|
|
|
namespace cppuhelper { namespace detail {
|
2002-06-14 12:20:20 +00:00
|
|
|
|
2014-06-05 08:08:06 +02:00
|
|
|
Reference< lang::XSingleComponentFactory > create_bootstrap_macro_expander_factory()
|
2002-06-14 12:20:20 +00:00
|
|
|
{
|
2007-05-09 12:25:36 +00:00
|
|
|
Reference< lang::XSingleComponentFactory > free(::cppu::createSingleComponentFactory(
|
|
|
|
service_create,
|
|
|
|
s_impl_name(),
|
|
|
|
s_get_service_names() ));
|
|
|
|
|
|
|
|
uno::Environment curr_env(Environment::getCurrent());
|
2013-12-16 16:45:46 +01:00
|
|
|
uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
|
2007-05-09 12:25:36 +00:00
|
|
|
|
|
|
|
uno::Mapping target2curr(target_env, curr_env);
|
|
|
|
|
|
|
|
return Reference<lang::XSingleComponentFactory>(
|
2015-03-31 13:13:09 +02:00
|
|
|
static_cast<lang::XSingleComponentFactory *>(
|
2015-04-01 08:38:16 +02:00
|
|
|
target2curr.mapInterface(free.get(), cppu::UnoType<decltype(free)>::get())),
|
2007-05-09 12:25:36 +00:00
|
|
|
SAL_NO_ACQUIRE);
|
2002-06-14 12:20:20 +00:00
|
|
|
}
|
|
|
|
|
2012-04-18 15:59:58 +02:00
|
|
|
} }
|
2010-10-14 08:30:07 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|