Kaydet (Commit) 2892f44e authored tarafından Kurt Zenker's avatar Kurt Zenker

INTEGRATION: CWS odbmacros2 (1.19.54); FILE MERGED

2007/12/22 13:37:26 fs 1.19.54.4: changed error message when no script found
2007/12/19 13:24:57 fs 1.19.54.3: #i49133# when invoking a script, temporarily set the XScriptInvocationContext as ThisComponent at the script
2007/12/17 12:43:37 fs 1.19.54.2: #i49133#
allow to create script providers for documents which do not support
embedded scripts themselves (i.e. don't have the XEmbeddedScripts
interface), but are able to point to such a do cument (via
XScriptInvocationContext) whose scripts they can execute
2007/12/10 11:08:55 fs 1.19.54.1: #i49133# don't use an SfxObjectShell, there's UNO equivalents nowadays, which also includes non-SFX documents then
üst 1a49a9f8
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
* *
* $RCSfile: basprov.cxx,v $ * $RCSfile: basprov.cxx,v $
* *
* $Revision: 1.19 $ * $Revision: 1.20 $
* *
* last change: $Author: obo $ $Date: 2006-09-16 12:26:15 $ * last change: $Author: kz $ $Date: 2008-03-06 16:17:12 $
* *
* The Contents of this file are made available subject to * The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
...@@ -56,6 +56,9 @@ ...@@ -56,6 +56,9 @@
#ifndef _COM_SUN_STAR_SCRIPT_PROVIDER_SCRIPTFRAMEWORKERRORTYPE_HPP_ #ifndef _COM_SUN_STAR_SCRIPT_PROVIDER_SCRIPTFRAMEWORKERRORTYPE_HPP_
#include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp> #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
#endif #endif
#ifndef _COM_SUN_STAR_DOCUMENT_XEMBEDDEDSCRIPTS_HPP_
#include <com/sun/star/document/XEmbeddedScripts.hpp>
#endif
#ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
#include <cppuhelper/implementationentry.hxx> #include <cppuhelper/implementationentry.hxx>
...@@ -82,6 +85,9 @@ ...@@ -82,6 +85,9 @@
#ifndef _BASMGR_HXX #ifndef _BASMGR_HXX
#include <basic/basmgr.hxx> #include <basic/basmgr.hxx>
#endif #endif
#ifndef BASICMANAGERREPOSITORY_HXX
#include <basic/basicmanagerrepository.hxx>
#endif
#ifndef _SB_SBSTAR_HXX #ifndef _SB_SBSTAR_HXX
#include <basic/sbstar.hxx> #include <basic/sbstar.hxx>
#endif #endif
...@@ -112,6 +118,7 @@ using namespace ::com::sun::star; ...@@ -112,6 +118,7 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::lang; using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::script; using namespace ::com::sun::star::script;
using namespace ::com::sun::star::document;
using namespace ::sf_misc; using namespace ::sf_misc;
//......................................................................... //.........................................................................
...@@ -305,38 +312,66 @@ namespace basprov ...@@ -305,38 +312,66 @@ namespace basprov
::vos::OGuard aGuard( Application::GetSolarMutex() ); ::vos::OGuard aGuard( Application::GetSolarMutex() );
if ( aArguments.getLength() == 1 && aArguments[0].getValueType() == ::getCppuType( (const ::rtl::OUString* ) NULL )) if ( aArguments.getLength() != 1 )
{ {
// Provider has been created with application context for user throw IllegalArgumentException(
// or share ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: incorrect argument count." ) ),
aArguments[0] >>= m_sScriptingContext; *this,
1
);
}
::rtl::OUString sUser = OUSTR("user"); Reference< frame::XModel > xModel;
::rtl::OUString sShare = OUSTR("share");
::rtl::OUString sDoc = OUSTR("vnd.sun.star.tdoc");
m_xInvocationContext.set( aArguments[0], UNO_QUERY );;
if ( m_xInvocationContext.is() )
{
xModel.set( m_xInvocationContext->getScriptContainer(), UNO_QUERY );
if ( !xModel.is() )
{
throw IllegalArgumentException(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: unable to determine the document model from the script invocation context." ) ),
*this,
1
);
}
}
else
{
if ( !( aArguments[0] >>= m_sScriptingContext ) )
{
throw IllegalArgumentException(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: incorrect argument type " ) ).concat( aArguments[0].getValueTypeName() ),
*this,
1
);
}
::rtl::OUString sDoc = OUSTR("vnd.sun.star.tdoc");
if ( m_sScriptingContext.indexOf( sDoc ) == 0 ) if ( m_sScriptingContext.indexOf( sDoc ) == 0 )
{ {
Reference< frame::XModel > xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext ); xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext );
// TODO: use ScriptingContantsPool for SCRIPTING_DOC_REF // TODO: use ScriptingContantsPool for SCRIPTING_DOC_REF
}
}
if ( xModel.is() ) if ( xModel.is() )
{ {
for ( SfxObjectShell* pObjShell = SfxObjectShell::GetFirst(); pObjShell; pObjShell = SfxObjectShell::GetNext( *pObjShell ) ) Reference< XEmbeddedScripts > xDocumentScripts( xModel, UNO_QUERY );
{ if ( xDocumentScripts.is() )
if ( xModel == pObjShell->GetModel() ) {
{ m_pDocBasicManager = ::basic::BasicManagerRepository::getDocumentBasicManager( xModel );
m_pDocBasicManager = pObjShell->GetBasicManager(); m_xLibContainerDoc.set( xDocumentScripts->getBasicLibraries(), UNO_QUERY );
m_xLibContainerDoc = Reference< script::XLibraryContainer >( pObjShell->GetBasicContainer(), UNO_QUERY ); OSL_ENSURE( m_pDocBasicManager && m_xLibContainerDoc.is(),
"BasicProviderImpl::initialize: invalid BasicManager, or invalid script container!" );
break; }
} m_bIsAppScriptCtx = false;
} }
} else
m_bIsAppScriptCtx = false; {
} // Provider has been created with application context for user
// or share
else if ( !m_sScriptingContext.equals( sUser ) ) if ( !m_sScriptingContext.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "user" ) ) )
{ {
m_bIsUserCtx = false; m_bIsUserCtx = false;
} }
...@@ -349,14 +384,6 @@ namespace basprov ...@@ -349,14 +384,6 @@ namespace basprov
*/ */
} }
} }
else
{
throw RuntimeException(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: incorrect argument type " ) ).concat( aArguments[0].getValueType().getTypeName() ),
Reference< XInterface >() );
}
// TODO // TODO
if ( !m_pAppBasicManager ) if ( !m_pAppBasicManager )
...@@ -387,7 +414,7 @@ namespace basprov ...@@ -387,7 +414,7 @@ namespace basprov
if ( !xFac.is() ) if ( !xFac.is() )
{ {
throw provider::ScriptFrameworkErrorException( throw provider::ScriptFrameworkErrorException(
OUSTR( "Failed to instantiate UriReferenceFactory" ), Reference< XInterface >(), OUSTR( "Failed to instantiate UriReferenceFactory" ), Reference< XInterface >(),
scriptURI, OUSTR("Basic"), scriptURI, OUSTR("Basic"),
provider::ScriptFrameworkErrorType::UNKNOWN ); provider::ScriptFrameworkErrorType::UNKNOWN );
} }
...@@ -452,7 +479,12 @@ namespace basprov ...@@ -452,7 +479,12 @@ namespace basprov
{ {
SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Find( aMethod, SbxCLASS_METHOD ) ); SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Find( aMethod, SbxCLASS_METHOD ) );
if ( pMethod ) if ( pMethod )
xScript = static_cast< provider::XScript* >( new BasicScriptImpl( aDescription, pMethod ) ); {
if ( m_pDocBasicManager == pBasicMgr )
xScript = new BasicScriptImpl( aDescription, pMethod, *m_pDocBasicManager, m_xInvocationContext );
else
xScript = new BasicScriptImpl( aDescription, pMethod );
}
} }
} }
} }
...@@ -461,8 +493,15 @@ namespace basprov ...@@ -461,8 +493,15 @@ namespace basprov
if ( !xScript.is() ) if ( !xScript.is() )
{ {
::rtl::OUStringBuffer aMessage;
aMessage.appendAscii( "The following Basic script could not be found:\n" );
aMessage.appendAscii( "library: '" ).append( aLibrary ).appendAscii( "'\n" );
aMessage.appendAscii( "module: '" ).append( aModule ).appendAscii( "'\n" );
aMessage.appendAscii( "method: '" ).append( aMethod ).appendAscii( "'\n" );
aMessage.appendAscii( "location: '" ).append( aLocation ).appendAscii( "'\n" );
throw provider::ScriptFrameworkErrorException( throw provider::ScriptFrameworkErrorException(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::getScript: no script!" ) ), Reference< XInterface >(), aMessage.makeStringAndClear(),
Reference< XInterface >(),
scriptURI, OUSTR("Basic"), scriptURI, OUSTR("Basic"),
provider::ScriptFrameworkErrorType::UNKNOWN ); provider::ScriptFrameworkErrorType::UNKNOWN );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment