diff options
-rw-r--r-- | scripting/source/inc/util/util.hxx | 15 | ||||
-rw-r--r-- | scripting/source/protocolhandler/scripthandler.cxx | 35 | ||||
-rw-r--r-- | scripting/source/provider/ActiveMSPList.cxx | 1 | ||||
-rwxr-xr-x | scripting/source/provider/MasterScriptProvider.cxx | 8 | ||||
-rw-r--r-- | scripting/source/provider/ProviderCache.cxx | 17 | ||||
-rw-r--r-- | scripting/source/provider/ScriptImpl.cxx | 8 | ||||
-rwxr-xr-x | scripting/source/provider/ScriptingContext.cxx | 5 | ||||
-rw-r--r-- | scripting/source/runtimemgr/ScriptNameResolverImpl.cxx | 71 | ||||
-rwxr-xr-x | scripting/source/runtimemgr/ScriptRuntimeManager.cxx | 61 | ||||
-rw-r--r-- | scripting/source/runtimemgr/StorageBridge.cxx | 32 | ||||
-rw-r--r-- | scripting/source/storage/ScriptMetadataImporter.cxx | 29 | ||||
-rwxr-xr-x | scripting/source/storage/ScriptSecurityManager.cxx | 162 | ||||
-rw-r--r-- | scripting/source/storage/ScriptStorage.cxx | 67 | ||||
-rw-r--r-- | scripting/source/storage/ScriptStorageManager.cxx | 53 |
14 files changed, 153 insertions, 411 deletions
diff --git a/scripting/source/inc/util/util.hxx b/scripting/source/inc/util/util.hxx index 27e5c19ccc91..a07d66452e0d 100644 --- a/scripting/source/inc/util/util.hxx +++ b/scripting/source/inc/util/util.hxx @@ -29,21 +29,6 @@ #ifndef _COM_SUN_STAR_SCRIPTING_UTIL_UTIL_HXX_ #define _COM_SUN_STAR_SCRIPTING_UTIL_UTIL_HXX_ -#include <rtl/ustrbuf.hxx> -#include <osl/diagnose.h> - #define OUSTR(x) ::rtl::OUString( ::rtl::OUString::createFromAscii(x) ) -namespace scripting_util -{ - inline void validateXRef(::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xRef, const sal_Char* Msg) throw (::com::sun::star::uno::RuntimeException) - { - OSL_ENSURE( xRef.is(), Msg ); - - if(!xRef.is()) - { - throw ::com::sun::star::uno::RuntimeException(OUSTR(Msg), ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >()); - } - } -} #endif //_COM_SUN_STAR_SCRIPTING_UTIL_UTIL_HXX_ diff --git a/scripting/source/protocolhandler/scripthandler.cxx b/scripting/source/protocolhandler/scripthandler.cxx index 7c24b98e5a71..e9d12be12b5e 100644 --- a/scripting/source/protocolhandler/scripthandler.cxx +++ b/scripting/source/protocolhandler/scripthandler.cxx @@ -49,6 +49,7 @@ #include <sfx2/frame.hxx> #include <sfx2/sfxdlg.hxx> #include <vcl/abstdlg.hxx> +#include <tools/diagnose_ex.h> #include <cppuhelper/factory.hxx> #include <cppuhelper/exc_hlp.hxx> @@ -70,7 +71,6 @@ using namespace ::com::sun::star::lang; using namespace ::com::sun::star::script; using namespace ::com::sun::star::script::provider; using namespace ::com::sun::star::document; -using namespace ::scripting_util; namespace scripting_protocolhandler { @@ -98,8 +98,7 @@ void SAL_CALL ScriptProtocolHandler::initialize( throw RuntimeException( temp, Reference< XInterface >() ); } - validateXRef( m_xFactory, - "ScriptProtocolHandler::initialize: No Service Manager available" ); + ENSURE_OR_THROW( m_xFactory.is(), "ScriptProtocolHandler::initialize: No Service Manager available" ); m_bInitialised = true; } @@ -163,7 +162,7 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( { try { - bool bIsDocumentScript = ( aURL.Complete.indexOf( ::rtl::OUString::createFromAscii( "document" ) ) !=-1 ); + bool bIsDocumentScript = ( aURL.Complete.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "document" ) ) !=-1 ); // TODO: isn't this somewhat strange? This should be a test for a location=document parameter, shouldn't it? if ( bIsDocumentScript ) @@ -183,7 +182,7 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( Reference< provider::XScript > xFunc = m_xScriptProvider->getScript( aURL.Complete ); - validateXRef( xFunc, + ENSURE_OR_THROW( xFunc.is(), "ScriptProtocolHandler::dispatchWithNotification: validate xFunc - unable to obtain XScript interface" ); @@ -254,16 +253,6 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( bCaughtException = TRUE; } -#ifdef _DEBUG - catch ( ... ) - { - ::rtl::OUString reason = ::rtl::OUString::createFromAscii( - "ScriptProtocolHandler::dispatch: caught unknown exception" ); - - invokeResult <<= reason; - } -#endif - } else { @@ -364,13 +353,11 @@ ScriptProtocolHandler::getScriptInvocation() return m_xScriptInvocation.is(); } -void -ScriptProtocolHandler::createScriptProvider() +void ScriptProtocolHandler::createScriptProvider() { if ( m_xScriptProvider.is() ) - { return; - } + try { // first, ask the component supporting the XScriptInvocationContext interface @@ -403,6 +390,7 @@ ScriptProtocolHandler::createScriptProvider() m_xScriptProvider = xSPS->getScriptProvider(); } + // if nothing of this is successful, use the master script provider if ( !m_xScriptProvider.is() ) { Reference< XPropertySet > xProps( m_xFactory, UNO_QUERY_THROW ); @@ -436,15 +424,6 @@ ScriptProtocolHandler::createScriptProvider() ::rtl::OUString temp = OUSTR( "ScriptProtocolHandler::createScriptProvider: " ); throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); } -#ifdef _DEBUG - catch ( ... ) - { - throw RuntimeException( - OUSTR( "ScriptProtocolHandler::createScriptProvider: UnknownException: " ), - Reference< XInterface > () ); - } -#endif - } ScriptProtocolHandler::ScriptProtocolHandler( diff --git a/scripting/source/provider/ActiveMSPList.cxx b/scripting/source/provider/ActiveMSPList.cxx index 3c6206d8d051..bbabbb21405c 100644 --- a/scripting/source/provider/ActiveMSPList.cxx +++ b/scripting/source/provider/ActiveMSPList.cxx @@ -49,7 +49,6 @@ using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::script; -using namespace ::scripting_util; using namespace ::sf_misc; namespace func_provider diff --git a/scripting/source/provider/MasterScriptProvider.cxx b/scripting/source/provider/MasterScriptProvider.cxx index 94ea78f80c73..33d371e3d51b 100755 --- a/scripting/source/provider/MasterScriptProvider.cxx +++ b/scripting/source/provider/MasterScriptProvider.cxx @@ -33,6 +33,8 @@ #include <cppuhelper/implementationentry.hxx> #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/factory.hxx> +#include <tools/diagnose_ex.h> + #include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/lang/EventObject.hpp> #include <com/sun/star/container/XContentEnumerationAccess.hpp> @@ -60,7 +62,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::script; using namespace ::com::sun::star::document; using namespace ::sf_misc; -using namespace ::scripting_util; namespace func_provider { @@ -95,10 +96,9 @@ MasterScriptProvider::MasterScriptProvider( const Reference< XComponentContext > m_xContext( xContext ), m_bIsValid( false ), m_bInitialised( false ), m_bIsPkgMSP( false ), m_pPCache( 0 ) { - validateXRef( m_xContext, "MasterScriptProvider::MasterScriptProvider: No context available\n" ); + ENSURE_OR_THROW( m_xContext.is(), "MasterScriptProvider::MasterScriptProvider: No context available\n" ); m_xMgr = m_xContext->getServiceManager(); - validateXRef( m_xMgr, - "MasterScriptProvider::MasterScriptProvider: No service manager available\n" ); + ENSURE_OR_THROW( m_xMgr.is(), "MasterScriptProvider::MasterScriptProvider: No service manager available\n" ); m_bIsValid = true; } diff --git a/scripting/source/provider/ProviderCache.cxx b/scripting/source/provider/ProviderCache.cxx index 5d3350f635e3..bea38a67a8f1 100644 --- a/scripting/source/provider/ProviderCache.cxx +++ b/scripting/source/provider/ProviderCache.cxx @@ -29,6 +29,7 @@ #include "precompiled_scripting.hxx" #include <cppuhelper/implementationentry.hxx> #include <cppuhelper/factory.hxx> +#include <tools/diagnose_ex.h> #include <util/scriptingconstants.hxx> #include <util/util.hxx> @@ -39,7 +40,6 @@ using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::script; -using namespace ::scripting_util; namespace func_provider { @@ -51,7 +51,7 @@ ProviderCache::ProviderCache( const Reference< XComponentContext >& xContext, co // will use createContentEnumeration m_xMgr = m_xContext->getServiceManager(); - validateXRef( m_xMgr, "ProviderCache::ProviderCache() failed to obtain ServiceManager" ); + ENSURE_OR_THROW( m_xMgr.is(), "ProviderCache::ProviderCache() failed to obtain ServiceManager" ); populateCache(); } @@ -64,7 +64,7 @@ ProviderCache::ProviderCache( const Reference< XComponentContext >& xContext, co // will use createContentEnumeration m_xMgr = m_xContext->getServiceManager(); - validateXRef( m_xMgr, "ProviderCache::ProviderCache() failed to obtain ServiceManager" ); + ENSURE_OR_THROW( m_xMgr.is(), "ProviderCache::ProviderCache() failed to obtain ServiceManager" ); populateCache(); } @@ -163,14 +163,8 @@ ProviderCache::populateCache() throw ( RuntimeException ) while ( xEnum->hasMoreElements() ) { - Reference< lang::XSingleComponentFactory > factory; - if ( sal_False == ( xEnum->nextElement() >>= factory ) ) - { - throw new RuntimeException( ::rtl::OUString::createFromAscii( " error extracting XSingleComponentFactory from Content enumeration. " ), Reference< XInterface >() ); - } - validateXRef( factory, "ProviderCache::populateCache() invalid factory" ); + Reference< lang::XSingleComponentFactory > factory( xEnum->nextElement(), UNO_QUERY_THROW ); Reference< lang::XServiceInfo > xServiceInfo( factory, UNO_QUERY_THROW ); - validateXRef( xServiceInfo, "ProviderCache::populateCache() failed to get XServiceInfo from factory" ); Sequence< ::rtl::OUString > serviceNames = xServiceInfo->getSupportedServiceNames(); @@ -207,9 +201,8 @@ ProviderCache::createProvider( ProviderDetails& details ) throw ( RuntimeExcepti { try { - details.provider = Reference< provider::XScriptProvider >( + details.provider.set( details.factory->createInstanceWithArgumentsAndContext( m_Sctx, m_xContext ), UNO_QUERY_THROW ); - validateXRef( details.provider, "ProviderCache::createProvider, failed to create provider"); } catch ( RuntimeException& e ) { diff --git a/scripting/source/provider/ScriptImpl.cxx b/scripting/source/provider/ScriptImpl.cxx index f5b93a802138..08d548e3461c 100644 --- a/scripting/source/provider/ScriptImpl.cxx +++ b/scripting/source/provider/ScriptImpl.cxx @@ -46,15 +46,11 @@ ScriptImpl::ScriptImpl( const Reference< runtime::XScriptInvocation > & runtimeMgr, const ::rtl::OUString& scriptURI ) throw ( RuntimeException ) : - m_XScriptingContext( scriptingContext ), - m_RunTimeManager( runtimeMgr ), + m_XScriptingContext( scriptingContext, UNO_SET_THROW ), + m_RunTimeManager( runtimeMgr, UNO_SET_THROW ), m_ScriptURI( scriptURI ) { OSL_TRACE( "<!constucting a ScriptImpl>\n" ); - validateXRef( m_XScriptingContext, - "ScriptImpl::ScriptImpl: No XScriptingContext\n" ); - validateXRef( m_RunTimeManager, - "ScriptImpl::ScriptImpl: No XScriptInvocation\n" ); } //************************************************************************* diff --git a/scripting/source/provider/ScriptingContext.cxx b/scripting/source/provider/ScriptingContext.cxx index 08a27a19562f..0394bd3653d1 100755 --- a/scripting/source/provider/ScriptingContext.cxx +++ b/scripting/source/provider/ScriptingContext.cxx @@ -55,13 +55,10 @@ namespace func_provider //************************************************************************* ScriptingContext::ScriptingContext( const Reference< XComponentContext > & xContext ) : //ScriptingContextImpl_BASE( GetMutex()), OPropertyContainer( GetBroadcastHelper() ), - m_xContext( xContext ) + m_xContext( xContext, UNO_SET_THROW ) { OSL_TRACE( "< ScriptingContext ctor called >\n" ); - validateXRef( m_xContext, - "ScriptingContext::ScriptingContext: No context available\n" ); - Any nullAny; scripting_constants::ScriptingConstantsPool& scriptingConstantsPool = diff --git a/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx b/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx index 48b960c6c9aa..8dafab0e8d4c 100644 --- a/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx +++ b/scripting/source/runtimemgr/ScriptNameResolverImpl.cxx @@ -70,13 +70,11 @@ static ::std::vector< sal_Int32 >* m_pSearchIDs = NULL; //************************************************************************* ScriptNameResolverImpl::ScriptNameResolverImpl( const Reference< XComponentContext > & xContext ) : - m_xContext( xContext ) + m_xContext( xContext, UNO_SET_THROW ) { OSL_TRACE( "< ScriptNameResolverImpl ctor called >\n" ); validateXRef( m_xContext, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid context" ); - m_xMultiComFac = m_xContext->getServiceManager(); - - validateXRef( m_xMultiComFac, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid XMultiComponentFactory " ); + m_xMultiComFac.set( m_xContext->getServiceManager(), UNO_SET_THROW ); if( !m_pSearchIDs ) { @@ -220,11 +218,13 @@ throw ( lang::IllegalArgumentException, script::CannotConvertException, RuntimeE OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: " ); throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); } - Reference< XInterface > xInterface = m_xMultiComFac->createInstanceWithContext( - ::rtl::OUString::createFromAscii( - "com.sun.star.ucb.SimpleFileAccess" ), m_xContext ); - validateXRef( xInterface, - "ScriptProvider::initialise: cannot get SimpleFileAccess Service\n" ); + Reference< XInterface > xInterface( + m_xMultiComFac->createInstanceWithContext( + ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), + m_xContext + ), + UNO_SET_THROW + ); Reference < ucb::XSimpleFileAccess > xSimpleFileAccess = Reference < ucb::XSimpleFileAccess > ( xInterface, UNO_QUERY_THROW ); @@ -236,15 +236,8 @@ throw ( lang::IllegalArgumentException, script::CannotConvertException, RuntimeE try { // need to get the ScriptStorageManager - Any a = m_xContext->getValueByName( - scriptingConstantsPool.SCRIPTSTORAGEMANAGER_SERVICE ); - if ( sal_False == ( a >>= xScriptStorageMgr ) ) - { - OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: failed to get ScriptStorageManager" ); - throw RuntimeException( temp, Reference< XInterface >() ); - // need to throw - } - validateXRef( xScriptStorageMgr, "Cannot get ScriptStorageManager" ); + xScriptStorageMgr.set( m_xContext->getValueByName( + scriptingConstantsPool.SCRIPTSTORAGEMANAGER_SERVICE ), UNO_QUERY_THROW ); filesysScriptStorageID = xScriptStorageMgr->createScriptStorageWithURI( xSimpleFileAccess, filesysURL ); @@ -364,20 +357,12 @@ throw ( lang::IllegalArgumentException, script::CannotConvertException, RuntimeE if( filesysScriptStorageID > 2 ) { // get the filesys storage and dispose of it - Reference< XInterface > xScriptStorage = - xScriptStorageMgr->getScriptStorage( filesysScriptStorageID ); - validateXRef( xScriptStorage, - "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" ); + Reference< XInterface > xScriptStorage( xScriptStorageMgr->getScriptStorage( filesysScriptStorageID ), UNO_SET_THROW ); Reference< storage::XScriptInfoAccess > xScriptInfoAccess = Reference< storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW ); - validateXRef( xScriptInfoAccess, - "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptInfoAccess" ); Sequence< Reference< storage::XScriptInfo > > results = xScriptInfoAccess->getAllImplementations( ); - Reference < lang::XEventListener > xEL_ScriptStorageMgr = - Reference< lang::XEventListener > - ( xScriptStorageMgr ,UNO_QUERY_THROW ); - validateXRef( xEL_ScriptStorageMgr, "ScriptNameResolverImpl::resolve: can't get ScriptStorageManager XEventListener interface when trying to dispose of filesystem storage" ); + Reference < lang::XEventListener > xEL_ScriptStorageMgr(( xScriptStorageMgr ,UNO_QUERY_THROW ); lang::EventObject event( results[ 0 ] ); xEL_ScriptStorageMgr->disposing( event ); } @@ -447,9 +432,7 @@ SAL_THROW ( ( lang::IllegalArgumentException, css::security::AccessControlExcept throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() ); } } - Reference< storage::XScriptInfoAccess > storage = getStorageInstance( sid, permissionURI ); - validateXRef( storage, - "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptInfoAccess" ); + Reference< storage::XScriptInfoAccess > storage( getStorageInstance( sid, permissionURI ), UNO_SET_THROW ); Sequence< Reference< storage::XScriptInfo > > results = storage->getImplementations( scriptURI ); @@ -516,22 +499,10 @@ const ::rtl::OUString & permissionURI ) SAL_THROW ( ( RuntimeException, css::sec Reference< storage::XScriptInfoAccess > xScriptInfoAccess; try { - Reference< XInterface > xInterface; - - Any a = m_xContext->getValueByName( - OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ); - if ( sal_False == ( a >>= xInterface ) ) - { - throw RuntimeException( - OUSTR( "ScriptNameResolverImpl::getStorageInstance: could not obtain ScriptStorageManager singleton" ), - Reference< XInterface >() ); - } - validateXRef( xInterface, - "ScriptNameResolverImpl::getStorageInstance: cannot get Storage service" ); + Reference< XInterface > xInterface( m_xContext->getValueByName( + OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ), UNO_QUERY_THROW ); // check that we have permissions for this storage Reference< dcsssf::security::XScriptSecurity > xScriptSecurity( xInterface, UNO_QUERY_THROW ); - validateXRef( xScriptSecurity, - "ScriptNameResolverImpl::getStorageInstance: cannot get Script Security service" ); scripting_constants::ScriptingConstantsPool& scriptingConstantsPool = scripting_constants::ScriptingConstantsPool::instance(); // if we dealing with a document storage (ie. not user or share @@ -546,14 +517,8 @@ const ::rtl::OUString & permissionURI ) SAL_THROW ( ( RuntimeException, css::sec OSL_TRACE( "ScriptNameResolverImpl::getStorageInstance: got execute permission for ID=%d", sid ); } Reference< storage::XScriptStorageManager > xScriptStorageManager( xInterface, UNO_QUERY_THROW ); - validateXRef( xScriptStorageManager, - "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage Manager service" ); - Reference< XInterface > xScriptStorage = - xScriptStorageManager->getScriptStorage( sid ); - validateXRef( xScriptStorage, - "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" ); - xScriptInfoAccess = Reference< - storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW ); + Reference< XInterface > xScriptStorage( ScriptStorageManager->getScriptStorage( sid ), UNO_SET_THROW ); + xScriptInfoAccess.set( xScriptStorage, UNO_QUERY_THROW ); } catch ( lang::IllegalArgumentException & e ) { diff --git a/scripting/source/runtimemgr/ScriptRuntimeManager.cxx b/scripting/source/runtimemgr/ScriptRuntimeManager.cxx index 4780d58acc88..79a44bebce7d 100755 --- a/scripting/source/runtimemgr/ScriptRuntimeManager.cxx +++ b/scripting/source/runtimemgr/ScriptRuntimeManager.cxx @@ -37,6 +37,7 @@ #include <util/scriptingconstants.hxx> #include <cppuhelper/implementationentry.hxx> +#include <tools/diagnose_ex.h> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/lang/XEventListener.hpp> @@ -68,14 +69,10 @@ static Sequence< OUString > s_serviceNames = Sequence< OUString >( &s_serviceNam // ScriptRuntimeManager Constructor ScriptRuntimeManager::ScriptRuntimeManager( const Reference< XComponentContext > & xContext ) : - m_xContext( xContext ) + m_xContext( xContext, UNO_SET_THROW ) { OSL_TRACE( "< ScriptRuntimeManager ctor called >\n" ); - validateXRef( m_xContext, - "ScriptRuntimeManager::ScriptRuntimeManager: invalid context" ); - m_xMgr = m_xContext->getServiceManager(); - validateXRef( m_xMgr, - "ScriptRuntimeManager::ScriptRuntimeManager: cannot get ServiceManager" ); + m_xMgr.set( m_xContext->getServiceManager(), UNO_SET_THROW ); s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt ); // test //scripting_securitymgr::ScriptSecurityManager ssm(xContext); @@ -106,22 +103,12 @@ throw( RuntimeException ) Reference< storage::XScriptInfo > sinfo = Reference< storage::XScriptInfo >( scriptInfo, UNO_QUERY_THROW ); - OUStringBuffer *buf = new OUStringBuffer(80); - buf->appendAscii("/singletons/drafts.com.sun.star.script.framework.runtime.theScriptRuntimeFor"); - buf->append(sinfo->getLanguage()); + OUStringBuffer* buf( 80 ); + buf.appendAscii("/singletons/drafts.com.sun.star.script.framework.runtime.theScriptRuntimeFor"); + buf.append(sinfo->getLanguage()); - Any a = m_xContext->getValueByName(buf->makeStringAndClear()); - - if ( sal_False == ( a >>= xInterface ) ) - { - throw RuntimeException( - sinfo->getLanguage().concat( OUSTR( " runtime support is not installed for this language" ) ), - Reference< XInterface >() ); - } - validateXRef( xInterface, - "ScriptRuntimeManager::GetScriptRuntime: cannot get appropriate ScriptRuntime Service" - ); - xScriptInvocation = Reference< runtime::XScriptInvocation >( xInterface, UNO_QUERY_THROW ); + xInterface.set( m_xContext->getValueByName( buf.makeStringAndClear() ), UNO_QUERY_THROW ); + xScriptInvocation.set( xInterface, UNO_QUERY_THROW ); } catch ( Exception & e ) { @@ -143,13 +130,14 @@ throw( RuntimeException ) try { - Reference< XInterface > xInterface = m_xMgr->createInstanceWithContext( - OUString::createFromAscii( - "drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" ), - m_xContext ); - validateXRef( xInterface, - "ScriptRuntimeManager::GetScriptRuntime: cannot get instance of DefaultScriptNameResolver" ); - xScriptNameResolver = Reference< runtime::XScriptNameResolver >( xInterface, UNO_QUERY_THROW ); + Reference< XInterface > xInterface( + m_xMgr->createInstanceWithContext( + OUString::createFromAscii("drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" ), + m_xContext + ), + UNO_SET_THROW + ); + xScriptNameResolver.set( xInterface, UNO_QUERY_THROW ); } catch ( Exception & e ) { @@ -182,9 +170,8 @@ Any SAL_CALL ScriptRuntimeManager::invoke( try { - Reference< storage::XScriptInfo > resolvedScript = resolve( scriptURI, - resolvedCtx ); - validateXRef( resolvedScript, "ScriptRuntimeManager::invoke: No resolvedURI" ); + Reference< storage::XScriptInfo > resolvedScript = resolve( scriptURI, resolvedCtx ); + ENSURE_OR_THROW( resolvedScript.is(), "ScriptRuntimeManager::invoke: No resolvedURI" ); Reference< beans::XPropertySet > xPropSetResolvedCtx; if ( sal_False == ( resolvedCtx >>= xPropSetResolvedCtx ) ) @@ -216,7 +203,7 @@ Any SAL_CALL ScriptRuntimeManager::invoke( Reference< runtime::XScriptInvocation > xScriptInvocation = getScriptRuntime( resolvedScript ); - validateXRef( xScriptInvocation, + ENSURE_OR_THROW( xScriptInvocation.is(), "ScriptRuntimeManager::invoke: cannot get instance of language specific runtime." ); // the scriptURI is currently passed to the language-dept runtime but @@ -232,13 +219,7 @@ Any SAL_CALL ScriptRuntimeManager::invoke( { Any a = m_xContext->getValueByName( scriptingConstantsPool.SCRIPTSTORAGEMANAGER_SERVICE ); - Reference < lang::XEventListener > xEL_ScriptStorageManager; - if ( sal_False == ( a >>= xEL_ScriptStorageManager ) ) - { - throw RuntimeException( OUSTR( "ScriptRuntimeManager::invoke: can't get ScriptStorageManager XEventListener interface when trying to dispose of filesystem storage" ), - Reference< XInterface > () ); - } - validateXRef( xEL_ScriptStorageManager, "Cannot get XEventListener from ScriptStorageManager" ); + Reference < lang::XEventListener > xEL_ScriptStorageManager( a, UNO_QUERY_THROW ); lang::EventObject event(resolvedScript); xEL_ScriptStorageManager->disposing( event ); } @@ -310,7 +291,7 @@ throw( lang::IllegalArgumentException, script::CannotConvertException, RuntimeEx Reference< storage::XScriptInfo > resolvedURI; Reference< runtime::XScriptNameResolver > xScriptNameResolver = getScriptNameResolver(); - validateXRef( xScriptNameResolver, + ENSURE_OR_THROW( xScriptNameResolver.is(), "ScriptRuntimeManager::resolve: No ScriptNameResolver" ); try diff --git a/scripting/source/runtimemgr/StorageBridge.cxx b/scripting/source/runtimemgr/StorageBridge.cxx index d1915afba9e5..1e15cf808870 100644 --- a/scripting/source/runtimemgr/StorageBridge.cxx +++ b/scripting/source/runtimemgr/StorageBridge.cxx @@ -54,9 +54,8 @@ const int STORAGEPROXY = 0; //************************************************************************* // StorageBridge Constructor StorageBridge::StorageBridge( const Reference< XComponentContext >& xContext, - sal_Int32 sid ) : m_xContext( xContext ), m_sid( sid ) + sal_Int32 sid ) : m_xContext( xContext, UNO_SET_THROW ), m_sid( sid ) { - validateXRef( m_xContext, "StorageBridge::StorageBridge: invalid context" ); try { initStorage(); @@ -74,31 +73,12 @@ StorageBridge::initStorage() throw ( ::com::sun::star::uno::RuntimeException ) { try { - Reference< lang::XMultiComponentFactory > xMultiComFac = - m_xContext->getServiceManager(); - validateXRef( xMultiComFac, - "StorageBridge::StorageBridge: cannot get multicomponentfactory from multiservice factory" ); - Reference< XInterface > temp; - - Any a = m_xContext->getValueByName( - OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ); - if ( sal_False == ( a >>= temp ) ) - { - throw RuntimeException( - OUSTR( "StorageBridge::StorageBridge: could not obtain ScriptStorageManager singleton" ), - Reference< XInterface >() ); - } - validateXRef( temp, - "StorageBridge::StorageBridge: cannot get Storage service" ); + Reference< lang::XMultiComponentFactory > xMultiComFac( m_xContext->getServiceManager(), UNO_SET_THROW ); + Reference< XInterface > temp( m_xContext->getValueByName( + OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ), UNO_QUERY_THROW ); Reference< storage::XScriptStorageManager > xScriptStorageManager( temp, UNO_QUERY_THROW ); - validateXRef( xScriptStorageManager, - "StorageBridge::StorageBridge: cannot get Script Storage Manager service" ); - Reference< XInterface > xScriptStorage = - xScriptStorageManager->getScriptStorage( m_sid ); - validateXRef( xScriptStorage, - "StorageBridge::StorageBridge: cannot get Script Storage service" ); - m_xScriptInfoAccess = - Reference< storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW ); + Reference< XInterface > xScriptStorage( xScriptStorageManager->getScriptStorage( m_sid ), UNO_SET_THROW ); + m_xScriptInfoAccess.set( xScriptStorage, UNO_QUERY_THROW ); } catch ( RuntimeException & re ) { diff --git a/scripting/source/storage/ScriptMetadataImporter.cxx b/scripting/source/storage/ScriptMetadataImporter.cxx index 64dd87b2546b..96faf6e9c1f4 100644 --- a/scripting/source/storage/ScriptMetadataImporter.cxx +++ b/scripting/source/storage/ScriptMetadataImporter.cxx @@ -38,7 +38,7 @@ #include <com/sun/star/xml/sax/XParser.hpp> #include <rtl/string.h> - +#include <tools/diagnose_ex.h> #include <util/util.hxx> @@ -82,31 +82,14 @@ void ScriptMetadataImporter::parseMetaData( ms_parcelURI = parcelURI; //Get the parser service - validateXRef( m_xContext, + ENSURE_OR_THROW( m_xContext.is(), "ScriptMetadataImporter::parseMetaData: No context available" ); - Reference< lang::XMultiComponentFactory > xMgr = - m_xContext->getServiceManager(); - - validateXRef( xMgr, - "ScriptMetadataImporter::parseMetaData: No service manager available" ); - - Reference< XInterface > xInterface = xMgr->createInstanceWithContext( - OUString::createFromAscii( "com.sun.star.xml.sax.Parser" ), m_xContext ); + Reference< lang::XMultiComponentFactory > xMgr( m_xContext->getServiceManager(), UNO_SET_THROW ); - validateXRef( xInterface, "ScriptMetadataImporter::parseMetaData: cannot get SAX Parser" ); - Reference< xml::sax::XParser > xParser; - try - { - xParser.set( xInterface ,UNO_QUERY_THROW ); - } - catch (RuntimeException & re ) - { - OUString msg = OUString::createFromAscii( - "ScriptMetadata:Importer::parserMetaData cannot get XParser" ); - msg.concat( re.Message ); - throw RuntimeException( msg, Reference< XInterface > () ); - } + Reference< xml::sax::XParser > xParser( + xMgr->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.xml.sax.Parser" ), m_xContext ), + UNO_QUERY_THROW ); // xxx todo: error handler, entity resolver omitted // This class is the document handler for the parser diff --git a/scripting/source/storage/ScriptSecurityManager.cxx b/scripting/source/storage/ScriptSecurityManager.cxx index 3fde4e466974..fbe6f41b4663 100755 --- a/scripting/source/storage/ScriptSecurityManager.cxx +++ b/scripting/source/storage/ScriptSecurityManager.cxx @@ -47,7 +47,7 @@ #include "ScriptSecurityManager.hxx" #include <util/util.hxx> #include <util/scriptingconstants.hxx> - +#include <tools/diagnose_ex.h> using namespace ::rtl; using namespace ::osl; @@ -85,28 +85,15 @@ static const int ADD_TO_PATH = 2; // ScriptSecurityManager Constructor ScriptSecurityManager::ScriptSecurityManager( const Reference< XComponentContext > & xContext ) throw ( RuntimeException ) - : m_xContext( xContext) + : m_xContext( xContext, UNO_SET_THROW ) { OSL_TRACE( "< ScriptSecurityManager ctor called >\n" ); - validateXRef( m_xContext, - "ScriptSecurityManager::ScriptSecurityManager: invalid context" ); // get the service manager from the context - Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef( xMgr, - "ScriptSecurityManager::ScriptSecurityManager: cannot get ServiceManager" ); + Reference< lang::XMultiComponentFactory > xMgr( m_xContext->getServiceManager(), UNO_SET_THROW ); // create an instance of the ConfigurationProvider - Reference< XInterface > xInterface = xMgr->createInstanceWithContext( - s_configProv, m_xContext ); - validateXRef( xInterface, - "ScriptSecurityManager::ScriptSecurityManager: cannot get ConfigurationProvider" ); - // create an instance of the ConfigurationAccess for accessing the - // scripting security settings - m_xConfigProvFactory = Reference < lang::XMultiServiceFactory > ( xInterface, UNO_QUERY ); - validateXRef( m_xConfigProvFactory, - "ScriptSecurityManager::ScriptSecurityManager: cannot get XMultiServiceFactory interface from ConfigurationProvider" ); - + m_xConfigProvFactory.set( xMgr->createInstanceWithContext( s_configProv, m_xContext ), UNO_QUERY_THROW ); } void ScriptSecurityManager::addScriptStorage( rtl::OUString scriptStorageURL, @@ -131,35 +118,6 @@ throw ( RuntimeException ) //need to check if storage has any scripts try { - /* need to replace this with something better, now logical names are - * gone - - Reference< XInterface > xInterface; - Any a = m_xContext->getValueByName( - OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ); - if ( sal_False == ( a >>= xInterface ) ) - { - throw RuntimeException( - OUSTR( "ScriptSecurityManager::addScriptStorage: could not obtain ScriptStorageManager singleton" ), - Reference< XInterface >() ); - } - validateXRef( xInterface, - "ScriptSecurityManager::addScriptStorage: cannot get Storage service" ); - Reference< storage::XScriptStorageManager > xScriptStorageManager( - xInterface, UNO_QUERY_THROW ); - Reference< XInterface > xScriptStorage = - xScriptStorageManager->getScriptStorage( storageID ); - validateXRef( xScriptStorage, - "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" ); - Reference< storage::XScriptInfoAccess > xScriptInfoAccess = - Reference< storage::XScriptInfoAccess > ( xScriptStorage, - UNO_QUERY_THROW ); - Sequence< ::rtl::OUString > logicalNames = xScriptInfoAccess->getScriptLogicalNames(); - if( !logicalNames.getLength() ) // we have no logical names - { - return; - } */ - // we have some scripts so read config & decide on that basis // Setup flags: m_runMacroSetting, m_warning, m_confirmationRequired, readConfiguration(); @@ -317,17 +275,12 @@ throw ( RuntimeException ) short result; try { - Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef( xMgr, - "ScriptSecurityManager::executeDialog: cannot get ServiceManager" ); - Reference< XInterface > xInterface = - xMgr->createInstanceWithArgumentsAndContext( s_securityDialog, - aArgs, m_xContext ); - validateXRef( xInterface, "ScriptSecurityManager::executeDialog: Can't create SecurityDialog" ); - Reference< awt::XDialog > xDialog( xInterface, UNO_QUERY_THROW ); + Reference< lang::XMultiComponentFactory > xMgr( m_xContext->getServiceManager(), UNO_SET_THROW ); + Reference< awt::XDialog > xDialog( + xMgr->createInstanceWithArgumentsAndContext( s_securityDialog, aArgs, m_xContext ), + UNO_QUERY_THROW ); result = xDialog->execute(); - Reference< lang::XComponent > xComponent( xInterface, UNO_QUERY_THROW ); - validateXRef( xInterface, "ScriptSecurityManager::executeDialog: Can't get XComponent to dispose dialog" ); + Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY_THROW ); xComponent->dispose(); } catch ( RuntimeException & rte ) @@ -410,31 +363,20 @@ void ScriptSecurityManager::removePermissionSettings ( ::rtl::OUString & scriptS void ScriptSecurityManager::readConfiguration() throw ( RuntimeException) { - Reference< XInterface > xInterface; try { - beans::PropertyValue configPath; - configPath.Name = ::rtl::OUString::createFromAscii( "nodepath" ); - configPath.Value <<= ::rtl::OUString::createFromAscii( "org.openoffice.Office.Common/Security/Scripting" ); - Sequence < Any > aargs( 1 ); - aargs[ 0 ] <<= configPath; - validateXRef( m_xConfigProvFactory, - "ScriptSecurityManager::readConfiguration: ConfigProviderFactory no longer valid!" ); - xInterface = m_xConfigProvFactory->createInstanceWithArguments( s_configAccess, - aargs ); - validateXRef( xInterface, - "ScriptSecurityManager::readConfiguration: cannot get ConfigurationAccess" ); - // get the XPropertySet interface from the ConfigurationAccess service - Reference < beans::XPropertySet > xPropSet( xInterface, UNO_QUERY ); - Any value; - - value=xPropSet->getPropertyValue( OUSTR( "Confirmation" ) ); - if ( sal_False == ( value >>= m_confirmationRequired ) ) - { - throw RuntimeException( - OUSTR( "ScriptSecurityManager:readConfiguration: can't get Confirmation setting" ), - Reference< XInterface > () ); - } + beans::PropertyValue configPath; + configPath.Name = ::rtl::OUString::createFromAscii( "nodepath" ); + configPath.Value <<= ::rtl::OUString::createFromAscii( "org.openoffice.Office.Common/Security/Scripting" ); + Sequence < Any > aargs( 1 ); + aargs[ 0 ] <<= configPath; + ENSURE_OR_THROW( m_xConfigProvFactory.is(), + "ScriptSecurityManager::readConfiguration: ConfigProviderFactory no longer valid!" ); + // get the XPropertySet interface from the ConfigurationAccess service + Reference < beans::XPropertySet > xPropSet( m_xConfigProvFactory->createInstanceWithArguments( s_configAccess, aargs ), UNO_QUERY_THROW ); + + m_confirmationRequired = sal_True; + OSL_VERIFY( xPropSet->getPropertyValue( OUSTR( "Confirmation" ) ) >>= m_confirmationRequired ); if ( m_confirmationRequired == sal_True ) { OSL_TRACE( "ScriptSecurityManager:readConfiguration: confirmation is true" ); @@ -443,13 +385,10 @@ void ScriptSecurityManager::readConfiguration() { OSL_TRACE( "ScriptSecurityManager:readConfiguration: confirmation is false" ); } - value=xPropSet->getPropertyValue( OUSTR( "Warning" ) ); - if ( sal_False == ( value >>= m_warning ) ) - { - throw RuntimeException( - OUSTR( "ScriptSecurityManager:readConfiguration: can't get Warning setting" ), - Reference< XInterface > () ); - } + + m_warning = true; + OSL_VERIFY( xPropSet->getPropertyValue( OUSTR( "Warning" ) ) >>= m_warning ); + if ( m_warning == sal_True ) { OSL_TRACE( "ScriptSecurityManager:readConfiguration: warning is true" ); @@ -458,21 +397,13 @@ void ScriptSecurityManager::readConfiguration() { OSL_TRACE( "ScriptSecurityManager:readConfiguration: warning is false" ); } - value=xPropSet->getPropertyValue( OUSTR( "OfficeBasic" ) ); - if ( sal_False == ( value >>= m_runMacroSetting ) ) - { - throw RuntimeException( - OUSTR( "ScriptSecurityManager:readConfiguration: can't get OfficeBasic setting" ), - Reference< XInterface > () ); - } + + m_runMacroSetting = sal_True; + OSL_VERIFY( xPropSet->getPropertyValue( OUSTR( "OfficeBasic" ) ) >>= m_runMacroSetting ); OSL_TRACE( "ScriptSecurityManager:readConfiguration: OfficeBasic = %d", m_runMacroSetting ); - value=xPropSet->getPropertyValue( OUSTR( "SecureURL" ) ); - if ( sal_False == ( value >>= m_secureURL ) ) - { - throw RuntimeException( - OUSTR( "ScriptSecurityManager:readConfiguration: can't get SecureURL setting" ), - Reference< XInterface > () ); - } + + m_secureURL = ::rtl::OUString(); + OSL_VERIFY( xPropSet->getPropertyValue( OUSTR( "SecureURL" ) ) >>= m_secureURL ); } catch ( beans::UnknownPropertyException & upe ) { @@ -508,18 +439,14 @@ void ScriptSecurityManager::readConfiguration() int length = m_secureURL.getLength(); // PathSubstitution needed to interpret variables found in config - Reference< lang::XMultiComponentFactory > xMgr = m_xContext->getServiceManager(); - validateXRef( xMgr, - "ScriptSecurityManager::readConfiguration: cannot get XMultiComponentFactory" ); - xInterface = xMgr->createInstanceWithContext( - ::rtl::OUString::createFromAscii( - "com.sun.star.util.PathSubstitution"), m_xContext); - validateXRef( xInterface, - "ScriptSecurityManager::readConfiguration: cannot get ConfigurationProvider" ); + Reference< lang::XMultiComponentFactory > xMgr( m_xContext->getServiceManager(), UNO_SET_THROW ); + Reference< XInterface > xInterface = ); Reference< util::XStringSubstitution > xStringSubstitution( - xInterface, UNO_QUERY); - validateXRef( xStringSubstitution, - "ScriptSecurityManager::readConfiguration: cannot get ConfigurationProvider" ); + xMgr->createInstanceWithContext( + ::rtl::OUString::createFromAscii( "com.sun.star.util.PathSubstitution" ), m_xContext + ), + UNO_QUERY_THROW + ); for( int i = 0; i < length; i++ ) { OSL_TRACE( "ScriptSecurityManager:readConfiguration path = %s", @@ -552,16 +479,9 @@ throw ( RuntimeException ) configPath.Value <<= ::rtl::OUString::createFromAscii( "org.openoffice.Office.Common/Security/Scripting" ); Sequence < Any > aargs( 1 ); aargs[ 0 ] <<= configPath; - Reference< XInterface > xInterface = m_xConfigProvFactory->createInstanceWithArguments( s_configUpdate, - aargs ); - validateXRef( xInterface, - "ScriptSecurityManager::addToSecurePaths: ScriptSecurityManager: cannot get ConfigurationUpdateAccess" ); - Reference < container::XNameReplace > xNameReplace( xInterface, UNO_QUERY ); - validateXRef( xNameReplace, - "ScriptSecurityManager::addToSecurePaths: ScriptSecurityManager: cannot get XNameReplace" ); - Reference < util::XChangesBatch > xChangesBatch( xInterface, UNO_QUERY ); - validateXRef( xChangesBatch, - "ScriptSecurityManager::addToSecurePaths: cannot get XChangesBatch" ); + Reference < container::XNameReplace > xNameReplace( + m_xConfigProvFactory->createInstanceWithArguments( s_configUpdate, aargs ), UNO_QUERY_THROW ); + Reference < util::XChangesBatch > xChangesBatch( xNameReplace, UNO_QUERY_THROW ); OSL_TRACE( "--->ScriptSecurityManager::addToSecurePaths: after if stuff" ); Reference < beans::XPropertySet > xPropSet( xInterface, UNO_QUERY ); diff --git a/scripting/source/storage/ScriptStorage.cxx b/scripting/source/storage/ScriptStorage.cxx index 7315e9d35dd5..e4ea5f231f47 100644 --- a/scripting/source/storage/ScriptStorage.cxx +++ b/scripting/source/storage/ScriptStorage.cxx @@ -84,16 +84,11 @@ const sal_uInt16 NUMBER_STORAGE_INITIALIZE_ARGS = 3; ScriptStorage::ScriptStorage( const Reference < XComponentContext > & xContext ) throw ( RuntimeException ) - : m_xContext( xContext ), m_bInitialised( false ) + : m_xContext( xContext, UNO_SET_THROW ), m_bInitialised( false ) { OSL_TRACE( "< ScriptStorage ctor called >\n" ); - validateXRef( m_xContext, - "ScriptStorage::ScriptStorage : cannot get component context" ); - - m_xMgr = m_xContext->getServiceManager(); - validateXRef( m_xMgr, - "ScriptStorage::ScriptStorage : cannot get service manager" ); + m_xMgr.set( m_xContext->getServiceManager(), UNO_SET_THROW ); if( !mh_scriptLangs ) { @@ -101,47 +96,30 @@ throw ( RuntimeException ) if( !mh_scriptLangs ) { mh_scriptLangs = new ScriptLanguages_hash(); - Reference< XInterface > xInterface = - m_xMgr->createInstanceWithContext( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationProvider" ) - , m_xContext ); - validateXRef( xInterface, - "ScriptStorage::ScriptStorage: cannot get ConfigurationProvider" ); + Reference< lang::XMultiServiceFactory > xConfigProvFactory( + m_xMgr->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ), m_xContext ), + UNO_QUERY_THROW ); // create an instance of the ConfigurationAccess for accessing the // scripting runtime settings - Reference< lang::XMultiServiceFactory > xConfigProvFactory = - Reference < lang::XMultiServiceFactory > - ( xInterface, UNO_QUERY_THROW ); - validateXRef( xConfigProvFactory, - "ScriptStorage::ScriptStorage: cannot get XMultiServiceFactory interface from ConfigurationProvider" ); beans::PropertyValue configPath; configPath.Name = ::rtl::OUString::createFromAscii( "nodepath" ); configPath.Value <<= ::rtl::OUString::createFromAscii( "org.openoffice.Office.Scripting/ScriptRuntimes" ); Sequence < Any > aargs( 1 ); aargs[ 0 ] <<= configPath; - xInterface = xConfigProvFactory->createInstanceWithArguments( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationAccess"), - aargs ); - validateXRef( xInterface, - "ScriptStorage::ScriptStorage: cannot get ConfigurationAccess" ); - Reference< container::XNameAccess > xNameAccess = - Reference < container::XNameAccess > ( xInterface, - UNO_QUERY_THROW ); - validateXRef( xNameAccess, - "ScriptStorage::ScriptStorage: cannot get ConfigurationAccess" ); + Reference< container::XNameAccess > xNameAccess( + xConfigProvFactory->createInstanceWithArguments( + OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" ), + aargs + ), + UNO_QUERY_THROW ); + Sequence< OUString > names = xNameAccess->getElementNames(); for( int i = 0 ; i < names.getLength() ; i++ ) { OSL_TRACE( "Getting propertyset for Lang=%s", ::rtl::OUStringToOString( names[i], RTL_TEXTENCODING_ASCII_US ).pData->buffer ); - Reference< beans::XPropertySet > xPropSet = - Reference< beans::XPropertySet >( xNameAccess->getByName(names[i]), - UNO_QUERY_THROW ); - validateXRef( xPropSet, - "ScriptStorage::ScriptStorage: cannot get XPropertySet for name" ); + Reference< beans::XPropertySet > xPropSet( xNameAccess->getByName( names[i] ), UNO_QUERY_THROW ); Any aProp = xPropSet->getPropertyValue( OUString::createFromAscii( "SupportedFileExtensions") ); Sequence< OUString > extns; @@ -285,9 +263,7 @@ throw ( RuntimeException, Exception ) OUString xStringUri(m_stringUri); ScriptMetadataImporter* SMI = new ScriptMetadataImporter( m_xContext ); - Reference< xml::sax::XExtendedDocumentHandler > xSMI( SMI ); - - validateXRef( xSMI, "ScriptStorage::create: failed to obtain valid XExtendedDocumentHandler" ); + Reference< xml::sax::XExtendedDocumentHandler > xSMI( SMI, UNO_SET_THROW ); xStringUri = xStringUri.concat( ::rtl::OUString::createFromAscii( SCRIPT_DIR ) ); @@ -587,15 +563,14 @@ throw ( RuntimeException ) "/parcel.xml" ) ), RTL_TEXTENCODING_ASCII_US ).pData->buffer ); - Reference< XInterface > xInterface = + xHandler.set( 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 ); + OUString::createFromAscii( "com.sun.star.xml.sax.Writer" ), + m_xContext + ), + UNO_QUERY_THROW + ); + xSource.set( xHandler, UNO_QUERY_THROW ); xSource->setOutputStream( xOS ); writeMetadataHeader( xHandler ); diff --git a/scripting/source/storage/ScriptStorageManager.cxx b/scripting/source/storage/ScriptStorageManager.cxx index 77ca5a45dd15..424f2752bc47 100644 --- a/scripting/source/storage/ScriptStorageManager.cxx +++ b/scripting/source/storage/ScriptStorageManager.cxx @@ -45,6 +45,7 @@ #include "ScriptStorageManager.hxx" #include <util/util.hxx> #include <util/scriptingconstants.hxx> +#include <tools/diagnose_ex.h> using namespace ::rtl; using namespace ::com::sun::star; @@ -70,32 +71,19 @@ static Sequence< OUString > s_serviceNames = Sequence< OUString >( &s_serviceNam // ScriptStorageManager Constructor ScriptStorageManager::ScriptStorageManager( const Reference< XComponentContext > & xContext ) SAL_THROW ( ( RuntimeException ) ) - : m_xContext( xContext ), m_count( 0 ), m_securityMgr( xContext ) + : m_xContext( xContext, UNO_SET_THROW ), m_count( 0 ), m_securityMgr( xContext ) { 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" ); + m_xMgr.set( m_xContext->getServiceManager(), UNO_SET_THROW ); try { // 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" ) ); - Reference< util::XMacroExpander > xME; - if ( sal_False == ( aAny >>= xME ) ) - { - throw RuntimeException( - OUSTR( "ScriptStorageManager::ScriptStorageManager: can't get XMacroExpander" ), - Reference< XInterface >() ); - } - validateXRef( xME, "ScriptStorageManager constructor: can't get MacroExpander" ); + Reference< util::XMacroExpander > xME( m_xContext->getValueByName( OUString::createFromAscii( + "/singletons/com.sun.star.util.theMacroExpander" ) ), UNO_QUERY_THROW ); OUString base = OUString::createFromAscii( SAL_CONFIGFILE( "${$BRAND_BASE_DIR/program/bootstrap" ) ); @@ -126,12 +114,13 @@ SAL_THROW ( ( RuntimeException ) ) { try { - Reference< XInterface > xInterface = + Reference< ucb::XSimpleFileAccess > xSFA( 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 ); + OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), + m_xContext + ), + UNO_QUERY_THROW + ); setupAnyStorage( xSFA, xME->expandMacros( storageStr ), appStr ); } @@ -168,13 +157,14 @@ SAL_THROW ( ( RuntimeException ) ) ::rtl::OUStringToOString( storageStr, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); - Reference< XInterface > xInterface = + Reference< XInterface > xInterface( m_xMgr->createInstanceWithArgumentsAndContext( - OUString::createFromAscii( - "drafts.com.sun.star.script.framework.storage.ScriptStorage" ), - aArgs, m_xContext ); - - validateXRef( xInterface, "ScriptStorageManager:: setupAnyStorage: Can't create ScriptStorage for share" ); + OUString::createFromAscii( "drafts.com.sun.star.script.framework.storage.ScriptStorage" ), + aArgs, + m_xContext + ), + UNO_QUERY_THROW + ); // and place it in the hash_map. Increment the counter m_ScriptStorageMap[ m_count++ ] = xInterface; @@ -215,8 +205,7 @@ ScriptStorageManager::createScriptStorage( throw ( RuntimeException ) { OSL_TRACE( "** ==> ScriptStorageManager in createScriptingStorage\n" ); - validateXRef( xSFA, - "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" ); + ENSURE_OR_THROW( xSFA.is(), "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" ); return setupAnyStorage( xSFA, ::rtl::OUString::createFromAscii( "" ), ::rtl::OUString::createFromAscii( "" ) ); @@ -229,7 +218,7 @@ ScriptStorageManager::createScriptStorageWithURI( throw ( RuntimeException ) { OSL_TRACE( "** ==> ScriptStorageManager in createScriptingStorageWithURI\n" ); - validateXRef( xSFA, "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" ); + ENSURE_OR_THROW( xSFA.is(), "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" ); // related to issue 11866 // warning dialog gets launched when adding binding to script in doc @@ -313,7 +302,7 @@ throw( RuntimeException ) OUSTR( "ScriptStorageManager::getScriptStorage: invalid storage ID" ), Reference< XInterface >() ); } - validateXRef( itr->second, + ENSURE_OR_THROW( itr->second.is(), "ScriptStorageManager::getScriptStorage: Cannot get ScriptStorage from ScriptStorageHash" ); return itr->second; } |