2001-10-11 08:40:44 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 03:24:49 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
2005-09-08 03:24:49 -05:00
|
|
|
* $RCSfile: bootstrap.cxx,v $
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
2006-12-01 10:18:20 -06:00
|
|
|
* $Revision: 1.28 $
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
2006-12-01 10:18:20 -06:00
|
|
|
* last change: $Author: rt $ $Date: 2006-12-01 17:18:20 $
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
2005-09-08 03:24:49 -05:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 03:24:49 -05:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
2005-09-08 03:24:49 -05:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
2005-09-08 03:24:49 -05:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
2005-09-08 03:24:49 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2001-10-11 08:40:44 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 06:39:21 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_cppuhelper.hxx"
|
|
|
|
|
2002-02-21 04:44:33 -06:00
|
|
|
#include <string.h>
|
2001-10-11 08:40:44 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2003-03-20 05:26:21 -06:00
|
|
|
#include "rtl/process.h"
|
|
|
|
#include "rtl/bootstrap.hxx"
|
2004-05-28 09:58:42 -05:00
|
|
|
#include "rtl/random.h"
|
2003-03-20 05:26:21 -06:00
|
|
|
#include "rtl/string.hxx"
|
|
|
|
#include "rtl/ustrbuf.hxx"
|
2004-04-13 06:27:38 -05:00
|
|
|
#include "rtl/uri.hxx"
|
2003-04-15 10:34:00 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2003-03-20 05:26:21 -06:00
|
|
|
#include "rtl/strbuf.hxx"
|
2001-10-11 08:40:44 -05:00
|
|
|
#endif
|
2003-03-20 05:26:21 -06:00
|
|
|
#include "osl/diagnose.h"
|
|
|
|
#include "osl/file.hxx"
|
|
|
|
#include "osl/module.hxx"
|
|
|
|
#include "osl/security.hxx"
|
2004-05-28 09:58:42 -05:00
|
|
|
#include "osl/thread.hxx"
|
2003-03-20 05:26:21 -06:00
|
|
|
|
|
|
|
#include "cppuhelper/shlib.hxx"
|
|
|
|
#include "cppuhelper/bootstrap.hxx"
|
|
|
|
#include "cppuhelper/component_context.hxx"
|
|
|
|
#include "cppuhelper/access_control.hxx"
|
|
|
|
|
|
|
|
#include "com/sun/star/uno/XComponentContext.hpp"
|
|
|
|
#include "com/sun/star/uno/XCurrentContext.hpp"
|
|
|
|
|
|
|
|
#include "com/sun/star/lang/XSingleServiceFactory.hpp"
|
|
|
|
#include "com/sun/star/lang/XSingleComponentFactory.hpp"
|
|
|
|
#include "com/sun/star/lang/XInitialization.hpp"
|
|
|
|
#include "com/sun/star/lang/XServiceInfo.hpp"
|
|
|
|
#include "com/sun/star/registry/XSimpleRegistry.hpp"
|
|
|
|
#include "com/sun/star/container/XSet.hpp"
|
|
|
|
#include "com/sun/star/beans/PropertyValue.hpp"
|
2004-04-13 06:27:38 -05:00
|
|
|
#include "com/sun/star/io/IOException.hpp"
|
2004-07-23 09:02:43 -05:00
|
|
|
#include "com/sun/star/bridge/UnoUrlResolver.hpp"
|
2004-05-28 09:58:42 -05:00
|
|
|
#include "com/sun/star/bridge/XUnoUrlResolver.hpp"
|
2001-10-11 08:40:44 -05:00
|
|
|
|
|
|
|
#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
|
2004-05-28 09:58:42 -05:00
|
|
|
#define ARLEN(x) sizeof (x) / sizeof *(x)
|
2001-10-11 08:40:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
using namespace ::rtl;
|
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
|
|
|
|
namespace cppu
|
|
|
|
{
|
|
|
|
|
2003-03-20 05:26:21 -06:00
|
|
|
OUString const & get_this_libpath()
|
|
|
|
{
|
|
|
|
static OUString s_path;
|
|
|
|
if (0 == s_path.getLength())
|
|
|
|
{
|
|
|
|
OUString path;
|
2006-10-27 06:13:07 -05:00
|
|
|
Module::getUrlFromAddress( reinterpret_cast<oslGenericFunction>(get_this_libpath), path );
|
2003-03-20 05:26:21 -06:00
|
|
|
path = path.copy( 0, path.lastIndexOf( '/' ) );
|
|
|
|
MutexGuard guard( Mutex::getGlobalMutex() );
|
|
|
|
if (0 == s_path.getLength())
|
|
|
|
s_path = path;
|
|
|
|
}
|
|
|
|
return s_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bootstrap const & get_unorc() SAL_THROW( () )
|
|
|
|
{
|
|
|
|
static rtlBootstrapHandle s_bstrap = 0;
|
|
|
|
if (! s_bstrap)
|
|
|
|
{
|
2003-04-23 10:27:08 -05:00
|
|
|
OUString iniName(
|
|
|
|
get_this_libpath() + OUSTR("/" SAL_CONFIGFILE("uno")) );
|
2003-03-20 05:26:21 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *(Bootstrap const *)&s_bstrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
void addFactories(
|
|
|
|
char const * const * ppNames /* lib, implname, ..., 0 */,
|
|
|
|
OUString const & bootstrapPath,
|
|
|
|
Reference< lang::XMultiComponentFactory > const & xMgr,
|
|
|
|
Reference< registry::XRegistryKey > const & xKey )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
|
|
|
Reference< container::XSet > xSet( xMgr, UNO_QUERY );
|
|
|
|
OSL_ASSERT( xSet.is() );
|
|
|
|
Reference< lang::XMultiServiceFactory > xSF( xMgr, UNO_QUERY );
|
|
|
|
|
|
|
|
while (*ppNames)
|
|
|
|
{
|
|
|
|
OUString lib( OUString::createFromAscii( *ppNames++ ) );
|
|
|
|
OUString implName( OUString::createFromAscii( *ppNames++ ) );
|
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
Any aFac( makeAny( loadSharedLibComponentFactory(
|
|
|
|
lib, bootstrapPath, implName, xSF, xKey ) ) );
|
2001-10-11 08:40:44 -05:00
|
|
|
xSet->insert( aFac );
|
2003-04-15 10:34:00 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-10-11 08:40:44 -05:00
|
|
|
if (xSet->has( aFac ))
|
|
|
|
{
|
|
|
|
Reference< lang::XServiceInfo > xInfo;
|
|
|
|
if (aFac >>= xInfo)
|
|
|
|
{
|
2003-04-23 10:27:08 -05:00
|
|
|
::fprintf(
|
|
|
|
stderr, "> implementation %s supports: ", ppNames[ -1 ] );
|
|
|
|
Sequence< OUString > supported(
|
|
|
|
xInfo->getSupportedServiceNames() );
|
2001-10-11 08:40:44 -05:00
|
|
|
for ( sal_Int32 nPos = supported.getLength(); nPos--; )
|
|
|
|
{
|
|
|
|
OString str( OUStringToOString(
|
|
|
|
supported[ nPos ], RTL_TEXTENCODING_ASCII_US ) );
|
|
|
|
::fprintf( stderr, nPos ? "%s, " : "%s\n", str.getStr() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
::fprintf(
|
|
|
|
stderr,
|
2003-04-23 10:27:08 -05:00
|
|
|
"> implementation %s provides NO lang::XServiceInfo!!!\n",
|
|
|
|
ppNames[ -1 ] );
|
2001-10-11 08:40:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2003-04-15 10:34:00 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2001-10-11 08:40:44 -05:00
|
|
|
if (! xSet->has( aFac ))
|
|
|
|
{
|
|
|
|
OStringBuffer buf( 64 );
|
|
|
|
buf.append( "### failed inserting shared lib \"" );
|
|
|
|
buf.append( ppNames[ -2 ] );
|
|
|
|
buf.append( "\"!!!" );
|
|
|
|
OString str( buf.makeStringAndClear() );
|
|
|
|
OSL_ENSURE( 0, str.getStr() );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// private forward decl
|
|
|
|
Reference< lang::XMultiComponentFactory > bootstrapInitialSF(
|
|
|
|
OUString const & rBootstrapPath )
|
|
|
|
SAL_THROW( (Exception) );
|
2003-04-23 10:27:08 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
Reference< XComponentContext > bootstrapInitialContext(
|
|
|
|
Reference< lang::XMultiComponentFactory > const & xSF,
|
|
|
|
Reference< registry::XSimpleRegistry > const & types_xRegistry,
|
|
|
|
Reference< registry::XSimpleRegistry > const & services_xRegistry,
|
2002-01-11 03:06:02 -06:00
|
|
|
OUString const & rBootstrapPath, Bootstrap const & bootstrap )
|
2001-10-11 08:40:44 -05:00
|
|
|
SAL_THROW( (Exception) );
|
|
|
|
|
|
|
|
Reference< XComponentContext > SAL_CALL createInitialCfgComponentContext(
|
|
|
|
ContextEntry_Init const * pEntries, sal_Int32 nEntries,
|
|
|
|
Reference< XComponentContext > const & xDelegate )
|
|
|
|
SAL_THROW( () );
|
2003-04-23 10:27:08 -05:00
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
Reference< registry::XSimpleRegistry > SAL_CALL createRegistryWrapper(
|
|
|
|
const Reference< XComponentContext >& xContext );
|
|
|
|
|
2006-06-19 04:32:32 -05:00
|
|
|
namespace {
|
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
template< class T >
|
2006-06-19 04:32:32 -05:00
|
|
|
inline beans::PropertyValue createPropertyValue(
|
2001-10-11 08:40:44 -05:00
|
|
|
OUString const & name, T const & value )
|
|
|
|
SAL_THROW( () )
|
|
|
|
{
|
2003-04-23 10:27:08 -05:00
|
|
|
return beans::PropertyValue(
|
|
|
|
name, -1, makeAny( value ), beans::PropertyState_DIRECT_VALUE );
|
2001-10-11 08:40:44 -05:00
|
|
|
}
|
|
|
|
|
2006-06-19 04:32:32 -05:00
|
|
|
OUString findBoostrapArgument(
|
2001-10-11 08:40:44 -05:00
|
|
|
const Bootstrap & bootstrap,
|
|
|
|
const OUString & arg_name,
|
|
|
|
sal_Bool * pFallenBack )
|
|
|
|
SAL_THROW(())
|
|
|
|
{
|
|
|
|
OUString result;
|
|
|
|
|
2003-03-20 05:26:21 -06:00
|
|
|
OUString prefixed_arg_name = OUSTR("UNO_");
|
2001-10-11 08:40:44 -05:00
|
|
|
prefixed_arg_name += arg_name.toAsciiUpperCase();
|
|
|
|
|
|
|
|
// environment not set -> try relative to executable
|
|
|
|
if(!bootstrap.getFrom(prefixed_arg_name, result))
|
|
|
|
{
|
|
|
|
if(pFallenBack)
|
|
|
|
*pFallenBack = sal_True;
|
|
|
|
|
|
|
|
OUString fileName;
|
|
|
|
bootstrap.getIniName(fileName);
|
|
|
|
|
|
|
|
// cut the rc extension
|
2003-03-20 05:26:21 -06:00
|
|
|
OUStringBuffer result_buf( 64 );
|
2003-04-23 10:27:08 -05:00
|
|
|
result_buf.append(
|
|
|
|
fileName.copy(
|
|
|
|
0, fileName.getLength() - strlen(SAL_CONFIGFILE(""))) );
|
2003-03-20 05:26:21 -06:00
|
|
|
result_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("_") );
|
|
|
|
result_buf.append( arg_name.toAsciiLowerCase() );
|
|
|
|
result_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(".rdb") );
|
|
|
|
result = result_buf.makeStringAndClear();
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-15 10:34:00 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2003-04-23 10:27:08 -05:00
|
|
|
OString result_dbg =
|
|
|
|
OUStringToOString(result, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OString arg_name_dbg =
|
|
|
|
OUStringToOString(arg_name, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OSL_TRACE(
|
|
|
|
"cppuhelper::findBoostrapArgument - "
|
|
|
|
"setting %s relative to executable: %s\n",
|
|
|
|
arg_name_dbg.getStr(),
|
|
|
|
result_dbg.getStr() );
|
2001-10-11 08:40:44 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(pFallenBack)
|
|
|
|
*pFallenBack = sal_False;
|
|
|
|
|
2003-04-15 10:34:00 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-10-11 08:40:44 -05:00
|
|
|
OString prefixed_arg_name_dbg = OUStringToOString(
|
|
|
|
prefixed_arg_name, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
OString result_dbg = OUStringToOString(
|
|
|
|
result, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
OSL_TRACE(
|
|
|
|
"cppuhelper::findBoostrapArgument - found %s in env: %s",
|
|
|
|
prefixed_arg_name_dbg.getStr(),
|
|
|
|
result_dbg.getStr() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-06-19 04:32:32 -05:00
|
|
|
Reference< registry::XSimpleRegistry > nestRegistries(
|
2001-10-11 08:40:44 -05:00
|
|
|
const OUString baseDir,
|
|
|
|
const Reference< lang::XSingleServiceFactory > & xSimRegFac,
|
|
|
|
const Reference< lang::XSingleServiceFactory > & xNesRegFac,
|
|
|
|
OUString csl_rdbs,
|
|
|
|
const OUString & write_rdb,
|
|
|
|
sal_Bool forceWrite_rdb,
|
2006-06-19 04:32:32 -05:00
|
|
|
sal_Bool bFallenBack )
|
2001-10-11 08:40:44 -05:00
|
|
|
SAL_THROW((Exception))
|
|
|
|
{
|
|
|
|
sal_Int32 index;
|
|
|
|
Reference< registry::XSimpleRegistry > lastRegistry;
|
|
|
|
|
|
|
|
if(write_rdb.getLength()) // is there a write registry given?
|
|
|
|
{
|
|
|
|
lastRegistry.set(xSimRegFac->createInstance(), UNO_QUERY);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2003-03-20 05:26:21 -06:00
|
|
|
lastRegistry->open(write_rdb, sal_False, forceWrite_rdb);
|
2001-10-11 08:40:44 -05:00
|
|
|
}
|
|
|
|
catch (registry::InvalidRegistryException & invalidRegistryException)
|
|
|
|
{
|
2004-11-09 06:40:32 -06:00
|
|
|
(void) invalidRegistryException;
|
2003-04-15 10:34:00 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-10-11 08:40:44 -05:00
|
|
|
OString rdb_name_tmp = OUStringToOString(
|
|
|
|
write_rdb, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OString message_dbg = OUStringToOString(
|
|
|
|
invalidRegistryException.Message, RTL_TEXTENCODING_ASCII_US);
|
|
|
|
OSL_TRACE(
|
|
|
|
"warning: couldn't open %s cause of %s",
|
|
|
|
rdb_name_tmp.getStr(), message_dbg.getStr() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!lastRegistry->isValid())
|
|
|
|
lastRegistry.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
index = csl_rdbs.indexOf((sal_Unicode)' ');
|
|
|
|
OUString rdb_name = (index == -1) ? csl_rdbs : csl_rdbs.copy(0, index);
|
|
|
|
csl_rdbs = (index == -1) ? OUString() : csl_rdbs.copy(index + 1);
|
|
|
|
|
2002-04-26 11:05:29 -05:00
|
|
|
if (! rdb_name.getLength())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool optional = ('?' == rdb_name[ 0 ]);
|
|
|
|
if (optional)
|
|
|
|
rdb_name = rdb_name.copy( 1 );
|
|
|
|
|
2001-10-11 08:40:44 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference<registry::XSimpleRegistry> simpleRegistry(
|
2006-12-01 10:18:20 -06:00
|
|
|
xSimRegFac->createInstance(), UNO_QUERY_THROW );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
|
|
|
osl::FileBase::getAbsoluteFileURL(baseDir, rdb_name, rdb_name);
|
|
|
|
simpleRegistry->open(rdb_name, sal_True, sal_False);
|
|
|
|
|
|
|
|
if(lastRegistry.is())
|
|
|
|
{
|
|
|
|
Reference< registry::XSimpleRegistry > nestedRegistry(
|
|
|
|
xNesRegFac->createInstance(), UNO_QUERY );
|
|
|
|
Reference< lang::XInitialization > nestedRegistry_xInit(
|
|
|
|
nestedRegistry, UNO_QUERY );
|
|
|
|
|
|
|
|
Sequence<Any> aArgs(2);
|
|
|
|
aArgs[0] <<= lastRegistry;
|
|
|
|
aArgs[1] <<= simpleRegistry;
|
|
|
|
|
|
|
|
nestedRegistry_xInit->initialize(aArgs);
|
|
|
|
|
|
|
|
lastRegistry = nestedRegistry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lastRegistry = simpleRegistry;
|
|
|
|
}
|
|
|
|
catch(registry::InvalidRegistryException & invalidRegistryException)
|
|
|
|
{
|
2002-04-26 11:05:29 -05:00
|
|
|
if (! optional)
|
|
|
|
{
|
|
|
|
// if a registry was explicitly given, the exception shall fly
|
|
|
|
if( ! bFallenBack )
|
|
|
|
throw;
|
|
|
|
}
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2004-11-09 06:40:32 -06:00
|
|
|
(void) invalidRegistryException;
|
2003-04-15 10:34:00 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-10-11 08:40:44 -05:00
|
|
|
OString rdb_name_tmp = OUStringToOString(
|
|
|
|
rdb_name, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
OString message_dbg = OUStringToOString(
|
|
|
|
invalidRegistryException.Message, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
OSL_TRACE(
|
|
|
|
"warning: couldn't open %s cause of %s",
|
|
|
|
rdb_name_tmp.getStr(), message_dbg.getStr() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(index != -1 && csl_rdbs.getLength()); // are there more rdbs in list?
|
|
|
|
|
|
|
|
return lastRegistry;
|
|
|
|
}
|
|
|
|
|
2006-06-19 04:32:32 -05:00
|
|
|
Reference< XComponentContext >
|
2003-04-23 10:27:08 -05:00
|
|
|
SAL_CALL defaultBootstrap_InitialComponentContext(
|
2002-06-14 07:20:20 -05:00
|
|
|
Bootstrap const & bootstrap )
|
2001-10-11 08:40:44 -05:00
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
2003-03-20 05:26:21 -06:00
|
|
|
OUString bootstrapPath( get_this_libpath() );
|
2001-10-11 08:40:44 -05:00
|
|
|
OUString iniDir;
|
2002-01-16 09:24:14 -06:00
|
|
|
|
|
|
|
osl_getProcessWorkingDir(&iniDir.pData);
|
2001-10-11 08:40:44 -05:00
|
|
|
|
|
|
|
Reference<lang::XMultiComponentFactory> smgr_XMultiComponentFactory(
|
|
|
|
bootstrapInitialSF(bootstrapPath) );
|
|
|
|
Reference<lang::XMultiServiceFactory> smgr_XMultiServiceFactory(
|
|
|
|
smgr_XMultiComponentFactory, UNO_QUERY );
|
|
|
|
|
|
|
|
Reference<registry::XRegistryKey> xEmptyKey;
|
|
|
|
Reference<lang::XSingleServiceFactory> xSimRegFac(
|
|
|
|
loadSharedLibComponentFactory(
|
2003-04-23 10:27:08 -05:00
|
|
|
OUSTR("simplereg.uno" SAL_DLLEXTENSION), bootstrapPath,
|
2003-03-20 05:26:21 -06:00
|
|
|
OUSTR("com.sun.star.comp.stoc.SimpleRegistry"),
|
2001-10-11 08:40:44 -05:00
|
|
|
smgr_XMultiServiceFactory,
|
|
|
|
xEmptyKey),
|
|
|
|
UNO_QUERY);
|
|
|
|
|
|
|
|
Reference<lang::XSingleServiceFactory> xNesRegFac(
|
|
|
|
loadSharedLibComponentFactory(
|
2003-04-23 10:27:08 -05:00
|
|
|
OUSTR("nestedreg.uno" SAL_DLLEXTENSION), bootstrapPath,
|
2003-03-20 05:26:21 -06:00
|
|
|
OUSTR("com.sun.star.comp.stoc.NestedRegistry"),
|
2001-10-11 08:40:44 -05:00
|
|
|
smgr_XMultiServiceFactory,
|
|
|
|
xEmptyKey),
|
|
|
|
UNO_QUERY);
|
|
|
|
|
|
|
|
sal_Bool bFallenback_types;
|
2003-04-23 10:27:08 -05:00
|
|
|
OUString cls_uno_types =
|
|
|
|
findBoostrapArgument( bootstrap, OUSTR("TYPES"), &bFallenback_types );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
Reference<registry::XSimpleRegistry> types_xRegistry =
|
|
|
|
nestRegistries(
|
|
|
|
iniDir, xSimRegFac, xNesRegFac, cls_uno_types,
|
2006-06-19 04:32:32 -05:00
|
|
|
OUString(), sal_False, bFallenback_types );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
// ==== bootstrap from services registry ====
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
sal_Bool bFallenback_services;
|
|
|
|
OUString cls_uno_services = findBoostrapArgument(
|
|
|
|
bootstrap, OUSTR("SERVICES"), &bFallenback_services );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
sal_Bool fallenBackWriteRegistry;
|
|
|
|
OUString write_rdb = findBoostrapArgument(
|
|
|
|
bootstrap, OUSTR("WRITERDB"), &fallenBackWriteRegistry );
|
|
|
|
if (fallenBackWriteRegistry)
|
2001-10-11 08:40:44 -05:00
|
|
|
{
|
2003-04-23 10:27:08 -05:00
|
|
|
// no standard write rdb anymore
|
|
|
|
write_rdb = OUString();
|
|
|
|
}
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
Reference<registry::XSimpleRegistry> services_xRegistry = nestRegistries(
|
|
|
|
iniDir, xSimRegFac, xNesRegFac, cls_uno_services, write_rdb,
|
2006-06-19 04:32:32 -05:00
|
|
|
!fallenBackWriteRegistry, bFallenback_services );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
Reference< XComponentContext > xContext(
|
|
|
|
bootstrapInitialContext(
|
2002-01-11 03:06:02 -06:00
|
|
|
smgr_XMultiComponentFactory, types_xRegistry, services_xRegistry,
|
|
|
|
bootstrapPath, bootstrap ) );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
// initialize sf
|
|
|
|
Reference< lang::XInitialization > xInit(
|
|
|
|
smgr_XMultiComponentFactory, UNO_QUERY );
|
|
|
|
OSL_ASSERT( xInit.is() );
|
|
|
|
Sequence< Any > aSFInit( 1 );
|
|
|
|
aSFInit[ 0 ] <<= services_xRegistry;
|
|
|
|
xInit->initialize( aSFInit );
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
return xContext;
|
2001-10-11 08:40:44 -05:00
|
|
|
}
|
2002-01-11 03:06:02 -06:00
|
|
|
|
2006-06-19 04:32:32 -05:00
|
|
|
}
|
2002-06-14 07:20:20 -05:00
|
|
|
|
2003-04-23 10:27:08 -05:00
|
|
|
Reference< XComponentContext >
|
|
|
|
SAL_CALL defaultBootstrap_InitialComponentContext(
|
2002-06-14 07:20:20 -05:00
|
|
|
OUString const & iniFile )
|
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
|
|
|
Bootstrap bootstrap( iniFile );
|
2004-04-13 06:27:38 -05:00
|
|
|
if (bootstrap.getHandle() == 0)
|
|
|
|
throw io::IOException(OUSTR("Cannot open for reading: ") + iniFile, 0);
|
2002-12-06 03:12:29 -06:00
|
|
|
return defaultBootstrap_InitialComponentContext( bootstrap );
|
2002-06-14 07:20:20 -05:00
|
|
|
}
|
2003-04-23 10:27:08 -05:00
|
|
|
|
|
|
|
Reference< XComponentContext >
|
|
|
|
SAL_CALL defaultBootstrap_InitialComponentContext()
|
2001-10-11 08:40:44 -05:00
|
|
|
SAL_THROW( (Exception) )
|
|
|
|
{
|
2002-12-06 03:12:29 -06:00
|
|
|
return defaultBootstrap_InitialComponentContext( get_unorc() );
|
2001-10-11 08:40:44 -05:00
|
|
|
}
|
|
|
|
|
2004-05-28 09:58:42 -05:00
|
|
|
BootstrapException::BootstrapException()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BootstrapException::BootstrapException( const ::rtl::OUString & rMessage )
|
|
|
|
:m_aMessage( rMessage )
|
|
|
|
{
|
|
|
|
}
|
2001-10-11 08:40:44 -05:00
|
|
|
|
2004-05-28 09:58:42 -05:00
|
|
|
BootstrapException::BootstrapException( const BootstrapException & e )
|
|
|
|
{
|
|
|
|
m_aMessage = e.m_aMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
BootstrapException::~BootstrapException()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BootstrapException & BootstrapException::operator=( const BootstrapException & e )
|
|
|
|
{
|
|
|
|
m_aMessage = e.m_aMessage;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ::rtl::OUString & BootstrapException::getMessage() const
|
|
|
|
{
|
|
|
|
return m_aMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XComponentContext > SAL_CALL bootstrap()
|
|
|
|
{
|
|
|
|
Reference< XComponentContext > xRemoteContext;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// create default local component context
|
|
|
|
Reference< XComponentContext > xLocalContext(
|
|
|
|
defaultBootstrap_InitialComponentContext() );
|
|
|
|
if ( !xLocalContext.is() )
|
|
|
|
throw BootstrapException( OUSTR( "no local component context!" ) );
|
|
|
|
|
|
|
|
// URL to office executable
|
2004-06-28 08:17:16 -05:00
|
|
|
OUString sOfficeURL( get_this_libpath() + OUSTR( "/soffice" ) );
|
2004-05-28 09:58:42 -05:00
|
|
|
|
|
|
|
// create a random pipe name
|
|
|
|
rtlRandomPool hPool = rtl_random_createPool();
|
|
|
|
if ( hPool == 0 )
|
|
|
|
throw BootstrapException( OUSTR( "cannot create random pool!" ) );
|
2004-08-12 07:34:35 -05:00
|
|
|
sal_uInt8 bytes[ 16 ];
|
2004-05-28 09:58:42 -05:00
|
|
|
if ( rtl_random_getBytes( hPool, bytes, ARLEN( bytes ) )
|
|
|
|
!= rtl_Random_E_None )
|
|
|
|
throw BootstrapException( OUSTR( "random pool error!" ) );
|
|
|
|
rtl_random_destroyPool( hPool );
|
|
|
|
::rtl::OUStringBuffer buf;
|
2004-08-12 07:34:35 -05:00
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "uno" ) );
|
2004-05-28 09:58:42 -05:00
|
|
|
for ( sal_uInt32 i = 0; i < ARLEN( bytes ); ++i )
|
2004-08-12 07:34:35 -05:00
|
|
|
buf.append( static_cast< sal_Int32 >( bytes[ i ] ) );
|
2004-05-28 09:58:42 -05:00
|
|
|
OUString sPipeName( buf.makeStringAndClear() );
|
|
|
|
|
|
|
|
// accept string
|
|
|
|
OSL_ASSERT( buf.getLength() == 0 );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "-accept=pipe,name=" ) );
|
|
|
|
buf.append( sPipeName );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ";urp;" ) );
|
|
|
|
|
|
|
|
// arguments
|
|
|
|
OUString args [] = {
|
2006-01-20 03:11:31 -06:00
|
|
|
OUSTR( "-nologo" ),
|
|
|
|
OUSTR( "-nodefault" ),
|
|
|
|
OUSTR( "-norestore" ),
|
|
|
|
OUSTR( "-nocrashreport" ),
|
|
|
|
OUSTR( "-nolockcheck" ),
|
|
|
|
buf.makeStringAndClear()
|
2004-05-28 09:58:42 -05:00
|
|
|
};
|
|
|
|
rtl_uString * ar_args [] = {
|
2006-02-03 10:12:54 -06:00
|
|
|
args[ 0 ].pData,
|
|
|
|
args[ 1 ].pData,
|
|
|
|
args[ 2 ].pData,
|
|
|
|
args[ 3 ].pData,
|
|
|
|
args[ 4 ].pData,
|
|
|
|
args[ 5 ].pData
|
2004-05-28 09:58:42 -05:00
|
|
|
};
|
|
|
|
::osl::Security sec;
|
|
|
|
|
|
|
|
// start office process
|
|
|
|
oslProcess hProcess = 0;
|
|
|
|
oslProcessError rc = osl_executeProcess(
|
|
|
|
sOfficeURL.pData, ar_args, ARLEN( ar_args ),
|
|
|
|
osl_Process_DETACHED,
|
|
|
|
sec.getHandle(),
|
|
|
|
0, // => current working dir
|
|
|
|
0, 0, // => no env vars
|
|
|
|
&hProcess );
|
|
|
|
switch ( rc )
|
|
|
|
{
|
|
|
|
case osl_Process_E_None:
|
|
|
|
break;
|
|
|
|
case osl_Process_E_NotFound:
|
|
|
|
throw BootstrapException( OUSTR( "image not found!" ) );
|
|
|
|
case osl_Process_E_TimedOut:
|
|
|
|
throw BootstrapException( OUSTR( "timout occured!" ) );
|
|
|
|
case osl_Process_E_NoPermission:
|
|
|
|
throw BootstrapException( OUSTR( "permission denied!" ) );
|
|
|
|
case osl_Process_E_Unknown:
|
|
|
|
throw BootstrapException( OUSTR( "unknown error!" ) );
|
|
|
|
case osl_Process_E_InvalidError:
|
|
|
|
default:
|
|
|
|
throw BootstrapException( OUSTR( "unmapped error!" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a URL resolver
|
|
|
|
Reference< bridge::XUnoUrlResolver > xUrlResolver(
|
2004-07-23 09:02:43 -05:00
|
|
|
bridge::UnoUrlResolver::create( xLocalContext ) );
|
2004-05-28 09:58:42 -05:00
|
|
|
|
|
|
|
// connection string
|
|
|
|
OSL_ASSERT( buf.getLength() == 0 );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "uno:pipe,name=" ) );
|
|
|
|
buf.append( sPipeName );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
|
|
|
|
";urp;StarOffice.ComponentContext" ) );
|
|
|
|
OUString sConnectString( buf.makeStringAndClear() );
|
|
|
|
|
|
|
|
// wait until office is started
|
|
|
|
for ( ; ; )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// try to connect to office
|
|
|
|
xRemoteContext.set(
|
|
|
|
xUrlResolver->resolve( sConnectString ), UNO_QUERY_THROW );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
catch ( connection::NoConnectException & )
|
|
|
|
{
|
|
|
|
// wait 500 ms, then try to connect again
|
|
|
|
TimeValue tv = { 0 /* secs */, 500000000 /* nanosecs */ };
|
|
|
|
::osl::Thread::wait( tv );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( Exception & e )
|
|
|
|
{
|
|
|
|
throw BootstrapException(
|
|
|
|
OUSTR( "unexpected UNO exception caught: " ) + e.Message );
|
|
|
|
}
|
|
|
|
|
|
|
|
return xRemoteContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cppu
|