2003-09-16 14:23:32 +00:00
/*************************************************************************
*
2008-04-11 09:24:59 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2003-09-16 14:23:32 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2003-09-16 14:23:32 +00:00
*
2008-04-11 09:24:59 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2003-09-16 14:23:32 +00:00
*
2008-04-11 09:24:59 +00:00
* This file is part of OpenOffice . org .
2003-09-16 14:23:32 +00:00
*
2008-04-11 09:24:59 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2003-09-16 14:23:32 +00:00
*
2008-04-11 09:24:59 +00:00
* OpenOffice . org 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 version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2003-09-16 14:23:32 +00:00
*
2008-04-11 09:24:59 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
2003-09-16 14:23:32 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-16 11:26:15 +00:00
// MARKER(update_precomp.py): autogen include statement, do not remove
# include "precompiled_scripting.hxx"
2003-09-16 14:23:32 +00:00
# include "basprov.hxx"
# include "basscript.hxx"
2003-09-23 09:09:14 +00:00
# include "baslibnode.hxx"
2003-09-16 14:23:32 +00:00
# include <com/sun/star/frame/XModel.hpp>
2004-10-22 13:02:27 +00:00
# include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
# include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
2008-03-06 15:17:12 +00:00
# include <com/sun/star/document/XEmbeddedScripts.hpp>
2004-07-23 13:07:20 +00:00
2003-09-16 14:23:32 +00:00
# ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
# include <cppuhelper/implementationentry.hxx>
# endif
2004-08-12 12:17:46 +00:00
# include <rtl/uri.hxx>
# include <osl/process.h>
# include <osl/file.hxx>
2005-01-13 16:43:11 +00:00
# include <vos/mutex.hxx>
# include <vcl/svapp.hxx>
2005-04-13 07:13:40 +00:00
# include <basic/sbx.hxx>
2003-09-16 14:23:32 +00:00
# include <basic/basmgr.hxx>
2008-03-06 15:17:12 +00:00
# include <basic/basicmanagerrepository.hxx>
2003-09-16 14:23:32 +00:00
# include <basic/sbstar.hxx>
# include <basic/sbmod.hxx>
# include <basic/sbmeth.hxx>
# include <sfx2/app.hxx>
# include <sfx2/objsh.hxx>
2003-10-15 07:35:32 +00:00
# include <com/sun/star/util/XMacroExpander.hpp>
# include <com/sun/star/script/XLibraryContainer2.hpp>
2004-04-19 22:13:45 +00:00
# include <com/sun/star/uri/XUriReference.hpp>
# include <com/sun/star/uri/XUriReferenceFactory.hpp>
# include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
2004-07-23 13:07:20 +00:00
# include <util/util.hxx>
# include <util/MiscUtils.hxx>
2003-09-16 14:23:32 +00:00
using namespace : : com : : sun : : star ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : uno ;
2004-10-22 13:02:27 +00:00
using namespace : : com : : sun : : star : : script ;
2008-03-06 15:17:12 +00:00
using namespace : : com : : sun : : star : : document ;
2004-07-23 13:07:20 +00:00
using namespace : : sf_misc ;
2003-09-16 14:23:32 +00:00
//.........................................................................
namespace basprov
{
//.........................................................................
// =============================================================================
// component operations
// =============================================================================
static : : rtl : : OUString getImplementationName_BasicProviderImpl ( )
{
static : : rtl : : OUString * pImplName = 0 ;
if ( ! pImplName )
{
: : osl : : MutexGuard aGuard ( : : osl : : Mutex : : getGlobalMutex ( ) ) ;
if ( ! pImplName )
{
static : : rtl : : OUString aImplName ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.comp.scripting.ScriptProviderForBasic " ) ) ;
pImplName = & aImplName ;
}
}
return * pImplName ;
}
// -----------------------------------------------------------------------------
static Sequence < : : rtl : : OUString > getSupportedServiceNames_BasicProviderImpl ( )
{
static Sequence < : : rtl : : OUString > * pNames = 0 ;
if ( ! pNames )
{
: : osl : : MutexGuard aGuard ( : : osl : : Mutex : : getGlobalMutex ( ) ) ;
if ( ! pNames )
{
2004-10-22 13:02:27 +00:00
static Sequence < : : rtl : : OUString > aNames ( 4 ) ;
aNames . getArray ( ) [ 0 ] = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.script.provider.ScriptProviderForBasic " ) ) ;
aNames . getArray ( ) [ 1 ] = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.script.provider.LanguageScriptProvider " ) ) ;
aNames . getArray ( ) [ 2 ] = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.script.provider.ScriptProvider " ) ) ;
aNames . getArray ( ) [ 3 ] = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.script.browse.BrowseNode " ) ) ;
2003-09-16 14:23:32 +00:00
pNames = & aNames ;
}
}
return * pNames ;
}
// =============================================================================
// BasicProviderImpl
// =============================================================================
BasicProviderImpl : : BasicProviderImpl ( const Reference < XComponentContext > & xContext )
2003-10-15 07:35:32 +00:00
: m_pAppBasicManager ( 0 )
, m_pDocBasicManager ( 0 )
, m_xLibContainerApp ( 0 )
, m_xLibContainerDoc ( 0 )
2003-09-16 14:23:32 +00:00
, m_xContext ( xContext )
2004-04-19 22:13:45 +00:00
, m_bIsAppScriptCtx ( true )
, m_bIsUserCtx ( true )
2003-09-16 14:23:32 +00:00
{
}
// -----------------------------------------------------------------------------
BasicProviderImpl : : ~ BasicProviderImpl ( )
{
}
2004-08-12 12:17:46 +00:00
// -----------------------------------------------------------------------------
bool BasicProviderImpl : : isLibraryShared ( const Reference < script : : XLibraryContainer > & rxLibContainer , const : : rtl : : OUString & rLibName )
{
bool bIsShared = false ;
Reference < script : : XLibraryContainer2 > xLibContainer ( rxLibContainer , UNO_QUERY ) ;
if ( xLibContainer . is ( ) & & xLibContainer - > hasByName ( rLibName ) & & xLibContainer - > isLibraryLink ( rLibName ) )
{
: : rtl : : OUString aFileURL ;
if ( m_xContext . is ( ) )
{
Reference < uri : : XUriReferenceFactory > xUriFac ;
Reference < lang : : XMultiComponentFactory > xSMgr ( m_xContext - > getServiceManager ( ) ) ;
if ( xSMgr . is ( ) )
{
xUriFac . set ( xSMgr - > createInstanceWithContext ( : : rtl : : OUString : : createFromAscii (
" com.sun.star.uri.UriReferenceFactory " ) , m_xContext ) , UNO_QUERY ) ;
}
if ( xUriFac . is ( ) )
{
: : rtl : : OUString aLinkURL ( xLibContainer - > getLibraryLinkURL ( rLibName ) ) ;
Reference < uri : : XUriReference > xUriRef ( xUriFac - > parse ( aLinkURL ) , UNO_QUERY ) ;
if ( xUriRef . is ( ) )
{
: : rtl : : OUString aScheme = xUriRef - > getScheme ( ) ;
if ( aScheme . equalsIgnoreAsciiCaseAscii ( " file " ) )
{
aFileURL = aLinkURL ;
}
else if ( aScheme . equalsIgnoreAsciiCaseAscii ( " vnd.sun.star.pkg " ) )
{
: : rtl : : OUString aAuthority = xUriRef - > getAuthority ( ) ;
if ( aAuthority . matchIgnoreAsciiCaseAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " vnd.sun.star.expand: " ) ) )
{
: : rtl : : OUString aDecodedURL ( aAuthority . copy ( sizeof ( " vnd.sun.star.expand: " ) - 1 ) ) ;
aDecodedURL = : : rtl : : Uri : : decode ( aDecodedURL , rtl_UriDecodeWithCharset , RTL_TEXTENCODING_UTF8 ) ;
Reference < util : : XMacroExpander > xMacroExpander (
m_xContext - > getValueByName (
: : rtl : : OUString : : createFromAscii ( " /singletons/com.sun.star.util.theMacroExpander " ) ) ,
UNO_QUERY ) ;
if ( xMacroExpander . is ( ) )
aFileURL = xMacroExpander - > expandMacros ( aDecodedURL ) ;
}
}
}
}
}
if ( aFileURL . getLength ( ) )
{
osl : : DirectoryItem aFileItem ;
osl : : FileStatus aFileStatus ( FileStatusMask_FileURL ) ;
OSL_VERIFY ( osl : : DirectoryItem : : get ( aFileURL , aFileItem ) = = osl : : FileBase : : E_None ) ;
OSL_VERIFY ( aFileItem . getFileStatus ( aFileStatus ) = = osl : : FileBase : : E_None ) ;
: : rtl : : OUString aCanonicalFileURL ( aFileStatus . getFileURL ( ) ) ;
2008-07-07 10:56:35 +00:00
: : rtl : : OUString aSearchURL1 ( RTL_CONSTASCII_USTRINGPARAM ( " share/basic " ) ) ;
: : rtl : : OUString aSearchURL2 ( RTL_CONSTASCII_USTRINGPARAM ( " share/uno_packages " ) ) ;
if ( aCanonicalFileURL . indexOf ( aSearchURL1 ) ! = - 1 | | aCanonicalFileURL . indexOf ( aSearchURL2 ) ! = - 1 )
2004-08-12 12:17:46 +00:00
bIsShared = true ;
}
}
return bIsShared ;
}
2003-09-16 14:23:32 +00:00
// -----------------------------------------------------------------------------
// XServiceInfo
// -----------------------------------------------------------------------------
: : rtl : : OUString BasicProviderImpl : : getImplementationName ( ) throw ( RuntimeException )
{
return getImplementationName_BasicProviderImpl ( ) ;
}
// -----------------------------------------------------------------------------
sal_Bool BasicProviderImpl : : supportsService ( const : : rtl : : OUString & rServiceName ) throw ( RuntimeException )
{
Sequence < : : rtl : : OUString > aNames ( getSupportedServiceNames ( ) ) ;
const : : rtl : : OUString * pNames = aNames . getConstArray ( ) ;
const : : rtl : : OUString * pEnd = pNames + aNames . getLength ( ) ;
for ( ; pNames ! = pEnd & & ! pNames - > equals ( rServiceName ) ; + + pNames )
;
return pNames ! = pEnd ;
}
// -----------------------------------------------------------------------------
Sequence < : : rtl : : OUString > BasicProviderImpl : : getSupportedServiceNames ( ) throw ( RuntimeException )
{
return getSupportedServiceNames_BasicProviderImpl ( ) ;
}
// -----------------------------------------------------------------------------
// XInitialization
// -----------------------------------------------------------------------------
void BasicProviderImpl : : initialize ( const Sequence < Any > & aArguments ) throw ( Exception , RuntimeException )
{
// TODO
2005-01-13 16:43:11 +00:00
: : vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
2003-09-16 14:23:32 +00:00
2008-03-06 15:17:12 +00:00
if ( aArguments . getLength ( ) ! = 1 )
2003-09-16 14:23:32 +00:00
{
2008-03-06 15:17:12 +00:00
throw IllegalArgumentException (
: : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " BasicProviderImpl::initialize: incorrect argument count. " ) ) ,
* this ,
1
) ;
}
2003-10-15 07:35:32 +00:00
2008-03-06 15:17:12 +00:00
Reference < frame : : XModel > xModel ;
2003-09-16 14:23:32 +00:00
2008-03-06 15:17:12 +00:00
m_xInvocationContext . set ( aArguments [ 0 ] , UNO_QUERY ) ; ;
if ( m_xInvocationContext . is ( ) )
{
xModel . set ( m_xInvocationContext - > getScriptContainer ( ) , UNO_QUERY ) ;
if ( ! xModel . is ( ) )
{
throw IllegalArgumentException (
: : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " BasicProviderImpl::initialize: unable to determine the document model from the script invocation context. " ) ) ,
* this ,
1
) ;
}
}
else
{
if ( ! ( aArguments [ 0 ] > > = m_sScriptingContext ) )
{
throw IllegalArgumentException (
: : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " BasicProviderImpl::initialize: incorrect argument type " ) ) . concat ( aArguments [ 0 ] . getValueTypeName ( ) ) ,
* this ,
1
) ;
}
: : rtl : : OUString sDoc = OUSTR ( " vnd.sun.star.tdoc " ) ;
2004-07-23 13:07:20 +00:00
if ( m_sScriptingContext . indexOf ( sDoc ) = = 0 )
2003-09-16 14:23:32 +00:00
{
2008-03-06 15:17:12 +00:00
xModel = MiscUtils : : tDocUrlToModel ( m_sScriptingContext ) ;
2003-09-16 14:23:32 +00:00
// TODO: use ScriptingContantsPool for SCRIPTING_DOC_REF
2008-03-06 15:17:12 +00:00
}
}
2003-09-16 14:23:32 +00:00
2008-03-06 15:17:12 +00:00
if ( xModel . is ( ) )
{
Reference < XEmbeddedScripts > xDocumentScripts ( xModel , UNO_QUERY ) ;
if ( xDocumentScripts . is ( ) )
{
m_pDocBasicManager = : : basic : : BasicManagerRepository : : getDocumentBasicManager ( xModel ) ;
m_xLibContainerDoc . set ( xDocumentScripts - > getBasicLibraries ( ) , UNO_QUERY ) ;
OSL_ENSURE ( m_pDocBasicManager & & m_xLibContainerDoc . is ( ) ,
" BasicProviderImpl::initialize: invalid BasicManager, or invalid script container! " ) ;
}
m_bIsAppScriptCtx = false ;
}
else
{
// Provider has been created with application context for user
// or share
if ( ! m_sScriptingContext . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " user " ) ) )
2004-07-23 13:07:20 +00:00
{
m_bIsUserCtx = false ;
2003-09-16 14:23:32 +00:00
}
else
{
/*
throw RuntimeException (
: : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " BasicProviderImpl::initialize: no scripting context! " ) ) ,
Reference < XInterface > ( ) ) ;
*/
}
}
2004-07-23 13:07:20 +00:00
// TODO
if ( ! m_pAppBasicManager )
m_pAppBasicManager = SFX_APP ( ) - > GetBasicManager ( ) ;
2003-10-15 07:35:32 +00:00
if ( ! m_xLibContainerApp . is ( ) )
m_xLibContainerApp = Reference < script : : XLibraryContainer > ( SFX_APP ( ) - > GetBasicContainer ( ) , UNO_QUERY ) ;
2003-09-16 14:23:32 +00:00
}
// -----------------------------------------------------------------------------
2003-10-15 07:35:32 +00:00
2003-09-16 14:23:32 +00:00
// XScriptProvider
// -----------------------------------------------------------------------------
Reference < provider : : XScript > BasicProviderImpl : : getScript ( const : : rtl : : OUString & scriptURI )
2004-07-23 13:07:20 +00:00
throw ( provider : : ScriptFrameworkErrorException , RuntimeException )
2003-09-16 14:23:32 +00:00
{
// TODO
2005-01-13 16:43:11 +00:00
: : vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
2003-09-16 14:23:32 +00:00
Reference < provider : : XScript > xScript ;
2004-04-19 22:13:45 +00:00
Reference < lang : : XMultiComponentFactory > xMcFac ( m_xContext - > getServiceManager ( ) ) ;
Reference < uri : : XUriReferenceFactory > xFac (
xMcFac - > createInstanceWithContext ( rtl : : OUString : : createFromAscii (
" com.sun.star.uri.UriReferenceFactory " ) , m_xContext ) , UNO_QUERY ) ;
2003-09-16 14:23:32 +00:00
2004-04-19 22:13:45 +00:00
if ( ! xFac . is ( ) )
2003-10-15 07:35:32 +00:00
{
2004-07-23 13:07:20 +00:00
throw provider : : ScriptFrameworkErrorException (
2008-03-06 15:17:12 +00:00
OUSTR ( " Failed to instantiate UriReferenceFactory " ) , Reference < XInterface > ( ) ,
2004-07-23 13:07:20 +00:00
scriptURI , OUSTR ( " Basic " ) ,
provider : : ScriptFrameworkErrorType : : UNKNOWN ) ;
2003-10-15 07:35:32 +00:00
}
2004-04-19 22:13:45 +00:00
Reference < uri : : XUriReference > uriRef (
xFac - > parse ( scriptURI ) , UNO_QUERY ) ;
Reference < uri : : XVndSunStarScriptUrl > sfUri ( uriRef , UNO_QUERY ) ;
if ( ! uriRef . is ( ) | | ! sfUri . is ( ) )
{
: : rtl : : OUString errorMsg = : : rtl : : OUString : : createFromAscii ( " BasicProviderImpl::getScript: failed to parse URI: " ) ;
2004-07-23 13:07:20 +00:00
errorMsg = errorMsg . concat ( scriptURI ) ;
throw provider : : ScriptFrameworkErrorException (
errorMsg , Reference < XInterface > ( ) ,
scriptURI , OUSTR ( " Basic " ) ,
2008-10-16 06:57:26 +00:00
provider : : ScriptFrameworkErrorType : : MALFORMED_URL ) ;
2004-04-19 22:13:45 +00:00
}
: : rtl : : OUString aDescription = sfUri - > getName ( ) ;
: : rtl : : OUString aLocation = sfUri - > getParameter (
: : rtl : : OUString : : createFromAscii ( " location " ) ) ;
2003-09-16 14:23:32 +00:00
sal_Int32 nIndex = 0 ;
: : rtl : : OUString aLibrary = aDescription . getToken ( 0 , ( sal_Unicode ) ' . ' , nIndex ) ;
: : rtl : : OUString aModule ;
if ( nIndex ! = - 1 )
aModule = aDescription . getToken ( 0 , ( sal_Unicode ) ' . ' , nIndex ) ;
: : rtl : : OUString aMethod ;
if ( nIndex ! = - 1 )
aMethod = aDescription . getToken ( 0 , ( sal_Unicode ) ' . ' , nIndex ) ;
2003-10-15 07:35:32 +00:00
if ( aLibrary . getLength ( ) ! = 0 & & aModule . getLength ( ) ! = 0 & & aMethod . getLength ( ) ! = 0 & & aLocation . getLength ( ) ! = 0 )
2003-09-16 14:23:32 +00:00
{
2003-10-15 07:35:32 +00:00
BasicManager * pBasicMgr = NULL ;
if ( aLocation . equals ( : : rtl : : OUString : : createFromAscii ( " document " ) ) )
{
pBasicMgr = m_pDocBasicManager ;
}
else if ( aLocation . equals ( : : rtl : : OUString : : createFromAscii ( " application " ) ) )
{
pBasicMgr = m_pAppBasicManager ;
}
if ( pBasicMgr )
2003-09-16 14:23:32 +00:00
{
2003-10-15 07:35:32 +00:00
StarBASIC * pBasic = pBasicMgr - > GetLib ( aLibrary ) ;
2003-09-16 14:23:32 +00:00
if ( ! pBasic )
{
2003-10-15 07:35:32 +00:00
USHORT nId = pBasicMgr - > GetLibId ( aLibrary ) ;
2008-06-06 12:27:17 +00:00
if ( nId ! = LIB_NOTFOUND )
{
pBasicMgr - > LoadLib ( nId ) ;
pBasic = pBasicMgr - > GetLib ( aLibrary ) ;
}
2003-09-16 14:23:32 +00:00
}
if ( pBasic )
{
SbModule * pModule = pBasic - > FindModule ( aModule ) ;
if ( pModule )
{
SbxArray * pMethods = pModule - > GetMethods ( ) ;
if ( pMethods )
{
2003-09-23 09:09:14 +00:00
SbMethod * pMethod = static_cast < SbMethod * > ( pMethods - > Find ( aMethod , SbxCLASS_METHOD ) ) ;
2010-08-06 09:35:51 +02:00
if ( pMethod & & ! pMethod - > IsHidden ( ) )
2008-03-06 15:17:12 +00:00
{
if ( m_pDocBasicManager = = pBasicMgr )
xScript = new BasicScriptImpl ( aDescription , pMethod , * m_pDocBasicManager , m_xInvocationContext ) ;
else
xScript = new BasicScriptImpl ( aDescription , pMethod ) ;
}
2003-09-16 14:23:32 +00:00
}
}
}
}
}
if ( ! xScript . is ( ) )
{
2008-03-06 15:17:12 +00:00
: : rtl : : OUStringBuffer aMessage ;
aMessage . appendAscii ( " The following Basic script could not be found: \n " ) ;
aMessage . appendAscii ( " library: ' " ) . append ( aLibrary ) . appendAscii ( " ' \n " ) ;
aMessage . appendAscii ( " module: ' " ) . append ( aModule ) . appendAscii ( " ' \n " ) ;
aMessage . appendAscii ( " method: ' " ) . append ( aMethod ) . appendAscii ( " ' \n " ) ;
aMessage . appendAscii ( " location: ' " ) . append ( aLocation ) . appendAscii ( " ' \n " ) ;
2004-07-23 13:07:20 +00:00
throw provider : : ScriptFrameworkErrorException (
2008-03-06 15:17:12 +00:00
aMessage . makeStringAndClear ( ) ,
Reference < XInterface > ( ) ,
2004-07-23 13:07:20 +00:00
scriptURI , OUSTR ( " Basic " ) ,
2008-10-16 06:57:26 +00:00
provider : : ScriptFrameworkErrorType : : NO_SUCH_SCRIPT ) ;
2003-09-16 14:23:32 +00:00
}
return xScript ;
}
2003-09-23 09:09:14 +00:00
// -----------------------------------------------------------------------------
// XBrowseNode
// -----------------------------------------------------------------------------
: : rtl : : OUString BasicProviderImpl : : getName ( ) throw ( RuntimeException )
{
// TODO
2005-01-13 16:43:11 +00:00
: : vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
2003-09-23 09:09:14 +00:00
return : : rtl : : OUString : : createFromAscii ( " Basic " ) ;
}
// -----------------------------------------------------------------------------
Sequence < Reference < browse : : XBrowseNode > > BasicProviderImpl : : getChildNodes ( ) throw ( RuntimeException )
{
2005-01-13 16:43:11 +00:00
: : vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
2003-09-23 09:09:14 +00:00
2004-08-12 12:17:46 +00:00
Reference < script : : XLibraryContainer > xLibContainer ;
BasicManager * pBasicManager = NULL ;
if ( m_bIsAppScriptCtx )
{
xLibContainer = m_xLibContainerApp ;
pBasicManager = m_pAppBasicManager ;
}
else
{
xLibContainer = m_xLibContainerDoc ;
pBasicManager = m_pDocBasicManager ;
}
2003-10-15 07:35:32 +00:00
2003-09-23 09:09:14 +00:00
Sequence < Reference < browse : : XBrowseNode > > aChildNodes ;
2004-08-12 12:17:46 +00:00
if ( pBasicManager & & xLibContainer . is ( ) )
2003-09-23 09:09:14 +00:00
{
2003-10-15 07:35:32 +00:00
Sequence < : : rtl : : OUString > aLibNames = xLibContainer - > getElementNames ( ) ;
2003-09-23 09:09:14 +00:00
sal_Int32 nLibCount = aLibNames . getLength ( ) ;
const : : rtl : : OUString * pLibNames = aLibNames . getConstArray ( ) ;
aChildNodes . realloc ( nLibCount ) ;
Reference < browse : : XBrowseNode > * pChildNodes = aChildNodes . getArray ( ) ;
2003-10-15 07:35:32 +00:00
sal_Int32 childsFound = 0 ;
2004-02-04 13:13:28 +00:00
2004-08-12 12:17:46 +00:00
for ( sal_Int32 i = 0 ; i < nLibCount ; + + i )
2003-09-23 09:09:14 +00:00
{
2004-08-12 12:17:46 +00:00
bool bCreate = false ;
if ( m_bIsAppScriptCtx )
2003-10-15 07:35:32 +00:00
{
2004-08-12 12:17:46 +00:00
bool bShared = isLibraryShared ( xLibContainer , pLibNames [ i ] ) ;
if ( ( m_bIsUserCtx & & ! bShared ) | | ( ! m_bIsUserCtx & & bShared ) )
bCreate = true ;
2003-10-15 07:35:32 +00:00
}
else
{
2004-08-12 12:17:46 +00:00
bCreate = true ;
}
if ( bCreate )
{
pChildNodes [ childsFound + + ] = static_cast < browse : : XBrowseNode * > ( new BasicLibraryNodeImpl (
m_xContext , m_sScriptingContext , pBasicManager , xLibContainer , pLibNames [ i ] , m_bIsAppScriptCtx ) ) ;
2003-10-15 07:35:32 +00:00
}
}
2004-08-12 12:17:46 +00:00
if ( childsFound ! = nLibCount )
2003-10-15 07:35:32 +00:00
aChildNodes . realloc ( childsFound ) ;
2003-09-23 09:09:14 +00:00
}
2004-08-12 12:17:46 +00:00
2003-09-23 09:09:14 +00:00
return aChildNodes ;
}
// -----------------------------------------------------------------------------
sal_Bool BasicProviderImpl : : hasChildNodes ( ) throw ( RuntimeException )
{
2005-01-13 16:43:11 +00:00
: : vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
2003-09-23 09:09:14 +00:00
sal_Bool bReturn = sal_False ;
2003-10-15 07:35:32 +00:00
Reference < script : : XLibraryContainer > xLibContainer ;
if ( m_bIsAppScriptCtx )
{
xLibContainer = m_xLibContainerApp ;
}
else
{
xLibContainer = m_xLibContainerDoc ;
}
if ( xLibContainer . is ( ) )
bReturn = xLibContainer - > hasElements ( ) ;
2003-09-23 09:09:14 +00:00
return bReturn ;
}
// -----------------------------------------------------------------------------
sal_Int16 BasicProviderImpl : : getType ( ) throw ( RuntimeException )
{
2005-01-13 16:43:11 +00:00
: : vos : : OGuard aGuard ( Application : : GetSolarMutex ( ) ) ;
2003-09-23 09:09:14 +00:00
return browse : : BrowseNodeTypes : : CONTAINER ;
}
2003-09-16 14:23:32 +00:00
// =============================================================================
// component operations
// =============================================================================
static Reference < XInterface > SAL_CALL create_BasicProviderImpl (
Reference < XComponentContext > const & xContext )
SAL_THROW ( ( ) )
{
return static_cast < lang : : XTypeProvider * > ( new BasicProviderImpl ( xContext ) ) ;
}
// -----------------------------------------------------------------------------
static struct : : cppu : : ImplementationEntry s_component_entries [ ] =
{
{
create_BasicProviderImpl , getImplementationName_BasicProviderImpl ,
getSupportedServiceNames_BasicProviderImpl , : : cppu : : createSingleComponentFactory ,
0 , 0
} ,
{ 0 , 0 , 0 , 0 , 0 , 0 }
} ;
// -----------------------------------------------------------------------------
//.........................................................................
} // namespace basprov
//.........................................................................
// =============================================================================
// component exports
// =============================================================================
extern " C "
{
2008-12-30 13:32:01 +00:00
SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment (
2003-09-16 14:23:32 +00:00
const sal_Char * * ppEnvTypeName , uno_Environment * * ppEnv )
{
2006-06-19 09:18:23 +00:00
( void ) ppEnv ;
2003-09-16 14:23:32 +00:00
* ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
}
2008-12-30 13:32:01 +00:00
SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo (
2003-09-16 14:23:32 +00:00
lang : : XMultiServiceFactory * pServiceManager , registry : : XRegistryKey * pRegistryKey )
{
return : : cppu : : component_writeInfoHelper (
pServiceManager , pRegistryKey , : : basprov : : s_component_entries ) ;
}
2008-12-30 13:32:01 +00:00
SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory (
2003-09-16 14:23:32 +00:00
const sal_Char * pImplName , lang : : XMultiServiceFactory * pServiceManager ,
registry : : XRegistryKey * pRegistryKey )
{
return : : cppu : : component_getFactoryHelper (
pImplName , pServiceManager , pRegistryKey , : : basprov : : s_component_entries ) ;
}
}