diff options
Diffstat (limited to 'scripting/source/runtimemgr')
-rw-r--r-- | scripting/source/runtimemgr/ScriptExecDialog.hrc | 28 | ||||
-rw-r--r-- | scripting/source/runtimemgr/ScriptExecDialog.src | 36 | ||||
-rw-r--r-- | scripting/source/runtimemgr/ScriptNameResolverImpl.cxx | 663 | ||||
-rw-r--r-- | scripting/source/runtimemgr/ScriptNameResolverImpl.hxx | 113 | ||||
-rw-r--r-- | scripting/source/runtimemgr/ScriptRuntimeManager.cxx | 567 | ||||
-rw-r--r-- | scripting/source/runtimemgr/ScriptRuntimeManager.hxx | 152 | ||||
-rw-r--r-- | scripting/source/runtimemgr/StorageBridge.cxx | 155 | ||||
-rw-r--r-- | scripting/source/runtimemgr/StorageBridge.hxx | 88 | ||||
-rw-r--r-- | scripting/source/runtimemgr/StorageBridgeFactory.cxx | 72 | ||||
-rw-r--r-- | scripting/source/runtimemgr/StorageBridgeFactory.hxx | 61 | ||||
-rw-r--r-- | scripting/source/runtimemgr/exports.dxp | 3 | ||||
-rw-r--r-- | scripting/source/runtimemgr/makefile.mk | 48 | ||||
-rwxr-xr-x | scripting/source/runtimemgr/runtimemgr.xml | 47 |
13 files changed, 2033 insertions, 0 deletions
diff --git a/scripting/source/runtimemgr/ScriptExecDialog.hrc b/scripting/source/runtimemgr/ScriptExecDialog.hrc new file mode 100644 index 000000000000..e4d65665bc36 --- /dev/null +++ b/scripting/source/runtimemgr/ScriptExecDialog.hrc @@ -0,0 +1,28 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#define DLG_SCRIPTEXEC 1000 diff --git a/scripting/source/runtimemgr/ScriptExecDialog.src b/scripting/source/runtimemgr/ScriptExecDialog.src new file mode 100644 index 000000000000..1daf2ea6984a --- /dev/null +++ b/scripting/source/runtimemgr/ScriptExecDialog.src @@ -0,0 +1,36 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +#include "ScriptExecDialog.hrc" + +QueryBox DLG_SCRIPTEXEC +{ + Buttons = WB_YES_NO ; + DefButton = WB_DEF_YES ; + Title = "Script execution" ; + Message = "You are about to execute a script. Do you want to execute this script?" ; +}; diff --git a/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx b/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx new file mode 100644 index 000000000000..4f7d09ad403c --- /dev/null +++ b/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx @@ -0,0 +1,663 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" + +#include <vector> +#include <stdlib.h> + +#include <cppuhelper/implementationentry.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/security/AccessControlException.hpp> + +#include <util/util.hxx> +#include <util/scriptingconstants.hxx> + +#include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp> +#include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp> + +#include "ScriptNameResolverImpl.hxx" +#include "ScriptRuntimeManager.hxx" + +using namespace ::rtl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::drafts::com::sun::star::script::framework; + +namespace scripting_runtimemgr +{ + +const sal_Char* const LANGUAGE_TO_RESOLVE_ON[] = { "All" }; // should be configurable +OUString nrs_implName = OUString::createFromAscii( + "drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" ); +OUString nrs_serviceName = OUString::createFromAscii( + "drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" ); +Sequence< OUString > nrs_serviceNames = Sequence< OUString >( &nrs_serviceName, 1 ); + +const char* const SCRIPTSTORAGEMANAGER_SERVICE = + "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager"; + +extern ::rtl_StandardModuleCount s_moduleCount; + +// define storages to search +static ::std::vector< sal_Int32 >* m_pSearchIDs = NULL; + +//************************************************************************* +ScriptNameResolverImpl::ScriptNameResolverImpl( + const Reference< XComponentContext > & xContext ) : + m_xContext( xContext ) +{ + OSL_TRACE( "< ScriptNameResolverImpl ctor called >\n" ); + validateXRef( m_xContext, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid context" ); + m_xMultiComFac = m_xContext->getServiceManager(); + + validateXRef( m_xMultiComFac, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid XMultiComponentFactory " ); + + if( !m_pSearchIDs ) + { + osl::Guard< osl::Mutex > aGuard( m_mutex ); + if( !m_pSearchIDs ) + { + scripting_constants::ScriptingConstantsPool& scriptingConstantsPool = + scripting_constants::ScriptingConstantsPool::instance(); + m_pSearchIDs = new ::std::vector< sal_Int32 >(); + m_pSearchIDs->push_back( scriptingConstantsPool.DOC_STORAGE_ID_NOT_SET ); + m_pSearchIDs->push_back( scriptingConstantsPool.USER_STORAGE_ID ); + m_pSearchIDs->push_back( scriptingConstantsPool.SHARED_STORAGE_ID ); + } + } + + s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt ); +} + +//************************************************************************* +ScriptNameResolverImpl::~ScriptNameResolverImpl() +{ + OSL_TRACE( "< ScriptNameResolverImpl dtor called >\n" ); + s_moduleCount.modCnt.release( &s_moduleCount.modCnt ); +} + +//************************************************************************* +Reference< storage::XScriptInfo > ScriptNameResolverImpl::resolve( +const ::rtl::OUString & scriptURI, Any& invocationCtx ) +throw ( lang::IllegalArgumentException, script::CannotConvertException, RuntimeException ) +{ + + Reference< storage::XScriptInfo > resolvedName; + Reference< beans::XPropertySet > xPropSetScriptingContext; + scripting_constants::ScriptingConstantsPool& scriptingConstantsPool = + scripting_constants::ScriptingConstantsPool::instance(); + + OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - start" ); + + if ( sal_False == ( invocationCtx >>= xPropSetScriptingContext ) ) + { + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolve : unable to get XScriptingContext from param" ), + Reference< XInterface > () ); + } + + Any any; + OUString docUri; + sal_Int32 filesysScriptStorageID = -1; + Reference < storage::XScriptStorageManager > xScriptStorageMgr; + sal_Int32 docSid; + try + { + any = xPropSetScriptingContext->getPropertyValue( + scriptingConstantsPool.DOC_URI ); + OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - got anyUri" ); + if ( sal_False == ( any >>= docUri ) ) + { + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolve : unable to get doc Uri from xPropSetScriptingContext" ), + Reference< XInterface > () ); + } + any = xPropSetScriptingContext->getPropertyValue( + scriptingConstantsPool.DOC_STORAGE_ID ); + if ( sal_False == ( any >>= docSid ) ) + { + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolve : unable to get doc storage id from xPropSetScriptingContext" ), + Reference< XInterface > () ); + } + } + catch ( Exception & e ) + { + OUString temp = OUSTR( + "ScriptNameResolverImpl::resolve : problem with getPropertyValue" ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } +#ifdef _DEBUG + catch ( ... ) + { + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolve Unknown Exception caught - RuntimeException rethrown" ), + Reference< XInterface > () ); + } +#endif + + + ::rtl::OString docUriO( + ::rtl::OUStringToOString( docUri , RTL_TEXTENCODING_ASCII_US ) ); + OSL_TRACE( + "ScriptNameResolverImpl::resolve: *** >>> DOC URI: %s, doc sid is %d\n", + docUriO.pData->buffer, docSid ); + + + OSL_TRACE( "ScriptNameResolverImpl::resolve Starting..." ); + OUString docString = OUString::createFromAscii( "location=document" ); + OUString userString = OUString::createFromAscii( "location=user" ); + OUString shareString = OUString::createFromAscii( "location=share" ); + OUString filesysString = OUString::createFromAscii( "location=filesystem" ); + + // initialise vector with doc, user and share + + // m_pSearchIDs is initialised as follows, + // m_pSearchIDs [ 0 ] empty + // m_pSearchIDs [ 1 ] user storage id + // m_pSearchIDs [ 2 ] share " " + + ::std::vector< sal_Int32 > m_vSearchIDs = *m_pSearchIDs; + m_vSearchIDs[ 0 ] = docSid; + + if ( scriptURI.indexOf( docString ) != -1 ) + { + OSL_TRACE("Full resolution available, search document"); + // search in document + m_vSearchIDs.resize( 1 ); + } + else if ( scriptURI.indexOf( userString ) != -1 ) + { + OSL_TRACE("Full resolution available, search user"); + // search in user + m_vSearchIDs[ 0 ] = ( *m_pSearchIDs )[ 1 ]; + m_vSearchIDs.resize( 1 ); + } + else if ( scriptURI.indexOf( shareString ) != -1 ) + { + OSL_TRACE("Full resolution available, search share"); + // search in share + m_vSearchIDs[ 0 ] = ( *m_pSearchIDs )[ 2 ]; + m_vSearchIDs.resize( 1 ); + } + else if ( scriptURI.indexOf( filesysString ) != -1 ) + { + OSL_TRACE("Full resolution available, create & search filesystem"); + OUString filesysURL; + try + { + filesysURL = getFilesysURL( scriptURI ); + } + catch ( lang::IllegalArgumentException & e ) + { + OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } + Reference< XInterface > xInterface = m_xMultiComFac->createInstanceWithContext( + ::rtl::OUString::createFromAscii( + "com.sun.star.ucb.SimpleFileAccess" ), m_xContext ); + validateXRef( xInterface, + "ScriptProvider::initialise: cannot get SimpleFileAccess Service\n" ); + Reference < ucb::XSimpleFileAccess > xSimpleFileAccess = Reference < + ucb::XSimpleFileAccess > ( xInterface, UNO_QUERY_THROW ); + + // do we need to encode this? hope not. + OSL_TRACE( ">>>> About to create storage for %s", + ::rtl::OUStringToOString( filesysURL, + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + // ask storage manager to create storage + try + { + // need to get the ScriptStorageManager + Any a = m_xContext->getValueByName( + scriptingConstantsPool.SCRIPTSTORAGEMANAGER_SERVICE ); + if ( sal_False == ( a >>= xScriptStorageMgr ) ) + { + OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: failed to get ScriptStorageManager" ); + throw RuntimeException( temp, Reference< XInterface >() ); + // need to throw + } + validateXRef( xScriptStorageMgr, "Cannot get ScriptStorageManager" ); + filesysScriptStorageID = + xScriptStorageMgr->createScriptStorageWithURI( + xSimpleFileAccess, filesysURL ); + OSL_TRACE( ">>>> Created storage %d - for %s ", + filesysScriptStorageID, ::rtl::OUStringToOString( + filesysURL, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + } + catch ( RuntimeException & e ) + { + OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } + m_vSearchIDs[ 0 ] = filesysScriptStorageID; + m_vSearchIDs.resize( 1 ); + } + else + { + OSL_TRACE("Only partial uri available, search doc, user & share"); + // is this illegal or do we search in a default way + // if we get to here a uri has been passed in that has: + // a) not got a location specified + // b) an illegal location + + // detect illegal location + if ( scriptURI.indexOf( OUString::createFromAscii( "location=" ) ) != -1 ) + { + OSL_TRACE( + "ScriptNameResolver::resolve, throwing IllegalArgException" ); + throw lang::IllegalArgumentException( + OUSTR( "invalid URI: " ).concat( scriptURI ), + Reference < XInterface > (), 1 ); + + } + // leave vSearchIDs take care of the search... + } + + ::std::vector< sal_Int32 >::const_iterator iter; + ::std::vector< sal_Int32 >::const_iterator iterEnd = m_vSearchIDs.end(); + + for ( iter = m_vSearchIDs.begin() ; iter != iterEnd; ++iter ) + { + try + { + OSL_TRACE( "** about to resolve from storage using id %d from vector of size %d", + *iter, m_vSearchIDs.size() ); + if ( ( resolvedName = resolveURIFromStorageID( *iter, docUri, scriptURI ) ).is() ) + { + OSL_TRACE( "found match in uri from storage %d", *iter ); + xPropSetScriptingContext->setPropertyValue( + scriptingConstantsPool.RESOLVED_STORAGE_ID, makeAny(*iter) ); + break; + } + + } + catch ( css::security::AccessControlException & e ) + { + // no execute permission + OSL_TRACE( "ScriptNameResolverImpl::resolve : AccessControlException " ); + continue; + } + catch ( beans::UnknownPropertyException & e ) + { + OUString temp = OUSTR( + "ScriptNameResolverImpl::resolve : UnknownPropertyException" ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } + catch ( beans::PropertyVetoException & e ) + { + OUString temp = OUSTR( + "ScriptNameResolverImpl::resolve : PropertyVetoException " ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } + catch ( lang::IllegalArgumentException & e ) + { + OUString temp = OUSTR( + "ScriptNameResolverImpl::resolve : IllegalArgumentException " ); + throw lang::IllegalArgumentException( temp.concat( e.Message ), + Reference< XInterface > (), e.ArgumentPosition ); + } + catch ( lang::WrappedTargetException & e ) + { + OUString temp = OUSTR( + "ScriptNameResolverImpl::resolve : WrappedTargetException " ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } + catch ( Exception & e ) + { + OSL_TRACE( + "Exception thrown by storage %d, failed to match uri: %s", + *iter, + ::rtl::OUStringToOString( e.Message, + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + OUString temp = OUSTR( + "ScriptNameResolverImpl::resolve : unknown exception" ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } +#ifdef _DEBUG + catch ( ... ) + { + OSL_TRACE( + "unknown exception thrown by storage %d, failed to match uri", + *iter ); + OUString temp = OUSTR( + "ScriptNameResolverImpl::resolve Unknown exception caught - RuntimeException rethrown" ); + throw RuntimeException( temp, + Reference< XInterface > () ); + } +#endif + + } + if ( !resolvedName.is() ) + { + if( filesysScriptStorageID > 2 ) + { + // get the filesys storage and dispose of it + Reference< XInterface > xScriptStorage = + xScriptStorageMgr->getScriptStorage( filesysScriptStorageID ); + validateXRef( xScriptStorage, + "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" ); + Reference< storage::XScriptInfoAccess > xScriptInfoAccess = Reference< + storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW ); + validateXRef( xScriptInfoAccess, + "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptInfoAccess" ); + Sequence< Reference< storage::XScriptInfo > > results = + xScriptInfoAccess->getAllImplementations( ); + Reference < lang::XEventListener > xEL_ScriptStorageMgr = + Reference< lang::XEventListener > + ( xScriptStorageMgr ,UNO_QUERY_THROW ); + validateXRef( xEL_ScriptStorageMgr, "ScriptNameResolverImpl::resolve: can't get ScriptStorageManager XEventListener interface when trying to dispose of filesystem storage" ); + lang::EventObject event( results[ 0 ] ); + xEL_ScriptStorageMgr->disposing( event ); + } + throw lang::IllegalArgumentException( OUSTR( + "ScriptNameResolverImpl::resolve: no script found for uri=" ).concat( scriptURI ), + Reference< XInterface > (), 0 ); + } + return resolvedName; +} + +//************************************************************************* +OUString SAL_CALL +ScriptNameResolverImpl::getImplementationName( ) +throw( RuntimeException ) +{ + return nrs_implName; +} + +//************************************************************************* +sal_Bool SAL_CALL +ScriptNameResolverImpl::supportsService( const OUString& serviceName ) +throw( RuntimeException ) +{ + OUString const * pNames = nrs_serviceNames.getConstArray(); + for ( sal_Int32 nPos = nrs_serviceNames.getLength(); nPos--; ) + { + if ( serviceName.equals( pNames[ nPos ] ) ) + { + return sal_True; + } + } + return sal_False; +} + +//************************************************************************* + +Reference< storage::XScriptInfo > +ScriptNameResolverImpl::resolveURIFromStorageID +( sal_Int32 sid, const ::rtl::OUString & docURI, + const ::rtl::OUString& scriptURI ) +SAL_THROW ( ( lang::IllegalArgumentException, css::security::AccessControlException, RuntimeException ) ) +{ + Reference< storage::XScriptInfo > resolvedScriptInfo; + scripting_constants::ScriptingConstantsPool& scriptingConstantsPool = + scripting_constants::ScriptingConstantsPool::instance(); + if ( sid == scriptingConstantsPool.DOC_STORAGE_ID_NOT_SET ) + { + OSL_TRACE( "@@@@ **** ScriptNameResolverImpl::resolve DOC_STORAGE_ID_NOT_SET" ); + return resolvedScriptInfo; + } + try + { + OUString permissionURI = docURI; + OUString filesysString = OUString::createFromAscii( "location=filesystem" ); + if ( scriptURI.indexOf( filesysString ) != -1 ) + { + // in the case of filesys scripts we're checking whether the + // location of the script, rather than the location of the document, + // has execute permission + try + { + permissionURI = getFilesysURL( scriptURI ); + } + catch ( lang::IllegalArgumentException & e ) + { + OUString temp = OUSTR( "ScriptNameResolverImpl::resolveFromURI: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } + } + Reference< storage::XScriptInfoAccess > storage = getStorageInstance( sid, permissionURI ); + validateXRef( storage, + "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptInfoAccess" ); + Sequence< Reference< storage::XScriptInfo > > results = + storage->getImplementations( scriptURI ); + + const sal_Int32 length = results.getLength(); + + if ( !length ) + { + return resolvedScriptInfo; + } + + OSL_TRACE( "ScriptNameResolverImpl::resolve Got some results..." ); + // if we get results, just return first in list, + // storage has already matched language, function name etc. if + // that information was in the uri + resolvedScriptInfo = results[ 0 ]; + } + catch ( css::security::AccessControlException & ace ) + { + OUString temp = OUSTR( + "ScriptRuntimeManager::resolveURIFromStorageID AccessControlException: " ); + throw css::security::AccessControlException( temp.concat( ace.Message ), + Reference< XInterface > (), + ace.LackingPermission ); + } + catch ( lang::IllegalArgumentException & iae ) + { + OUString temp = OUSTR( + "ScriptRuntimeManager::resolveURIFromStorageID IllegalArgumentException: " ); + throw lang::IllegalArgumentException( temp.concat( iae.Message ), + Reference< XInterface > (), + iae.ArgumentPosition ); + } + catch ( RuntimeException & re ) + { + OUString temp = OUSTR( + "ScriptRuntimeManager::resolveURIFromStorageID RuntimeException: " ); + throw RuntimeException( temp.concat( re.Message ), + Reference< XInterface > () ); + } + catch ( Exception & e ) + { + OUString temp = OUSTR( + "ScriptNameResolverImpl::resolveURIFromStorageID : Exception caught - RuntimeException rethrown" ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } +#ifdef _DEBUG + catch ( ... ) + { + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolveURIFromStorageID Unknown exception caught - RuntimeException rethrown" ), + Reference< XInterface > () ); + } +#endif + return resolvedScriptInfo; +} +//************************************************************************* + +Reference< storage::XScriptInfoAccess > + +ScriptNameResolverImpl::getStorageInstance( sal_Int32 sid, +const ::rtl::OUString & permissionURI ) SAL_THROW ( ( RuntimeException, css::security::AccessControlException, lang::IllegalArgumentException ) ) +{ + Reference< storage::XScriptInfoAccess > xScriptInfoAccess; + try + { + Reference< XInterface > xInterface; + + Any a = m_xContext->getValueByName( + OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ); + if ( sal_False == ( a >>= xInterface ) ) + { + throw RuntimeException( + OUSTR( "ScriptNameResolverImpl::getStorageInstance: could not obtain ScriptStorageManager singleton" ), + Reference< XInterface >() ); + } + validateXRef( xInterface, + "ScriptNameResolverImpl::getStorageInstance: cannot get Storage service" ); + // check that we have permissions for this storage + Reference< dcsssf::security::XScriptSecurity > xScriptSecurity( xInterface, UNO_QUERY_THROW ); + validateXRef( xScriptSecurity, + "ScriptNameResolverImpl::getStorageInstance: cannot get Script Security service" ); + scripting_constants::ScriptingConstantsPool& scriptingConstantsPool = + scripting_constants::ScriptingConstantsPool::instance(); + // if we dealing with a document storage (ie. not user or share + // we need to check the permission + if( ( sid != scriptingConstantsPool.USER_STORAGE_ID ) && + ( sid != scriptingConstantsPool.SHARED_STORAGE_ID ) ) + { + xScriptSecurity->checkPermission( permissionURI, + OUString::createFromAscii( "execute" ) ); + // if we get here, the checkPermission hasn't thrown an + // AccessControlException, ie. permission has been granted + OSL_TRACE( "ScriptNameResolverImpl::getStorageInstance: got execute permission for ID=%d", sid ); + } + Reference< storage::XScriptStorageManager > xScriptStorageManager( xInterface, UNO_QUERY_THROW ); + validateXRef( xScriptStorageManager, + "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage Manager service" ); + Reference< XInterface > xScriptStorage = + xScriptStorageManager->getScriptStorage( sid ); + validateXRef( xScriptStorage, + "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" ); + xScriptInfoAccess = Reference< + storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW ); + } + catch ( lang::IllegalArgumentException & e ) + { + OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " ); + throw lang::IllegalArgumentException( temp.concat( e.Message ), + Reference< XInterface >(), e.ArgumentPosition ); + } + catch ( css::security::AccessControlException & e ) + { + OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: AccessControlException " ); + throw css::security::AccessControlException( temp.concat( e.Message ), Reference< XInterface >(), e.LackingPermission ); + } + catch ( RuntimeException & re ) + { + OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " ); + throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() ); + } + catch ( Exception & e ) + { + OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } + return xScriptInfoAccess; +} +//************************************************************************* +OUString +ScriptNameResolverImpl::getFilesysURL( const OUString & scriptURI ) +throw( lang::IllegalArgumentException ) +{ + OUString filePath; + OUString fileName; + OUString filesysString = OUString::createFromAscii( "location=filesystem" ); + sal_Int32 locationPos = scriptURI.indexOf( filesysString ); + // expect location=filesys:file:///foo/bar/myscript.bsh etc + // except the file url at this point is encoded + // so we should be ok searching for the '&' + sal_Int32 filesysStrLen = filesysString.getLength() + 1; + sal_Int32 endOfLocn = scriptURI.indexOf( '&', locationPos ); + if (endOfLocn == -1 ) + { + filePath = scriptURI.copy( locationPos + filesysString.getLength() + 1 ); + } + else + { + filePath = scriptURI.copy( locationPos + filesysStrLen, + endOfLocn - locationPos - filesysStrLen ); + } + //file name shoul also be encoded so again ok to search for '&' + OUString functionKey = OUString::createFromAscii( "function=" ); + sal_Int32 functionKeyLength = functionKey.getLength(); + sal_Int32 functionNamePos = scriptURI.indexOf( functionKey ); + if ( functionNamePos > 0 ) + { + sal_Int32 endOfFn = scriptURI.indexOf( '&', functionNamePos ); + if ( endOfFn == -1 ) + { + fileName = scriptURI.copy( functionNamePos + functionKeyLength ); + } + else + { + fileName = scriptURI.copy( functionNamePos + functionKeyLength, + endOfFn - functionNamePos - functionKeyLength ); + } + } + else + { + // we need to throw + OUString temp = OUSTR( "ScriptNameResolverImpl::getFilesysURL: error getting the filesysURL" ); + throw lang::IllegalArgumentException( temp, Reference< XInterface >(), 0 ); + } + filePath+=fileName; + OSL_TRACE( "ScriptNameResolverImpl::getFilesysURL: filesys URL = %s", + ::rtl::OUStringToOString( filePath, + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + return filePath; +} +//************************************************************************* +Sequence<OUString> SAL_CALL +ScriptNameResolverImpl::getSupportedServiceNames( ) +throw( RuntimeException ) +{ + return nrs_serviceNames; +} + +//************************************************************************* +Reference< XInterface > SAL_CALL scriptnri_create( + Reference< XComponentContext > const & xComponentContext ) +SAL_THROW( ( Exception ) ) +{ + return ( cppu::OWeakObject * ) new ScriptNameResolverImpl( xComponentContext ); +} + +//************************************************************************* +Sequence< OUString > scriptnri_getSupportedServiceNames() SAL_THROW( () ) +{ + return nrs_serviceNames; +} + +//************************************************************************* +OUString scriptnri_getImplementationName() SAL_THROW( () ) +{ + return nrs_implName; +} +} // namespace scripting_runtimemgr + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/runtimemgr/ScriptNameResolverImpl.hxx b/scripting/source/runtimemgr/ScriptNameResolverImpl.hxx new file mode 100644 index 000000000000..089b300a1b6b --- /dev/null +++ b/scripting/source/runtimemgr/ScriptNameResolverImpl.hxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* +* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * +************************************************************************/ + +#ifndef _FRAMEWORK_SCRIPT_SCRIPTNAMERESOLVERIMPL_HXX_ +#define _FRAMEWORK_SCRIPT_SCRIPTNAMERESOLVERIMPL_HXX_ + +#include <cppuhelper/implbase1.hxx> // helper for XInterface, XTypeProvider etc. + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/script/CannotConvertException.hpp> +#include <com/sun/star/reflection/InvocationTargetException.hpp> + +#include <drafts/com/sun/star/script/framework/runtime/XScriptNameResolver.hpp> +#include <drafts/com/sun/star/script/framework/storage/XScriptInfoAccess.hpp> +#include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp> + +namespace scripting_runtimemgr +{ +// for simplification +#define css ::com::sun::star +#define dcsssf ::drafts::com::sun::star::script::framework + +class ScriptNameResolverImpl : public + ::cppu::WeakImplHelper1 < dcsssf::runtime::XScriptNameResolver > +{ +public: + /********************************************** + ScriptNameResolverImpl Constructor + @param the current context + */ + ScriptNameResolverImpl( + const css::uno::Reference< css::uno::XComponentContext > & xContext ); + ~ScriptNameResolverImpl(); + + // XServiceInfo implementation + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw( css::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw( css::uno::RuntimeException ); + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw( css::uno::RuntimeException ); + + /********************************************** + resolve method + @param scriptURI this is the given ScriptURI + @param invocationCtx the invocation context contains the + documentStorageID and document reference for use in script name + resolving. On full name resolution it sets the resolvedScriptStorageID to + the actual storage location of the fully resolved script. May or may not * be the + same as the documentStorageID. + @exception CannotResolveScriptNameException + @exception IllegalArgumentException + @exception NullPointerException + @return the resolved XScriptURI + */ + css::uno::Reference < dcsssf::storage::XScriptInfo > SAL_CALL resolve( + const ::rtl::OUString & scriptURI, + css::uno::Any& invocationCtx ) + throw( css::script::CannotConvertException, css::lang::IllegalArgumentException, + css::uno::RuntimeException ); +private: + css::uno::Reference < dcsssf::storage::XScriptInfo > + resolveURIFromStorageID( sal_Int32 sid, const rtl::OUString & docURI, + const ::rtl::OUString & nameToResolve ) + SAL_THROW ( ( css::lang::IllegalArgumentException, css::uno::RuntimeException ) ); + css::uno::Reference< dcsssf::storage::XScriptInfoAccess > + getStorageInstance( sal_Int32 sid, const rtl::OUString & permissionURI) + SAL_THROW ( ( css::uno::RuntimeException ) ); + ::rtl::OUString + ScriptNameResolverImpl::getFilesysURL( const ::rtl::OUString & scriptURI ) + throw( css::lang::IllegalArgumentException ); + + /********************************************** + Reference< XComponentContext > m_xContext + to obtain other services if needed + */ + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::lang::XMultiComponentFactory > m_xMultiComFac; + ::osl::Mutex m_mutex; + +}; +} // scripting_runtimemgr + +#endif //_FRAMEWORK_SCRIPT_SCRIPTNAMERESOLVERIMPL_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/runtimemgr/ScriptRuntimeManager.cxx b/scripting/source/runtimemgr/ScriptRuntimeManager.cxx new file mode 100644 index 000000000000..ec5a8e8a85f7 --- /dev/null +++ b/scripting/source/runtimemgr/ScriptRuntimeManager.cxx @@ -0,0 +1,567 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" + +#include <vcl/msgbox.hxx> + +#include "ScriptExecDialog.hrc" + +#include <util/scriptingconstants.hxx> + +#include <cppuhelper/implementationentry.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/lang/EventObject.hpp> + +#include "ScriptNameResolverImpl.hxx" +#include "ScriptRuntimeManager.hxx" +#include <util/util.hxx> +#include <util/scriptingconstants.hxx> + +using namespace ::rtl; +using namespace ::osl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::drafts::com::sun::star::script::framework; + +namespace scripting_runtimemgr +{ + +static OUString s_implName = ::rtl::OUString::createFromAscii( + "drafts.com.sun.star.script.framework.runtime.ScriptRuntimeManager" ); +static OUString s_serviceName = ::rtl::OUString::createFromAscii( + "drafts.com.sun.star.script.framework.runtime.ScriptRuntimeManager" ); +static Sequence< OUString > s_serviceNames = Sequence< OUString >( &s_serviceName, 1 ); + +::rtl_StandardModuleCount s_moduleCount = MODULE_COUNT_INIT; + +//************************************************************************* +// ScriptRuntimeManager Constructor +ScriptRuntimeManager::ScriptRuntimeManager( + const Reference< XComponentContext > & xContext ) : + m_xContext( xContext ) +{ + OSL_TRACE( "< ScriptRuntimeManager ctor called >\n" ); + validateXRef( m_xContext, + "ScriptRuntimeManager::ScriptRuntimeManager: invalid context" ); + m_xMgr = m_xContext->getServiceManager(); + validateXRef( m_xMgr, + "ScriptRuntimeManager::ScriptRuntimeManager: cannot get ServiceManager" ); + s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt ); + // test + //scripting_securitymgr::ScriptSecurityManager ssm(xContext); +} + +//************************************************************************* +// ScriptRuntimeManager Destructor +ScriptRuntimeManager::~ScriptRuntimeManager() +{ + OSL_TRACE( "< ScriptRuntimeManager dtor called >\n" ); + s_moduleCount.modCnt.release( &s_moduleCount.modCnt ); +} + +//************************************************************************* +// Get the proper XScriptInvocation +Reference< runtime::XScriptInvocation > SAL_CALL ScriptRuntimeManager::getScriptRuntime( +const Reference< XInterface >& scriptInfo ) +throw( RuntimeException ) +{ + OSL_TRACE( "** ==> ScriptRuntimeManager in getScriptRuntime\n" ); + + Reference< runtime::XScriptInvocation > xScriptInvocation; + + try + { + Reference< XInterface > xInterface; + + Reference< storage::XScriptInfo > sinfo = + Reference< storage::XScriptInfo >( scriptInfo, UNO_QUERY_THROW ); + + OUStringBuffer *buf = new OUStringBuffer(80); + buf->appendAscii("/singletons/drafts.com.sun.star.script.framework.runtime.theScriptRuntimeFor"); + buf->append(sinfo->getLanguage()); + + Any a = m_xContext->getValueByName(buf->makeStringAndClear()); + + if ( sal_False == ( a >>= xInterface ) ) + { + throw RuntimeException( + sinfo->getLanguage().concat( OUSTR( " runtime support is not installed for this language" ) ), + Reference< XInterface >() ); + } + validateXRef( xInterface, + "ScriptRuntimeManager::GetScriptRuntime: cannot get appropriate ScriptRuntime Service" + ); + xScriptInvocation = Reference< runtime::XScriptInvocation >( xInterface, UNO_QUERY_THROW ); + } + catch ( Exception & e ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::GetScriptRuntime: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } + + return xScriptInvocation; +} + +//************************************************************************* +// Get the proper XScriptNameResolver +Reference< runtime::XScriptNameResolver > SAL_CALL +ScriptRuntimeManager::getScriptNameResolver() +throw( RuntimeException ) +{ + OSL_TRACE( "** ==> ScriptRuntimeManager in getScriptNameResolver\n" ); + Reference< runtime::XScriptNameResolver > xScriptNameResolver; + + try + { + Reference< XInterface > xInterface = m_xMgr->createInstanceWithContext( + OUString::createFromAscii( + "drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" ), + m_xContext ); + validateXRef( xInterface, + "ScriptRuntimeManager::GetScriptRuntime: cannot get instance of DefaultScriptNameResolver" ); + xScriptNameResolver = Reference< runtime::XScriptNameResolver >( xInterface, UNO_QUERY_THROW ); + } + catch ( Exception & e ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::GetScriptNameResolver: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } + return xScriptNameResolver; +} + +//************************************************************************* +// XScriptInvocation implementation +Any SAL_CALL ScriptRuntimeManager::invoke( + const ::rtl::OUString & scriptURI, + const Any& invocationCtx, const Sequence< Any >& aParams, + Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) + throw ( lang::IllegalArgumentException, script::CannotConvertException, + reflection::InvocationTargetException, RuntimeException ) +{ + OSL_TRACE( "** ==> ScriptRuntimeManager in runtimemgr invoke\n" ); + + Any results; + scripting_constants::ScriptingConstantsPool& scriptingConstantsPool = + scripting_constants::ScriptingConstantsPool::instance(); + + // Initialise resolved context with invocation context, + // the resolved context (resolvedCtx will be modified by the + // resolve method to contain the storage where the script code is + // stored + Any resolvedCtx = invocationCtx; + + try + { + Reference< storage::XScriptInfo > resolvedScript = resolve( scriptURI, + resolvedCtx ); + validateXRef( resolvedScript, "ScriptRuntimeManager::invoke: No resolvedURI" ); + + Reference< beans::XPropertySet > xPropSetResolvedCtx; + if ( sal_False == ( resolvedCtx >>= xPropSetResolvedCtx ) ) + { + throw RuntimeException( OUSTR( + "ScriptRuntimeManager::invoke : unable to get XPropSetScriptingContext from param" ), + Reference< XInterface > () ); + } + + Any any = xPropSetResolvedCtx->getPropertyValue( + scriptingConstantsPool.RESOLVED_STORAGE_ID ); + sal_Int32 resolvedSid; + if ( sal_False == ( any >>= resolvedSid ) ) + { + throw RuntimeException( OUSTR( + "ScriptRuntimeManager::invoke : unable to get resolved storage id from xPropSetResolvedCtx" ), + Reference< XInterface > () ); + } + + OSL_TRACE("Storage sid is: %d\n", resolvedSid); + + // modifying the XPropertySet on the resolved Context to contain the + // full script info + Any aResolvedScript; + aResolvedScript <<= resolvedScript; + + xPropSetResolvedCtx->setPropertyValue( scriptingConstantsPool.SCRIPT_INFO, + aResolvedScript ); + + Reference< runtime::XScriptInvocation > xScriptInvocation = + getScriptRuntime( resolvedScript ); + validateXRef( xScriptInvocation, + "ScriptRuntimeManager::invoke: cannot get instance of language specific runtime." ); + + // the scriptURI is currently passed to the language-dept runtime but + // is not used (may be useful in the future?). All of the script info + // is contained as a property(SCRIPT_INFO) within the resolvedCtx + results = xScriptInvocation->invoke( scriptURI, resolvedCtx, aParams, + aOutParamIndex, aOutParam ); + + // need to dispose of filesystem storage + OUString filesysString = OUString::createFromAscii( + "location=filesystem" ); + if ( scriptURI.indexOf( filesysString ) != -1 ) + { + Any a = m_xContext->getValueByName( + scriptingConstantsPool.SCRIPTSTORAGEMANAGER_SERVICE ); + Reference < lang::XEventListener > xEL_ScriptStorageManager; + if ( sal_False == ( a >>= xEL_ScriptStorageManager ) ) + { + throw RuntimeException( OUSTR( "ScriptRuntimeManager::invoke: can't get ScriptStorageManager XEventListener interface when trying to dispose of filesystem storage" ), + Reference< XInterface > () ); + } + validateXRef( xEL_ScriptStorageManager, "Cannot get XEventListener from ScriptStorageManager" ); + lang::EventObject event(resolvedScript); + xEL_ScriptStorageManager->disposing( event ); + } + } + catch ( lang::IllegalArgumentException & iae ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::invoke IllegalArgumentException: " ); + throw lang::IllegalArgumentException( temp.concat( iae.Message ), + Reference< XInterface > (), + iae.ArgumentPosition ); + } + catch ( script::CannotConvertException & cce ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::invoke CannotConvertException: " ); + throw script::CannotConvertException( temp.concat( cce.Message ), + Reference< XInterface > (), + cce.DestinationTypeClass, cce.Reason, + cce.ArgumentIndex ); + } + catch ( reflection::InvocationTargetException & ite ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::invoke InvocationTargetException: " ); + throw reflection::InvocationTargetException( temp.concat( ite.Message ), + Reference< XInterface > (), ite.TargetException ); + } + catch ( beans::UnknownPropertyException & e ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::invoke UnknownPropertyException: " ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } + catch ( lang::WrappedTargetException & e ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::invoke WrappedTargetException : " ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } + catch ( RuntimeException & re ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::invoke RuntimeException: " ); + throw RuntimeException( temp.concat( re.Message ), + Reference< XInterface > () ); + } + catch ( Exception & e ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::invoke Exception: " ); + throw RuntimeException( temp.concat( e.Message ), + Reference< XInterface > () ); + } +#ifdef _DEBUG + catch ( ... ) + { + throw RuntimeException( OUSTR( "ScriptRuntimeManager::invoke UnknownException: " ), + Reference< XInterface > () ); + } +#endif + OSL_TRACE( "** ==> ScriptRuntimeManager returned from invoke: %s\n", ::rtl::OUStringToOString( results.getValueTypeName(), RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + return results; +} + +//************************************************************************* +// XScriptNameResolver implementation +Reference< storage::XScriptInfo > SAL_CALL +ScriptRuntimeManager::resolve( const ::rtl::OUString& scriptURI, + Any& invocationCtx ) +throw( lang::IllegalArgumentException, script::CannotConvertException, RuntimeException ) +{ + OSL_TRACE( "** ==> ScriptRuntimeManager in resolve\n" ); + Reference< storage::XScriptInfo > resolvedURI; + + Reference< runtime::XScriptNameResolver > xScriptNameResolver = getScriptNameResolver(); + validateXRef( xScriptNameResolver, + "ScriptRuntimeManager::resolve: No ScriptNameResolver" ); + + try + { + resolvedURI = xScriptNameResolver->resolve( scriptURI, invocationCtx ); + } + catch ( lang::IllegalArgumentException & iae ) + { + OUString temp = + OUSTR( "ScriptRuntimeManager::resolve IllegalArgumentException: " ); + throw lang::IllegalArgumentException( temp.concat( iae.Message ), + Reference< XInterface > (), + iae.ArgumentPosition ); + } + catch ( script::CannotConvertException & cce ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::resolve CannotConvertException: " ); + throw script::CannotConvertException( temp.concat( cce.Message ), + Reference< XInterface > (), + cce.DestinationTypeClass, cce.Reason, + cce.ArgumentIndex ); + } + catch ( RuntimeException & re ) + { + OUString temp = OUSTR( "ScriptRuntimeManager::resolve RuntimeException: " ); + throw RuntimeException( temp.concat( re.Message ), + Reference< XInterface > () ); + } +#ifdef _DEBUG + catch ( ... ) + { + throw RuntimeException( + OUSTR( "ScriptRuntimeManager::resolve UnknownException: " ), + Reference< XInterface > () ); + } +#endif + + return resolvedURI; +} + +//************************************************************************* +OUString SAL_CALL ScriptRuntimeManager::getImplementationName( ) +throw( RuntimeException ) +{ + return s_implName; +} + +//************************************************************************* +sal_Bool SAL_CALL ScriptRuntimeManager::supportsService( const OUString& serviceName ) +throw( RuntimeException ) +{ + OUString const * pNames = s_serviceNames.getConstArray(); + for ( sal_Int32 nPos = s_serviceNames.getLength(); nPos--; ) + { + if ( serviceName.equals( pNames[ nPos ] ) ) + { + return sal_True; + } + } + return sal_False; +} + +//************************************************************************* +Sequence<OUString> SAL_CALL ScriptRuntimeManager::getSupportedServiceNames( ) +throw( RuntimeException ) +{ + return s_serviceNames; +} + +//************************************************************************* +static Reference< XInterface > SAL_CALL srm_create( + const Reference< XComponentContext > & xCompC ) +{ + return ( cppu::OWeakObject * ) new ScriptRuntimeManager( xCompC ); +} + +//************************************************************************* +static Sequence<OUString> srm_getSupportedServiceNames( ) +SAL_THROW( () ) +{ + return s_serviceNames; +} + +//************************************************************************* +static OUString srm_getImplementationName( ) +SAL_THROW( () ) +{ + return s_implName; +} + +//************************************************************************* +Reference< XInterface > SAL_CALL scriptnri_create( + Reference< XComponentContext > const & xComponentContext ) +SAL_THROW( ( Exception ) ); + +//************************************************************************* +Sequence< OUString > scriptnri_getSupportedServiceNames() SAL_THROW( () ); + +//************************************************************************* +OUString scriptnri_getImplementationName() SAL_THROW( () ); + +//******************** ScriptStorageMangaer defines *********************** +Reference< XInterface > SAL_CALL ssm_create( + Reference< XComponentContext > const & xComponentContext ) +SAL_THROW( ( Exception ) ); +//************************************************************************* +Sequence< OUString > ssm_getSupportedServiceNames() SAL_THROW( () ); +//************************************************************************* +OUString ssm_getImplementationName() SAL_THROW( () ); +//************************************************************************* + +//************ Script Provider defines ************************************ +Reference< XInterface > SAL_CALL sp_create( const Reference< XComponentContext > & xCompC ); +//******************** ScriptProvider defines *************************** +Sequence< OUString > sp_getSupportedServiceNames( ) SAL_THROW( () ); +//************************************************************************* +OUString sp_getImplementationName( ) SAL_THROW( () ); +//************************************************************************* + +//************ ScriptStorage defines ************************************** +Reference< XInterface > SAL_CALL ss_create( const Reference< XComponentContext > & xCompC ); +//******************** ScriptProvider defines *************************** +Sequence< OUString > ss_getSupportedServiceNames( ) SAL_THROW( () ); +//************************************************************************* +OUString ss_getImplementationName( ) SAL_THROW( () ); +//************************************************************************* + + +static struct cppu::ImplementationEntry s_entries [] = + { + { + srm_create, srm_getImplementationName, + srm_getSupportedServiceNames, cppu::createSingleComponentFactory, + &s_moduleCount.modCnt, 0 + }, + { + scriptnri_create, scriptnri_getImplementationName, + scriptnri_getSupportedServiceNames, cppu::createSingleComponentFactory, + &s_moduleCount.modCnt, 0 + }, + { + ssm_create, ssm_getImplementationName, + ssm_getSupportedServiceNames, cppu::createSingleComponentFactory, + 0, 0 + }, + { + ss_create, ss_getImplementationName, + ss_getSupportedServiceNames, cppu::createSingleComponentFactory, + 0, 0 + }, + { + sp_create, sp_getImplementationName, + sp_getSupportedServiceNames, cppu::createSingleComponentFactory, + 0, 0 + }, + { 0, 0, 0, 0, 0, 0 } + }; +} // Namespace + +//####################################################################################### +//#### EXPORTED ######################################################################### +//####################################################################################### + +/** + * Gives the environment this component belongs to. + */ +extern "C" +{ + void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, + uno_Environment ** ppEnv ) + { + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + /** + * This function creates an implementation section in the registry and another subkey + * + * for each supported service. + * @param pServiceManager the service manager + * @param pRegistryKey the registry key + */ + sal_Bool SAL_CALL component_writeInfo( lang::XMultiServiceFactory * pServiceManager, + registry::XRegistryKey * pRegistryKey ) + { + if (::cppu::component_writeInfoHelper( pServiceManager, pRegistryKey, + ::scripting_runtimemgr::s_entries )) + { + try + { + // register RuntimeManager singleton + + registry::XRegistryKey * pKey = + reinterpret_cast< registry::XRegistryKey * >(pRegistryKey); + + Reference< registry::XRegistryKey > xKey( + pKey->createKey( + + OUSTR("drafts.com.sun.star.script.framework.runtime.ScriptRuntimeManager/UNO/SINGLETONS/drafts.com.sun.star.script.framework.runtime.theScriptRuntimeManager"))); + xKey->setStringValue( OUSTR("drafts.com.sun.star.script.framework.runtime.ScriptRuntimeManager") ); + + // ScriptStorage Mangaer singleton + + xKey = pKey->createKey( + OUSTR("drafts.com.sun.star.script.framework.storage.ScriptStorageManager/UNO/SINGLETONS/drafts.com.sun.star.script.framework.storage.theScriptStorageManager")); + xKey->setStringValue( OUSTR("drafts.com.sun.star.script.framework.storage.ScriptStorageManager") ); + // Singleton entries are not handled by the setup process + // below is the only alternative at the momement which + // is to programmatically do this. + + // "Java" Runtime singleton entry + + xKey = pKey->createKey( + OUSTR("com.sun.star.scripting.runtime.java.ScriptRuntimeForJava$_ScriptRuntimeForJava/UNO/SINGLETONS/drafts.com.sun.star.script.framework.runtime.theScriptRuntimeForJava")); + xKey->setStringValue( OUSTR("drafts.com.sun.star.script.framework.runtime.ScriptRuntimeForJava") ); + + // "JavaScript" Runtime singleton entry + + xKey = pKey->createKey( + OUSTR("com.sun.star.scripting.runtime.javascript.ScriptRuntimeForJavaScript$_ScriptRuntimeForJavaScript/UNO/SINGLETONS/drafts.com.sun.star.script.framework.runtime.theScriptRuntimeForJavaScript")); + xKey->setStringValue( OUSTR("drafts.com.sun.star.script.framework.runtime.ScriptRuntimeForJavaScript") ); + + // "BeanShell" Runtime singleton entry + + xKey = pKey->createKey( + OUSTR("com.sun.star.scripting.runtime.beanshell.ScriptRuntimeForBeanShell$_ScriptRuntimeForBeanShell/UNO/SINGLETONS/drafts.com.sun.star.script.framework.runtime.theScriptRuntimeForBeanShell")); + xKey->setStringValue( OUSTR("drafts.com.sun.star.script.framework.runtime.ScriptRuntimeForBeanShell") ); + + return sal_True; + } + catch (Exception & exc) + { + } + } + return sal_False; + } + + /** + * This function is called to get service factories for an implementation. + * + * @param pImplName name of implementation + * @param pServiceManager a service manager, need for component creation + * @param pRegistryKey the registry key for this component, need for persistent + * data + * @return a component factory + */ + void * SAL_CALL component_getFactory( const sal_Char * pImplName, + lang::XMultiServiceFactory * pServiceManager, + registry::XRegistryKey * pRegistryKey ) + { + return ::cppu::component_getFactoryHelper( pImplName, pServiceManager, + pRegistryKey, ::scripting_runtimemgr::s_entries ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/runtimemgr/ScriptRuntimeManager.hxx b/scripting/source/runtimemgr/ScriptRuntimeManager.hxx new file mode 100644 index 000000000000..9f97f00bdad4 --- /dev/null +++ b/scripting/source/runtimemgr/ScriptRuntimeManager.hxx @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* +* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * +************************************************************************/ + + +#ifndef _FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ +#define _FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ + +#include <osl/mutex.hxx> + +#include <cppuhelper/implbase3.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/script/CannotConvertException.hpp> +#include <com/sun/star/reflection/InvocationTargetException.hpp> + +#include <drafts/com/sun/star/script/framework/runtime/XScriptInvocation.hpp> +#include <drafts/com/sun/star/script/framework/runtime/XScriptNameResolver.hpp> + +namespace scripting_runtimemgr +{ +// for simplification +#define css ::com::sun::star +#define dcsssf ::drafts::com::sun::star::script::framework + +/** + * Class responsible for managing the various ScriptRuntime implementations. + */ +class ScriptRuntimeManager : public + ::cppu::WeakImplHelper3< dcsssf::runtime::XScriptInvocation, css::lang::XServiceInfo, + dcsssf::runtime::XScriptNameResolver > +{ +public: + explicit ScriptRuntimeManager( + const css::uno::Reference< css::uno::XComponentContext > & xContext ); + ~ScriptRuntimeManager(); + + + // XServiceInfo implementation + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw( css::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw( css::uno::RuntimeException ); + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw( css::uno::RuntimeException ); + + /** + * implements XScriptInvocation, invokes the script named in scriptURI + * (resolving it first, if necessary), with the args passed. + * + * @param scriptURI the URI, which may not be fully qualified, for the + * script to be invoked + * + ************************************************************* + Invoke + @param scriptUri script uri describing the script + @param invocationCtx + the invocation context contains the documentStorageID and document reference + for use in script name resolving + + @param aParams all parameters; pure, out params are undefined in sequence, + i.e., the value has to be ignored by the callee + @param aOutParamIndex out indices + @param aOutParam out parameters + + @returns + the value returned from the function being invoked + + @throws IllegalArgumentException + if there is no matching script name + + @throws CannotConvertException + if args do not match or cannot be converted the those + of the invokee + + @throws InvocationTargetException + if the running script throws an exception this information is captured and + rethrown as this exception type. + + */ + virtual css::uno::Any SAL_CALL invoke( + const ::rtl::OUString & scriptUri, + const css::uno::Any& invocationCtx, + const css::uno::Sequence< css::uno::Any >& aParams, + css::uno::Sequence< sal_Int16 >& aOutParamIndex, + css::uno::Sequence< css::uno::Any >& aOutParam ) + throw ( css::lang::IllegalArgumentException, + css::script::CannotConvertException, + css::reflection::InvocationTargetException, + css::uno::RuntimeException ); + + /** + * implements XScriptNameResolver, attempts to resolve the script URI + * passed in + * + * @param scriptURI the URI to be resolved + * @param invocationCtx the invocation context contains the + * documentStorageID and document reference for use in script name + * resolving. On full name resolution it sets the resolvedScriptStorageID to + * the actual storage location of the fully resolved script. May or may not * be the + same as the documentStorageID. + * @return the resolved URI + */ + virtual css::uno::Reference< dcsssf::storage::XScriptInfo > SAL_CALL resolve( + const ::rtl::OUString& scriptUri, + css::uno::Any& invocationCtx ) + throw( css::lang::IllegalArgumentException, css::script::CannotConvertException, + css::uno::RuntimeException ); + +private: + css::uno::Reference< dcsssf::runtime::XScriptInvocation > SAL_CALL getScriptRuntime( + const css::uno::Reference< css::uno::XInterface > & scriptInfo ) + throw( css::uno::RuntimeException ); + css::uno::Reference< dcsssf::runtime::XScriptNameResolver > SAL_CALL getScriptNameResolver() + throw( css::uno::RuntimeException ); + + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; + ::osl::Mutex m_mutex; +}; +} // scripting_runtimemgr + +#endif //_FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/runtimemgr/StorageBridge.cxx b/scripting/source/runtimemgr/StorageBridge.cxx new file mode 100644 index 000000000000..91734fb9a4da --- /dev/null +++ b/scripting/source/runtimemgr/StorageBridge.cxx @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" + +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp> + +#include "StorageBridge.hxx" +#include <util/util.hxx> + +using namespace ::rtl; +using namespace ::osl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::drafts::com::sun::star::script::framework; + +namespace scripting_runtimemgr +{ + +const char* const SCRIPTIMPLACCESS_SERVICE = + "drafts.com.sun.star.script.framework.storage.StorageProxy"; +const char* const SCRIPTSTORAGEMANAGER_SERVICE = + "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager"; +const int STORAGEID = 0; +const int STORAGEPROXY = 0; + + +//************************************************************************* +// StorageBridge Constructor +StorageBridge::StorageBridge( const Reference< XComponentContext >& xContext, + sal_Int32 sid ) : m_xContext( xContext ), m_sid( sid ) +{ + validateXRef( m_xContext, "StorageBridge::StorageBridge: invalid context" ); + try + { + initStorage(); + } + catch ( RuntimeException & re ) + { + OUString temp = OUSTR( "StorageBridge::StorageBridge(salIn32&): " ); + throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() ); + } +} + +//************************************************************************* +void +StorageBridge::initStorage() throw ( ::com::sun::star::uno::RuntimeException ) +{ + try + { + Reference< lang::XMultiComponentFactory > xMultiComFac = + m_xContext->getServiceManager(); + validateXRef( xMultiComFac, + "StorageBridge::StorageBridge: cannot get multicomponentfactory from multiservice factory" ); + Reference< XInterface > temp; + + Any a = m_xContext->getValueByName( + OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ); + if ( sal_False == ( a >>= temp ) ) + { + throw RuntimeException( + OUSTR( "StorageBridge::StorageBridge: could not obtain ScriptStorageManager singleton" ), + Reference< XInterface >() ); + } + validateXRef( temp, + "StorageBridge::StorageBridge: cannot get Storage service" ); + Reference< storage::XScriptStorageManager > xScriptStorageManager( temp, UNO_QUERY_THROW ); + validateXRef( xScriptStorageManager, + "StorageBridge::StorageBridge: cannot get Script Storage Manager service" ); + Reference< XInterface > xScriptStorage = + xScriptStorageManager->getScriptStorage( m_sid ); + validateXRef( xScriptStorage, + "StorageBridge::StorageBridge: cannot get Script Storage service" ); + m_xScriptInfoAccess = + Reference< storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW ); + } + catch ( RuntimeException & re ) + { + OUString temp = OUSTR( "StorageBridge::StorageBridge: " ); + throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() ); + } + catch ( Exception & e ) + { + OUString temp = OUSTR( "StorageBridge::StorageBridge: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } +} +//************************************************************************* +Sequence< ::rtl::OUString > +StorageBridge::getScriptLogicalNames() +throw ( lang::IllegalArgumentException, + RuntimeException ) +{ + OSL_TRACE( "In StorageBridge getScriptLogicalNames...\n" ); + Sequence < ::rtl::OUString > results; + try + { + results = m_xScriptInfoAccess->getScriptLogicalNames(); + } + catch ( Exception e ) + { + OUString temp = OUSTR( "StorageBridge::getScriptLogicalNames: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } + return results; +} + +//************************************************************************* +Sequence < Reference< storage::XScriptInfo > > +StorageBridge::getImplementations( const ::rtl::OUString& queryURI ) +throw ( lang::IllegalArgumentException, RuntimeException ) +{ + OSL_TRACE( "In StorageBridge getImplementations...\n" ); + Sequence < Reference< storage::XScriptInfo > > results; + try + { + results = m_xScriptInfoAccess->getImplementations( queryURI ); + } + catch ( Exception e ) + { + OUString temp = OUSTR( "StorageBridge::getImplementations: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + } + return results; +} +}// namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/runtimemgr/StorageBridge.hxx b/scripting/source/runtimemgr/StorageBridge.hxx new file mode 100644 index 000000000000..7d0e0ca8986e --- /dev/null +++ b/scripting/source/runtimemgr/StorageBridge.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* +* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * +************************************************************************/ + + +#ifndef _FRAMEWORK_SCRIPT_STORAGEBRIDGE_HXX_ +#define _FRAMEWORK_SCRIPT_STORAGEBRIDGE_HXX_ + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <drafts/com/sun/star/script/framework/storage/XScriptInfoAccess.hpp> +#include "StorageBridgeFactory.hxx" + +namespace scripting_runtimemgr +{ +// for simplification +#define css ::com::sun::star +#define dcsssf ::drafts::com::sun::star::script::framework + +class StorageBridge : public ::cppu::WeakImplHelper1< dcsssf::storage::XScriptInfoAccess > +{ + friend class StorageBridgeFactory; +public: + //XScriptInfoAccess + //========================================================================= + /** + * Get the implementations for a given URI + * + * @param queryURI + * The URI to get the implementations for + * + * @return XScriptURI + * The URIs of the implementations + */ + virtual css::uno::Sequence< css::uno::Reference< dcsssf::storage::XScriptInfo > > + SAL_CALL getImplementations( + const ::rtl::OUString& queryURI ) + throw ( css::lang::IllegalArgumentException, + css::uno::RuntimeException ); + //========================================================================= + /** + * Get the all logical names stored in this storage + * + * @return sequence < ::rtl::OUString > + * The logical names + */ + virtual css::uno::Sequence< ::rtl::OUString > + SAL_CALL getScriptLogicalNames() + throw ( css::lang::IllegalArgumentException, css::uno::RuntimeException ); +private: + StorageBridge( const css::uno::Reference< css::uno::XComponentContext >& xContext, + sal_Int32 sid ); + + void initStorage() throw ( css::uno::RuntimeException ); + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< dcsssf::storage::XScriptInfoAccess > m_xScriptInfoAccess; + sal_Int32 m_sid; +}; +} + +#endif //_COM_SUN_STAR_SCRIPTING_STORAGEBRIDGE_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/runtimemgr/StorageBridgeFactory.cxx b/scripting/source/runtimemgr/StorageBridgeFactory.cxx new file mode 100644 index 000000000000..9392eaf75184 --- /dev/null +++ b/scripting/source/runtimemgr/StorageBridgeFactory.cxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* +* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * +************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_scripting.hxx" + + +#include "StorageBridgeFactory.hxx" + +#include "StorageBridge.hxx" + +using namespace ::drafts::com::sun::star::script::framework; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star; + +namespace scripting_runtimemgr +{ + +//************************************************************************* +StorageBridgeFactory::StorageBridgeFactory( + const Reference< XComponentContext >& xContext ) : + m_xContext( xContext ) +{} + + + +//************************************************************************* +// StorageBridge is a bridge between us an storage, the StorageBridge implements the +// XScriptInfoAccess +// interface, it allows both the "real" storage and a java test storage component to be +// configured. +// @param location contains a url for the document. +// @returns a storage instance for the location "location". +// @see StorageBridge.cxx for flag "STORAGEPROXY", set to use java "test" component or +// use "real" storage. + +Reference< storage::XScriptInfoAccess > +StorageBridgeFactory::getStorageInstance( sal_Int32 sid ) +{ + + Reference< storage::XScriptInfoAccess > storage = new StorageBridge( m_xContext, + sid ) ; + return storage; +} +} //scripting_runtimemgr + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/runtimemgr/StorageBridgeFactory.hxx b/scripting/source/runtimemgr/StorageBridgeFactory.hxx new file mode 100644 index 000000000000..9631f9bb90b1 --- /dev/null +++ b/scripting/source/runtimemgr/StorageBridgeFactory.hxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* +* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * +************************************************************************/ + + +#ifndef _FRAMEWORK_SCRIPT_STORAGEBRIDGEFACTORY_HXX_ +#define _FRAMEWORK_SCRIPT_STORAGEBRIDGEFACTORY_HXX_ + +#include <rtl/ustring> + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <drafts/com/sun/star/script/framework/storage/XScriptInfoAccess.hpp> + +namespace scripting_runtimemgr +{ +// for simplification +#define css ::com::sun::star +#define dcsssf ::drafts::com::sun::star::script::framework + +class StorageBridgeFactory +{ + +public: + explicit StorageBridgeFactory( + const css::uno::Reference < css::uno::XComponentContext > & xContext ); + css::uno::Reference < dcsssf::storage::XScriptInfoAccess > + getStorageInstance( sal_Int32 sid ); +private: + StorageBridgeFactory(); // No definition for default ctor + css::uno::Reference< css::uno::XComponentContext > m_xContext; +}; +} // scripting_runtimemgr +#endif //_FRAMEWORK_SCRIPT_NAMERESOLVER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/runtimemgr/exports.dxp b/scripting/source/runtimemgr/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/scripting/source/runtimemgr/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/scripting/source/runtimemgr/makefile.mk b/scripting/source/runtimemgr/makefile.mk new file mode 100644 index 000000000000..d802fd240a2c --- /dev/null +++ b/scripting/source/runtimemgr/makefile.mk @@ -0,0 +1,48 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# 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. +# +# 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). +# +# 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. +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME= scripting +TARGET= runtimemgr +USE_DEFFILE= TRUE +ENABLE_EXCEPTIONS=TRUE +COMP1TYPELIST=$(TARGET) + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# ------------------------------------------------------------------ + +SLOFILES=\ + $(SLO)$/ScriptNameResolverImpl.obj\ + $(SLO)$/ScriptRuntimeManager.obj \ + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/scripting/source/runtimemgr/runtimemgr.xml b/scripting/source/runtimemgr/runtimemgr.xml new file mode 100755 index 000000000000..51efee1fd618 --- /dev/null +++ b/scripting/source/runtimemgr/runtimemgr.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd"> +<module-description xmlns:xlink="http://www.w3.org/1999/xlink"> + <module-name> ScriptRuntimeManager </module-name> + <component-description> + <author> Alexis Ledoux</author> + <name> drafts.com.sun.star.script.framework.ScriptRuntimeManager </name> + <description> + This component is part of the Scripting Framework +</description> + <loader-name> com.sun.star.loader.SharedLibrary </loader-name> + <language> c++ </language> + <status value="final"/> + <supported-service> drafts.com.sun.star.script.framework.ScriptRuntimeManager </supported-service> + <type> com.sun.star.lang.XSingleServiceFactory </type> + <type> com.sun.star.lang.XMultiComponentFactory </type> + <type> com.sun.star.lang.XSingleComponentFactory </type> + <type> com.sun.star.uno.XNamingService </type> + <type> com.sun.star.uno.XWeak </type> + <type> com.sun.star.lang.XMain </type> + <type> com.sun.star.uno.XAggregation </type> + <type> com.sun.star.lang.XMultiServiceFactory </type> + <type> com.sun.star.lang.XTypeProvider </type> + <type> com.sun.star.registry.XSimpleRegistry </type> + <type> com.sun.star.loader.XImplementationLoader </type> + <type> com.sun.star.registry.XImplementationRegistration </type> + <type> com.sun.star.lang.XComponent </type> + <type> com.sun.star.connection.XAcceptor </type> + <type> com.sun.star.connection.XConnector </type> + <type> com.sun.star.container.XHierarchicalNameAccess </type> + <type> com.sun.star.lang.XServiceInfo </type> + <type> com.sun.star.io.XOutputStream </type> + <type> drafts.com.sun.star.script.framework.storage.XScriptInfoAccess </type> + <type> drafts.com.sun.star.script.framework.storage.XScriptStorageManager </type> + <type> drafts.com.sun.star.script.framework.runtime.XScriptInvocation </type> + <type> drafts.com.sun.star.script.framework.runtime.XScriptNameResolver </type> + </component-description> + <project-build-dependency> cppuhelper </project-build-dependency> + <project-build-dependency> cppu </project-build-dependency> + <project-build-dependency> sal </project-build-dependency> + <runtime-module-dependency> cppuhelper$(UDK_MAJOR)$(COM) </runtime-module-dependency> + <runtime-module-dependency> salhelper$(UDK_MAJOR)$(COM) </runtime-module-dependency> + <runtime-module-dependency> cppu$(UDK_MAJOR) </runtime-module-dependency> + <runtime-module-dependency> reg$(UDK_MAJOR) </runtime-module-dependency> + <runtime-module-dependency> store$(UDK_MAJOR) </runtime-module-dependency> + <runtime-module-dependency> sal$(UDK_MAJOR) </runtime-module-dependency> +</module-description> |