diff options
author | John Rice <jmrice@openoffice.org> | 2002-09-27 11:16:30 +0000 |
---|---|---|
committer | John Rice <jmrice@openoffice.org> | 2002-09-27 11:16:30 +0000 |
commit | e168de6dd36a1a38dd81b7f4fcae5df817ad11a6 (patch) | |
tree | 85270cac2b7422cb0d58e884dccbc99da61bff23 /scripting | |
parent | a9dcd87448499e3d23f4b50c23a5ad6ee1641527 (diff) |
Updates from code review for end of September release
Diffstat (limited to 'scripting')
18 files changed, 2471 insertions, 1980 deletions
diff --git a/scripting/source/protocolhandler/scripthandler.cxx b/scripting/source/protocolhandler/scripthandler.cxx index 32302bf13f79..5eedc9f29d5a 100644 --- a/scripting/source/protocolhandler/scripthandler.cxx +++ b/scripting/source/protocolhandler/scripthandler.cxx @@ -1,65 +1,64 @@ /************************************************************************* - * - * $RCSfile: scripthandler.cxx,v $ - * - * $Revision: 1.1 $ - * - * last change: $Author: dfoster $ $Date: 2002-09-20 14:33:13 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ - -#include <stdio.h> +* +* $RCSfile: scripthandler.cxx,v $ +* +* $Revision: 1.2 $ +* +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:23 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ + #include "scripthandler.hxx" #include <osl/mutex.hxx> @@ -83,212 +82,267 @@ namespace scripting_protocolhandler { const sal_Char * const MYSERVICENAME = "com.sun.star.frame.ProtocolHandler"; -const sal_Char * const MYIMPLNAME = "com.sun.star.comp.ScriptProtocolHandler"; +const sal_Char * const MYIMPLNAME = "com.sun.star.comp.ScriptProtocolHandler"; const sal_Char * MYSCHEME = "script:"; const sal_Int32 MYSCHEME_LEN = 7; -void SAL_CALL ScriptProtocolHandler::initialize( const css::uno::Sequence < css::uno::Any >& aArguments ) throw ( css::uno::Exception ) +void SAL_CALL ScriptProtocolHandler::initialize( + const css::uno::Sequence < css::uno::Any >& aArguments ) + throw ( css::uno::Exception ) { - if (m_bInitialised) + if ( m_bInitialised ) { - OSL_TRACE("ScriptProtocolHandler Already initialised"); - return; + OSL_TRACE( "ScriptProtocolHandler Already initialised" ); + return ; } - // first argument contains a reference to the frame (may be empty or the desktop, but usually it's a "real" frame) - aArguments[0] >>= m_xFrame; + // first argument contains a reference to the frame (may be empty or the desktop, + // but usually it's a "real" frame) + aArguments[ 0 ] >>= m_xFrame; - validateXRef(m_xFactory, "ScriptProtocolHandler::initialize: No Service Manager available"); - OSL_TRACE("ScriptProtocolHandler::initialize\n " ); + validateXRef( m_xFactory, + "ScriptProtocolHandler::initialize: No Service Manager available" ); + OSL_TRACE( "ScriptProtocolHandler::initialize\n " ); try { - css::uno::Sequence < css::uno::Any > args(1); - Reference < XModel > xModel; + css::uno::Sequence < css::uno::Any > args( 1 ); + Reference< XModel > xModel; if ( m_xFrame.is() ) { - Reference < XController > xController = m_xFrame->getController(); + Reference< XController > xController = m_xFrame->getController(); if ( xController .is() ) + { xModel = xController->getModel(); + } } - args[0] <<= xModel; - Reference< XInterface > xXinterface = m_xFactory->createInstanceWithArguments(::rtl::OUString::createFromAscii( - "drafts.com.sun.star.script.framework.provider.FunctionProvider"),args); - validateXRef(xXinterface, "ScriptProtocolHandler::initialize: cannot get instance of FunctionProvider" ); - - m_xFunctionProvider = Reference< provider::XFunctionProvider >(xXinterface, UNO_QUERY_THROW); + args[ 0 ] <<= xModel; + Reference< XInterface > xXinterface = + m_xFactory->createInstanceWithArguments( + ::rtl::OUString::createFromAscii( + "drafts.com.sun.star.script.framework.provider.FunctionProvider" ), + args ); + validateXRef( xXinterface, + "ScriptProtocolHandler::initialize: cannot get instance of FunctionProvider" ); + + m_xFunctionProvider = Reference< provider::XFunctionProvider >( xXinterface, + UNO_QUERY_THROW ); m_bInitialised = true; } - catch(RuntimeException &e) + catch ( RuntimeException & e ) { - throw RuntimeException(OUSTR("ScriptProtocolHandler::initialize: ") + e.Message, Reference< XInterface >()); + ::rtl::OUString temp = OUSTR( "ScriptProtocolHandler::initialize: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); } - catch (Exception &e) + catch ( Exception & e ) { - throw RuntimeException(OUSTR("ScriptProtocolHandler::initialize: ") + e.Message, Reference< XInterface >()); - OSL_TRACE("ScriptProtocolHandler::initialise: Caught Exception %s",::rtl::OUStringToOString(e.Message,RTL_TEXTENCODING_ASCII_US).pData->buffer); + ::rtl::OUString temp = OUSTR( "ScriptProtocolHandler::initialize: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); + OSL_TRACE( "ScriptProtocolHandler::initialise: Caught Exception %s", + ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer + ); } #ifdef _DEBUG catch ( ... ) { - throw RuntimeException(OUSTR("criptProtocolHandler::initialize: UnknownException: "), - Reference<XInterface> ()); + throw RuntimeException( + OUSTR( "ScriptProtocolHandler::initialize: UnknownException: " ), + Reference< XInterface > () ); - OSL_TRACE("ScriptProtocolHandler::initialize: Unknown exception caught"); + OSL_TRACE( "ScriptProtocolHandler::initialize: Unknown exception caught" ); } #endif } -Reference< XDispatch > SAL_CALL ScriptProtocolHandler::queryDispatch( const URL& aURL, const ::rtl::OUString& sTargetFrameName, - sal_Int32 nSearchFlags ) throw( ::com::sun::star::uno::RuntimeException ) +Reference< XDispatch > SAL_CALL ScriptProtocolHandler::queryDispatch( + const URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags ) + throw( ::com::sun::star::uno::RuntimeException ) { Reference< XDispatch > xDispatcher; - OSL_TRACE("ScriptProtocolHandler::queryDispatch - 1\n" ); + OSL_TRACE( "ScriptProtocolHandler::queryDispatch - 1\n" ); - if( aURL.Complete.compareToAscii( ::scripting_protocolhandler::MYSCHEME, - ::scripting_protocolhandler::MYSCHEME_LEN ) == 0 ) + if ( aURL.Complete.compareToAscii( ::scripting_protocolhandler::MYSCHEME, + ::scripting_protocolhandler::MYSCHEME_LEN ) == 0 ) + { xDispatcher = this; - OSL_TRACE("ScriptProtocolHandler::queryDispatch - 2\n" ); - + } + OSL_TRACE( "ScriptProtocolHandler::queryDispatch - 2\n" ); return xDispatcher; } -Sequence< Reference < XDispatch > > SAL_CALL -ScriptProtocolHandler::queryDispatches( const Sequence < DispatchDescriptor >& seqDescriptor ) +Sequence< Reference< XDispatch > > SAL_CALL +ScriptProtocolHandler::queryDispatches( +const Sequence < DispatchDescriptor >& seqDescriptor ) throw( RuntimeException ) { sal_Int32 nCount = seqDescriptor.getLength(); - Sequence< Reference < XDispatch > > lDispatcher(nCount); - for( sal_Int32 i=0; i<nCount; ++i ) - lDispatcher[i] = this->queryDispatch( seqDescriptor[i].FeatureURL, - seqDescriptor[i].FrameName, - seqDescriptor[i].SearchFlags ); - OSL_TRACE("ScriptProtocolHandler::queryDispatches \n" ); + Sequence< Reference< XDispatch > > lDispatcher( nCount ); + for ( sal_Int32 i = 0; i < nCount; ++i ) + { + lDispatcher[ i ] = this->queryDispatch( seqDescriptor[ i ].FeatureURL, + seqDescriptor[ i ].FrameName, + seqDescriptor[ i ].SearchFlags ); + } + OSL_TRACE( "ScriptProtocolHandler::queryDispatches \n" ); return lDispatcher; } -void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( const URL& aURL, const Sequence < PropertyValue >& lArgs, - const Reference< XDispatchResultListener >& xListener ) throw (RuntimeException) +void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( + const URL& aURL, const Sequence < PropertyValue >& lArgs, + const Reference< XDispatchResultListener >& xListener ) + throw ( RuntimeException ) { sal_Bool bSuccess = sal_False; Any invokeResult; - OSL_TRACE("ScriptProtocolHandler::dispatchWithNotification - start \nInput URL %s \n", - ::rtl::OUStringToOString(aURL.Complete,RTL_TEXTENCODING_ASCII_US).pData->buffer); + OSL_TRACE( "ScriptProtocolHandler::dispatchWithNotification - start \nInput URL %s \n", + ::rtl::OUStringToOString( aURL.Complete, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); if ( m_bInitialised ) { try { - Reference < provider::XFunction > xFunc = m_xFunctionProvider->getFunction(aURL.Complete); - validateXRef(xFunc, "ScriptProtocolHandler::dispatchWithNotification: validate xFunc - unable to obtain XFunction interface"); + Reference< provider::XFunction > xFunc = + m_xFunctionProvider->getFunction( aURL.Complete ); + validateXRef( xFunc, + "ScriptProtocolHandler::dispatchWithNotification: validate xFunc - unable to obtain XFunction interface" ); - Sequence< Any > inArgs(0); - Sequence< Any > outArgs(0); + Sequence< Any > inArgs( 0 ); + Sequence< Any > outArgs( 0 ); Sequence< sal_Int16 > outIndex; - invokeResult = xFunc->invoke(inArgs,outIndex,outArgs); + invokeResult = xFunc->invoke( inArgs, outIndex, outArgs ); bSuccess = sal_True; } // Office doesn't handle exceptions rethrown here very well, it cores, // all we can is log them and then set fail for the dispatch event! // (if there is a listener of course) - catch(RuntimeException &e) + catch ( RuntimeException & e ) { - OSL_TRACE("ScriptProtocolHandler::dispatchWithNotificationn caught RuntimeException: %s",::rtl::OUStringToOString(e.Message,RTL_TEXTENCODING_ASCII_US).pData->buffer); - ::rtl::OUString reason; - reason.createFromAscii("ScriptProtocolHandler::dispatchWithNotification: caught RuntimeException: "); - reason = reason + e.Message; + OSL_TRACE( "ScriptProtocolHandler::dispatchWithNotificationn caught RuntimeException: %s", + ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer + ); + ::rtl::OUString reason = ::rtl::OUString::createFromAscii( + "ScriptProtocolHandler::dispatchWithNotification: caught RuntimeException: " + ); + reason.concat( e.Message ); invokeResult <<= reason; } - catch (Exception &e) + catch ( Exception & e ) { - OSL_TRACE("ScriptProtocolHandler::dispatchWithNotificationn caught Exception: %s",::rtl::OUStringToOString(e.Message,RTL_TEXTENCODING_ASCII_US).pData->buffer); - ::rtl::OUString reason; - reason.createFromAscii("ScriptProtocolHandler::dispatchWithNotification: caught Exception: "); - reason = reason + e.Message; + OSL_TRACE( "ScriptProtocolHandler::dispatchWithNotificationn caught Exception: %s", + ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer + ); + ::rtl::OUString reason = ::rtl::OUString::createFromAscii( + "ScriptProtocolHandler::dispatchWithNotification: caught Exception: " + ); + reason.concat( e.Message ); invokeResult <<= reason; } #ifdef _DEBUG catch ( ... ) { - ::rtl::OUString reason; - reason.createFromAscii("ScriptProtocolHandler::dispatchWithNotification: caught unknown exception "); + ::rtl::OUString reason = ::rtl::OUString::createFromAscii( + "ScriptProtocolHandler::dispatchWithNotification: caught unknown exception " + ); invokeResult <<= reason; } #endif + } else { - OSL_TRACE("ScriptProtocolHandler::dispatchWithNotification: failed, ScriptProtocolHandler not initialised"); - ::rtl::OUString reason; - reason.createFromAscii("ScriptProtocolHandler::dispatchWithNotification failed, ScriptProtocolHandler not initialised"); + OSL_TRACE( "ScriptProtocolHandler::dispatchWithNotification: failed, ScriptProtocolHandler not initialised" ); + ::rtl::OUString reason = ::rtl::OUString::createFromAscii( + "ScriptProtocolHandler::dispatchWithNotification failed, ScriptProtocolHandler not initialised" + ); invokeResult <<= reason; } - if( xListener.is() ) + if ( xListener.is() ) { // always call dispatchFinished(), because we didn't load a document but // executed a macro instead! ::com::sun::star::frame::DispatchResultEvent aEvent; - aEvent.Source = static_cast< ::cppu::OWeakObject* >(this); + aEvent.Source = static_cast< ::cppu::OWeakObject* >( this ); aEvent.Result = invokeResult; - if( bSuccess ) + if ( bSuccess ) + { aEvent.State = ::com::sun::star::frame::DispatchResultState::SUCCESS; + } else + { aEvent.State = ::com::sun::star::frame::DispatchResultState::FAILURE; + } - xListener->dispatchFinished( aEvent ) ; + try + { + xListener->dispatchFinished( aEvent ) ; + } + catch(RuntimeException & e) + { + OSL_TRACE( + "ScriptProtocolHandler::dispatchWithNotification: caught RuntimeException" + "while dispatchFinished %s", + ::rtl::OUStringToOString( e.Message, + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + } } - OSL_TRACE("ScriptProtocolHandler::dispatchWithNotification - end\n" ); + OSL_TRACE( "ScriptProtocolHandler::dispatchWithNotification - end" ); } -void SAL_CALL ScriptProtocolHandler::dispatch( const URL& aURL, const Sequence< PropertyValue >& lArgs ) +void SAL_CALL ScriptProtocolHandler::dispatch( +const URL& aURL, const Sequence< PropertyValue >& lArgs ) throw ( RuntimeException ) { - dispatchWithNotification( aURL, lArgs, Reference < XDispatchResultListener >() ); + dispatchWithNotification( aURL, lArgs, Reference< XDispatchResultListener >() ); } -void SAL_CALL ScriptProtocolHandler::addStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) -throw (RuntimeException) +void SAL_CALL ScriptProtocolHandler::addStatusListener( +const Reference< XStatusListener >& xControl, const URL& aURL ) +throw ( RuntimeException ) { // implement if status is supported } -void SAL_CALL ScriptProtocolHandler::removeStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) -throw (RuntimeException) -{ -} +void SAL_CALL ScriptProtocolHandler::removeStatusListener( +const Reference< XStatusListener >& xControl, const URL& aURL ) +throw ( RuntimeException ) +{} -ScriptProtocolHandler::ScriptProtocolHandler( Reference < css::lang::XMultiServiceFactory > const& rFact ) - : m_xFactory( rFact ), m_bInitialised(false) +ScriptProtocolHandler::ScriptProtocolHandler( +Reference< css::lang::XMultiServiceFactory > const& rFact ) : +m_xFactory( rFact ), m_bInitialised( false ) { - OSL_TRACE("ScriptProtocolHandler::ScriptProtocolHandler - ctor\n" ); + OSL_TRACE( "ScriptProtocolHandler::ScriptProtocolHandler - ctor" ); } ScriptProtocolHandler::~ScriptProtocolHandler() { - OSL_TRACE("ScriptProtocolHandler::ScriptProtocolHandler - dtor\n" ); + OSL_TRACE( "ScriptProtocolHandler::ScriptProtocolHandler - dtor" ); } /* XServiceInfo */ -::rtl::OUString SAL_CALL ScriptProtocolHandler::getImplementationName() throw( RuntimeException ) +::rtl::OUString SAL_CALL ScriptProtocolHandler::getImplementationName( ) +throw( RuntimeException ) { return impl_getStaticImplementationName(); } /* XServiceInfo */ -sal_Bool SAL_CALL ScriptProtocolHandler::supportsService( const ::rtl::OUString& sServiceName ) throw( RuntimeException ) +sal_Bool SAL_CALL ScriptProtocolHandler::supportsService( +const ::rtl::OUString& sServiceName ) +throw( RuntimeException ) { Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames(); const ::rtl::OUString* pArray = seqServiceNames.getConstArray(); - for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) + for ( sal_Int32 nCounter = 0; nCounter < seqServiceNames.getLength(); nCounter++ ) { - if ( pArray[nCounter] == sServiceName ) + if ( pArray[ nCounter ] == sServiceName ) { return sal_True ; } @@ -298,7 +352,8 @@ sal_Bool SAL_CALL ScriptProtocolHandler::supportsService( const ::rtl::OUString& } /* XServiceInfo */ -Sequence< ::rtl::OUString > SAL_CALL ScriptProtocolHandler::getSupportedServiceNames() throw( RuntimeException ) +Sequence< ::rtl::OUString > SAL_CALL ScriptProtocolHandler::getSupportedServiceNames() +throw( RuntimeException ) { return impl_getStaticSupportedServiceNames(); } @@ -308,77 +363,90 @@ Sequence< ::rtl::OUString > ScriptProtocolHandler::impl_getStaticSupportedServic { ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); Sequence< ::rtl::OUString > seqServiceNames( 1 ); - seqServiceNames.getArray() [0] = ::rtl::OUString::createFromAscii( ::scripting_protocolhandler::MYSERVICENAME ); + seqServiceNames.getArray() [ 0 ] = + ::rtl::OUString::createFromAscii( ::scripting_protocolhandler::MYSERVICENAME ); return seqServiceNames ; } /* Helper for XServiceInfo */ ::rtl::OUString ScriptProtocolHandler::impl_getStaticImplementationName() { - return ::rtl::OUString::createFromAscii( ::scripting_protocolhandler::MYIMPLNAME); + return ::rtl::OUString::createFromAscii( ::scripting_protocolhandler::MYIMPLNAME ); } /* Helper for registry */ -Reference < XInterface > SAL_CALL ScriptProtocolHandler::impl_createInstance( const Reference < css::lang::XMultiServiceFactory >& xServiceManager ) throw( RuntimeException ) +Reference< XInterface > SAL_CALL ScriptProtocolHandler::impl_createInstance( +const Reference< css::lang::XMultiServiceFactory >& xServiceManager ) +throw( RuntimeException ) { - return Reference < XInterface > ( *new ScriptProtocolHandler( xServiceManager ) ); + return Reference< XInterface > ( *new ScriptProtocolHandler( xServiceManager ) ); } /* Factory for registration */ -Reference < XSingleServiceFactory > ScriptProtocolHandler::impl_createFactory( const Reference< XMultiServiceFactory >& xServiceManager ) +Reference< XSingleServiceFactory > ScriptProtocolHandler::impl_createFactory( +const Reference< XMultiServiceFactory >& xServiceManager ) { - Reference < XSingleServiceFactory > xReturn ( + Reference< XSingleServiceFactory > xReturn ( cppu::createSingleFactory( xServiceManager, - ScriptProtocolHandler::impl_getStaticImplementationName(), - ScriptProtocolHandler::impl_createInstance, - ScriptProtocolHandler::impl_getStaticSupportedServiceNames() ) + ScriptProtocolHandler::impl_getStaticImplementationName(), + ScriptProtocolHandler::impl_createInstance, + ScriptProtocolHandler::impl_getStaticSupportedServiceNames() ) ); return xReturn; } -}// namespace scripting_protocolhandler +} // namespace scripting_protocolhandler /* exported functions for registration */ -extern "C" { +extern "C" +{ - void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvironmentTypeName , - uno_Environment** ppEnvironment ) + void SAL_CALL component_getImplementationEnvironment( + const sal_Char** ppEnvironmentTypeName, uno_Environment** ppEnvironment ) { *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ; } - sal_Bool SAL_CALL component_writeInfo( void* pServiceManager , - void* pRegistryKey ) + sal_Bool SAL_CALL component_writeInfo( void * pServiceManager , + void * pRegistryKey ) { - Reference< css::registry::XRegistryKey > xKey( reinterpret_cast< css::registry::XRegistryKey* >( pRegistryKey ) ) ; + Reference< css::registry::XRegistryKey > xKey( + reinterpret_cast< css::registry::XRegistryKey* >( pRegistryKey ) ) ; - ::rtl::OUString aStr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); - aStr += ::scripting_protocolhandler::ScriptProtocolHandler::impl_getStaticImplementationName(); + ::rtl::OUString aStr = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ); + aStr += + ::scripting_protocolhandler::ScriptProtocolHandler::impl_getStaticImplementationName(); - aStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES")); + aStr += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES" ) ); Reference< css::registry::XRegistryKey > xNewKey = xKey->createKey( aStr ); - xNewKey->createKey( ::rtl::OUString::createFromAscii(::scripting_protocolhandler::MYSERVICENAME) ); + xNewKey->createKey( + ::rtl::OUString::createFromAscii( ::scripting_protocolhandler::MYSERVICENAME ) + ); return sal_True; } - void* SAL_CALL component_getFactory( const sal_Char* pImplementationName , - void* pServiceManager , - void* pRegistryKey ) + void* SAL_CALL component_getFactory( const sal_Char * pImplementationName , + void * pServiceManager , + void * pRegistryKey ) { // Set default return value for this operation - if it failed. - void* pReturn = NULL ; + void * pReturn = NULL ; if ( ( pImplementationName != NULL ) && - ( pServiceManager != NULL ) + ( pServiceManager != NULL ) ) { // Define variables which are used in following macros. - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory ; - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager( reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ) ; - - if ( ::scripting_protocolhandler::ScriptProtocolHandler::impl_getStaticImplementationName().equals( ::rtl::OUString::createFromAscii( pImplementationName ) ) ) + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XSingleServiceFactory > xFactory ; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + xServiceManager( reinterpret_cast< + ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ) ; + + if ( ::scripting_protocolhandler::ScriptProtocolHandler::impl_getStaticImplementationName().equals( + ::rtl::OUString::createFromAscii( pImplementationName ) ) ) { xFactory = ::scripting_protocolhandler::ScriptProtocolHandler::impl_createFactory( xServiceManager ); } diff --git a/scripting/source/protocolhandler/scripthandler.hxx b/scripting/source/protocolhandler/scripthandler.hxx index ed4b16fa66ca..d89189e158e0 100644 --- a/scripting/source/protocolhandler/scripthandler.hxx +++ b/scripting/source/protocolhandler/scripthandler.hxx @@ -1,100 +1,75 @@ /************************************************************************* - * - * $RCSfile: scripthandler.hxx,v $ - * - * $Revision: 1.1 $ - * - * last change: $Author: dfoster $ $Date: 2002-09-20 14:33:14 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ +* +* $RCSfile: scripthandler.hxx,v $ +* +* $Revision: 1.2 $ +* +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:23 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ + +#ifndef _FRAMEWORK_SCRIPT_SCRIPTHANDLER_HXX +#define _FRAMEWORK_SCRIPT_SCRIPTHANDLER_HXX -#ifndef _SFX2_SCRIPTHANDLER_HXX -#define _SFX2_SCRIPTHANDLER_HXX - -// .. as always -#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ -#include <com/sun/star/uno/Reference.h> -#endif - -#ifndef _COM_SUN_STAR_UNO_RUNTIMEEXCEPTION_HPP_ #include <com/sun/star/uno/RuntimeException.hpp> -#endif - -// base classes -#ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_ #include <com/sun/star/frame/XDispatchProvider.hpp> -#endif - -#ifndef _COM_SUN_STAR_FRAME_XNOTIFYINGDISPATCJ_HPP_ #include <com/sun/star/frame/XNotifyingDispatch.hpp> -#endif - -#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ #include <com/sun/star/lang/XServiceInfo.hpp> -#endif - -#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ #include <com/sun/star/lang/XInitialization.hpp> -#endif - -#ifndef _CPPUHELPER_IMPLBASE4_HXX_ #include <cppuhelper/implbase4.hxx> -#endif - #include <drafts/com/sun/star/script/framework/provider/XFunctionProvider.hpp> - namespace rtl { class OUString; @@ -143,47 +118,74 @@ namespace scripting_protocolhandler #define css ::com::sun::star #define dcss ::drafts::com::sun::star -class ScriptProtocolHandler : public ::cppu::WeakImplHelper4< css::frame::XDispatchProvider, css::frame::XNotifyingDispatch, css::lang::XServiceInfo, css::lang::XInitialization > +class ScriptProtocolHandler : +public ::cppu::WeakImplHelper4< css::frame::XDispatchProvider, + css::frame::XNotifyingDispatch, css::lang::XServiceInfo, css::lang::XInitialization > { private: bool m_bInitialised; css::uno::Reference < css::lang::XMultiServiceFactory > m_xFactory; css::uno::Reference < css::frame::XFrame > m_xFrame; - css::uno::Reference < dcss::script::framework::provider::XFunctionProvider > m_xFunctionProvider; + css::uno::Reference < dcss::script::framework::provider::XFunctionProvider > + m_xFunctionProvider; public: - ScriptProtocolHandler( const css::uno::Reference < css::lang::XMultiServiceFactory >& xFactory ); - virtual ~ScriptProtocolHandler(); + ScriptProtocolHandler( const css::uno::Reference < + css::lang::XMultiServiceFactory >& xFactory ); + virtual ~ScriptProtocolHandler(); /* XServiceInfo */ - virtual ::rtl::OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException ); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException ); - virtual css::uno::Sequence < ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException ); + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw( css::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) + throw( css::uno::RuntimeException ); + virtual css::uno::Sequence < ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw( css::uno::RuntimeException ); /* Helper for XServiceInfo */ static css::uno::Sequence < ::rtl::OUString > impl_getStaticSupportedServiceNames(); static ::rtl::OUString impl_getStaticImplementationName(); /* Helper for registry */ - static css::uno::Reference < css::uno::XInterface > SAL_CALL impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::RuntimeException ); - static css::uno::Reference < css::lang::XSingleServiceFactory > impl_createFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ); + static css::uno::Reference < css::uno::XInterface > SAL_CALL + impl_createInstance( + const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) + throw( css::uno::RuntimeException ); + static css::uno::Reference < css::lang::XSingleServiceFactory > impl_createFactory( + const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ); /* Implementation for XDispatchProvider */ virtual css::uno::Reference < css::frame::XDispatch > SAL_CALL queryDispatch( const css::util::URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 eSearchFlags ) throw( css::uno::RuntimeException ) ; virtual css::uno::Sequence< css::uno::Reference < css::frame::XDispatch > > SAL_CALL - queryDispatches( const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescriptor ) + queryDispatches( + const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescriptor ) throw( css::uno::RuntimeException ); /* Implementation for X(Notifying)Dispatch */ - virtual void SAL_CALL dispatchWithNotification( const css::util::URL& aURL, const css::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArgs, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& Listener ) throw (css::uno::RuntimeException); - virtual void SAL_CALL dispatch( const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue >& lArgs ) throw (css::uno::RuntimeException); - virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) throw (css::uno::RuntimeException); - virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) throw (css::uno::RuntimeException); + virtual void SAL_CALL dispatchWithNotification( + const css::util::URL& aURL, + const css::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArgs, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& Listener ) + throw ( css::uno::RuntimeException ); + virtual void SAL_CALL dispatch( + const css::util::URL& aURL, + const css::uno::Sequence< css::beans::PropertyValue >& lArgs ) + throw ( css::uno::RuntimeException ); + virtual void SAL_CALL addStatusListener( + const css::uno::Reference< css::frame::XStatusListener >& xControl, + const css::util::URL& aURL ) + throw ( css::uno::RuntimeException ); + virtual void SAL_CALL removeStatusListener( + const css::uno::Reference< css::frame::XStatusListener >& xControl, + const css::util::URL& aURL ) + throw ( css::uno::RuntimeException ); /* Implementation for XInitialization */ - virtual void SAL_CALL initialize( const css::uno::Sequence < css::uno::Any >& aArguments ) throw ( css::uno::Exception ); + virtual void SAL_CALL initialize( + const css::uno::Sequence < css::uno::Any >& aArguments ) + throw ( css::uno::Exception ); }; } diff --git a/scripting/source/provider/ScriptingContext.cxx b/scripting/source/provider/ScriptingContext.cxx index 63113eac62f6..742831f201ed 100755 --- a/scripting/source/provider/ScriptingContext.cxx +++ b/scripting/source/provider/ScriptingContext.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ScriptingContext.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aledoux $ $Date: 2002-09-25 09:14:20 $ + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:25 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,8 +59,6 @@ * ************************************************************************/ -#include <stdio.h> - #include <cppuhelper/implementationentry.hxx> #include <cppuhelper/factory.hxx> @@ -79,32 +77,29 @@ namespace func_provider // XScriptingContext implementation // //************************************************************************* -ScriptingContext::ScriptingContext( const Reference< XComponentContext > & xContext ) : m_xContext( xContext ) +ScriptingContext::ScriptingContext( const Reference< XComponentContext > & xContext ) : + m_xContext( xContext ) { OSL_TRACE( "< ScriptingContext ctor called >\n" ); - validateXRef(m_xContext, "ScriptingContext::ScriptingContext: No context available\n"); + validateXRef( m_xContext, + "ScriptingContext::ScriptingContext: No context available\n" ); //Setup internal hash map Any nullAny; - /*m_propertyMap[scripting_constants::DOC_REF] = nullAny; - m_propertyMap[scripting_constants::DOC_STORAGE_ID] = nullAny; - m_propertyMap[scripting_constants::DOC_URI] = nullAny; - m_propertyMap[scripting_constants::RESOLVED_STORAGE_ID] = nullAny;*/ - doc_ref = nullAny; - doc_storage_id = nullAny; - doc_uri = nullAny; - resolved_storage_id = nullAny; + m_propertyMap[ scripting_constants::DOC_REF ] = nullAny; + m_propertyMap[ scripting_constants::DOC_STORAGE_ID ] = nullAny; + m_propertyMap[ scripting_constants::DOC_URI ] = nullAny; + m_propertyMap[ scripting_constants::RESOLVED_STORAGE_ID ] = nullAny; } //************************************************************************* -/*bool ScriptingContext::validateKey( const ::rtl::OUString& key) +bool ScriptingContext::validateKey( const ::rtl::OUString& key ) { ::osl::Guard< osl::Mutex > aGuard( m_mutex ); - return ( m_propertyMap.find( key ) != m_propertyMap.end() ); -}*/ +} //************************************************************************* ScriptingContext::~ScriptingContext() @@ -114,92 +109,94 @@ ScriptingContext::~ScriptingContext() //************************************************************************* // XPropertySet implementation -// //************************************************************************* -Reference< beans::XPropertySetInfo > SAL_CALL ScriptingContext::getPropertySetInfo( ) throw (RuntimeException) +Reference< beans::XPropertySetInfo > SAL_CALL ScriptingContext::getPropertySetInfo( ) + throw ( RuntimeException ) { return Reference< beans::XPropertySetInfo > (); // Not supported } //************************************************************************* - - - - - - -void SAL_CALL ScriptingContext::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException) +void SAL_CALL ScriptingContext::setPropertyValue( const ::rtl::OUString& aPropertyName, + const Any& aValue ) + throw ( beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + RuntimeException ) { - /*if ( !validateKey(aPropertyName) ) + if ( !validateKey( aPropertyName ) ) { - throw RuntimeException(OUSTR("ScriptingContext::setPropertyValue: invalid key"), - Reference< XInterface >()); -}*/ + throw RuntimeException( + OUSTR( "ScriptingContext::setPropertyValue: invalid key" ), + Reference< XInterface >() ); + } ::osl::Guard< osl::Mutex > aGuard( m_mutex ); - if ( aPropertyName.equals(scripting_constants::DOC_REF) ) - doc_ref = aValue; - if ( aPropertyName.equals(scripting_constants::DOC_STORAGE_ID) ) - doc_storage_id = aValue; - if ( aPropertyName.equals(scripting_constants::DOC_URI) ) - doc_uri = aValue; - if ( aPropertyName.equals(scripting_constants::RESOLVED_STORAGE_ID) ) - resolved_storage_id = aValue; - //m_propertyMap[ aPropertyName ] = aValue; + m_propertyMap[ aPropertyName ] = aValue; } //************************************************************************* - - - -Any SAL_CALL ScriptingContext::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) +Any SAL_CALL ScriptingContext::getPropertyValue( const ::rtl::OUString& PropertyName ) + throw ( beans::UnknownPropertyException, + lang::WrappedTargetException, RuntimeException ) { - Any temp; - /*if ( !validateKey(PropertyName) ) + if ( !validateKey( PropertyName ) ) { - throw RuntimeException(OUSTR("ScriptingContext::getPropertyValue: invalid key"), - Reference< XInterface >()); -}*/ - if ( PropertyName.equals(scripting_constants::DOC_REF) ) - return doc_ref; - if ( PropertyName.equals(scripting_constants::DOC_STORAGE_ID) ) - return doc_storage_id; - if ( PropertyName.equals(scripting_constants::DOC_URI) ) - return doc_uri; - if ( PropertyName.equals(scripting_constants::RESOLVED_STORAGE_ID) ) - return resolved_storage_id; - - return temp; + throw RuntimeException( + OUSTR( "ScriptingContext::getPropertyValue: invalid key" ), + Reference< XInterface >() ); + } + + ::osl::Guard< osl::Mutex > aGuard( m_mutex ); + Any returnValue = m_propertyMap[ PropertyName ]; + + return returnValue; } //************************************************************************* -void SAL_CALL ScriptingContext::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) +void SAL_CALL ScriptingContext::addPropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const Reference< beans::XPropertyChangeListener >& xListener ) + throw ( beans::UnknownPropertyException, lang::WrappedTargetException, + RuntimeException ) { - throw RuntimeException(OUSTR("ScriptingContext::addPropertyChangeListener: method not supported"), - Reference< XInterface >()); + throw RuntimeException( + OUSTR( "ScriptingContext::addPropertyChangeListener: method not supported" ), + Reference< XInterface >() ); } //************************************************************************* -void SAL_CALL ScriptingContext::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) +void SAL_CALL ScriptingContext::removePropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const Reference< beans::XPropertyChangeListener >& aListener ) + throw ( beans::UnknownPropertyException, lang::WrappedTargetException, + RuntimeException ) { - throw RuntimeException(OUSTR("ScriptingContext::removePropertyChangeListener: method not supported"), - Reference< XInterface >()); + throw RuntimeException( + OUSTR( "ScriptingContext::removePropertyChangeListener: method not supported" ), + Reference< XInterface >() ); } //************************************************************************* -void SAL_CALL ScriptingContext::addVetoableChangeListener( const ::rtl::OUString& PropertyName, const Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) +void SAL_CALL ScriptingContext::addVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const Reference< beans::XVetoableChangeListener >& aListener ) + throw ( beans::UnknownPropertyException, lang::WrappedTargetException, + RuntimeException ) { - throw RuntimeException(OUSTR("ScriptingContext::addVetoableChangeListener: method not supported"), - Reference< XInterface >()); + throw RuntimeException( + OUSTR( "ScriptingContext::addVetoableChangeListener: method not supported" ), + Reference< XInterface >() ); } //************************************************************************* -void SAL_CALL ScriptingContext::removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) +void SAL_CALL ScriptingContext::removeVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const Reference< beans::XVetoableChangeListener >& aListener ) + throw ( beans::UnknownPropertyException, lang::WrappedTargetException, + RuntimeException ) { - throw RuntimeException(OUSTR("ScriptingContext::removeVetoableChangeListener: method not supported"), - Reference< XInterface >()); + throw RuntimeException( + OUSTR( "ScriptingContext::removeVetoableChangeListener: method not supported" ), + Reference< XInterface >() ); } } // namespace func_provider - - - diff --git a/scripting/source/provider/ScriptingContext.hxx b/scripting/source/provider/ScriptingContext.hxx index 14900ddfcd92..57ae1b31d306 100644 --- a/scripting/source/provider/ScriptingContext.hxx +++ b/scripting/source/provider/ScriptingContext.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ScriptingContext.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aledoux $ $Date: 2002-09-25 09:14:20 $ + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:25 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,10 +59,10 @@ * ************************************************************************/ -#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_PROTOCOLHANDLER_SCRIPTING_CONTEXT_HXX_ -#define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_PROTOCOLHANDLER_SCRIPTING_CONTEXT_HXX_ +#ifndef _FRAMEWORK_SCRIPT_PROTOCOLHANDLER_SCRIPTING_CONTEXT_HXX_ +#define _FRAMEWORK_SCRIPT_PROTOCOLHANDLER_SCRIPTING_CONTEXT_HXX_ -//#include <hash_map> +#include <hash_map> #include <osl/mutex.hxx> #include <rtl/ustring> @@ -76,41 +76,75 @@ namespace func_provider //Typedefs //============================================================================= -//typedef ::std::hash_map < ::rtl::OUString, ::com::sun::star::uno::Any, -//::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > -//ScriptingConext_hash; -//typedef ::std::vector< ::rtl::OUString > -//OUString_vec; +typedef ::std::hash_map < ::rtl::OUString, ::com::sun::star::uno::Any, +::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ScriptingConext_hash; +typedef ::std::vector< ::rtl::OUString > OUString_vec; -class ScriptingContext : public ::cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertySet > +class ScriptingContext : + public ::cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertySet > { private: // to obtain other services if needed - //ScriptingConext_hash m_propertyMap; - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ScriptingConext_hash m_propertyMap; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; - osl::Mutex m_mutex; + osl::Mutex m_mutex; // Private helper methods - //bool validateKey( const ::rtl::OUString& key); - ::com::sun::star::uno::Any doc_ref; - ::com::sun::star::uno::Any doc_storage_id; - ::com::sun::star::uno::Any doc_uri; - ::com::sun::star::uno::Any resolved_storage_id; + bool validateKey( const ::rtl::OUString& key ); public: - ScriptingContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext ); + ScriptingContext( const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); ~ScriptingContext(); // XPropertySet implementation - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > + SAL_CALL getPropertySetInfo( ) + throw ( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL setPropertyValue( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Any& aValue ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::beans::PropertyVetoException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( + const ::rtl::OUString& PropertyName ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL addPropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL removePropertyChangeListener( + const ::rtl::OUString& aPropertyName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL addVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL removeVetoableChangeListener( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw ( ::com::sun::star::beans::UnknownPropertyException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); }; -}// func_provider -#endif //_DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_PROVIDER_XFUNCTIONPROVIDER_HXX_ +} // func_provider +#endif //_FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_ diff --git a/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx b/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx index cf7ffeb89490..db8943a7c452 100644 --- a/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx +++ b/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ScriptNameResolverImpl.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aledoux $ $Date: 2002-09-24 12:59:31 $ + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,10 +59,10 @@ * ************************************************************************/ -#include <stdio.h> #include <vector> #include <cppuhelper/implementationentry.hxx> + #include <util/util.hxx> #include <util/scriptingconstants.hxx> @@ -77,32 +77,37 @@ using namespace ::drafts::com::sun::star::script::framework; namespace scripting_runtimemgr { -const sal_Char* const SERVICE_NAME="drafts.com.sun.star.script.framework.DefaultScriptNameResolver"; -const sal_Char* const IMPL_NAME="drafts.com.sun.star.script.framework.DefaultScriptNameResolver"; -const sal_Char* const LANGUAGE_TO_RESOLVE_ON="Java"; // should be configurable -OUString nrs_implName = OUString::createFromAscii(IMPL_NAME); -OUString nrs_serviceName = OUString::createFromAscii(SERVICE_NAME); +const sal_Char* const LANGUAGE_TO_RESOLVE_ON = "Java"; // should be configurable +OUString nrs_implName = OUString::createFromAscii( + "drafts.com.sun.star.script.framework.DefaultScriptNameResolver" ); +OUString nrs_serviceName = OUString::createFromAscii( + "drafts.com.sun.star.script.framework.DefaultScriptNameResolver" ); Sequence< OUString > nrs_serviceNames = Sequence< OUString >( &nrs_serviceName, 1 ); -const sal_Int16 SHARED_STORAGE_ID = 1; // should be in constants def file!!!!???? TBD -const sal_Int16 USER_STORAGE_ID = 0; -const sal_Int16 DOC_STORAGE_ID_NOT_SET = -1; extern ::rtl_StandardModuleCount s_moduleCount; // define storages to search -::std::vector< int > SEARCHSIDS; +static ::std::vector< int >* m_pSearchIDs = NULL; //************************************************************************* -ScriptNameResolverImpl::ScriptNameResolverImpl(const Reference< XComponentContext > & xContext ):m_xContext(xContext),mStorageFactory(xContext) +ScriptNameResolverImpl::ScriptNameResolverImpl( + const Reference< XComponentContext > & xContext ) : + m_xContext( xContext ), m_StorageFactory( xContext ) { OSL_TRACE( "< ScriptNameResolverImpl ctor called >\n" ); - SEARCHSIDS.clear(); - SEARCHSIDS.push_back(DOC_STORAGE_ID_NOT_SET); - SEARCHSIDS.push_back(USER_STORAGE_ID); - SEARCHSIDS.push_back(SHARED_STORAGE_ID); + if(!m_pSearchIDs) + { + osl::Guard< osl::Mutex > aGuard( m_mutex ); + if(!m_pSearchIDs) + { + m_pSearchIDs = new ::std::vector< int >(); + m_pSearchIDs->push_back( ::scripting_constants::DOC_STORAGE_ID_NOT_SET ); + m_pSearchIDs->push_back( ::scripting_constants::USER_STORAGE_ID ); + m_pSearchIDs->push_back( ::scripting_constants::SHARED_STORAGE_ID ); + } + } s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt ); - } //************************************************************************* @@ -113,18 +118,20 @@ ScriptNameResolverImpl::~ScriptNameResolverImpl() } //************************************************************************* -Reference< scripturi::XScriptURI > -ScriptNameResolverImpl::resolve(const Reference<scripturi::XScriptURI> & scriptURI, Any& invocationCtx) -throw (lang::IllegalArgumentException, script::CannotConvertException, RuntimeException) +Reference< scripturi::XScriptURI > ScriptNameResolverImpl::resolve( +const Reference< scripturi::XScriptURI > & scriptURI, Any& invocationCtx ) +throw ( lang::IllegalArgumentException, script::CannotConvertException, RuntimeException ) { - Reference <scripturi::XScriptURI> resolvedName; + Reference< scripturi::XScriptURI > resolvedName; Reference< beans::XPropertySet > xPropSetScriptingContext; OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - start" ); - if (sal_False == (invocationCtx >>= xPropSetScriptingContext)) + if ( sal_False == ( invocationCtx >>= xPropSetScriptingContext ) ) { - throw RuntimeException(OUSTR("ScriptNameResolverImpl::resolve : unable to get XScriptingContext from invocationCtx in/out param"), Reference<XInterface> ()); + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolve : unable to get XScriptingContext from param" ), + Reference< XInterface > () ); } Any any; @@ -136,73 +143,88 @@ throw (lang::IllegalArgumentException, script::CannotConvertException, RuntimeEx 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> ()); + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolve : unable to get doc Uri from xPropSetScriptingContext" ), + Reference< XInterface > () ); } any = xPropSetScriptingContext->getPropertyValue( scripting_constants::DOC_STORAGE_ID ); if ( sal_False == ( any >>= docSid ) ) { - throw RuntimeException(OUSTR("ScriptNameResolverImpl::resolve : unable to get doc storage id from xPropSetScriptingContext"), Reference<XInterface> ()); + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolve : unable to get doc storage id from xPropSetScriptingContext" ), + Reference< XInterface > () ); } } - catch (Exception & e) + catch ( Exception & e ) { - OUString temp = OUSTR("ScriptNameResolverImpl::resolve : problem with getPropertyValue"); - throw RuntimeException(temp.concat(e.Message), - Reference<XInterface> ()); + 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> ()); + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolve Unknown Exception caught - RuntimeException rethrown" ), + Reference< XInterface > () ); } #endif #ifdef _DEBUG - ::rtl::OString docUriO(::rtl::OUStringToOString(docUri ,RTL_TEXTENCODING_ASCII_US)); - fprintf(stderr,"ScriptNameResolverImpl::resolve: *** >>> DOC URI: %s, doc sid is %d\n", docUriO.pData->buffer,docSid); + ::rtl::OString docUriO( + ::rtl::OUStringToOString( docUri , RTL_TEXTENCODING_ASCII_US ) ); + fprintf( stderr, + "ScriptNameResolverImpl::resolve: *** >>> DOC URI: %s, doc sid is %d\n", + docUriO.pData->buffer, docSid ); #endif - OSL_TRACE("ScriptNameResolverImpl::resolve Starting..."); - SEARCHSIDS[0] = docSid; + OSL_TRACE( "ScriptNameResolverImpl::resolve Starting..." ); + ::std::vector< int >& m_vSearchIDs = *m_pSearchIDs; + m_vSearchIDs[ 0 ] = docSid; ::std::vector< int >::const_iterator iter; + ::std::vector< int >::const_iterator iterEnd = m_vSearchIDs.end(); - - for ( iter = SEARCHSIDS.begin() ; iter != SEARCHSIDS.end(); ++iter) + 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,SEARCHSIDS.size()); - if ( (resolvedName = resolveURIFromStorageID(*iter,scriptURI) ).is() ) + OSL_TRACE( "** about to resolve from storage using id %d from vector of size %d", + *iter, m_vSearchIDs.size() ); + if ( ( resolvedName = resolveURIFromStorageID( *iter, scriptURI ) ).is() ) { - OSL_TRACE("found match in uri from storage %d",*iter); + OSL_TRACE( "found match in uri from storage %d", *iter ); break; } } - catch (Exception & e) + 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); + OSL_TRACE( "Exception thrown by storage %d, failed to match uri: %s", + *iter, + ::rtl::OUStringToOString( e.Message, + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); } #ifdef _DEBUG catch ( ... ) { - OSL_TRACE("unknown exception thrown by storage %d, failed to match uri",*iter); + OSL_TRACE( "unknown exception thrown by storage %d, failed to match uri", + *iter ); } #endif } - return resolvedName; } //************************************************************************* OUString SAL_CALL -ScriptNameResolverImpl::getImplementationName( ) -throw(RuntimeException) +ScriptNameResolverImpl::getImplementationName( ) +throw( RuntimeException ) { return nrs_implName; } @@ -210,12 +232,12 @@ throw(RuntimeException) //************************************************************************* sal_Bool SAL_CALL ScriptNameResolverImpl::supportsService( const OUString& serviceName ) -throw(RuntimeException) +throw( RuntimeException ) { OUString const * pNames = nrs_serviceNames.getConstArray(); for ( sal_Int32 nPos = nrs_serviceNames.getLength(); nPos--; ) { - if (serviceName.equals( pNames[ nPos ] )) + if ( serviceName.equals( pNames[ nPos ] ) ) { return sal_True; } @@ -226,89 +248,114 @@ throw(RuntimeException) //************************************************************************* Reference< scripturi::XScriptURI > -ScriptNameResolverImpl::resolveURIFromStorageID(sal_Int16 sid, const Reference< scripturi::XScriptURI >& scriptURI) SAL_THROW ( (lang::IllegalArgumentException, RuntimeException) ) +ScriptNameResolverImpl::resolveURIFromStorageID +( sal_Int16 sid, const Reference< scripturi::XScriptURI >& scriptURI ) +SAL_THROW ( ( lang::IllegalArgumentException, RuntimeException ) ) { #ifdef _DEBUG - ::rtl::OString locationO(::rtl::OUStringToOString(scriptURI->getLocation(),RTL_TEXTENCODING_ASCII_US)); - ::rtl::OString languageO(::rtl::OUStringToOString(scriptURI->getLanguage(),RTL_TEXTENCODING_ASCII_US)); - ::rtl::OString functionName(::rtl::OUStringToOString(scriptURI->getFunctionName(),RTL_TEXTENCODING_ASCII_US)); - ::rtl::OString logicalName(::rtl::OUStringToOString(scriptURI->getLogicalName(),RTL_TEXTENCODING_ASCII_US)); - fprintf(stderr,"trying to resolve URI, {location = %s}, {language = %s}, {funtionName = %s}, {logicalName = %s}\n", locationO.pData->buffer, languageO.pData->buffer,functionName.pData->buffer, logicalName.pData->buffer); + ::rtl::OString locationO( ::rtl::OUStringToOString( + scriptURI->getLocation(), RTL_TEXTENCODING_ASCII_US ) ); + ::rtl::OString languageO( ::rtl::OUStringToOString( + scriptURI->getLanguage(), RTL_TEXTENCODING_ASCII_US ) ); + ::rtl::OString functionName( ::rtl::OUStringToOString( + scriptURI->getFunctionName(), RTL_TEXTENCODING_ASCII_US ) ); + ::rtl::OString logicalName( ::rtl::OUStringToOString( + scriptURI->getLogicalName(), RTL_TEXTENCODING_ASCII_US ) ); + fprintf( stderr, + "trying to resolve URI, {location = %s}, {language = %s}, {funtionName = %s}, {logicalName = %s}\n", + locationO.pData->buffer, languageO.pData->buffer, + functionName.pData->buffer, logicalName.pData->buffer ); #endif Reference< scripturi::XScriptURI > resolvedName; - if ( sid == DOC_STORAGE_ID_NOT_SET ) + if ( sid == ::scripting_constants::DOC_STORAGE_ID_NOT_SET ) { return resolvedName; - } try { - Reference<storage::XScriptImplAccess> storage = mStorageFactory.getStorageInstance(sid); - validateXRef(storage, "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptImplAccess"); - Sequence< Reference< scripturi::XScriptURI > > results = storage->getImplementations(scriptURI); - if ( !results.getLength() ) + Reference< storage::XScriptImplAccess > storage = + m_StorageFactory.getStorageInstance( sid ); + validateXRef( storage, + "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptImplAccess" ); + Sequence< Reference< scripturi::XScriptURI > > results = + storage->getImplementations( scriptURI ); + + const sal_Int32 lenght = results.getLength(); + + if ( !lenght ) { return resolvedName; } - OSL_TRACE("ScriptNameResolverImpl::resolve Got some results..."); - for(int index=0;index<results.getLength();index++) + OSL_TRACE( "ScriptNameResolverImpl::resolve Got some results..." ); + for ( sal_Int32 index = 0;index < lenght;index++ ) { - Reference< scripturi::XScriptURI > uri = results[index]; + Reference< scripturi::XScriptURI > uri = results[ index ]; #ifdef _DEBUG - ::rtl::OString locationO(::rtl::OUStringToOString(uri->getLocation(),RTL_TEXTENCODING_ASCII_US)); - ::rtl::OString languageO(::rtl::OUStringToOString(uri->getLanguage(),RTL_TEXTENCODING_ASCII_US)); - ::rtl::OString functionName(::rtl::OUStringToOString(uri->getFunctionName(),RTL_TEXTENCODING_ASCII_US)); - ::rtl::OString logicalName(::rtl::OUStringToOString(uri->getLogicalName(),RTL_TEXTENCODING_ASCII_US)); - fprintf(stderr,"[%d] URI, {location = %s}, {language = %s}, {funtionName = %s}, {logicalName = %s}\n", - index, locationO.pData->buffer, languageO.pData->buffer,functionName.pData->buffer, logicalName.pData->buffer); + ::rtl::OString locationO( ::rtl::OUStringToOString( uri->getLocation(), + RTL_TEXTENCODING_ASCII_US ) ); + ::rtl::OString languageO( ::rtl::OUStringToOString( uri->getLanguage(), + RTL_TEXTENCODING_ASCII_US ) ); + ::rtl::OString functionName( ::rtl::OUStringToOString( uri->getFunctionName(), + RTL_TEXTENCODING_ASCII_US ) ); + ::rtl::OString logicalName( ::rtl::OUStringToOString( uri->getLogicalName(), + RTL_TEXTENCODING_ASCII_US ) ); + fprintf( stderr, "[%d] URI, {location = %s}, {language = %s}, {funtionName = %s}, {logicalName = %s}\n", + index, locationO.pData->buffer, languageO.pData->buffer, + functionName.pData->buffer, logicalName.pData->buffer ); #endif // just choose first one that has language=LANGUAGE_TO_RESOLVE_ON - ::rtl::OUString language(uri->getLanguage()); + ::rtl::OUString language( uri->getLanguage() ); - if (( language.compareToAscii(LANGUAGE_TO_RESOLVE_ON)== 0)) + if ( ( language.compareToAscii( LANGUAGE_TO_RESOLVE_ON ) == 0 ) ) { - OSL_TRACE("Found desired language\n"); + OSL_TRACE( "Found desired language\n" ); resolvedName = uri; break; } } } - catch (lang::IllegalArgumentException & iae) + catch ( lang::IllegalArgumentException & iae ) { - OUString temp = OUSTR("ScriptRuntimeManager::resolveURIFromStorageID IllegalArgumentException: "); - throw lang::IllegalArgumentException(temp.concat(iae.Message), - Reference<XInterface> (), iae.ArgumentPosition); + OUString temp = OUSTR( + "ScriptRuntimeManager::resolveURIFromStorageID IllegalArgumentException: " ); + throw lang::IllegalArgumentException( temp.concat( iae.Message ), + Reference< XInterface > (), + iae.ArgumentPosition ); } - catch (RuntimeException & re) + catch ( RuntimeException & re ) { - OUString temp = OUSTR("ScriptRuntimeManager::resolveURIFromStorageID RuntimeException: "); - throw RuntimeException(temp.concat(re.Message), - Reference<XInterface> ()); + OUString temp = OUSTR( + "ScriptRuntimeManager::resolveURIFromStorageID RuntimeException: " ); + throw RuntimeException( temp.concat( re.Message ), + Reference< XInterface > () ); } - catch (Exception & e) + catch ( Exception & e ) { - OUString temp = OUSTR("ScriptNameResolverImpl::resolveURIFromStorageID : Unknown Exception caught - RuntimeException rethrown"); - throw RuntimeException(temp.concat(e.Message), - Reference<XInterface> ()); + 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> ()); + throw RuntimeException( OUSTR( + "ScriptNameResolverImpl::resolveURIFromStorageID Unknown exception caught - RuntimeException rethrown" ), + Reference< XInterface > () ); } #endif return resolvedName; } //************************************************************************* Sequence<OUString> SAL_CALL -ScriptNameResolverImpl::getSupportedServiceNames( ) -throw(RuntimeException) +ScriptNameResolverImpl::getSupportedServiceNames( ) +throw( RuntimeException ) { return nrs_serviceNames; } @@ -316,9 +363,9 @@ throw(RuntimeException) //************************************************************************* Reference< XInterface > SAL_CALL scriptnri_create( Reference< XComponentContext > const & xComponentContext ) -SAL_THROW( (Exception) ) +SAL_THROW( ( Exception ) ) { - return (cppu::OWeakObject *)new ScriptNameResolverImpl( xComponentContext ); + return ( cppu::OWeakObject * ) new ScriptNameResolverImpl( xComponentContext ); } //************************************************************************* diff --git a/scripting/source/runtimemgr/ScriptNameResolverImpl.hxx b/scripting/source/runtimemgr/ScriptNameResolverImpl.hxx index 96cfcc48b18e..bb6b42d84efc 100644 --- a/scripting/source/runtimemgr/ScriptNameResolverImpl.hxx +++ b/scripting/source/runtimemgr/ScriptNameResolverImpl.hxx @@ -1,66 +1,66 @@ /************************************************************************* - * - * $RCSfile: ScriptNameResolverImpl.hxx,v $ - * - * $Revision: 1.1 $ - * - * last change: $Author: dfoster $ $Date: 2002-09-20 14:33:30 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ +* +* $RCSfile: ScriptNameResolverImpl.hxx,v $ +* +* $Revision: 1.2 $ +* +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:26 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ -#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_SCRIPTNAMERESOLVERIMPL_HXX_ -#define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_SCRIPTNAMERESOLVERIMPL_HXX_ +#ifndef _FRAMEWORK_SCRIPT_SCRIPTNAMERESOLVERIMPL_HXX_ +#define _FRAMEWORK_SCRIPT_SCRIPTNAMERESOLVERIMPL_HXX_ #include <cppuhelper/implbase1.hxx> // helper for XInterface, XTypeProvider etc. @@ -78,30 +78,28 @@ namespace scripting_runtimemgr { -class ScriptNameResolverImpl : public ::cppu::WeakImplHelper1< ::drafts::com::sun::star::script::framework::XScriptNameResolver > +class ScriptNameResolverImpl : + public ::cppu::WeakImplHelper1 < + ::drafts::com::sun::star::script::framework::XScriptNameResolver > { -private: - ::com::sun::star::uno::Reference< ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > resolveURIFromStorageID(sal_Int16 sid, const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::script::framework::scripturi::XScriptURI >& nameToResolve) SAL_THROW ( ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) ); - /********************************************** - Reference< XComponentContext > m_xContext - to obtain other services if needed - */ - - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; - StorageBridgeFactory mStorageFactory; - ::osl::Mutex m_mutex; public: /********************************************** ScriptNameResolverImpl Constructor @param the current context */ - ScriptNameResolverImpl(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext); + ScriptNameResolverImpl( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& + xContext ); ~ScriptNameResolverImpl(); // XServiceInfo implementation - virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames( ) + throw( ::com::sun::star::uno::RuntimeException ); /********************************************** resolve method @@ -109,19 +107,41 @@ public: @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. + 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 */ - ::com::sun::star::uno::Reference< ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > SAL_CALL - resolve(const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > & scriptURI, - ::com::sun::star::uno::Any& invocationCtx) - throw(::com::sun::star::script::CannotConvertException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::uno::RuntimeException); + ::com::sun::star::uno::Reference < + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > SAL_CALL + resolve( const ::com::sun::star::uno::Reference < + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > & + scriptURI, + ::com::sun::star::uno::Any& invocationCtx ) + throw( ::com::sun::star::script::CannotConvertException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException ); +private: + ::com::sun::star::uno::Reference < + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > + resolveURIFromStorageID( sal_Int16 sid, + const ::com::sun::star::uno::Reference < + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > & + nameToResolve ) + SAL_THROW ( ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException ) ); + /********************************************** + Reference< XComponentContext > m_xContext + to obtain other services if needed + */ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; + StorageBridgeFactory m_StorageFactory; + ::osl::Mutex m_mutex; + }; -}// scripting_runtimemgr +} // scripting_runtimemgr -#endif //_DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_SCRIPTNAMERESOLVERIMPL_HXX_ +#endif //_FRAMEWORK_SCRIPT_SCRIPTNAMERESOLVERIMPL_HXX_ diff --git a/scripting/source/runtimemgr/ScriptRuntimeManager.cxx b/scripting/source/runtimemgr/ScriptRuntimeManager.cxx index c33084d5b69e..9913160db979 100755 --- a/scripting/source/runtimemgr/ScriptRuntimeManager.cxx +++ b/scripting/source/runtimemgr/ScriptRuntimeManager.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ScriptRuntimeManager.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aledoux $ $Date: 2002-09-24 12:59:32 $ + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,12 +59,10 @@ * ************************************************************************/ -#include <stdio.h> - #include <cppuhelper/implementationentry.hxx> -#include "ScriptRuntimeManager.hxx" #include "ScriptNameResolverImpl.hxx" +#include "ScriptRuntimeManager.hxx" #include <util/util.hxx> using namespace ::rtl; @@ -76,19 +74,19 @@ using namespace ::drafts::com::sun::star::script::framework; namespace scripting_runtimemgr { -static const sal_Char* const SERVICENAME="drafts.com.sun.star.script.framework.ScriptRuntimeManager"; -static const sal_Char* const IMPLNAME="drafts.com.sun.star.script.framework.ScriptRuntimeManager"; - -static OUString s_implName = ::rtl::OUString::createFromAscii(IMPLNAME); -static OUString s_serviceName = ::rtl::OUString::createFromAscii(SERVICENAME); +static OUString s_implName = ::rtl::OUString::createFromAscii( + "drafts.com.sun.star.script.framework.ScriptRuntimeManager" ); +static OUString s_serviceName = ::rtl::OUString::createFromAscii( + "drafts.com.sun.star.script.framework.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 ) +ScriptRuntimeManager::ScriptRuntimeManager( + const Reference< XComponentContext > & xContext ) : + m_xContext( xContext ) { OSL_TRACE( "< ScriptRuntimeManager ctor called >\n" ); s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt ); @@ -104,29 +102,35 @@ ScriptRuntimeManager::~ScriptRuntimeManager() //************************************************************************* // Get the proper XScriptInvocation -Reference <XScriptInvocation> SAL_CALL ScriptRuntimeManager::getScriptRuntime(const Reference<scripturi::XScriptURI>& scriptURI) -throw(RuntimeException) +Reference< XScriptInvocation > SAL_CALL ScriptRuntimeManager::getScriptRuntime( +const Reference< scripturi::XScriptURI >& scriptURI ) +throw( RuntimeException ) { - OSL_TRACE("** ==> ScriptRuntimeManager in getScriptRuntime\n"); + OSL_TRACE( "** ==> ScriptRuntimeManager in getScriptRuntime\n" ); Reference< XScriptInvocation > xScriptInvocation; - validateXRef(m_xContext, "ScriptRuntimeManager::GetScriptRuntime: No context available"); + validateXRef( m_xContext, + "ScriptRuntimeManager::GetScriptRuntime: No context available" ); Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef(xMgr, "ScriptRuntimeManager::GetScriptRuntime: No service manager available"); + validateXRef( xMgr, + "ScriptRuntimeManager::GetScriptRuntime: No service manager available" ); try { Reference< XInterface > xx; - Any a = m_xContext->getValueByName(OUString::createFromAscii("/singletons/drafts.com.sun.star.script.framework.theScriptRuntimeForJava")); + Any a = m_xContext->getValueByName( OUString::createFromAscii( + "/singletons/drafts.com.sun.star.script.framework.theScriptRuntimeForJava" ) ); a >>= xx; - validateXRef(xx, "ScriptRuntimeManager::GetScriptRuntime: cannot get ScriptRuntimeForJava Service"); - xScriptInvocation = Reference<XScriptInvocation>(xx, UNO_QUERY_THROW); + validateXRef( xx, + "ScriptRuntimeManager::GetScriptRuntime: cannot get ScriptRuntimeForJava Service" + ); + xScriptInvocation = Reference< XScriptInvocation >( xx, UNO_QUERY_THROW ); } - catch (Exception &e) + catch ( Exception & e ) { - OUString temp = OUSTR("ScriptRuntimeManager::GetScriptRuntime: "); - throw RuntimeException( temp.concat(e.Message), Reference< XInterface >()); + OUString temp = OUSTR( "ScriptRuntimeManager::GetScriptRuntime: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); } return xScriptInvocation; @@ -134,27 +138,33 @@ throw(RuntimeException) //************************************************************************* // Get the proper XScriptNameResolver -Reference <XScriptNameResolver> SAL_CALL +Reference< XScriptNameResolver > SAL_CALL ScriptRuntimeManager::getScriptNameResolver() -throw(RuntimeException) +throw( RuntimeException ) { - OSL_TRACE("** ==> ScriptRuntimeManager in getScriptNameResolver\n"); + OSL_TRACE( "** ==> ScriptRuntimeManager in getScriptNameResolver\n" ); Reference< XScriptNameResolver > xScriptNameResolver; - validateXRef(m_xContext, "ScriptRuntimeManager::GetScriptNameResolver: No context available"); + validateXRef( m_xContext, + "ScriptRuntimeManager::GetScriptNameResolver: No context available" ); Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef(xMgr, "ScriptRuntimeManager::GetScriptRuntime: No Service Manager available"); + validateXRef( xMgr, + "ScriptRuntimeManager::GetScriptRuntime: No Service Manager available" ); try { - Reference< XInterface > xx = xMgr->createInstanceWithContext(OUString::createFromAscii("drafts.com.sun.star.script.framework.DefaultScriptNameResolver"),m_xContext ); - validateXRef(xx, "ScriptRuntimeManager::GetScriptRuntime: cannot get instance of DefaultScriptNameResolver" ); - xScriptNameResolver = Reference<XScriptNameResolver>(xx, UNO_QUERY_THROW); + Reference< XInterface > xx = xMgr->createInstanceWithContext( + OUString::createFromAscii( + "drafts.com.sun.star.script.framework.DefaultScriptNameResolver" ), + m_xContext ); + validateXRef( xx, + "ScriptRuntimeManager::GetScriptRuntime: cannot get instance of DefaultScriptNameResolver" ); + xScriptNameResolver = Reference< XScriptNameResolver >( xx, UNO_QUERY_THROW ); } - catch (Exception &e) + catch ( Exception & e ) { - OUString temp = OUSTR("ScriptRuntimeManager::GetScriptNameResolver: "); - throw RuntimeException( temp.concat(e.Message), Reference< XInterface >()); + OUString temp = OUSTR( "ScriptRuntimeManager::GetScriptNameResolver: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); } return xScriptNameResolver; } @@ -162,10 +172,13 @@ throw(RuntimeException) //************************************************************************* // XScriptInvocation implementation Any SAL_CALL ScriptRuntimeManager::invoke( - const Reference < scripturi::XScriptURI > & scriptURI, - const Any& invocationCtx, const Sequence< Any >& aParams, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) throw (lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, RuntimeException) + const Reference< scripturi::XScriptURI > & 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"); + OSL_TRACE( "** ==> ScriptRuntimeManager in runtimemgr invoke\n" ); Any results; // Initialise resolved context with invocation context, // the resolved context (resolvedCtx will be modified by the @@ -174,45 +187,51 @@ Any SAL_CALL ScriptRuntimeManager::invoke( Any resolvedCtx = invocationCtx; try { - Reference< scripturi::XScriptURI > resolvedURI = resolve(scriptURI, resolvedCtx); - validateXRef(resolvedURI, "ScriptRuntimeManager::invoke: No resolvedURI" ); + Reference< scripturi::XScriptURI > resolvedURI = resolve( scriptURI, + resolvedCtx ); + validateXRef( resolvedURI, "ScriptRuntimeManager::invoke: No resolvedURI" ); - Reference< XScriptInvocation > xScriptInvocation = getScriptRuntime(resolvedURI); - validateXRef(xScriptInvocation, "ScriptRuntimeManager::invoke: cannot get instance of language specific runtime."); + Reference< XScriptInvocation > xScriptInvocation = + getScriptRuntime( resolvedURI ); + validateXRef( xScriptInvocation, + "ScriptRuntimeManager::invoke: cannot get instance of language specific runtime." ); - results = xScriptInvocation->invoke(resolvedURI,resolvedCtx,aParams, - aOutParamIndex,aOutParam); + results = xScriptInvocation->invoke( resolvedURI, resolvedCtx, aParams, + aOutParamIndex, aOutParam ); } - catch (lang::IllegalArgumentException & iae) + catch ( lang::IllegalArgumentException & iae ) { - OUString temp = OUSTR("ScriptRuntimeManager::invoke IllegalArgumentException: "); - throw lang::IllegalArgumentException(temp.concat(iae.Message), - Reference<XInterface> (), iae.ArgumentPosition); + OUString temp = OUSTR( "ScriptRuntimeManager::invoke IllegalArgumentException: " ); + throw lang::IllegalArgumentException( temp.concat( iae.Message ), + Reference< XInterface > (), + iae.ArgumentPosition ); } - catch (script::CannotConvertException & cce) + 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); + 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) + catch ( reflection::InvocationTargetException & ite ) { - OUString temp = OUSTR("ScriptRuntimeManager::invoke InvocationTargetException: "); - throw reflection::InvocationTargetException(temp.concat(ite.Message), - Reference<XInterface> (), ite.TargetException); + OUString temp = OUSTR( "ScriptRuntimeManager::invoke InvocationTargetException: " ); + throw reflection::InvocationTargetException( temp.concat( ite.Message ), + Reference< XInterface > (), ite.TargetException ); } - catch (RuntimeException & re) + catch ( RuntimeException & re ) { - OUString temp = OUSTR("ScriptRuntimeManager::invoke RuntimeException: "); - throw RuntimeException(temp.concat(re.Message), - Reference<XInterface> ()); + OUString temp = OUSTR( "ScriptRuntimeManager::invoke RuntimeException: " ); + throw RuntimeException( temp.concat( re.Message ), + Reference< XInterface > () ); } #ifdef _DEBUG catch ( ... ) { - throw RuntimeException(OUSTR("ScriptRuntimeManager::invoke UnknownException: "), - Reference<XInterface> ()); + throw RuntimeException( OUSTR( "ScriptRuntimeManager::invoke UnknownException: " ), + Reference< XInterface > () ); } #endif return results; @@ -220,42 +239,50 @@ Any SAL_CALL ScriptRuntimeManager::invoke( //************************************************************************* // XScriptNameResolver implementation -Reference<scripturi::XScriptURI> SAL_CALL ScriptRuntimeManager::resolve(const Reference<scripturi::XScriptURI>& scriptURI,Any& invocationCtx) -throw(lang::IllegalArgumentException, script::CannotConvertException, RuntimeException) +Reference< scripturi::XScriptURI > SAL_CALL +ScriptRuntimeManager::resolve( const Reference< scripturi::XScriptURI >& scriptURI, + Any& invocationCtx ) +throw( lang::IllegalArgumentException, script::CannotConvertException, RuntimeException ) { - OSL_TRACE("** ==> ScriptRuntimeManager in resolve\n"); + OSL_TRACE( "** ==> ScriptRuntimeManager in resolve\n" ); Reference< scripturi::XScriptURI > resolvedURI; Reference< XScriptNameResolver > xScriptNameResolver = getScriptNameResolver(); - validateXRef(xScriptNameResolver, "ScriptRuntimeManager::resolve: No ScriptNameResolver"); + validateXRef( xScriptNameResolver, + "ScriptRuntimeManager::resolve: No ScriptNameResolver" ); try { - resolvedURI = xScriptNameResolver->resolve(scriptURI,invocationCtx); + resolvedURI = xScriptNameResolver->resolve( scriptURI, invocationCtx ); } - catch (lang::IllegalArgumentException & iae) + catch ( lang::IllegalArgumentException & iae ) { - OUString temp = OUSTR("ScriptRuntimeManager::resolve IllegalArgumentException: "); - throw lang::IllegalArgumentException(temp.concat(iae.Message), - Reference<XInterface> (), iae.ArgumentPosition); + OUString temp = + OUSTR( "ScriptRuntimeManager::resolve IllegalArgumentException: " ); + throw lang::IllegalArgumentException( temp.concat( iae.Message ), + Reference< XInterface > (), + iae.ArgumentPosition ); } - catch (script::CannotConvertException & cce) + 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); + OUString temp = OUSTR( "ScriptRuntimeManager::resolve CannotConvertException: " ); + throw script::CannotConvertException( temp.concat( cce.Message ), + Reference< XInterface > (), + cce.DestinationTypeClass, cce.Reason, + cce.ArgumentIndex ); } - catch (RuntimeException & re) + catch ( RuntimeException & re ) { - OUString temp = OUSTR("ScriptRuntimeManager::resolve RuntimeException: "); - throw RuntimeException(temp.concat(re.Message), - Reference<XInterface> ()); + 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> ()); + throw RuntimeException( + OUSTR( "ScriptRuntimeManager::resolve UnknownException: " ), + Reference< XInterface > () ); } #endif @@ -263,20 +290,20 @@ throw(lang::IllegalArgumentException, script::CannotConvertException, RuntimeExc } //************************************************************************* -OUString SAL_CALL ScriptRuntimeManager::getImplementationName( ) -throw(RuntimeException) +OUString SAL_CALL ScriptRuntimeManager::getImplementationName( ) +throw( RuntimeException ) { return s_implName; } //************************************************************************* sal_Bool SAL_CALL ScriptRuntimeManager::supportsService( const OUString& serviceName ) -throw(RuntimeException) +throw( RuntimeException ) { OUString const * pNames = s_serviceNames.getConstArray(); for ( sal_Int32 nPos = s_serviceNames.getLength(); nPos--; ) { - if (serviceName.equals( pNames[ nPos ] )) + if ( serviceName.equals( pNames[ nPos ] ) ) { return sal_True; } @@ -285,28 +312,28 @@ throw(RuntimeException) } //************************************************************************* -Sequence<OUString> SAL_CALL ScriptRuntimeManager::getSupportedServiceNames( ) -throw(RuntimeException) +Sequence<OUString> SAL_CALL ScriptRuntimeManager::getSupportedServiceNames( ) +throw( RuntimeException ) { return s_serviceNames; } //************************************************************************* -static Reference<XInterface> SAL_CALL srm_create( +static Reference< XInterface > SAL_CALL srm_create( const Reference< XComponentContext > & xCompC ) { - return (cppu::OWeakObject *)new ScriptRuntimeManager( xCompC ); + return ( cppu::OWeakObject * ) new ScriptRuntimeManager( xCompC ); } //************************************************************************* -static Sequence<OUString> srm_getSupportedServiceNames( ) +static Sequence<OUString> srm_getSupportedServiceNames( ) SAL_THROW( () ) { return s_serviceNames; } //************************************************************************* -static OUString srm_getImplementationName( ) +static OUString srm_getImplementationName( ) SAL_THROW( () ) { return s_implName; @@ -315,7 +342,7 @@ SAL_THROW( () ) //************************************************************************* Reference< XInterface > SAL_CALL scriptnri_create( Reference< XComponentContext > const & xComponentContext ) -SAL_THROW( (Exception) ); +SAL_THROW( ( Exception ) ); //************************************************************************* Sequence< OUString > scriptnri_getSupportedServiceNames() SAL_THROW( () ); @@ -340,16 +367,17 @@ static struct cppu::ImplementationEntry s_entries [] = }; } // Namespace -//################################################################################################## -//#### EXPORTED #################################################################################### -//################################################################################################## +//####################################################################################### +//#### EXPORTED ######################################################################### +//####################################################################################### /** * Gives the environment this component belongs to. */ extern "C" { - void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv) + void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, + uno_Environment ** ppEnv ) { *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; } @@ -361,9 +389,11 @@ extern "C" * @param pServiceManager the service manager * @param pRegistryKey the registry key */ - sal_Bool SAL_CALL component_writeInfo(lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey) + sal_Bool SAL_CALL component_writeInfo( lang::XMultiServiceFactory * pServiceManager, + registry::XRegistryKey * pRegistryKey ) { - return ::cppu::component_writeInfoHelper(pServiceManager, pRegistryKey, ::scripting_runtimemgr::s_entries); + return ::cppu::component_writeInfoHelper( pServiceManager, pRegistryKey, + ::scripting_runtimemgr::s_entries ); } /** @@ -371,11 +401,15 @@ extern "C" * * @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 + * @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) + 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); + return ::cppu::component_getFactoryHelper( pImplName, pServiceManager, + pRegistryKey, ::scripting_runtimemgr::s_entries ); } } diff --git a/scripting/source/runtimemgr/ScriptRuntimeManager.hxx b/scripting/source/runtimemgr/ScriptRuntimeManager.hxx index e375e519b2a5..415be3a93072 100644 --- a/scripting/source/runtimemgr/ScriptRuntimeManager.hxx +++ b/scripting/source/runtimemgr/ScriptRuntimeManager.hxx @@ -1,67 +1,67 @@ /************************************************************************* - * - * $RCSfile: ScriptRuntimeManager.hxx,v $ - * - * $Revision: 1.1 $ - * - * last change: $Author: dfoster $ $Date: 2002-09-20 14:33:32 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ - - -#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_SCRIPTRUNTIMEMANAGER_HXX_ -#define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_SCRIPTRUNTIMEMANAGER_HXX_ +* +* $RCSfile: ScriptRuntimeManager.hxx,v $ +* +* $Revision: 1.2 $ +* +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:26 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ + + +#ifndef _FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ +#define _FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ #include <osl/mutex.hxx> @@ -82,20 +82,26 @@ namespace scripting_runtimemgr /** * Class responsible for managing the various ScriptRuntime implementations. */ -class ScriptRuntimeManager : public ::cppu::WeakImplHelper3< ::drafts::com::sun::star::script::framework::XScriptInvocation, ::com::sun::star::lang::XServiceInfo, ::drafts::com::sun::star::script::framework::XScriptNameResolver > +class ScriptRuntimeManager : + public ::cppu::WeakImplHelper3< + ::drafts::com::sun::star::script::framework::XScriptInvocation, + ::com::sun::star::lang::XServiceInfo, + ::drafts::com::sun::star::script::framework::XScriptNameResolver > { - // to obtain other services if needed - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; - ::osl::Mutex m_mutex; public: - ScriptRuntimeManager( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext ); + explicit ScriptRuntimeManager( const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); ~ScriptRuntimeManager(); // XServiceInfo implementation - virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames( ) + throw( ::com::sun::star::uno::RuntimeException ); /** * implements XScriptInvocation, invokes the script named in scriptURI @@ -108,7 +114,8 @@ public: 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 + 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 @@ -126,12 +133,21 @@ public: of the invokee @throws InvocationTargetException - if the running script throws an exception this information is captured and rethrown as this exception type. + if the running script throws an exception this information is captured and + rethrown as this exception type. */ virtual ::com::sun::star::uno::Any SAL_CALL invoke( - const ::com::sun::star::uno::Reference < ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > & scriptUri, - const ::com::sun::star::uno::Any& invocationCtx, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams, ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::script::CannotConvertException, ::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException); + const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > & scriptUri, + const ::com::sun::star::uno::Any& invocationCtx, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams, + ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex, + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::script::CannotConvertException, + ::com::sun::star::reflection::InvocationTargetException, + ::com::sun::star::uno::RuntimeException ); /** * implements XScriptNameResolver, attempts to resolve the script URI @@ -141,19 +157,34 @@ public: * @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. + * the actual storage location of the fully resolved script. May or may not * be the + same as the documentStorageID. * @return the resolved URI */ - virtual ::com::sun::star::uno::Reference < ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > SAL_CALL - resolve( const ::com::sun::star::uno::Reference < ::drafts::com::sun::star::script::framework::scripturi::XScriptURI >& scriptUri ,::com::sun::star::uno::Any& invocationCtx) - throw(::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::script::CannotConvertException, - ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > SAL_CALL + resolve( + const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI >& scriptUri , + ::com::sun::star::uno::Any& invocationCtx ) + throw( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::script::CannotConvertException, + ::com::sun::star::uno::RuntimeException ); private: - ::com::sun::star::uno::Reference < ::drafts::com::sun::star::script::framework::XScriptInvocation > SAL_CALL getScriptRuntime(const ::com::sun::star::uno::Reference < ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > & scriptUri) throw( ::com::sun::star::uno::RuntimeException); - ::com::sun::star::uno::Reference < ::drafts::com::sun::star::script::framework::XScriptNameResolver > SAL_CALL getScriptNameResolver() throw( ::com::sun::star::uno::RuntimeException); + ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::XScriptInvocation > SAL_CALL + getScriptRuntime( const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > & scriptUri ) + throw( ::com::sun::star::uno::RuntimeException ); + ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::XScriptNameResolver > SAL_CALL + getScriptNameResolver() throw( ::com::sun::star::uno::RuntimeException ); + // to obtain other services if needed + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; + ::osl::Mutex m_mutex; }; } // scripting_runtimemgr -#endif //_COM_SUN_STAR_SCRIPTING_SCRIPTRUNTIMEMANAGER_HXX_ +#endif //_FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ diff --git a/scripting/source/runtimemgr/StorageBridge.cxx b/scripting/source/runtimemgr/StorageBridge.cxx index b46d85c98c79..17f3d488a634 100644 --- a/scripting/source/runtimemgr/StorageBridge.cxx +++ b/scripting/source/runtimemgr/StorageBridge.cxx @@ -2,9 +2,9 @@ * * $RCSfile: StorageBridge.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: aledoux $ $Date: 2002-09-24 12:59:32 $ + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,11 +59,6 @@ * ************************************************************************/ - -#include <stdio.h> -#include <rtl/ustring.hxx> -#include <osl/diagnose.h> - #include <com/sun/star/lang/XMultiComponentFactory.hpp> #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp> @@ -79,77 +74,91 @@ 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 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_Int16 sid ):m_xContext(xContext),m_sid(sid) +StorageBridge::StorageBridge( const Reference< XComponentContext >& xContext, + sal_uInt16 sid ) : m_xContext( xContext ), m_sid( sid ) { try { initStorage(); } - catch(RuntimeException& re) + catch ( RuntimeException & re ) { - OUString temp = OUSTR("StorageBridge::StorageBridge(salIn32&): "); - throw RuntimeException( temp.concat(re.Message), Reference< XInterface >()); + OUString temp = OUSTR( "StorageBridge::StorageBridge(salIn32&): " ); + throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() ); } } //************************************************************************* void -StorageBridge::initStorage() throw (::com::sun::star::uno::RuntimeException) +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< lang::XMultiComponentFactory > xMultiComFac = + m_xContext->getServiceManager(); + validateXRef( xMultiComFac, + "StorageBridge::StorageBridge: cannot get multicomponentfactory from multiservice factory" ); Reference< XInterface > temp; - if(STORAGEPROXY) + if ( STORAGEPROXY ) { - temp = xMultiComFac->createInstanceWithContext(OUString::createFromAscii(SCRIPTIMPLACCESS_SERVICE),m_xContext); - validateXRef(temp, "StorageBridge::StorageBridge: cannot get Storage service"); - m_xScriptImplAccess = Reference< storage::XScriptImplAccess > (temp, UNO_QUERY_THROW); + temp = xMultiComFac->createInstanceWithContext( + OUString::createFromAscii( SCRIPTIMPLACCESS_SERVICE ), m_xContext ); + validateXRef( temp, "StorageBridge::StorageBridge: cannot get Storage service" ); + m_xScriptImplAccess = Reference< storage::XScriptImplAccess > ( temp, + UNO_QUERY_THROW ); } else { - Any a = m_xContext->getValueByName(OUString::createFromAscii(SCRIPTSTORAGEMANAGER_SERVICE)); + Any a = m_xContext->getValueByName( + OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ); a >>= temp; - validateXRef(temp, "StorageBridge::StorageBridge: cannot get Storage service"); - Reference < storage::XScriptStorageManager > xScriptStorageManager = Reference< storage::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_xScriptImplAccess = Reference< storage::XScriptImplAccess > (xScriptStorage, UNO_QUERY_THROW); + validateXRef( temp, + "StorageBridge::StorageBridge: cannot get Storage service" ); + Reference< storage::XScriptStorageManager > xScriptStorageManager = + Reference< storage::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_xScriptImplAccess = + Reference< storage::XScriptImplAccess > ( xScriptStorage, UNO_QUERY_THROW ); } } - catch (Exception e) + catch ( Exception e ) { - OUString temp = OUSTR("StorageBridge::StorageBridge: "); - throw RuntimeException( temp.concat(e.Message), Reference< XInterface >()); + OUString temp = OUSTR( "StorageBridge::StorageBridge: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); } } //************************************************************************* Sequence < Reference< scripturi::XScriptURI > > -StorageBridge::getImplementations(const Reference< scripturi::XScriptURI >& queryURI ) -throw (lang::IllegalArgumentException, RuntimeException) +StorageBridge::getImplementations( const Reference< scripturi::XScriptURI >& queryURI ) +throw ( lang::IllegalArgumentException, RuntimeException ) { - OSL_TRACE("In StorageBridge getImplementations...\n"); + OSL_TRACE( "In StorageBridge getImplementations...\n" ); Sequence < Reference< scripturi::XScriptURI > > results; try { - results = m_xScriptImplAccess->getImplementations(queryURI); + results = m_xScriptImplAccess->getImplementations( queryURI ); } - catch (Exception e) + catch ( Exception e ) { - OUString temp = OUSTR("StorageBridge::getImplementations: "); - throw RuntimeException( temp.concat(e.Message), Reference< XInterface >()); + OUString temp = OUSTR( "StorageBridge::getImplementations: " ); + throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); } return results; } -} +}// namespace diff --git a/scripting/source/runtimemgr/StorageBridge.hxx b/scripting/source/runtimemgr/StorageBridge.hxx index 1fe2835eaed3..c0eee9431eb7 100644 --- a/scripting/source/runtimemgr/StorageBridge.hxx +++ b/scripting/source/runtimemgr/StorageBridge.hxx @@ -1,67 +1,67 @@ /************************************************************************* - * - * $RCSfile: StorageBridge.hxx,v $ - * - * $Revision: 1.1 $ - * - * last change: $Author: dfoster $ $Date: 2002-09-20 14:33:33 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ +* +* $RCSfile: StorageBridge.hxx,v $ +* +* $Revision: 1.2 $ +* +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:26 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ -#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGEBRIDGE_HXX_ -#define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGEBRIDGE_HXX_ +#ifndef _FRAMEWORK_SCRIPT_STORAGEBRIDGE_HXX_ +#define _FRAMEWORK_SCRIPT_STORAGEBRIDGE_HXX_ #include <cppuhelper/implbase1.hxx> #include <com/sun/star/uno/XComponentContext.hpp> @@ -71,18 +71,41 @@ namespace scripting_runtimemgr { -class StorageBridge : public ::cppu::WeakImplHelper1< ::drafts::com::sun::star::script::framework::storage::XScriptImplAccess > +class StorageBridge : + public ::cppu::WeakImplHelper1< + ::drafts::com::sun::star::script::framework::storage::XScriptImplAccess > { friend class StorageBridgeFactory; public: - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > > SAL_CALL getImplementations( const ::com::sun::star::uno::Reference< ::drafts::com::sun::star::script::framework::scripturi::XScriptURI >& queryURI ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + //XScriptImplAccess + //========================================================================= + /** + * Get the implementations for a given URI + * + * @param queryURI + * The URI to get the implementations for + * + * @return XScriptURI + * The URIs of the implementations + */ + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > > SAL_CALL + getImplementations( + const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI >& queryURI ) + throw ( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException ); private: - StorageBridge(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext, sal_Int16 sid ); + StorageBridge( const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext >& xContext, sal_uInt16 sid ); - void initStorage() throw (::com::sun::star::uno::RuntimeException); - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; - ::com::sun::star::uno::Reference< ::drafts::com::sun::star::script::framework::storage::XScriptImplAccess > m_xScriptImplAccess; - sal_Int16 m_sid; + void initStorage() throw ( ::com::sun::star::uno::RuntimeException ); + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; + ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::storage::XScriptImplAccess > + m_xScriptImplAccess; + sal_uInt16 m_sid; }; } diff --git a/scripting/source/runtimemgr/StorageBridgeFactory.cxx b/scripting/source/runtimemgr/StorageBridgeFactory.cxx index 5a613570c158..2c6f44c1705c 100644 --- a/scripting/source/runtimemgr/StorageBridgeFactory.cxx +++ b/scripting/source/runtimemgr/StorageBridgeFactory.cxx @@ -1,99 +1,100 @@ /************************************************************************* - * - * $RCSfile: StorageBridgeFactory.cxx,v $ - * - * $Revision: 1.1 $ - * - * last change: $Author: dfoster $ $Date: 2002-09-20 14:33:34 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ +* +* $RCSfile: StorageBridgeFactory.cxx,v $ +* +* $Revision: 1.2 $ +* +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:27 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ #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) -{ -} +StorageBridgeFactory::StorageBridgeFactory( + const Reference< XComponentContext >& xContext ) : + m_xContext( xContext ) +{} //************************************************************************* -// StorageBridge is a bridge between us an storage, the StorageBridge implements the XScriptImplAccess -// interface, it allows both the "real" storage and a java test storage component to be configured. +// StorageBridge is a bridge between us an storage, the StorageBridge implements the +// XScriptImplAccess +// 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. - +// @see StorageBridge.cxx for flag "STORAGEPROXY", set to use java "test" component or +// use "real" storage. Reference< storage::XScriptImplAccess > -StorageBridgeFactory::getStorageInstance(sal_Int16 sid) +StorageBridgeFactory::getStorageInstance( sal_Int16 sid ) { - Reference <storage::XScriptImplAccess> storage = new StorageBridge(m_xContext,sid) ; + Reference< storage::XScriptImplAccess > storage = new StorageBridge( m_xContext, + sid ) ; return storage; } } //scripting_runtimemgr diff --git a/scripting/source/runtimemgr/StorageBridgeFactory.hxx b/scripting/source/runtimemgr/StorageBridgeFactory.hxx index 4846e1b9d998..262370d22689 100644 --- a/scripting/source/runtimemgr/StorageBridgeFactory.hxx +++ b/scripting/source/runtimemgr/StorageBridgeFactory.hxx @@ -1,67 +1,67 @@ /************************************************************************* - * - * $RCSfile: StorageBridgeFactory.hxx,v $ - * - * $Revision: 1.1 $ - * - * last change: $Author: dfoster $ $Date: 2002-09-20 14:33:34 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ +* +* $RCSfile: StorageBridgeFactory.hxx,v $ +* +* $Revision: 1.2 $ +* +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:27 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ -#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGEBRIDGEFACTORY_HXX_ -#define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGEBRIDGEFACTORY_HXX_ +#ifndef _FRAMEWORK_SCRIPT_STORAGEBRIDGEFACTORY_HXX_ +#define _FRAMEWORK_SCRIPT_STORAGEBRIDGEFACTORY_HXX_ #include <rtl/ustring> @@ -76,11 +76,16 @@ class StorageBridgeFactory { public: - StorageBridgeFactory(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ); - ::com::sun::star::uno::Reference< ::drafts::com::sun::star::script::framework::storage::XScriptImplAccess > getStorageInstance(sal_Int16 sid); - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + explicit StorageBridgeFactory( const ::com::sun::star::uno::Reference < + ::com::sun::star::uno::XComponentContext > & xContext + ); + ::com::sun::star::uno::Reference < + ::drafts::com::sun::star::script::framework::storage::XScriptImplAccess > + getStorageInstance( sal_Int16 sid ); private: - StorageBridgeFactory();// No definition for default ctor + StorageBridgeFactory(); // No definition for default ctor + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; }; -}// scripting_runtimemgr -#endif //_DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_NAMERESOLVER_HXX_ +} // scripting_runtimemgr +#endif //_FRAMEWORK_SCRIPT_NAMERESOLVER_HXX_ diff --git a/scripting/source/storage/ScriptInfo.cxx b/scripting/source/storage/ScriptInfo.cxx index cebd13f894a8..6e29b9cc3487 100644 --- a/scripting/source/storage/ScriptInfo.cxx +++ b/scripting/source/storage/ScriptInfo.cxx @@ -1,332 +1,326 @@ -/*************************************************************************
- *
- * $RCSfile: ScriptInfo.cxx,v $
- *
- * $Revision: 1.3 $
- *
- * last change: $Author: dsherwin $ $Date: 2002-09-23 16:30:52 $
- *
- * The Contents of this file are made available subject to the terms of
- * either of the following licenses
- *
- * - GNU Lesser General Public License Version 2.1
- * - Sun Industry Standards Source License Version 1.1
- *
- * Sun Microsystems Inc., October, 2000
- *
- * GNU Lesser General Public License Version 2.1
- * =============================================
- * Copyright 2000 by Sun Microsystems, Inc.
- * 901 San Antonio Road, Palo Alto, CA 94303, USA
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
- *
- * Sun Industry Standards Source License Version 1.1
- * =================================================
- * The contents of this file are subject to the Sun Industry Standards
- * Source License Version 1.1 (the "License"); You may not use this file
- * except in compliance with the License. You may obtain a copy of the
- * License at http://www.openoffice.org/license.html.
- *
- * Software provided under this License is provided on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
- * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
- * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
- * See the License for the specific provisions governing your rights and
- * obligations concerning the Software.
- *
- * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
- *
- * Copyright: 2000 by Sun Microsystems, Inc.
- *
- * All Rights Reserved.
- *
- * Contributor(s): _______________________________________
- *
- *
- ************************************************************************/
-#include <stdio.h>
-
-#include <cppuhelper/implementationentry.hxx>
-
-#include <util/util.hxx>
-#include <ScriptInfo.hxx>
-#include <osl/file.hxx>
-
-#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_XSCRIPTSTORAGEMANAGER_HPP_
-#include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
-#endif
-#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_XPARCELINVOCATIONPREP_HPP_
-#include <drafts/com/sun/star/script/framework/storage/XParcelInvocationPrep.hpp>
-#endif
-
-using namespace ::rtl;
-using namespace ::com::sun::star::uno;
-using namespace com::sun::star::beans;
-using namespace ::drafts::com::sun::star::script::framework;
-using namespace ::drafts::com::sun::star::script::framework::storage;
-
-namespace scripting_impl
-{
-
-const sal_Char* const SI_SERVICE_NAME="drafts.com.sun.star.script.framework.storage.ScriptInfo";
-const sal_Char* const SI_IMPL_NAME="drafts.com.sun.star.script.framework.storage.ScriptInfo";
-
-static OUString si_implName = OUString::createFromAscii(SI_IMPL_NAME);
-static OUString si_serviceName = OUString::createFromAscii(SI_SERVICE_NAME);
-static Sequence< OUString > si_serviceNames = Sequence< OUString >( &si_serviceName, 1 );
-
-extern ::rtl_StandardModuleCount s_moduleCount;
-
-static sal_Char docUriPrefix [] = "vnd.sun.star.pkg";
-
-//*************************************************************************
-ScriptInfo::ScriptInfo( const Reference< XComponentContext > & xContext )
- : m_xContext( xContext )
-{
- OSL_TRACE( "< ++++++ ScriptInfo ctor called >\n" );
- s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt );
-}
-
-//*************************************************************************
-ScriptInfo::~ScriptInfo()
-{
- OSL_TRACE( "< ScriptInfo dtor called >\n" );
- s_moduleCount.modCnt.release( &s_moduleCount.modCnt );
-}
-
-//*************************************************************************
-void ScriptInfo::initialize(Sequence <Any> const & args)
-throw (RuntimeException, Exception)
-{
- try
- {
- if (((args[0] >>= m_scriptImplInfo) == sal_False) ||
- ((args[1] >>= m_storageID) == sal_False)) {
- throw RuntimeException(OUSTR("ScriptInfo: initialize(): "), Reference< XInterface >());
- }
- }
- catch (Exception &e)
- {
- throw RuntimeException(OUSTR("ScriptInfo: initialize(): ") + e.Message, Reference< XInterface >());
- }
-}
-
-//*************************************************************************
-OUString SAL_CALL ScriptInfo::getLogicalName( ) throw (RuntimeException)
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- return m_scriptImplInfo.logicalName;
-}
-
-//*************************************************************************
-void SAL_CALL ScriptInfo::setLogicalName( const OUString& name ) throw (RuntimeException)
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- m_scriptImplInfo.logicalName = name;
-}
-
-//*************************************************************************
-OUString SAL_CALL ScriptInfo::getDescription( ) throw (RuntimeException)
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- return m_scriptImplInfo.scriptDescription;
-}
-
-//*************************************************************************
-void SAL_CALL ScriptInfo::setDescription( const OUString& desc ) throw (RuntimeException)
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- m_scriptImplInfo.scriptDescription = desc;
-}
-
-//*************************************************************************
-OUString SAL_CALL ScriptInfo::getLanguage( ) throw (RuntimeException)
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- return m_scriptImplInfo.scriptLanguage;
-}
-
-//*************************************************************************
-void SAL_CALL ScriptInfo::setLanguage( const OUString& language ) throw (RuntimeException)
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- m_scriptImplInfo.scriptLanguage = language;
-}
-
-//*************************************************************************
-OUString SAL_CALL ScriptInfo::getScriptLocation()
- throw ( RuntimeException )
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- return m_scriptImplInfo.scriptLocation;
-}
-
-//*************************************************************************
-sal_Bool SAL_CALL ScriptInfo::hasSource( ) throw (RuntimeException)
-{
- return m_scriptImplInfo.scriptSource;
-}
-
-//*************************************************************************
-OUString SAL_CALL ScriptInfo::getLanguageSpecificName( ) throw (RuntimeException)
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- return m_scriptImplInfo.functionName;
-}
-
-//*************************************************************************
-void SAL_CALL ScriptInfo::setLanguageSpecificName( const OUString& langName ) throw (RuntimeException)
-{
- ::osl::Guard< ::osl::Mutex > aGuard( m_mutex );
- m_scriptImplInfo.functionName = langName;
-}
-
-//*************************************************************************
-OUString SAL_CALL ScriptInfo::getRoot( ) throw (RuntimeException)
-{
- return m_scriptImplInfo.scriptRoot;
-}
-
-//*************************************************************************
-Sequence< OUString > SAL_CALL ScriptInfo::getDependencies( ) throw (RuntimeException)
-{
- storage::ScriptDepFile *pArray = m_scriptImplInfo.scriptDependencies.getArray();
- int len = m_scriptImplInfo.scriptDependencies.getLength();
- Sequence< OUString > r_deps(len);
- for(int i = 0; i < len; i++)
- {
- r_deps[i] = pArray[i].fileName;
- }
-
- return r_deps;
-}
-
-//*************************************************************************
-OUString SAL_CALL ScriptInfo::getLocation( ) throw (RuntimeException)
-{
- OUString location = OUString::createFromAscii("need to be done");
-
- return location;
-}
-
-//*************************************************************************
-Reference< XPropertySet > SAL_CALL ScriptInfo::extraProperties( ) throw (RuntimeException)
-{
- Reference <XPropertySet> x;
-
- return x;
-}
-
-//*************************************************************************
-OUString SAL_CALL ScriptInfo::getImplementationName( )
-throw(RuntimeException)
-{
- return si_implName;
-}
-
-//*************************************************************************
-/**
- * This function prepares the script for invocation and returns the full path
- * to the prepared parcel folder
- *
- */
-::rtl::OUString SAL_CALL ScriptInfo::prepareForInvocation() throw(RuntimeException)
-{
- OSL_TRACE("******* In ScriptInfo::prepareForInvocation() *************\n");
- try
- {
- if (m_scriptImplInfo.parcelURI.compareToAscii(docUriPrefix, 16) != 0) {
- return m_scriptImplInfo.parcelURI;
- }
-
- validateXRef(m_xContext, "ScriptInfo::prepareForInvocation(): invalid context");
- Any aAny=m_xContext->getValueByName(
- OUString::createFromAscii(
- "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager"));
- Reference <XInterface> xx;
- if ((aAny >>= xx) == sal_False) {
- throw RuntimeException(OUSTR("ScriptInfo::prepareForInvocation(): could not get ScriptStorageManager"), Reference< XInterface >());
- }
-
- validateXRef(xx, "ScriptInfo::prepareForInvocation(): could not get XInterface");
- Reference<XScriptStorageManager> xSSM(xx,UNO_QUERY);
- validateXRef(xSSM, "ScriptInfo::prepareForInvocation(): could not get XScriptStorageManager");
- xx = xSSM->getScriptStorage(m_storageID);
- validateXRef(xx, "ScriptInfo::prepareForInvocation(): could not get XInterface");
- Reference <XParcelInvocationPrep> xPIP(xx, UNO_QUERY);
- validateXRef(xPIP, "ScriptInfo::prepareForInvocation(): could not get XParcelInvocationPrep");
- return xPIP->prepareForInvocation(m_scriptImplInfo.parcelURI);
- }
- catch(RuntimeException &e)
- {
- OUString temp = OUSTR(
- "ScriptInfo::prepareForInvocation RuntimeException: ");
- throw RuntimeException(temp.concat(e.Message),
- Reference<XInterface> ());
- }
-#ifdef _DEBUG
- catch ( ... )
- {
- throw RuntimeException(OUSTR(
- "ScriptInfo::prepareForInvocation UnknownException: "),
- Reference<XInterface> ());
- }
-#endif
-}
-
-//*************************************************************************
-sal_Bool SAL_CALL ScriptInfo::supportsService( const OUString& serviceName )
-throw(RuntimeException)
-{
- OUString const * pNames = si_serviceNames.getConstArray();
- for ( sal_Int32 nPos = si_serviceNames.getLength(); nPos--; )
- {
- if (serviceName.equals( pNames[ nPos ] ))
- {
- return sal_True;
- }
- }
- return sal_False;
-}
-
-//*************************************************************************
-Sequence<OUString> SAL_CALL ScriptInfo::getSupportedServiceNames( )
-throw(RuntimeException)
-{
- return si_serviceNames;
-}
-//*************************************************************************
-Reference<XInterface> SAL_CALL si_create(
- const Reference< XComponentContext > & xCompC )
-{
- return (cppu::OWeakObject *)new ScriptInfo( xCompC );
-}
-
-//*************************************************************************
-Sequence<OUString> si_getSupportedServiceNames( )
-SAL_THROW( () )
-{
- return si_serviceNames;
-}
-
-//*************************************************************************
-OUString si_getImplementationName( )
-SAL_THROW( () )
-{
- return si_implName;
-}
-}
+/************************************************************************* + * + * $RCSfile: ScriptInfo.cxx,v $ + * + * $Revision: 1.4 $ + * + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <cppuhelper/implementationentry.hxx> + +#include <util/util.hxx> +#include <ScriptInfo.hxx> +#include <osl/file.hxx> + +#include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp> +#include <drafts/com/sun/star/script/framework/storage/XParcelInvocationPrep.hpp> + +using namespace ::rtl; +using namespace com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::drafts::com::sun::star::script::framework; +using namespace ::drafts::com::sun::star::script::framework::storage; + +namespace scripting_impl +{ + +const sal_Char* const SI_SERVICE_NAME="drafts.com.sun.star.script.framework.storage.ScriptInfo"; +const sal_Char* const SI_IMPL_NAME="drafts.com.sun.star.script.framework.storage.ScriptInfo"; + +static OUString si_implName = OUString::createFromAscii(SI_IMPL_NAME); +static OUString si_serviceName = OUString::createFromAscii(SI_SERVICE_NAME); +static Sequence< OUString > si_serviceNames = Sequence< OUString >( &si_serviceName, 1 ); + +extern ::rtl_StandardModuleCount s_moduleCount; + +static sal_Char docUriPrefix [] = "vnd.sun.star.pkg"; + +//************************************************************************* +ScriptInfo::ScriptInfo( const Reference< XComponentContext > & xContext ) + : m_xContext( xContext ) +{ + OSL_TRACE( "< ++++++ ScriptInfo ctor called >\n" ); + s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt ); +} + +//************************************************************************* +ScriptInfo::~ScriptInfo() +{ + OSL_TRACE( "< ScriptInfo dtor called >\n" ); + s_moduleCount.modCnt.release( &s_moduleCount.modCnt ); +} + +//************************************************************************* +void ScriptInfo::initialize(Sequence <Any> const & args) +throw (RuntimeException, Exception) +{ + try + { + if (((args[0] >>= m_scriptImplInfo) == sal_False) || + ((args[1] >>= m_storageID) == sal_False)) { + throw RuntimeException(OUSTR("ScriptInfo: initialize(): "), Reference< XInterface >()); + } + } + catch (Exception &e) + { + throw RuntimeException(OUSTR("ScriptInfo: initialize(): ").concat(e.Message), Reference< XInterface >()); + } +} + +//************************************************************************* +OUString SAL_CALL ScriptInfo::getLogicalName( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + return m_scriptImplInfo.logicalName; +} + +//************************************************************************* +void SAL_CALL ScriptInfo::setLogicalName( const OUString& name ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + m_scriptImplInfo.logicalName = name; +} + +//************************************************************************* +OUString SAL_CALL ScriptInfo::getDescription( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + return m_scriptImplInfo.scriptDescription; +} + +//************************************************************************* +void SAL_CALL ScriptInfo::setDescription( const OUString& desc ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + m_scriptImplInfo.scriptDescription = desc; +} + +//************************************************************************* +OUString SAL_CALL ScriptInfo::getLanguage( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + return m_scriptImplInfo.scriptLanguage; +} + +//************************************************************************* +void SAL_CALL ScriptInfo::setLanguage( const OUString& language ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + m_scriptImplInfo.scriptLanguage = language; +} + +//************************************************************************* +OUString SAL_CALL ScriptInfo::getScriptLocation() + throw ( RuntimeException ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + return m_scriptImplInfo.scriptLocation; +} + +//************************************************************************* +sal_Bool SAL_CALL ScriptInfo::hasSource( ) throw (RuntimeException) +{ + return m_scriptImplInfo.scriptSource; +} + +//************************************************************************* +OUString SAL_CALL ScriptInfo::getLanguageSpecificName( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + return m_scriptImplInfo.functionName; +} + +//************************************************************************* +void SAL_CALL ScriptInfo::setLanguageSpecificName( const OUString& langName ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + m_scriptImplInfo.functionName = langName; +} + +//************************************************************************* +OUString SAL_CALL ScriptInfo::getRoot( ) throw (RuntimeException) +{ + return m_scriptImplInfo.scriptRoot; +} + +//************************************************************************* +Sequence< OUString > SAL_CALL ScriptInfo::getDependencies( ) throw (RuntimeException) +{ + storage::ScriptDepFile *pArray = m_scriptImplInfo.scriptDependencies.getArray(); + sal_Int32 len = m_scriptImplInfo.scriptDependencies.getLength(); + Sequence< OUString > r_deps(len); + for(sal_Int32 i = 0; i < len; i++) + { + r_deps[i] = pArray[i].fileName; + } + + return r_deps; +} + +//************************************************************************* +OUString SAL_CALL ScriptInfo::getLocation( ) throw (RuntimeException) +{ + OUString location = OUString::createFromAscii("need to be done"); + + return location; +} + +//************************************************************************* +Reference< beans::XPropertySet > SAL_CALL ScriptInfo::extraProperties( ) throw (RuntimeException) +{ + Reference < beans::XPropertySet > x; + + return x; +} + +//************************************************************************* +OUString SAL_CALL ScriptInfo::getImplementationName( ) +throw(RuntimeException) +{ + return si_implName; +} + +//************************************************************************* +/** + * This function prepares the script for invocation and returns the full path + * to the prepared parcel folder + * + */ +::rtl::OUString SAL_CALL ScriptInfo::prepareForInvocation() throw(RuntimeException) +{ + OSL_TRACE("******* In ScriptInfo::prepareForInvocation() *************\n"); + try + { + if (m_scriptImplInfo.parcelURI.compareToAscii(docUriPrefix, 16) != 0) { + return m_scriptImplInfo.parcelURI; + } + + validateXRef(m_xContext, "ScriptInfo::prepareForInvocation(): invalid context"); + Any aAny=m_xContext->getValueByName( + OUString::createFromAscii( + "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager")); + Reference <XInterface> xx; + if ((aAny >>= xx) == sal_False) { + throw RuntimeException(OUSTR("ScriptInfo::prepareForInvocation(): could not get ScriptStorageManager"), Reference< XInterface >()); + } + + validateXRef(xx, "ScriptInfo::prepareForInvocation(): could not get XInterface"); + Reference<XScriptStorageManager> xSSM(xx,UNO_QUERY); + validateXRef(xSSM, "ScriptInfo::prepareForInvocation(): could not get XScriptStorageManager"); + xx = xSSM->getScriptStorage(m_storageID); + validateXRef(xx, "ScriptInfo::prepareForInvocation(): could not get XInterface"); + Reference <XParcelInvocationPrep> xPIP(xx, UNO_QUERY); + validateXRef(xPIP, "ScriptInfo::prepareForInvocation(): could not get XParcelInvocationPrep"); + return xPIP->prepareForInvocation(m_scriptImplInfo.parcelURI); + } + catch(RuntimeException &e) + { + OUString temp = OUSTR( + "ScriptInfo::prepareForInvocation RuntimeException: "); + throw RuntimeException(temp.concat(e.Message), + Reference<XInterface> ()); + } +#ifdef _DEBUG + catch ( ... ) + { + throw RuntimeException(OUSTR( + "ScriptInfo::prepareForInvocation UnknownException: "), + Reference<XInterface> ()); + } +#endif +} + +//************************************************************************* +sal_Bool SAL_CALL ScriptInfo::supportsService( const OUString& serviceName ) +throw(RuntimeException) +{ + OUString const * pNames = si_serviceNames.getConstArray(); + for ( sal_Int32 nPos = si_serviceNames.getLength(); nPos--; ) + { + if (serviceName.equals( pNames[ nPos ] )) + { + return sal_True; + } + } + return sal_False; +} + +//************************************************************************* +Sequence<OUString> SAL_CALL ScriptInfo::getSupportedServiceNames( ) +throw(RuntimeException) +{ + return si_serviceNames; +} +//************************************************************************* +Reference<XInterface> SAL_CALL si_create( + const Reference< XComponentContext > & xCompC ) +{ + return (cppu::OWeakObject *)new ScriptInfo( xCompC ); +} + +//************************************************************************* +Sequence<OUString> si_getSupportedServiceNames( ) +SAL_THROW( () ) +{ + return si_serviceNames; +} + +//************************************************************************* +OUString si_getImplementationName( ) +SAL_THROW( () ) +{ + return si_implName; +} +} diff --git a/scripting/source/storage/ScriptInfo.hxx b/scripting/source/storage/ScriptInfo.hxx index 8196f2af4126..e84fe0e15d82 100644 --- a/scripting/source/storage/ScriptInfo.hxx +++ b/scripting/source/storage/ScriptInfo.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ScriptInfo.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: lkovacs $ $Date: 2002-09-23 14:08:29 $ + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,26 +70,19 @@ #include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp> #include <drafts/com/sun/star/script/framework/storage/ScriptImplInfo.hpp> -#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_XSCRIPTINVOCATIONPREP_HPP_ #include <drafts/com/sun/star/script/framework/storage/XScriptInvocationPrep.hpp> -#endif namespace scripting_impl { -class ScriptInfo : public ::cppu::WeakImplHelper4< ::com::sun::star::lang::XServiceInfo, ::com::sun::star::lang::XInitialization, ::drafts::com::sun::star::script::framework::storage::XScriptInfo, ::drafts::com::sun::star::script::framework::storage::XScriptInvocationPrep > +class ScriptInfo : +public ::cppu::WeakImplHelper4< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization, + ::drafts::com::sun::star::script::framework::storage::XScriptInfo, + ::drafts::com::sun::star::script::framework::storage::XScriptInvocationPrep > { - // private member -private: - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext; - - ::osl::Mutex m_mutex; - - ::drafts::com::sun::star::script::framework::storage::ScriptImplInfo m_scriptImplInfo; - sal_uInt16 m_storageID; - - // public interface public: - explicit ScriptInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& ); + explicit ScriptInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext); virtual ~ScriptInfo(); virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); @@ -123,6 +116,14 @@ public: */ virtual ::rtl::OUString SAL_CALL prepareForInvocation() throw (::com::sun::star::uno::RuntimeException); +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext; + + ::osl::Mutex m_mutex; + + ::drafts::com::sun::star::script::framework::storage::ScriptImplInfo m_scriptImplInfo; + sal_uInt16 m_storageID; + }; } diff --git a/scripting/source/storage/ScriptStorage.cxx b/scripting/source/storage/ScriptStorage.cxx index 578c75e872ae..b477e023218d 100644 --- a/scripting/source/storage/ScriptStorage.cxx +++ b/scripting/source/storage/ScriptStorage.cxx @@ -1,73 +1,71 @@ /************************************************************************* - * - * $RCSfile: ScriptStorage.cxx,v $ - * - * $Revision: 1.3 $ - * last change: $Author: npower $ $Date: 2002-09-24 15:50:28 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ -#include <stdio.h> - +* +* $RCSfile: ScriptStorage.cxx,v $ +* +* $Revision: 1.4 $ +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:29 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ +#include <osl/file.hxx> +#include <osl/time.h> #include <cppuhelper/implementationentry.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/ucb/CommandAbortedException.hpp> #include <com/sun/star/io/XActiveDataSource.hpp> #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> -#include <drafts/com/sun/star/script/framework/storage/ScriptImplInfo.hpp> - -#include <osl/file.hxx> +#include <drafts/com/sun/star/script/framework/storage/ScriptImplInfo.hpp> #include <util/util.hxx> #include "ScriptInfo.hxx" @@ -84,22 +82,33 @@ using namespace ::drafts::com::sun::star::script::framework; namespace scripting_impl { -const sal_Char* const SERVICE_NAME="drafts.com.sun.star.script.framework.storage.ScriptStorage"; -const sal_Char* const IMPL_NAME="drafts.com.sun.star.script.framework.storage.ScriptStorage"; +const sal_Char* const SERVICE_NAME = "drafts.com.sun.star.script.framework.storage.ScriptStorage"; +const sal_Char* const IMPL_NAME = "drafts.com.sun.star.script.framework.storage.ScriptStorage"; + +const sal_Char * const SCRIPT_DIR = "/Scripts"; +const sal_Char * const SCRIPT_PARCEL = "/parcel.xml"; +const sal_Char * const SCRIPT_PARCEL_NAME_ONLY = "parcel"; -static OUString ss_implName = OUString::createFromAscii(IMPL_NAME); -static OUString ss_serviceName = OUString::createFromAscii(SERVICE_NAME); +static OUString ss_implName = OUString::createFromAscii( IMPL_NAME ); +static OUString ss_serviceName = OUString::createFromAscii( SERVICE_NAME ); static Sequence< OUString > ss_serviceNames = Sequence< OUString >( &ss_serviceName, 1 ); +const sal_uInt16 NUMBER_STORAGE_INITIALIZE_ARGS = 3; + extern ::rtl_StandardModuleCount s_moduleCount; //************************************************************************* -ScriptStorage::ScriptStorage( const Reference< +ScriptStorage::ScriptStorage( const Reference < XComponentContext > & xContext ) - : m_xContext( xContext ) + : m_xContext( xContext ), m_bInitialised( false ) { OSL_TRACE( "< ScriptStorage ctor called >\n" ); s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt ); + + validateXRef( m_xContext, "ScriptStorage::ScriptStorage : cannot get component context" ); + + m_xMgr = m_xContext->getServiceManager(); + validateXRef( m_xMgr, "ScriptStorage::ScriptStorage : cannot get service manager" ); } //************************************************************************* @@ -110,215 +119,244 @@ ScriptStorage::~ScriptStorage() SAL_THROW( () ) } //************************************************************************* -void ScriptStorage::initialize( +void +ScriptStorage::initialize( const Sequence <Any> & args ) -throw (Exception) +throw ( RuntimeException, Exception ) { - OSL_TRACE("Entering ScriptStorage::initialize\n"); - // work in progress. - // what might we expect to get? - // at the moment only consider 3 possibilities - // 1. an XInputStream - [deprecated!!] - // 2. an XSimpleFileAccess - // 3. an OUString containing a URI - - ::osl::Guard< osl::Mutex > aGuard( m_mutex ); - - Reference< io::XInputStream > xInput; + OSL_TRACE( "Entering ScriptStorage::initialize\n" ); ::rtl::OUString xStringUri; - // need to replace this with a proper call to getService... - ScriptMetadataImporter* SMI = new ScriptMetadataImporter(m_xContext); - Reference<xml::sax::XExtendedDocumentHandler> xSMI(SMI); - if (args.getLength()) + // Should not be renitialised + if ( m_bInitialised ) { - if((sal_False != (args[0] >>= m_xSimpleFileAccess)) && - (sal_False != (args[1]>>=m_scriptStorageID))) + throw RuntimeException( OUSTR( "ScriptStorage::initalize already initialized" ), + Reference<XInterface> () ); + } + + { // Protect member variable writes + ::osl::Guard< osl::Mutex > aGuard( m_mutex ); + + // Check args + if ( args.getLength() != NUMBER_STORAGE_INITIALIZE_ARGS ) { - if(args.getLength()>2 && (sal_False == (args[2] >>= xStringUri))) - { - xStringUri=::rtl::OUString::createFromAscii(""); - } + OSL_TRACE( "ScriptStorage::initialize: got no args\n" ); + throw lang::IllegalArgumentException( + OUSTR( "Invalid number of arguments provided!" ), + Reference< XInterface >(), 0 ); } - /* deprecated? - else if((sal_False != (args[1]>>=m_scriptStorageID)) && - (sal_False != (args[0] >>= xStringUri))) - { - //probably need some check for type of URI???? - validateXRef(m_xContext, "ScriptStorage::initialize: No context available"); - Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef(xMgr, "ScriptStorage::initialize: No service manager available"); - Reference< XInterface > xx = xMgr->createInstanceWithContext(OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess"), m_xContext ); - validateXRef(xMgr, "ScriptStorage::initialize: cannot get XSimpleFileAccess"); - m_xSimpleFileAccess.set(xx, UNO_QUERY_THROW); - } */ - else + + if ( sal_False == ( args[ 0 ] >>= m_xSimpleFileAccess ) ) { - OSL_TRACE("ScriptStorage::initialize: got some unknown type of arg\n"); throw lang::IllegalArgumentException( - OUSTR("unexpected argument type provided!"), - static_cast< OWeakObject * >( this ), 0 ); + OUSTR( "Invalid XSimpleFileAccess argument provided!" ), + Reference< XInterface >(), 0 ); } - } - else //no args provided - { - OSL_TRACE("ScriptStorage::initialize: got no args\n"); - throw lang::IllegalArgumentException( - OUSTR("No arguments provided!"), - static_cast< OWeakObject * >( this ), 0 ); - } + + if ( sal_False == ( args[ 1 ] >>= m_scriptStorageID ) ) + { + throw lang::IllegalArgumentException( + OUSTR( "Invalid ScriptStorage ID argument provided!" ), + Reference< XInterface >(), 0 ); + } + + if ( sal_False == ( args[ 2 ] >>= xStringUri ) ) + { + throw lang::IllegalArgumentException( + OUSTR( "Invalid String Uri argument provided!" ), + Reference< XInterface >(), 0 ); + } + } // End - Protect member variable writes + #ifdef _DEBUG - fprintf(stderr,"uri: %s\n",::rtl::OUStringToOString(xStringUri,RTL_TEXTENCODING_ASCII_US).pData->buffer); + fprintf( stderr, "uri: %s\n", ::rtl::OUStringToOString( xStringUri, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); #endif try { - xStringUri=xStringUri.concat(::rtl::OUString::createFromAscii("/Scripts")); + ScriptMetadataImporter* SMI = new ScriptMetadataImporter( m_xContext ); + Reference<xml::sax::XExtendedDocumentHandler> xSMI( SMI ); - // get the list of files/folders under the Scripts directory - Sequence< ::rtl::OUString > results=m_xSimpleFileAccess->getFolderContents(xStringUri,true); - for(int i=0;i<results.getLength();i++) + + xStringUri = xStringUri.concat( ::rtl::OUString::createFromAscii( SCRIPT_DIR ) ); + + // get the list of language folders under the Scripts directory + Sequence< ::rtl::OUString > languageDirs = + m_xSimpleFileAccess->getFolderContents( xStringUri, true ); + + Reference< io::XInputStream > xInput; + sal_Int32 languageDirsLength = languageDirs.getLength(); + for ( int i = 0; i < languageDirsLength ; ++i ) { #ifdef _DEBUG - fprintf(stderr,"contains: %s\n",::rtl::OUStringToOString(results[i],RTL_TEXTENCODING_ASCII_US).pData->buffer); + fprintf( stderr, "contains: %s\n", ::rtl::OUStringToOString( languageDirs[ i ], + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); #endif - if(m_xSimpleFileAccess->isFolder(results[i])) + if ( ! m_xSimpleFileAccess->isFolder( languageDirs[ i ] ) ) + { + continue; + } + + //get the list of parcel folders for each language folder + // under Scripts + Sequence< ::rtl::OUString > parcelDirs = + m_xSimpleFileAccess->getFolderContents( languageDirs[ i ], true ); + + sal_Int32 parcelDirsLength = parcelDirs.getLength(); + for ( int j = 0; j < parcelDirsLength ; ++j ) { - //get the list of files/folders for each folder - // under Scripts/ - Sequence< ::rtl::OUString > subresults=m_xSimpleFileAccess->getFolderContents(results[i],true); - for(int j=0;j<subresults.getLength();j++) - { #ifdef _DEBUG - fprintf(stderr,"contains: %s\n",::rtl::OUStringToOString(subresults[j],RTL_TEXTENCODING_ASCII_US).pData->buffer); + fprintf( stderr, "contains: %s\n", + ::rtl::OUStringToOString( parcelDirs[ j ], + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); #endif - OUString parcelFile=subresults[j].concat(::rtl::OUString::createFromAscii("/parcel.xml")); - //if the subfolder Scripts/*/ has a file - //called parcel.xml - if(m_xSimpleFileAccess->isFolder(subresults[j]) && m_xSimpleFileAccess->exists(parcelFile) && !m_xSimpleFileAccess->isFolder(parcelFile)) - { + OUString parcelFile = parcelDirs[ j ].concat( + ::rtl::OUString::createFromAscii( SCRIPT_PARCEL ) ); + + // Do not have a valid parcel.xml + if ( !m_xSimpleFileAccess->exists( parcelFile ) || + m_xSimpleFileAccess->isFolder( parcelFile ) ) + { + continue; + } #ifdef _DEBUG - fprintf(stderr,"parcel file: %s\n",::rtl::OUStringToOString(parcelFile,RTL_TEXTENCODING_ASCII_US).pData->buffer); + fprintf( stderr, + "parcel file: %s\n", + ::rtl::OUStringToOString( parcelFile, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); #endif - xInput = m_xSimpleFileAccess->openFileRead(parcelFile); - if (xInput.is()) - { - // should I aquire the stream?? - OSL_TRACE("Parse the metadata \n"); -#ifndef TEST_ONLY - - Impls_vec vSII = SMI->parseMetaData( xInput, subresults[j] ); - xInput->closeInput(); -#else - - Impls_vec vSII; - storage::ScriptImplInfo m,m2,m3; - m.scriptLanguage=rtl::OUString::createFromAscii("java"); - ; - m.functionName=rtl::OUString::createFromAscii("com.sun.star.foo"); - ; - m.logicalName=rtl::OUString::createFromAscii("my.foo"); - ; - m2.scriptLanguage=rtl::OUString::createFromAscii("java"); - ; - m2.functionName=rtl::OUString::createFromAscii("com.sun.star.foo2"); - ; - m2.logicalName=rtl::OUString::createFromAscii("my.foo"); - ; - m3.scriptLanguage=rtl::OUString::createFromAscii("java"); - ; - m3.functionName=rtl::OUString::createFromAscii("com.sun.star.bar"); - ; - m3.logicalName=rtl::OUString::createFromAscii("my.bar"); - ; - vSII.push_back(m); - vSII.push_back(m2); - vSII.push_back(m3); + xInput = m_xSimpleFileAccess->openFileRead( parcelFile ); + // Failed to get input stream + if ( !xInput.is() ) + { + continue; + } -#endif - // should I now release the stream?? - updateMaps(vSII); - } + OSL_TRACE( "Parse the metadata \n" ); + Impls_vec vScriptImplInfos; + try + { + vScriptImplInfos = SMI->parseMetaData( xInput, parcelDirs[ j ] ); + } + catch ( xml::sax::SAXException saxe ) + { + if ( xInput.is() ) + { + xInput->closeInput(); } + OSL_TRACE( "caught com::sun::star::xml::sax::SAXException in ScriptStorage::initalize" ); + continue; } + catch ( io::IOException ioe ) + { + if ( xInput.is() ) + { + xInput->closeInput(); + } + OSL_TRACE( "caught com::sun::star::io::IOException in ScriptStorage::initalize" ); + continue; + } + xInput->closeInput(); + + updateMaps( vScriptImplInfos ); } } } - catch(xml::sax::SAXException saxe) + catch ( io::IOException ioe ) { //From ScriptMetadata Importer - OSL_TRACE("caught com::sun::star::xml::sax::SAXException in ScriptStorage::initalize"); - throw RuntimeException(OUSTR("ScriptStorage::initalize SAXException: ")+saxe.Message, - Reference<XInterface> ()); + OSL_TRACE( "caught com::sun::star::io::IOException in ScriptStorage::initalize" ); + throw RuntimeException( + OUSTR( "ScriptStorage::initalize IOException: " ).concat( ioe.Message ), + Reference<XInterface> () ); + } - catch(io::IOException ioe) + catch ( ucb::CommandAbortedException cae ) { - //From ScriptMetadata Importer - OSL_TRACE("caught com::sun::star::io::IOException in ScriptStorage::initalize"); - throw RuntimeException(OUSTR("ScriptStorage::initalize IOException: ")+ioe.Message, - Reference<XInterface> ()); - + OSL_TRACE( "caught com::sun::star::ucb::CommandAbortedException in ScriptStorage::initialize" ); + throw RuntimeException( + OUSTR( + "ScriptStorage::initalize CommandAbortedException: " ).concat( cae.Message ), + Reference<XInterface> () ); + } + catch ( RuntimeException re ) + { + OSL_TRACE( "caught com::sun::star::uno::RuntimeException in ScriptStorage::initialize" ); + throw RuntimeException( + OUSTR( "ScriptStorage::initalize RuntimeException: " ).concat( re.Message ), + Reference<XInterface> () ); } - catch(ucb::CommandAbortedException cae) + catch ( Exception ue ) { - OSL_TRACE("caught com::sun::star::ucb::CommandAbortedException in ScriptStorage::initialize"); - throw RuntimeException(OUSTR("ScriptStorage::initalize CommandAbortedException: ")+cae.Message, - Reference<XInterface> ()); + OSL_TRACE( "caught com::sun::star::uno::Exception in ScriptStorage::initialize" ); + throw RuntimeException( + OUSTR( "ScriptStorage::initalize Exception: " ).concat( ue.Message ), + Reference<XInterface> () ); } - catch(Exception ue) +#ifdef _DEBUG + catch ( ... ) { - OSL_TRACE("caught com::sun::star::uno::Exception in ScriptStorage::initialize"); - throw RuntimeException(OUSTR("ScriptStorage::initalize Exception: ")+ue.Message, - Reference<XInterface> ()); + OSL_TRACE( "caught com::sun::star::uno::Exception in ScriptStorage::initialize" ); + throw RuntimeException( + OUSTR( "ScriptStorage::initalize unknown exception: " ), + Reference<XInterface> () ); } - OSL_TRACE("Parsed the XML\n"); +#endif + + OSL_TRACE( "Parsed the XML\n" ); + + m_bInitialised = true; } //************************************************************************* // private method for updating hashmaps -void ScriptStorage::updateMaps(Impls_vec vScriptII) +void +ScriptStorage::updateMaps( const Impls_vec & vScriptImplInfos ) { ::osl::Guard< osl::Mutex > aGuard( m_mutex ); - Impls_vec::iterator it = vScriptII.begin(); - Impls_vec::iterator it_end = vScriptII.end(); + Impls_vec::const_iterator it_end = vScriptImplInfos.end(); // step through the vector of ScripImplInfos returned from parse - for(sal_Int32 count=0;it!=it_end;++it) + for ( Impls_vec::const_iterator it = vScriptImplInfos.begin() ; it != it_end; ++it ) { //find the Impls_vec for this logical name - ScriptInfo_hash::iterator h_it = mh_implementations.find(it->logicalName); + ScriptInfo_hash::iterator h_it = mh_implementations.find( it->logicalName ); - if(h_it==mh_implementations.end()) + if ( h_it == mh_implementations.end() ) { //if it's null, need to create a new Impls_vec #ifdef _DEBUG - fprintf(stderr,"updateMaps: new logical name: %s\n",rtl::OUStringToOString(it->logicalName,RTL_TEXTENCODING_ASCII_US).pData->buffer); - fprintf(stderr," language name: %s\n",rtl::OUStringToOString(it->functionName,RTL_TEXTENCODING_ASCII_US).pData->buffer); + fprintf( stderr, + "updateMaps: new logical name: %s\n", rtl::OUStringToOString( + it->logicalName, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + fprintf( stderr, "language name: %s\n", + rtl::OUStringToOString( + it->functionName, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); #endif Impls_vec v; - v.push_back(*it); - mh_implementations[it->logicalName]=v; + v.push_back( *it ); + mh_implementations[ it->logicalName ] = v; } else { #ifdef _DEBUG - fprintf(stderr,"updateMaps: existing logical name: %s\n",rtl::OUStringToOString(it->logicalName,RTL_TEXTENCODING_ASCII_US).pData->buffer); - fprintf(stderr," language name: %s\n",rtl::OUStringToOString(it->functionName,RTL_TEXTENCODING_ASCII_US).pData->buffer); + fprintf( stderr, "updateMaps: existing logical name: %s\n", rtl::OUStringToOString( it->logicalName, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + fprintf( stderr, " language name: %s\n", rtl::OUStringToOString( it->functionName, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); #endif - h_it->second.push_back(*it); + h_it->second.push_back( *it ); } } } //************************************************************************* // Not part of the interface yet, ie. not in the idl, and it should be!! -void ScriptStorage::save() -throw (RuntimeException) +void +ScriptStorage::save() +throw ( RuntimeException ) { ::osl::Guard< osl::Mutex > aGuard( m_mutex ); Reference< io::XActiveDataSource > xSource; @@ -326,76 +364,90 @@ throw (RuntimeException) // xScriptInvocation = Reference<XScriptInvocation>(xx, UNO_QUERY_THROW); Reference<xml::sax::XExtendedDocumentHandler> xHandler; - OUString parcel_suffix = OUString::createFromAscii("/parcel.xml"); + OUString parcel_suffix = OUString::createFromAscii( SCRIPT_PARCEL ); + OUString ou_parcel = OUString( RTL_CONSTASCII_USTRINGPARAM( SCRIPT_PARCEL_NAME_ONLY ) ); - validateXRef(m_xContext, "ScriptStorage::save: No context available"); - Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef(xMgr, "ScriptStorage::save: No service manager available"); - - OUString ou_parcel = OUString( RTL_CONSTASCII_USTRINGPARAM("parcel")); - - ScriptInfo_hash::iterator it = mh_implementations.begin(); - ScriptInfo_hash::iterator it_end = mh_implementations.end(); - for(sal_Int32 count=0;it!=it_end;++it) + try { - ::rtl::OUString logName=it->first; - Impls_vec::iterator it_impls_end =it->second.end(); - for( Impls_vec::iterator it_impls =it->second.begin(); it_impls!=it_impls_end;++it_impls) + ScriptInfo_hash::iterator it_end = mh_implementations.end(); + for ( ScriptInfo_hash::iterator it = mh_implementations.begin() ; it != it_end; ++it ) { - ScriptOutput_hash::iterator it_parcels = mh_parcels.find(it_impls->parcelURI); - if(it_parcels==mh_parcels.end()) + ::rtl::OUString logName = it->first; + Impls_vec::iterator it_impls_end = it->second.end(); + for ( Impls_vec::iterator it_impls = it->second.begin(); + it_impls != it_impls_end ; ++it_impls ) { - //create new outputstream - OUString parcel_xml_path = it_impls->parcelURI.concat(parcel_suffix); - m_xSimpleFileAccess->kill(parcel_xml_path); - xOS=m_xSimpleFileAccess->openFileWrite(parcel_xml_path); + ScriptOutput_hash::const_iterator it_parcels = + mh_parcels.find( it_impls->parcelURI ); + if ( it_parcels == mh_parcels.end() ) + { + //create new outputstream + OUString parcel_xml_path = it_impls->parcelURI.concat( parcel_suffix ); + m_xSimpleFileAccess->kill( parcel_xml_path ); + xOS = m_xSimpleFileAccess->openFileWrite( parcel_xml_path ); #ifdef _DEBUG - fprintf(stderr,"saving: %s\n",rtl::OUStringToOString(it_impls->parcelURI.concat(OUString::createFromAscii("/parcel.xml")),RTL_TEXTENCODING_ASCII_US).pData->buffer); + fprintf( stderr, "saving: %s\n", rtl::OUStringToOString( it_impls->parcelURI.concat( OUString::createFromAscii( "/parcel.xml" ) ), RTL_TEXTENCODING_ASCII_US ).pData->buffer ); #endif - Reference< XInterface > xx = xMgr->createInstanceWithContext(OUString::createFromAscii("com.sun.star.xml.sax.Writer"), m_xContext ); - validateXRef(xMgr, "ScriptStorage::save: cannot get sax.Writer"); - xHandler = Reference<xml::sax::XExtendedDocumentHandler>(xx, UNO_QUERY_THROW); - xSource = Reference< io::XActiveDataSource >( xHandler, UNO_QUERY_THROW ); - xSource->setOutputStream( xOS ); + Reference< XInterface > xInterface = + m_xMgr->createInstanceWithContext( + OUString::createFromAscii( "com.sun.star.xml.sax.Writer" ), + m_xContext ); + validateXRef( xInterface, "ScriptStorage::save: cannot get sax.Writer" ); + xHandler = + Reference<xml::sax::XExtendedDocumentHandler>( xInterface, + UNO_QUERY_THROW ); + xSource = Reference< io::XActiveDataSource >( xHandler, UNO_QUERY_THROW ); + xSource->setOutputStream( xOS ); - writeMetadataHeader(xHandler); + writeMetadataHeader( xHandler ); - xHandler->startElement( ou_parcel, Reference< xml::sax::XAttributeList >() ); + xHandler->startElement( ou_parcel, + Reference< xml::sax::XAttributeList >() ); - mh_parcels[it_impls->parcelURI]=xHandler; - } - else - { - xHandler=it_parcels->second; - } + mh_parcels[ it_impls->parcelURI ] = xHandler; + } + else + { + xHandler = it_parcels->second; + } - ScriptElement* pSE = new ScriptElement(*it_impls); - // this is to get pSE released correctly - Reference <xml::sax::XAttributeList> xal(pSE); - pSE->dump(xHandler); + ScriptElement* pSE = new ScriptElement( *it_impls ); + // this is to get pSE released correctly + Reference <xml::sax::XAttributeList> xal( pSE ); + pSE->dump( xHandler ); + } } - } - ScriptOutput_hash::const_iterator out_it_end = mh_parcels.end(); + ScriptOutput_hash::const_iterator out_it_end = mh_parcels.end(); - for(ScriptOutput_hash::const_iterator out_it = mh_parcels.begin(); - out_it != out_it_end; - ++out_it) - { - out_it->second->ignorableWhitespace( ::rtl::OUString() ); - out_it->second->endElement(ou_parcel); - out_it->second->endDocument(); - xSource.set( out_it->second, UNO_QUERY ); - Reference<io::XOutputStream> xOS = xSource->getOutputStream(); - xOS->closeOutput(); + for ( ScriptOutput_hash::const_iterator out_it = mh_parcels.begin(); + out_it != out_it_end; + ++out_it ) + { + out_it->second->ignorableWhitespace( ::rtl::OUString() ); + out_it->second->endElement( ou_parcel ); + out_it->second->endDocument(); + xSource.set( out_it->second, UNO_QUERY ); + Reference<io::XOutputStream> xOS = xSource->getOutputStream(); + xOS->closeOutput(); + } + } + // *** TODO - other exception handling IO etc. + catch ( RuntimeException re ) + { + OSL_TRACE( "caught com::sun::star::uno::RuntimeException in ScriptStorage::save" ); + throw RuntimeException( + OUSTR( "ScriptStorage::save RuntimeException: " ).concat( re.Message ), + Reference<XInterface> () ); } } //************************************************************************* -void ScriptStorage::writeMetadataHeader(Reference <xml::sax::XExtendedDocumentHandler> & xHandler) +void +ScriptStorage::writeMetadataHeader( Reference <xml::sax::XExtendedDocumentHandler> & xHandler ) { xHandler->startDocument(); OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM( @@ -411,40 +463,46 @@ void ScriptStorage::writeMetadataHeader(Reference <xml::sax::XExtendedDocumentHa //Eh, method name is not initiutive, maybe it //should be getScriptInfoInterfaces? (Need to change IDL) Sequence < Reference< storage::XScriptInfo > > -ScriptStorage::getScriptInfoService(const OUString & name) -throw (RuntimeException) +ScriptStorage::getScriptInfoService( const OUString & name ) +throw ( RuntimeException ) { ::osl::Guard< osl::Mutex > aGuard( m_mutex ); //Get iterator over the hash_map - ScriptInfo_hash::const_iterator h_iter = mh_implementations.find(name); - Impls_vec::const_iterator it = - h_iter->second.begin(), end_iter = h_iter->second.end(); - - Sequence< Reference< storage::XScriptInfo > > sr_xScriptInfo( - h_iter->second.size() ); - - //Get array of XScriptInfos - Reference< storage::XScriptInfo >* pScriptInfo = sr_xScriptInfo.getArray(); + ScriptInfo_hash::const_iterator h_iter = mh_implementations.find( name ); + Sequence< Reference< storage::XScriptInfo > > sr_xScriptInfo( h_iter->second.size() ); - validateXRef(m_xContext, "ScriptStorage::getScriptInfoService: No context available"); - Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef(xMgr, "ScriptStorage::getScriptInfoService: No service manager available"); - - for(sal_Int32 count = 0; it != end_iter; ++it) + try { -#ifdef _DEBUG - fprintf(stderr,"in for cycle, count is %d\n", count); -#endif + //Get array of XScriptInfos + // Reference< storage::XScriptInfo >* pScriptInfo = sr_xScriptInfo.getArray(); - Any a( makeAny( *it ) ); - Reference< XInterface > xx = xMgr->createInstanceWithArgumentsAndContext(OUString::createFromAscii("drafts.com.sun.star.script.framework.storage.ScriptInfo"), Sequence< Any >( &a, 1 ), m_xContext ); - validateXRef(xMgr, "ScriptStorage::getScriptInfoService: cannot get drafts.com.sun.star.script.framework.storage.ScriptInfo"); - pScriptInfo[ count ] = Reference< storage::XScriptInfo >(xx, UNO_QUERY_THROW ); - sr_xScriptInfo[ count ] = Reference< storage::XScriptInfo >(xx, UNO_QUERY_THROW ); - count++; + Impls_vec::const_iterator end_iter = h_iter->second.end(); + sal_Int32 count = 0; + for ( Impls_vec::const_iterator it = h_iter->second.begin(); it != end_iter; ++it ) + { + Any a( makeAny( *it ) ); + Reference< XInterface > xInterface = + m_xMgr->createInstanceWithArgumentsAndContext( + OUString::createFromAscii( + "drafts.com.sun.star.script.framework.storage.ScriptInfo" ), + Sequence< Any >( &a, 1 ), m_xContext ); + validateXRef( xInterface, + "ScriptStorage::getScriptInfoService: cannot get drafts.com.sun.star.script.framework.storage.ScriptInfo" ); + // pScriptInfo[ count ] = Reference< storage::XScriptInfo >(xInterface, + // UNO_QUERY_THROW ); + sr_xScriptInfo[ count ] = Reference< storage::XScriptInfo >( xInterface, + UNO_QUERY_THROW ); + count++; + } + } + catch ( RuntimeException re ) + { + OSL_TRACE( "caught com::sun::star::uno::RuntimeException in ScriptStorage::getScriptInfoService" ); + throw RuntimeException( + OUSTR( "ScriptStorage::getScriptInfoService RuntimeException: " ).concat( re.Message ), + Reference<XInterface> () ); } - return sr_xScriptInfo; } @@ -460,127 +518,169 @@ Reference<XInterface> ScriptStorage::getView( //************************************************************************* Sequence< Reference< scripturi::XScriptURI > > -ScriptStorage::getImplementations( const Reference< - scripturi::XScriptURI >& queryURI ) -throw (lang::IllegalArgumentException, - RuntimeException) +ScriptStorage::getImplementations( const Reference < + scripturi::XScriptURI > & queryURI ) +throw ( lang::IllegalArgumentException, + RuntimeException ) { - ::osl::Guard< osl::Mutex > aGuard( m_mutex ); - Sequence< Reference< scripturi::XScriptURI > > results; + ScriptInfo_hash::iterator h_it = mh_implementations.find( queryURI->getLogicalName() ); + Sequence< Reference< scripturi::XScriptURI > > results( h_it->second.size() ); try { //find the implementations for the given logical name - ScriptInfo_hash::iterator h_it = mh_implementations.find(queryURI->getLogicalName()); - if(h_it!=mh_implementations.end()) + if ( h_it == mh_implementations.end() ) { - Impls_vec::iterator it_impls =h_it->second.begin(); - Impls_vec::iterator it_impls_end =h_it->second.end(); - for(sal_Int32 count=0;it_impls!=it_impls_end;++it_impls) - { - //should we do any resolution here????? - // or leave it completely up to the resolver? - //construct new Reference<scripturi::ScriptURI> - Sequence<Any> aArgs(2); - aArgs[0]<<=*it_impls; - aArgs[1]<<=m_scriptStorageID; - - validateXRef(m_xContext, "ScriptStorage::getImplementations: No context available"); - Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef(xMgr, "ScriptStorage::getImplementations: No service manager available"); - Reference< XInterface > xx = xMgr->createInstanceWithArgumentsAndContext(OUString::createFromAscii("drafts.com.sun.star.script.framework.scripturi.ScriptURI"), aArgs, m_xContext ); - validateXRef(xMgr, "ScriptStorage::getImplementations: cannot get drafts.com.sun.star.script.framework.storage.ScriptInfo"); - Reference<scripturi::XScriptURI> uri(xx,UNO_QUERY_THROW); - //add to the sequence - //assuming that we'll usually only get 1 elt returned - //first realloc if we get 2 elts... - if(count>=results.getLength()) - { - results.realloc(results.getLength()+1); - } - results[count++]=uri; - } + return results; } + + ::osl::Guard< osl::Mutex > aGuard( m_mutex ); + + Impls_vec::const_iterator it_impls = h_it->second.begin(); + Impls_vec::const_iterator it_impls_end = h_it->second.end(); + for ( sal_Int32 count = 0; it_impls != it_impls_end ; ++it_impls ) + { + Sequence<Any> aArgs( 2 ); + aArgs[ 0 ] <<= *it_impls; + aArgs[ 1 ] <<= m_scriptStorageID; + + Reference< XInterface > xInterface = + m_xMgr->createInstanceWithArgumentsAndContext( + OUString::createFromAscii( + "drafts.com.sun.star.script.framework.scripturi.ScriptURI" ), aArgs, + m_xContext ); + validateXRef( xInterface, + "ScriptStorage::getImplementations: cannot get drafts.com.sun.star.script.framework.storage.ScriptURI" ); + Reference<scripturi::XScriptURI> uri( xInterface, UNO_QUERY_THROW ); + + results[ count++ ] = uri; + } + + } + catch ( RuntimeException re ) + { + throw RuntimeException( + OUSTR( "ScriptStorage::getImplementations RuntimeException: " ).concat( re.Message ), + Reference<XInterface> () ); } - catch(Exception e) + catch ( Exception e ) { - throw RuntimeException(OUSTR("ScriptStorage::getImplementations Exception: ")+e.Message, - Reference<XInterface> ()); + throw RuntimeException( OUSTR( "ScriptStorage::getImplementations Exception: " ).concat( e.Message ), + Reference<XInterface> () ); } return results; } //************************************************************************* -OUString SAL_CALL ScriptStorage::prepareForInvocation( const OUString& parcelURI ) throw (RuntimeException) +/** + copies a parcel to a temporary location + + @params parcelURI + the location of the parcel (file URI) to be copied + + @return + <type>::rtl::OUString</type> the new location of the parcel (file URI) +*/ +OUString SAL_CALL +ScriptStorage::prepareForInvocation( const OUString& parcelURI ) +throw ( RuntimeException ) { try { - validateXRef(m_xSimpleFileAccess, - "ScriptStorage::prepareForInvocation(): no SimpleFileAccess"); - - if ((m_xSimpleFileAccess->exists(parcelURI) != sal_True) || - (m_xSimpleFileAccess->isFolder(parcelURI) != sal_True)) + if ( ( m_xSimpleFileAccess->exists( parcelURI ) != sal_True ) || + ( m_xSimpleFileAccess->isFolder( parcelURI ) != sal_True ) ) { throw RuntimeException( - OUSTR("ScriptStorage::prepareForInvocation(): parcel URI is not valid"), - Reference<XInterface> ()); + OUSTR( "Parcel URI is not valid" ), + Reference<XInterface> () ); } OUString dest; - ::osl::FileBase::getTempDirURL(dest); + if ( ::osl::FileBase::E_None != ::osl::FileBase::getTempDirURL( dest ) ) + { + throw RuntimeException( + OUSTR( "getTempDirURL failed" ), + Reference<XInterface> () ); + } + + // Add time value to tmp dir name to prvent name clashes + TimeValue timeVal; + OUString sTime; + if ( sal_False != osl_getSystemTime( &timeVal ) ) + { + sTime = sTime.valueOf( static_cast<sal_Int32>( timeVal.Seconds ) ); + } + OSL_TRACE( ::rtl::OUStringToOString( + sTime.concat( OUString::createFromAscii( " Time to add to parcel name." ) ), RTL_TEXTENCODING_ASCII_US ).pData->buffer ); - sal_Int32 idx = parcelURI.lastIndexOf('/'); + sal_Int32 idx = parcelURI.lastIndexOf( '/' ); sal_Int32 len = parcelURI.getLength(); - if (idx == (len-1)) + if ( idx == ( len - 1 ) ) { // deal with the trailing separator - idx = parcelURI.lastIndexOf('/', len-2); - OUString parcel_base = parcelURI.copy(idx, len-idx-1); - dest = dest.concat(parcel_base); + idx = parcelURI.lastIndexOf( '/', len - 2 ); + OUString parcel_base = parcelURI.copy( idx, len - idx - 1 ); + dest = dest.concat( parcel_base ); } else { - dest = dest.concat(parcelURI.copy(idx)); + dest = dest.concat( parcelURI.copy( idx ) ); } - dest = dest.concat(OUString::valueOf((sal_Int32)m_scriptStorageID)); + dest = dest.concat( OUString::valueOf( ( sal_Int32 ) m_scriptStorageID ) ); - fprintf(stderr,"dest is: %s\n",rtl::OUStringToOString(dest, RTL_TEXTENCODING_ASCII_US).pData->buffer); + dest = dest.concat( sTime ); - copyFolder(parcelURI, dest); +#ifdef _DEBUG + + fprintf( stderr, "dest is: %s\n", + rtl::OUStringToOString( dest, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); +#endif + + copyFolder( parcelURI, dest ); return dest; } - catch(RuntimeException &e) + catch ( RuntimeException & e ) { - OUString temp = OUSTR( - "ScriptStorage::prepareForInvocation RuntimeException: "); - throw RuntimeException(temp.concat(e.Message), - Reference<XInterface> ()); + throw RuntimeException( + OUSTR( "ScriptStorage::prepareForInvocation RuntimeException: " ).concat( e.Message ), + Reference<XInterface> () ); + } + catch ( Exception & e ) + { + throw RuntimeException( + OUSTR( "ScriptStorage::prepareForInvocation Exception: " ).concat( e.Message ), + Reference<XInterface> () ); } #ifdef _DEBUG catch ( ... ) { - throw RuntimeException(OUSTR( - "ScriptStorage::prepareForInvocation UnknownException: "), - Reference<XInterface> ()); + throw RuntimeException( + OUSTR( "ScriptStorage::prepareForInvocation UnknownException: " ), + Reference<XInterface> () ); } #endif } //************************************************************************* /** - * This function copies the contents of the source folder into the - * destination folder. If the destination folder does not exist, it - * is created. If the destination folder exists, it is deleted and then - * created. All URIs supported by the relevant XSimpleFileAccess - * implementation are supported. - */ -void ScriptStorage::copyFolder(const OUString &src, const OUString &dest) throw (RuntimeException) + This function copies the contents of the source folder into the + destination folder. If the destination folder does not exist, it + is created. If the destination folder exists, it is deleted and then + created. All URIs supported by the relevant XSimpleFileAccess + implementation are supported. + + @params src + the source folder (file URI) + + @params dest + the destination folder (file URI) +*/ +void +ScriptStorage::copyFolder( const OUString &src, const OUString &dest ) +throw ( RuntimeException ) { try { - OUString new_dest; - sal_Int32 idx; - /* A mutex guard is needed to not write later into * a folder that has been deleted by an incoming thread. * Note that this calls into the SimpleFileAccess service @@ -589,76 +689,78 @@ void ScriptStorage::copyFolder(const OUString &src, const OUString &dest) throw */ ::osl::Guard< osl::Mutex > aGuard( m_mutex ); - if (m_xSimpleFileAccess->isFolder(dest) == sal_True) + if ( m_xSimpleFileAccess->isFolder( dest ) == sal_True ) { - m_xSimpleFileAccess->kill(dest); + m_xSimpleFileAccess->kill( dest ); } - m_xSimpleFileAccess->createFolder(dest); + m_xSimpleFileAccess->createFolder( dest ); - Sequence <OUString> seq = m_xSimpleFileAccess->getFolderContents( - src, sal_True); + Sequence <OUString> seq = m_xSimpleFileAccess->getFolderContents( + src, sal_True ); + OUString new_dest; + sal_Int32 idx; sal_Int32 len = seq.getLength(); - for(int i = 0; i < len; i++) + for ( int i = 0; i < len; i++ ) { new_dest = dest; - idx = seq[i].lastIndexOf('/'); - new_dest = new_dest.concat(seq[i].copy(idx)); + idx = seq[ i ].lastIndexOf( '/' ); + new_dest = new_dest.concat( seq[ i ].copy( idx ) ); - if (m_xSimpleFileAccess->isFolder(seq[i]) == sal_True) + if ( m_xSimpleFileAccess->isFolder( seq[ i ] ) == sal_True ) { - copyFolder(seq[i], new_dest); + copyFolder( seq[ i ], new_dest ); } else { - m_xSimpleFileAccess->copy(seq[i], new_dest); + m_xSimpleFileAccess->copy( seq[ i ], new_dest ); } } } - catch(ucb::CommandAbortedException &e) + catch ( ucb::CommandAbortedException & e ) { OUString temp = OUSTR( - "ScriptStorage::copyFolder CommandAbortedException: "); - throw RuntimeException(temp.concat(e.Message), - Reference<XInterface> ()); + "ScriptStorage::copyFolder CommandAbortedException: " ); + throw RuntimeException( temp.concat( e.Message ), + Reference<XInterface> () ); } - catch(RuntimeException &e) + catch ( RuntimeException & e ) { - OUString temp = OUSTR("ScriptStorage::copyFolder RuntimeException: "); - throw RuntimeException(temp.concat(e.Message), - Reference<XInterface> ()); + OUString temp = OUSTR( "ScriptStorage::copyFolder RuntimeException: " ); + throw RuntimeException( temp.concat( e.Message ), + Reference<XInterface> () ); } - catch(Exception &e) + catch ( Exception & e ) { - OUString temp = OUSTR("ScriptStorage::copyFolder Exception: "); - throw RuntimeException(temp.concat(e.Message), - Reference<XInterface> ()); + OUString temp = OUSTR( "ScriptStorage::copyFolder Exception: " ); + throw RuntimeException( temp.concat( e.Message ), + Reference<XInterface> () ); } #ifdef _DEBUG catch ( ... ) { - throw RuntimeException(OUSTR( - "ScriptStorage::copyFolder UnknownException: "), - Reference<XInterface> ()); + throw RuntimeException( OUSTR( + "ScriptStorage::copyFolder UnknownException: " ), + Reference<XInterface> () ); } #endif } //************************************************************************* -OUString SAL_CALL ScriptStorage::getImplementationName( ) -throw(RuntimeException) +OUString SAL_CALL ScriptStorage::getImplementationName( ) +throw( RuntimeException ) { return ss_implName; } //************************************************************************* sal_Bool SAL_CALL ScriptStorage::supportsService( const OUString& serviceName ) -throw(RuntimeException) +throw( RuntimeException ) { OUString const * pNames = ss_serviceNames.getConstArray(); for ( sal_Int32 nPos = ss_serviceNames.getLength(); nPos--; ) { - if (serviceName.equals( pNames[ nPos ] )) + if ( serviceName.equals( pNames[ nPos ] ) ) { return sal_True; } @@ -667,8 +769,8 @@ throw(RuntimeException) } //************************************************************************* -Sequence<OUString> SAL_CALL ScriptStorage::getSupportedServiceNames( ) -throw(RuntimeException) +Sequence<OUString> SAL_CALL ScriptStorage::getSupportedServiceNames( ) +throw( RuntimeException ) { return ss_serviceNames; } @@ -680,14 +782,14 @@ Reference<XInterface> SAL_CALL ss_create( } //************************************************************************* -Sequence<OUString> ss_getSupportedServiceNames( ) +Sequence<OUString> ss_getSupportedServiceNames( ) SAL_THROW( () ) { return ss_serviceNames; } //************************************************************************* -OUString ss_getImplementationName( ) +OUString ss_getImplementationName( ) SAL_THROW( () ) { return ss_implName; diff --git a/scripting/source/storage/ScriptStorage.hxx b/scripting/source/storage/ScriptStorage.hxx index 6efbbb145ba5..f54afc82077d 100644 --- a/scripting/source/storage/ScriptStorage.hxx +++ b/scripting/source/storage/ScriptStorage.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ScriptStorage.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: lkovacs $ $Date: 2002-09-23 14:17:49 $ + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,6 +70,11 @@ #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> + #include <drafts/com/sun/star/script/framework/storage/XScriptAccessManager.hpp> #include <drafts/com/sun/star/script/framework/storage/XScriptImplAccess.hpp> #include <drafts/com/sun/star/script/framework/storage/XScriptStorageExport.hpp> @@ -77,25 +82,18 @@ #include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp> #include <drafts/com/sun/star/script/framework/storage/NoSuchView.hpp> #include <drafts/com/sun/star/script/framework/scripturi/XScriptURI.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> -#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_XPARCELINVOCATIONPREP_HPP_ #include <drafts/com/sun/star/script/framework/storage/XParcelInvocationPrep.hpp> -#endif namespace scripting_impl { //Typedefs //============================================================================= -typedef ::std::vector< ::drafts::com::sun::star::script::framework::storage::ScriptImplInfo > -Impls_vec; +typedef ::std::vector< + ::drafts::com::sun::star::script::framework::storage::ScriptImplInfo > Impls_vec; //----------------------------------------------------------------------------- -typedef ::std::hash_map < ::rtl::OUString, Impls_vec, -::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > -ScriptInfo_hash; +typedef ::std::hash_map < ::rtl::OUString, + Impls_vec, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ScriptInfo_hash; //----------------------------------------------------------------------------- typedef ::std::hash_map < ::rtl::OUString, ::com::sun::star::uno::Reference< @@ -113,36 +111,6 @@ class ScriptStorage ::drafts::com::sun::star::script::framework::storage::XScriptAccessManager, ::drafts::com::sun::star::script::framework::storage::XParcelInvocationPrep > { - // private member -private: - - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; - ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > m_xSimpleFileAccess; - - ::std::vector < ::rtl::OUString > mv_logicalNames; - ScriptInfo_hash mh_implementations; - ScriptOutput_hash mh_parcels; - sal_uInt16 m_scriptStorageID; - - osl::Mutex m_mutex; - - void updateMaps(Impls_vec vScriptII); - void writeMetadataHeader(::com::sun::star::uno::Reference < ::com::sun::star::xml::sax::XExtendedDocumentHandler > & ); - /** - This function copies the contents of the source folder into the - destination folder. If the destination folder does not exist, it - is created. If the destination folder exists, it is deleted and then - created. All URIs supported by the relevant XSimpleFileAccess - implementation are supported. - - @params src - the source folder (file URI) - - @params dest - the destination folder (file URI) - */ - void copyFolder(const ::rtl::OUString & src, const ::rtl::OUString & dest) throw (::com::sun::star::uno::RuntimeException); - public: //Constructors and Destructors //========================================================================= @@ -154,26 +122,28 @@ public: // XServiceInfo impl //========================================================================= - virtual ::rtl::OUString SAL_CALL getImplementationName() - throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL + getImplementationName() + throw (::com::sun::star::uno::RuntimeException); //------------------------------------------------------------------------- - virtual sal_Bool SAL_CALL supportsService( - const ::rtl::OUString & ServiceName ) - throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL + supportsService( const ::rtl::OUString & ServiceName ) + throw (::com::sun::star::uno::RuntimeException); //------------------------------------------------------------------------- - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > - SAL_CALL getSupportedServiceNames() - throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames() + throw (::com::sun::star::uno::RuntimeException); //------------------------------------------------------------------------- - static ::com::sun::star::uno::Sequence< ::rtl::OUString > - SAL_CALL getSupportedServiceNames_Static(); + static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames_Static(); //========================================================================= // XInitialization impl //========================================================================= - virtual void SAL_CALL initialize( ::com::sun::star::uno::Sequence - < ::com::sun::star::uno::Any > const & args ) - throw (::com::sun::star::uno::Exception); + virtual void SAL_CALL + initialize( ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any > const & args ) + throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::uno::Exception); //========================================================================= // XScriptAccessManager impl @@ -189,11 +159,10 @@ public: * A sequence of XScriptInfos which represent the implementations * of the passed in logical name */ - virtual ::com::sun::star::uno::Sequence< - ::com::sun::star::uno::Reference< - ::drafts::com::sun::star::script::framework::storage::XScriptInfo > > - SAL_CALL getScriptInfoService( const ::rtl::OUString & name ) - throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::storage::XScriptInfo > > SAL_CALL + getScriptInfoService( const ::rtl::OUString & name ) + throw (::com::sun::star::uno::RuntimeException); //========================================================================= //XScriptImplAccess @@ -209,10 +178,11 @@ public: */ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< - ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > > - SAL_CALL getImplementations( const ::com::sun::star::uno::Reference< - ::drafts::com::sun::star::script::framework::scripturi::XScriptURI >& queryURI ) - throw (::com::sun::star::lang::IllegalArgumentException, + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI > > SAL_CALL + getImplementations( const ::com::sun::star::uno::Reference< + ::drafts::com::sun::star::script::framework::scripturi::XScriptURI >& + queryURI ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); //========================================================================= @@ -229,14 +199,15 @@ public: * The view of the hierarchy */ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > - ScriptStorage::getView( const ::rtl::OUString& viewName ) - throw (::drafts::com::sun::star::script::framework::storage::NoSuchView, + getView( const ::rtl::OUString& viewName ) + throw (::drafts::com::sun::star::script::framework::storage::NoSuchView, ::com::sun::star::uno::RuntimeException); //========================================================================= // XScriptStorageExport - void SAL_CALL save() - throw (::com::sun::star::uno::RuntimeException); + void SAL_CALL + save() + throw (::com::sun::star::uno::RuntimeException); //========================================================================= //XParcelInvocationPrep @@ -250,9 +221,48 @@ public: @return <type>::rtl::OUString</type> the new location of the parcel (file URI) */ - ::rtl::OUString SAL_CALL prepareForInvocation( const ::rtl::OUString& parcelURI ) - throw (::com::sun::star::uno::RuntimeException); + ::rtl::OUString SAL_CALL + prepareForInvocation( const ::rtl::OUString& parcelURI ) + throw (::com::sun::star::uno::RuntimeException); //========================================================================= +private: + + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XSimpleFileAccess > m_xSimpleFileAccess; + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiComponentFactory > m_xMgr; + + ::std::vector < ::rtl::OUString > mv_logicalNames; + ScriptInfo_hash mh_implementations; + ScriptOutput_hash mh_parcels; + sal_uInt16 m_scriptStorageID; + + osl::Mutex m_mutex; + bool m_bInitialised; + + void updateMaps(const Impls_vec & vScriptImplInfos); + void writeMetadataHeader( + ::com::sun::star::uno::Reference < + ::com::sun::star::xml::sax::XExtendedDocumentHandler > & ); + /** + This function copies the contents of the source folder into the + destination folder. If the destination folder does not exist, it + is created. If the destination folder exists, it is deleted and then + created. All URIs supported by the relevant XSimpleFileAccess + implementation are supported. + + @params src + the source folder (file URI) + + @params dest + the destination folder (file URI) + */ + void + copyFolder(const ::rtl::OUString & src, const ::rtl::OUString & dest) + throw (::com::sun::star::uno::RuntimeException); + } ; // class ScriptingStorage diff --git a/scripting/source/storage/ScriptStorageManager.cxx b/scripting/source/storage/ScriptStorageManager.cxx index 0180d74faf0f..32f9647c8222 100644 --- a/scripting/source/storage/ScriptStorageManager.cxx +++ b/scripting/source/storage/ScriptStorageManager.cxx @@ -1,63 +1,63 @@ /************************************************************************* - * - * $RCSfile: ScriptStorageManager.cxx,v $ - * - * $Revision: 1.2 $ - * - * last change: $Author: dfoster $ $Date: 2002-09-25 10:18:12 $ - * - * The Contents of this file are made available subject to the terms of - * either of the following licenses - * - * - GNU Lesser General Public License Version 2.1 - * - Sun Industry Standards Source License Version 1.1 - * - * Sun Microsystems Inc., October, 2000 - * - * GNU Lesser General Public License Version 2.1 - * ============================================= - * Copyright 2000 by Sun Microsystems, Inc. - * 901 San Antonio Road, Palo Alto, CA 94303, USA - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * - * Sun Industry Standards Source License Version 1.1 - * ================================================= - * The contents of this file are subject to the Sun Industry Standards - * Source License Version 1.1 (the "License"); You may not use this file - * except in compliance with the License. You may obtain a copy of the - * License at http://www.openoffice.org/license.html. - * - * Software provided under this License is provided on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, - * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, - * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. - * See the License for the specific provisions governing your rights and - * obligations concerning the Software. - * - * The Initial Developer of the Original Code is: Sun Microsystems, Inc. - * - * Copyright: 2000 by Sun Microsystems, Inc. - * - * All Rights Reserved. - * - * Contributor(s): _______________________________________ - * - * - ************************************************************************/ +* +* $RCSfile: ScriptStorageManager.cxx,v $ +* +* $Revision: 1.3 $ +* +* last change: $Author: jmrice $ $Date: 2002-09-27 12:16:30 $ +* +* The Contents of this file are made available subject to the terms of +* either of the following licenses +* +* - GNU Lesser General Public License Version 2.1 +* - Sun Industry Standards Source License Version 1.1 +* +* Sun Microsystems Inc., October, 2000 +* +* GNU Lesser General Public License Version 2.1 +* ============================================= +* Copyright 2000 by Sun Microsystems, Inc. +* 901 San Antonio Road, Palo Alto, CA 94303, USA +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License version 2.1, as published by the Free Software Foundation. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +* +* Sun Industry Standards Source License Version 1.1 +* ================================================= +* The contents of this file are subject to the Sun Industry Standards +* Source License Version 1.1 (the "License"); You may not use this file +* except in compliance with the License. You may obtain a copy of the +* License at http://www.openoffice.org/license.html. +* +* Software provided under this License is provided on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +* See the License for the specific provisions governing your rights and +* obligations concerning the Software. +* +* The Initial Developer of the Original Code is: Sun Microsystems, Inc. +* +* Copyright: 2000 by Sun Microsystems, Inc. +* +* All Rights Reserved. +* +* Contributor(s): _______________________________________ +* +* +************************************************************************/ #include <stdio.h> @@ -80,89 +80,145 @@ using namespace ::drafts::com::sun::star::script::framework; namespace scripting_impl { -static const sal_Char* const SERVICENAME="drafts.com.sun.star.script.framework.storage.ScriptStorageManager"; -static const sal_Char* const IMPLNAME="drafts.com.sun.star.script.framework.storage.ScriptStorageManager"; - -static OUString s_implName = ::rtl::OUString::createFromAscii(IMPLNAME); -static OUString s_serviceName = ::rtl::OUString::createFromAscii(SERVICENAME); +static OUString s_implName = + ::rtl::OUString::createFromAscii( + "drafts.com.sun.star.script.framework.storage.ScriptStorageManager" ); +static OUString s_serviceName = + ::rtl::OUString::createFromAscii( + "drafts.com.sun.star.script.framework.storage.ScriptStorageManager" ); static Sequence< OUString > s_serviceNames = Sequence< OUString >( &s_serviceName, 1 ); -::rtl_StandardModuleCount s_moduleCount = MODULE_COUNT_INIT; +extern ::rtl_StandardModuleCount s_moduleCount = MODULE_COUNT_INIT; //************************************************************************* // ScriptStorageManager Constructor -ScriptStorageManager::ScriptStorageManager(const Reference< XComponentContext > & xContext) - : m_xContext( xContext ) +ScriptStorageManager::ScriptStorageManager( const Reference< XComponentContext > & xContext ) + : m_xContext( xContext ), m_count( 0 ) + SAL_THROW ( ( RuntimeException ) ) { OSL_TRACE( "< ScriptStorageManager ctor called >\n" ); s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt ); + + validateXRef( m_xContext, "ScriptStorageManager::ScriptStorageManager : cannot get component context" ); + + m_xMgr = m_xContext->getServiceManager(); + validateXRef( m_xMgr, "ScriptStorageManager::ScriptStorageManager : cannot get service manager" ); + try { - count=0; // obtain the macro expander singleton to use in determining the // location of the application script storage - Any aAny = m_xContext->getValueByName(OUString::createFromAscii("/singletons/com.sun.star.util.theMacroExpander")); + Any aAny = m_xContext->getValueByName( OUString::createFromAscii( + "/singletons/com.sun.star.util.theMacroExpander" ) ); Reference<util::XMacroExpander> xME; - OSL_ASSERT(sal_False!=(aAny>>=xME)); - OSL_ASSERT(xME.is()); - validateXRef(xME,"ScriptStorageManager constructor: Can't get MacroExpander"); + if ( sal_False == ( aAny >>= xME ) ) + { + throw RuntimeException( + OUSTR( "ScriptStorageManager::ScriptStorageManager: can't get XMacroExpander" ), + Reference< XInterface >() ); + } + validateXRef( xME, "ScriptStorageManager constructor: can't get MacroExpander" ); + + OUString base = OUString::createFromAscii( + SAL_CONFIGFILE( "${$SYSBINDIR/bootstrap" ) ); + + setupAppStorage( xME, + base.concat( OUString::createFromAscii( "::BaseInstallation}/share" ) ) ); + setupAppStorage( xME, + base.concat( OUString::createFromAscii( "::UserInstallation}/user" ) ) ); + + } + catch ( Exception & e ) + { + throw RuntimeException( OUSTR( "ScriptStorageManager::ScriptStorageManager: " ) + e.Message, Reference< XInterface >() ); + } + OSL_ASSERT( m_count == 2 ); +} + +//************************************************************************* +// ScriptStorageManager setupAppStorage +void +ScriptStorageManager::setupAppStorage( + const Reference<util::XMacroExpander> & xME, + const OUString & storageStr ) +SAL_THROW ( ( RuntimeException ) ) +{ + try + { + Reference<XInterface> xInterface = + m_xMgr->createInstanceWithContext( + OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), m_xContext ); + validateXRef( xInterface, + "ScriptStorageManager constructor: can't get SimpleFileAccess XInterface" ); + Reference<ucb::XSimpleFileAccess> xSFA( xInterface, UNO_QUERY_THROW ); + + setupAnyStorage( xSFA, xME->expandMacros( storageStr ) ); + } + catch ( Exception & e ) + { + throw RuntimeException( + OUSTR( "ScriptStorageManager::setupAppStorage: " ).concat( e.Message ), + Reference< XInterface >() ); + } +} - // get the MultiComponentFactory and use it to create a - // SimpleFileAccess component - Reference<lang::XMultiComponentFactory> xMCF = m_xContext->getServiceManager(); - validateXRef(xMCF,"ScriptStorageManager::ScriptStorageManager : cannot get service manager"); - Reference<XInterface> xx = xMCF->createInstanceWithContext(OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess"), m_xContext); - Reference<ucb::XSimpleFileAccess> xSFA(xx,UNO_QUERY); +//************************************************************************* +// ScriptStorageManager setupAnyStorage +sal_uInt16 +ScriptStorageManager::setupAnyStorage( + const Reference< ucb::XSimpleFileAccess > & xSFA, + const OUString & storageStr ) +SAL_THROW ( ( RuntimeException ) ) +{ + // Required for scope of fnc to protect all access read and writes to m_count + ::osl::Guard< ::osl::Mutex > aGuard( m_mutex ); + try + { // create a ScriptingStorage using the SimpleFileAccess, the storageID // (from the count), and the URL to the application's shared area - Sequence <Any> aArgs(3); - OUString base=OUString::createFromAscii( SAL_CONFIGFILE("${$SYSBINDIR/bootstrap")); - aArgs[0] <<= xSFA; - aArgs[1] <<= count; - aArgs[2] <<= xME->expandMacros(base.concat(OUString::createFromAscii("::BaseInstallation}/share"))); + Sequence <Any> aArgs( 3 ); + aArgs[ 0 ] <<= xSFA; + aArgs[ 1 ] <<= m_count; + aArgs[ 2 ] <<= storageStr; + #ifdef _DEBUG - fprintf(stderr,"creating storage for: %s\n",::rtl::OUStringToOString(xME->expandMacros(base.concat(OUString::createFromAscii("::BaseInstallation}/share"))),RTL_TEXTENCODING_ASCII_US).pData->buffer); + fprintf( stderr, "creating storage for: %s\n", + ::rtl::OUStringToOString( + storageStr, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); #endif - xx = xMCF->createInstanceWithArgumentsAndContext(OUString::createFromAscii("drafts.com.sun.star.script.framework.storage.ScriptStorage"), aArgs, m_xContext); - OSL_ASSERT(xx.is()); - xx->acquire(); - validateXRef(xx,"ScriptStorageManager constructor: Can't create ScriptStorage for share"); - // and place it in the hash_map. Increment the counter - m_ScriptStorageHash[count++]=xx; -#ifdef _DEBUG + Reference<XInterface> xInterface = + m_xMgr->createInstanceWithArgumentsAndContext( + OUString::createFromAscii( + "drafts.com.sun.star.script.framework.storage.ScriptStorage" ), + aArgs, m_xContext ); - fprintf(stderr,"\tcreated with ID=%d\n",count-1); -#endif - //Repeat the procedure with the application user area - aArgs[1] <<= count; - aArgs[2] <<= xME->expandMacros(base.concat(OUString::createFromAscii("::UserInstallation}/user"))); -#ifdef _DEBUG + validateXRef( xInterface, "ScriptStorageManager:: setupAnyStorage: Can't create ScriptStorage for share" ); - fprintf(stderr,"creating storage for: %s\n",::rtl::OUStringToOString(xME->expandMacros(base.concat(OUString::createFromAscii("::UserInstallation}/user"))),RTL_TEXTENCODING_ASCII_US).pData->buffer); -#endif + // and place it in the hash_map. Increment the counter + m_ScriptStorageHash[ m_count++ ] = xInterface; - xx = xMCF->createInstanceWithArgumentsAndContext(OUString::createFromAscii("drafts.com.sun.star.script.framework.storage.ScriptStorage"), aArgs, m_xContext); - OSL_ASSERT(xx.is()); - xx->acquire(); - validateXRef(xx,"ScriptStorageManager constructor: Can't create ScriptStorage for share"); - m_ScriptStorageHash[count++]=xx; #ifdef _DEBUG - fprintf(stderr,"\tcreated with ID=%d\n",count-1); + fprintf( stderr, "\tcreated with ID=%d\n", m_count - 1 ); #endif } - catch (Exception &e) + catch ( Exception & e ) { - throw RuntimeException(OUSTR("ScriptStorageManager::ScriptStorageManager: ").concat(e.Message), Reference< XInterface >()); + throw RuntimeException( + OUSTR( "ScriptStorageManager::setupAnyStorage: " ).concat( e.Message ), + Reference< XInterface >() ); } + + return m_count -1; } //************************************************************************* // ScriptStorageManager Destructor ScriptStorageManager::~ScriptStorageManager() +SAL_THROW ( () ) { OSL_TRACE( "< ScriptStorageManager dtor called >\n" ); s_moduleCount.modCnt.release( &s_moduleCount.modCnt ); @@ -171,73 +227,68 @@ ScriptStorageManager::~ScriptStorageManager() //************************************************************************* // This method assumes that the XSimpleFileAccess knows it's on root URL // and can be used with relative URLs -sal_uInt16 SAL_CALL ScriptStorageManager::createScriptStorage( const Reference< ucb::XSimpleFileAccess >& xSFA ) throw (RuntimeException) +sal_uInt16 SAL_CALL +ScriptStorageManager::createScriptStorage( + const Reference< ucb::XSimpleFileAccess >& xSFA ) +throw ( RuntimeException ) { - OSL_TRACE("** ==> ScriptStorageManager in createScriptingStorage\n"); - validateXRef(xSFA, "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid"); - Sequence <Any> aArgs(2); - aArgs[0] <<= xSFA; - aArgs[1] <<= count; - Reference<lang::XMultiComponentFactory> xMCF = m_xContext->getServiceManager(); - validateXRef(xMCF,"ScriptStorageManager::createScriptStorage"); - Reference<XInterface>xx = xMCF->createInstanceWithArgumentsAndContext(OUString::createFromAscii("drafts.com.sun.star.script.framework.storage.ScriptStorage"), aArgs, m_xContext); - OSL_ASSERT(xx.is()); - m_ScriptStorageHash[count++]=xx; -#ifdef _DEBUG - - fprintf(stderr,"\tcreated with ID=%d\n",count-1); -#endif + OSL_TRACE( "** ==> ScriptStorageManager in createScriptingStorage\n" ); + validateXRef( xSFA, + "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" ); - return count-1; + return setupAnyStorage( xSFA, ::rtl::OUString::createFromAscii( "" ) ); } //************************************************************************* -sal_uInt16 SAL_CALL ScriptStorageManager::createScriptStorageWithURI( const Reference< ucb::XSimpleFileAccess >& xSFA, const OUString & stringURI ) throw (RuntimeException) +sal_uInt16 SAL_CALL +ScriptStorageManager::createScriptStorageWithURI( + const Reference< ucb::XSimpleFileAccess >& xSFA, const OUString & stringURI ) +throw ( RuntimeException ) { - OSL_TRACE("** ==> ScriptStorageManager in createScriptingStorageWithURI\n"); - validateXRef(xSFA, "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid"); - Sequence <Any> aArgs(3); - aArgs[0] <<= xSFA; - aArgs[1] <<= count; - aArgs[2] <<= stringURI; - Reference<lang::XMultiComponentFactory> xMCF = m_xContext->getServiceManager(); - validateXRef(xMCF,"ScriptStorageManager::createScriptStorageWithURI"); - Reference<XInterface> xx = xMCF->createInstanceWithArgumentsAndContext(OUString::createFromAscii("drafts.com.sun.star.script.framework.storage.ScriptStorage"), aArgs, m_xContext); - OSL_ASSERT(xx.is()); - m_ScriptStorageHash[count++]=xx; -#ifdef _DEBUG + OSL_TRACE( "** ==> ScriptStorageManager in createScriptingStorageWithURI\n" ); + validateXRef( xSFA, "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" ); - fprintf(stderr,"\tcreated with ID=%d\n",count-1); -#endif - - return count-1; + return setupAnyStorage( xSFA, stringURI ); } //************************************************************************* -Reference <XInterface> SAL_CALL ScriptStorageManager::getScriptStorage(sal_uInt16 scriptStorageID) -throw(RuntimeException) +Reference <XInterface> SAL_CALL +ScriptStorageManager::getScriptStorage( sal_uInt16 scriptStorageID ) +throw( RuntimeException ) { - OSL_TRACE("** ==> ScriptStorageManager in getStorageInstance\n"); - Reference<XInterface> result=m_ScriptStorageHash[scriptStorageID]; - validateXRef(result, "ScriptStorageManager::getScriptStorage: Cannot get ScriptStorage from ScriptStorageHash"); - return result; + OSL_TRACE( "** ==> ScriptStorageManager in getStorageInstance\n" ); + + ScriptStorage_hash::const_iterator itr = + m_ScriptStorageHash.find( scriptStorageID ); + + if ( itr == m_ScriptStorageHash.end() ) + { + throw RuntimeException( + OUSTR( "ScriptStorageManager::getScriptStorage: invalid storage ID" ), + Reference< XInterface >() ); + } + validateXRef( itr->second, + "ScriptStorageManager::getScriptStorage: Cannot get ScriptStorage from ScriptStorageHash" ); + return itr->second; } //************************************************************************* -OUString SAL_CALL ScriptStorageManager::getImplementationName( ) -throw(RuntimeException) +OUString SAL_CALL +ScriptStorageManager::getImplementationName( ) +throw( RuntimeException ) { return s_implName; } //************************************************************************* -sal_Bool SAL_CALL ScriptStorageManager::supportsService( const OUString& serviceName ) -throw(RuntimeException) +sal_Bool SAL_CALL +ScriptStorageManager::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 ] )) + if ( serviceName.equals( pNames[ nPos ] ) ) { return sal_True; } @@ -246,34 +297,40 @@ throw(RuntimeException) } //************************************************************************* -Sequence<OUString> SAL_CALL ScriptStorageManager::getSupportedServiceNames( ) -throw(RuntimeException) +Sequence<OUString> SAL_CALL +ScriptStorageManager::getSupportedServiceNames( ) +throw( RuntimeException ) { return s_serviceNames; } //************************************************************************* -void SAL_CALL ScriptStorageManager::disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL +ScriptStorageManager::disposing( const ::com::sun::star::lang::EventObject& Source ) +throw ( ::com::sun::star::uno::RuntimeException ) { - OSL_TRACE("ScriptStorageManager::disposing started"); + OSL_TRACE( "ScriptStorageManager::disposing started" ); } //************************************************************************* -static Reference<XInterface> SAL_CALL ssm_create( +static Reference<XInterface> SAL_CALL +ssm_create( const Reference< XComponentContext > & xCompC ) { - return (cppu::OWeakObject *)new ScriptStorageManager( xCompC ); + return ( cppu::OWeakObject * ) new ScriptStorageManager( xCompC ); } //************************************************************************* -static Sequence<OUString> ssm_getSupportedServiceNames( ) +static Sequence<OUString> +ssm_getSupportedServiceNames( ) SAL_THROW( () ) { return s_serviceNames; } //************************************************************************* -static OUString ssm_getImplementationName( ) +static OUString +ssm_getImplementationName( ) SAL_THROW( () ) { return s_implName; @@ -281,15 +338,15 @@ SAL_THROW( () ) //************************************************************************* Reference<XInterface> SAL_CALL ss_create( const Reference< XComponentContext > & xCompC ); //************************************************************************* -Sequence<OUString> ss_getSupportedServiceNames( ) SAL_THROW( () ); +Sequence<OUString> ss_getSupportedServiceNames( ) SAL_THROW( () ); //************************************************************************* -OUString ss_getImplementationName( ) SAL_THROW( () ); +OUString ss_getImplementationName( ) SAL_THROW( () ); //************************************************************************* Reference<XInterface> SAL_CALL si_create( const Reference< XComponentContext > & xCompC ); //************************************************************************* -Sequence<OUString> si_getSupportedServiceNames( ) SAL_THROW( () ); +Sequence<OUString> si_getSupportedServiceNames( ) SAL_THROW( () ); //************************************************************************* -OUString si_getImplementationName( ) SAL_THROW( () ); +OUString si_getImplementationName( ) SAL_THROW( () ); //************************************************************************* static struct cppu::ImplementationEntry s_entries [] = { @@ -321,7 +378,7 @@ static struct cppu::ImplementationEntry s_entries [] = */ extern "C" { - void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv) + void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) { *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; } @@ -333,9 +390,9 @@ extern "C" * @param pServiceManager the service manager * @param pRegistryKey the registry key */ - sal_Bool SAL_CALL component_writeInfo(lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey) + sal_Bool SAL_CALL component_writeInfo( lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey ) { - return ::cppu::component_writeInfoHelper(pServiceManager, pRegistryKey, ::scripting_impl::s_entries); + return ::cppu::component_writeInfoHelper( pServiceManager, pRegistryKey, ::scripting_impl::s_entries ); } /** @@ -346,8 +403,8 @@ extern "C" * @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) + void * SAL_CALL component_getFactory( const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey ) { - return ::cppu::component_getFactoryHelper(pImplName, pServiceManager, pRegistryKey, ::scripting_impl::s_entries); + return ::cppu::component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey, ::scripting_impl::s_entries ); } } diff --git a/scripting/source/storage/ScriptStorageManager.hxx b/scripting/source/storage/ScriptStorageManager.hxx index 928ad025c8c4..f87cfd485413 100644 --- a/scripting/source/storage/ScriptStorageManager.hxx +++ b/scripting/source/storage/ScriptStorageManager.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ScriptStorageManager.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: dfoster $ $Date: 2002-09-20 14:33:54 $ + * last change: $Author: jmrice $ $Date: 2002-09-27 12:16:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -63,14 +63,15 @@ #ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_ #define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_ -#include <osl/mutex.hxx> #include <hash_map> +#include <osl/mutex.hxx> #include <cppuhelper/implbase3.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/uno/RuntimeException.hpp> + #include <drafts/com/sun/star/script/framework/scripturi/XScriptURI.hpp> #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp> @@ -78,27 +79,39 @@ namespace scripting_impl { // Define a hash_map used to store the ScriptingStorages key;d by ID -typedef ::std::hash_map < sal_Int16, ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > > ScriptStorage_hash; - -class ScriptStorageManager : public ::cppu::WeakImplHelper3< ::drafts::com::sun::star::script::framework::storage::XScriptStorageManager, ::com::sun::star::lang::XServiceInfo, ::com::sun::star::lang::XEventListener> +typedef ::std::hash_map < + sal_Int16, + ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > > + ScriptStorage_hash; + +class ScriptStorageManager : +public ::cppu::WeakImplHelper3< + ::drafts::com::sun::star::script::framework::storage::XScriptStorageManager, + ::com::sun::star::lang::XServiceInfo, ::com::sun::star::lang::XEventListener > { - // to obtain other services if needed - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; - ::osl::Mutex m_mutex; - ScriptStorage_hash m_ScriptStorageHash; - sal_Int16 count; public: - ScriptStorageManager( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext ); - ~ScriptStorageManager(); + explicit ScriptStorageManager( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ) + SAL_THROW ( (RuntimeException) ); +; + ~ScriptStorageManager() SAL_THROW ( () ); // XServiceInfo implementation //====================================================================== - virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL + getImplementationName() + throw(::com::sun::star::uno::RuntimeException); //---------------------------------------------------------------------- - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL + supportsService( + const ::rtl::OUString& ServiceName ) + throw(::com::sun::star::uno::RuntimeException); //---------------------------------------------------------------------- - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames() + throw(::com::sun::star::uno::RuntimeException); //====================================================================== //XScriptStorageManager @@ -114,7 +127,11 @@ public: @returns an unsigned short ScriptStorage ID, which can be used in the getScriptStorage method */ - virtual sal_uInt16 SAL_CALL createScriptStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFA ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_uInt16 SAL_CALL + createScriptStorage( + const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XSimpleFileAccess > & xSFA ) + throw (::com::sun::star::uno::RuntimeException); //---------------------------------------------------------------------- /** create a ScriptStorage using the XSimpleFileAccess, and a string URL @@ -129,7 +146,12 @@ public: @returns an unsigned short ScriptStorage ID, which can be used in the getScriptStorage method */ - virtual sal_uInt16 SAL_CALL createScriptStorageWithURI( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFA, const ::rtl::OUString& stringURI ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_uInt16 SAL_CALL + createScriptStorageWithURI( + const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XSimpleFileAccess >& xSFA, + const ::rtl::OUString& stringURI ) + throw (::com::sun::star::uno::RuntimeException); //---------------------------------------------------------------------- /** get a ScriptStorage component using its scriptStorageID @@ -142,13 +164,47 @@ public: @returns an XInterface to a component that implements the ScriptStorage service */ - virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getScriptStorage( sal_uInt16 scriptStorageID ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface > SAL_CALL + getScriptStorage( sal_uInt16 scriptStorageID ) + throw (::com::sun::star::uno::RuntimeException); //====================================================================== //XEventListener //====================================================================== - virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL + disposing( const ::com::sun::star::lang::EventObject& Source ) + throw (::com::sun::star::uno::RuntimeException); + + static const sal_uInt16 APP_SHARE_STORAGE_ID = 0; + static const sal_uInt16 APP_USER_STORAGE_ID = 1; + +private: + ScriptStorageManager(const ScriptStorageManager & ); + ScriptStorageManager& operator= (const ScriptStorageManager &); + + // to obtain other services if needed + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiComponentFactory > m_xMgr; + ::osl::Mutex m_mutex; + ScriptStorage_hash m_ScriptStorageHash; + sal_Int16 m_count; + + void setupAppStorage( + const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XMacroExpander > & xME, + const ::rtl::OUString & storageStr ) + SAL_THROW ( ( ::com::sun::star::uno::RuntimeException ) ); + + sal_uInt16 setupAnyStorage( + const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XSimpleFileAccess> & xSFA, + const ::rtl::OUString & storageStr ) + SAL_THROW ( ( ::com::sun::star::uno::RuntimeException ) ); + }; } // scripting_impl |