1*2c696243SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2c696243SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2c696243SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2c696243SAndrew Rist * distributed with this work for additional information 6*2c696243SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2c696243SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2c696243SAndrew Rist * "License"); you may not use this file except in compliance 9*2c696243SAndrew Rist * with the License. You may obtain a copy of the License at 10*2c696243SAndrew Rist * 11*2c696243SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2c696243SAndrew Rist * 13*2c696243SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2c696243SAndrew Rist * software distributed under the License is distributed on an 15*2c696243SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2c696243SAndrew Rist * KIND, either express or implied. See the License for the 17*2c696243SAndrew Rist * specific language governing permissions and limitations 18*2c696243SAndrew Rist * under the License. 19*2c696243SAndrew Rist * 20*2c696243SAndrew Rist *************************************************************/ 21*2c696243SAndrew Rist 22*2c696243SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_scripting.hxx" 26cdf0e10cSrcweir #include "basprov.hxx" 27cdf0e10cSrcweir #include "basscript.hxx" 28cdf0e10cSrcweir #include "baslibnode.hxx" 29cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 30cdf0e10cSrcweir #include <com/sun/star/script/browse/BrowseNodeTypes.hpp> 31cdf0e10cSrcweir #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp> 32cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ 35cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir #include <rtl/uri.hxx> 38cdf0e10cSrcweir #include <osl/process.h> 39cdf0e10cSrcweir #include <osl/file.hxx> 40cdf0e10cSrcweir #include <vos/mutex.hxx> 41cdf0e10cSrcweir #include <vcl/svapp.hxx> 42cdf0e10cSrcweir #include <basic/sbx.hxx> 43cdf0e10cSrcweir #include <basic/basmgr.hxx> 44cdf0e10cSrcweir #include <basic/basicmanagerrepository.hxx> 45cdf0e10cSrcweir #include <basic/sbstar.hxx> 46cdf0e10cSrcweir #include <basic/sbmod.hxx> 47cdf0e10cSrcweir #include <basic/sbmeth.hxx> 48cdf0e10cSrcweir #include <sfx2/app.hxx> 49cdf0e10cSrcweir #include <sfx2/objsh.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp> 52cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer2.hpp> 53cdf0e10cSrcweir #include <com/sun/star/uri/XUriReference.hpp> 54cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp> 55cdf0e10cSrcweir #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp> 56cdf0e10cSrcweir 57cdf0e10cSrcweir #include <util/util.hxx> 58cdf0e10cSrcweir #include <util/MiscUtils.hxx> 59cdf0e10cSrcweir 60cdf0e10cSrcweir 61cdf0e10cSrcweir using namespace ::com::sun::star; 62cdf0e10cSrcweir using namespace ::com::sun::star::lang; 63cdf0e10cSrcweir using namespace ::com::sun::star::uno; 64cdf0e10cSrcweir using namespace ::com::sun::star::script; 65cdf0e10cSrcweir using namespace ::com::sun::star::document; 66cdf0e10cSrcweir using namespace ::sf_misc; 67cdf0e10cSrcweir 68cdf0e10cSrcweir //......................................................................... 69cdf0e10cSrcweir namespace basprov 70cdf0e10cSrcweir { 71cdf0e10cSrcweir //......................................................................... 72cdf0e10cSrcweir 73cdf0e10cSrcweir // ============================================================================= 74cdf0e10cSrcweir // component operations 75cdf0e10cSrcweir // ============================================================================= 76cdf0e10cSrcweir getImplementationName_BasicProviderImpl()77cdf0e10cSrcweir static ::rtl::OUString getImplementationName_BasicProviderImpl() 78cdf0e10cSrcweir { 79cdf0e10cSrcweir static ::rtl::OUString* pImplName = 0; 80cdf0e10cSrcweir if ( !pImplName ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 83cdf0e10cSrcweir if ( !pImplName ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.scripting.ScriptProviderForBasic" ) ); 86cdf0e10cSrcweir pImplName = &aImplName; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir } 89cdf0e10cSrcweir return *pImplName; 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir // ----------------------------------------------------------------------------- 93cdf0e10cSrcweir getSupportedServiceNames_BasicProviderImpl()94cdf0e10cSrcweir static Sequence< ::rtl::OUString > getSupportedServiceNames_BasicProviderImpl() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir static Sequence< ::rtl::OUString >* pNames = 0; 97cdf0e10cSrcweir if ( !pNames ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 100cdf0e10cSrcweir if ( !pNames ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir static Sequence< ::rtl::OUString > aNames(4); 103cdf0e10cSrcweir aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.provider.ScriptProviderForBasic" ) ); 104cdf0e10cSrcweir aNames.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.provider.LanguageScriptProvider" ) ); 105cdf0e10cSrcweir aNames.getArray()[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.provider.ScriptProvider" ) ); 106cdf0e10cSrcweir aNames.getArray()[3] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.browse.BrowseNode" ) ); 107cdf0e10cSrcweir pNames = &aNames; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir return *pNames; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // ============================================================================= 114cdf0e10cSrcweir // BasicProviderImpl 115cdf0e10cSrcweir // ============================================================================= 116cdf0e10cSrcweir BasicProviderImpl(const Reference<XComponentContext> & xContext)117cdf0e10cSrcweir BasicProviderImpl::BasicProviderImpl( const Reference< XComponentContext >& xContext ) 118cdf0e10cSrcweir :m_pAppBasicManager( 0 ) 119cdf0e10cSrcweir ,m_pDocBasicManager( 0 ) 120cdf0e10cSrcweir ,m_xLibContainerApp( 0 ) 121cdf0e10cSrcweir ,m_xLibContainerDoc( 0 ) 122cdf0e10cSrcweir ,m_xContext( xContext ) 123cdf0e10cSrcweir ,m_bIsAppScriptCtx( true ) 124cdf0e10cSrcweir ,m_bIsUserCtx(true) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir // ----------------------------------------------------------------------------- 129cdf0e10cSrcweir ~BasicProviderImpl()130cdf0e10cSrcweir BasicProviderImpl::~BasicProviderImpl() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir // ----------------------------------------------------------------------------- 135cdf0e10cSrcweir isLibraryShared(const Reference<script::XLibraryContainer> & rxLibContainer,const::rtl::OUString & rLibName)136cdf0e10cSrcweir bool BasicProviderImpl::isLibraryShared( const Reference< script::XLibraryContainer >& rxLibContainer, const ::rtl::OUString& rLibName ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir bool bIsShared = false; 139cdf0e10cSrcweir 140cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xLibContainer( rxLibContainer, UNO_QUERY ); 141cdf0e10cSrcweir if ( xLibContainer.is() && xLibContainer->hasByName( rLibName ) && xLibContainer->isLibraryLink( rLibName ) ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir ::rtl::OUString aFileURL; 144cdf0e10cSrcweir if ( m_xContext.is() ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir Reference< uri::XUriReferenceFactory > xUriFac; 147cdf0e10cSrcweir Reference< lang::XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() ); 148cdf0e10cSrcweir if ( xSMgr.is() ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir xUriFac.set( xSMgr->createInstanceWithContext( ::rtl::OUString::createFromAscii( 151cdf0e10cSrcweir "com.sun.star.uri.UriReferenceFactory" ), m_xContext ), UNO_QUERY ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir if ( xUriFac.is() ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir ::rtl::OUString aLinkURL( xLibContainer->getLibraryLinkURL( rLibName ) ); 157cdf0e10cSrcweir Reference< uri::XUriReference > xUriRef( xUriFac->parse( aLinkURL ), UNO_QUERY ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir if ( xUriRef.is() ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir ::rtl::OUString aScheme = xUriRef->getScheme(); 162cdf0e10cSrcweir if ( aScheme.equalsIgnoreAsciiCaseAscii( "file" ) ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir aFileURL = aLinkURL; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir else if ( aScheme.equalsIgnoreAsciiCaseAscii( "vnd.sun.star.pkg" ) ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir ::rtl::OUString aAuthority = xUriRef->getAuthority(); 169cdf0e10cSrcweir if ( aAuthority.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.expand:" ) ) ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir ::rtl::OUString aDecodedURL( aAuthority.copy( sizeof ( "vnd.sun.star.expand:" ) - 1 ) ); 172cdf0e10cSrcweir aDecodedURL = ::rtl::Uri::decode( aDecodedURL, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); 173cdf0e10cSrcweir Reference<util::XMacroExpander> xMacroExpander( 174cdf0e10cSrcweir m_xContext->getValueByName( 175cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ), 176cdf0e10cSrcweir UNO_QUERY ); 177cdf0e10cSrcweir if ( xMacroExpander.is() ) 178cdf0e10cSrcweir aFileURL = xMacroExpander->expandMacros( aDecodedURL ); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir } 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir if ( aFileURL.getLength() ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir osl::DirectoryItem aFileItem; 188cdf0e10cSrcweir osl::FileStatus aFileStatus( FileStatusMask_FileURL ); 189cdf0e10cSrcweir OSL_VERIFY( osl::DirectoryItem::get( aFileURL, aFileItem ) == osl::FileBase::E_None ); 190cdf0e10cSrcweir OSL_VERIFY( aFileItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None ); 191cdf0e10cSrcweir ::rtl::OUString aCanonicalFileURL( aFileStatus.getFileURL() ); 192cdf0e10cSrcweir 193cdf0e10cSrcweir ::rtl::OUString aSearchURL1( RTL_CONSTASCII_USTRINGPARAM( "share/basic" ) ); 194cdf0e10cSrcweir ::rtl::OUString aSearchURL2( RTL_CONSTASCII_USTRINGPARAM( "share/uno_packages" ) ); 195cdf0e10cSrcweir if( aCanonicalFileURL.indexOf( aSearchURL1 ) != -1 || aCanonicalFileURL.indexOf( aSearchURL2 ) != -1 ) 196cdf0e10cSrcweir bIsShared = true; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir return bIsShared; 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir // ----------------------------------------------------------------------------- 204cdf0e10cSrcweir // XServiceInfo 205cdf0e10cSrcweir // ----------------------------------------------------------------------------- 206cdf0e10cSrcweir getImplementationName()207cdf0e10cSrcweir ::rtl::OUString BasicProviderImpl::getImplementationName( ) throw (RuntimeException) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir return getImplementationName_BasicProviderImpl(); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir // ----------------------------------------------------------------------------- 213cdf0e10cSrcweir supportsService(const::rtl::OUString & rServiceName)214cdf0e10cSrcweir sal_Bool BasicProviderImpl::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); 217cdf0e10cSrcweir const ::rtl::OUString* pNames = aNames.getConstArray(); 218cdf0e10cSrcweir const ::rtl::OUString* pEnd = pNames + aNames.getLength(); 219cdf0e10cSrcweir for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) 220cdf0e10cSrcweir ; 221cdf0e10cSrcweir 222cdf0e10cSrcweir return pNames != pEnd; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir // ----------------------------------------------------------------------------- 226cdf0e10cSrcweir getSupportedServiceNames()227cdf0e10cSrcweir Sequence< ::rtl::OUString > BasicProviderImpl::getSupportedServiceNames( ) throw (RuntimeException) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir return getSupportedServiceNames_BasicProviderImpl(); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir // ----------------------------------------------------------------------------- 233cdf0e10cSrcweir // XInitialization 234cdf0e10cSrcweir // ----------------------------------------------------------------------------- 235cdf0e10cSrcweir initialize(const Sequence<Any> & aArguments)236cdf0e10cSrcweir void BasicProviderImpl::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir // TODO 239cdf0e10cSrcweir 240cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 241cdf0e10cSrcweir 242cdf0e10cSrcweir if ( aArguments.getLength() != 1 ) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir throw IllegalArgumentException( 245cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: incorrect argument count." ) ), 246cdf0e10cSrcweir *this, 247cdf0e10cSrcweir 1 248cdf0e10cSrcweir ); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir Reference< frame::XModel > xModel; 252cdf0e10cSrcweir 253cdf0e10cSrcweir m_xInvocationContext.set( aArguments[0], UNO_QUERY );; 254cdf0e10cSrcweir if ( m_xInvocationContext.is() ) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir xModel.set( m_xInvocationContext->getScriptContainer(), UNO_QUERY ); 257cdf0e10cSrcweir if ( !xModel.is() ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir throw IllegalArgumentException( 260cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: unable to determine the document model from the script invocation context." ) ), 261cdf0e10cSrcweir *this, 262cdf0e10cSrcweir 1 263cdf0e10cSrcweir ); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir } 266cdf0e10cSrcweir else 267cdf0e10cSrcweir { 268cdf0e10cSrcweir if ( !( aArguments[0] >>= m_sScriptingContext ) ) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir throw IllegalArgumentException( 271cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: incorrect argument type " ) ).concat( aArguments[0].getValueTypeName() ), 272cdf0e10cSrcweir *this, 273cdf0e10cSrcweir 1 274cdf0e10cSrcweir ); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir ::rtl::OUString sDoc = OUSTR("vnd.sun.star.tdoc"); 278cdf0e10cSrcweir if ( m_sScriptingContext.indexOf( sDoc ) == 0 ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir xModel = MiscUtils::tDocUrlToModel( m_sScriptingContext ); 281cdf0e10cSrcweir // TODO: use ScriptingContantsPool for SCRIPTING_DOC_REF 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir if ( xModel.is() ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir Reference< XEmbeddedScripts > xDocumentScripts( xModel, UNO_QUERY ); 288cdf0e10cSrcweir if ( xDocumentScripts.is() ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir m_pDocBasicManager = ::basic::BasicManagerRepository::getDocumentBasicManager( xModel ); 291cdf0e10cSrcweir m_xLibContainerDoc.set( xDocumentScripts->getBasicLibraries(), UNO_QUERY ); 292cdf0e10cSrcweir OSL_ENSURE( m_pDocBasicManager && m_xLibContainerDoc.is(), 293cdf0e10cSrcweir "BasicProviderImpl::initialize: invalid BasicManager, or invalid script container!" ); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir m_bIsAppScriptCtx = false; 296cdf0e10cSrcweir } 297cdf0e10cSrcweir else 298cdf0e10cSrcweir { 299cdf0e10cSrcweir // Provider has been created with application context for user 300cdf0e10cSrcweir // or share 301cdf0e10cSrcweir if ( !m_sScriptingContext.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "user" ) ) ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir m_bIsUserCtx = false; 304cdf0e10cSrcweir } 305cdf0e10cSrcweir else 306cdf0e10cSrcweir { 307cdf0e10cSrcweir /* 308cdf0e10cSrcweir throw RuntimeException( 309cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: no scripting context!" ) ), 310cdf0e10cSrcweir Reference< XInterface >() ); 311cdf0e10cSrcweir */ 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir // TODO 316cdf0e10cSrcweir if ( !m_pAppBasicManager ) 317cdf0e10cSrcweir m_pAppBasicManager = SFX_APP()->GetBasicManager(); 318cdf0e10cSrcweir 319cdf0e10cSrcweir if ( !m_xLibContainerApp.is() ) 320cdf0e10cSrcweir m_xLibContainerApp = Reference< script::XLibraryContainer >( SFX_APP()->GetBasicContainer(), UNO_QUERY ); 321cdf0e10cSrcweir } 322cdf0e10cSrcweir 323cdf0e10cSrcweir // ----------------------------------------------------------------------------- 324cdf0e10cSrcweir 325cdf0e10cSrcweir // XScriptProvider 326cdf0e10cSrcweir // ----------------------------------------------------------------------------- 327cdf0e10cSrcweir getScript(const::rtl::OUString & scriptURI)328cdf0e10cSrcweir Reference < provider::XScript > BasicProviderImpl::getScript( const ::rtl::OUString& scriptURI ) 329cdf0e10cSrcweir throw ( provider::ScriptFrameworkErrorException, RuntimeException) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir // TODO 332cdf0e10cSrcweir 333cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 334cdf0e10cSrcweir 335cdf0e10cSrcweir Reference< provider::XScript > xScript; 336cdf0e10cSrcweir Reference< lang::XMultiComponentFactory > xMcFac ( m_xContext->getServiceManager() ); 337cdf0e10cSrcweir Reference< uri::XUriReferenceFactory > xFac ( 338cdf0e10cSrcweir xMcFac->createInstanceWithContext( rtl::OUString::createFromAscii( 339cdf0e10cSrcweir "com.sun.star.uri.UriReferenceFactory"), m_xContext ) , UNO_QUERY ); 340cdf0e10cSrcweir 341cdf0e10cSrcweir if ( !xFac.is() ) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir throw provider::ScriptFrameworkErrorException( 344cdf0e10cSrcweir OUSTR( "Failed to instantiate UriReferenceFactory" ), Reference< XInterface >(), 345cdf0e10cSrcweir scriptURI, OUSTR("Basic"), 346cdf0e10cSrcweir provider::ScriptFrameworkErrorType::UNKNOWN ); 347cdf0e10cSrcweir } 348cdf0e10cSrcweir 349cdf0e10cSrcweir Reference< uri::XUriReference > uriRef( 350cdf0e10cSrcweir xFac->parse( scriptURI ), UNO_QUERY ); 351cdf0e10cSrcweir 352cdf0e10cSrcweir Reference < uri::XVndSunStarScriptUrl > sfUri( uriRef, UNO_QUERY ); 353cdf0e10cSrcweir 354cdf0e10cSrcweir if ( !uriRef.is() || !sfUri.is() ) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir ::rtl::OUString errorMsg = ::rtl::OUString::createFromAscii( "BasicProviderImpl::getScript: failed to parse URI: " ); 357cdf0e10cSrcweir errorMsg = errorMsg.concat( scriptURI ); 358cdf0e10cSrcweir throw provider::ScriptFrameworkErrorException( 359cdf0e10cSrcweir errorMsg, Reference< XInterface >(), 360cdf0e10cSrcweir scriptURI, OUSTR("Basic"), 361cdf0e10cSrcweir provider::ScriptFrameworkErrorType::MALFORMED_URL ); 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir 365cdf0e10cSrcweir ::rtl::OUString aDescription = sfUri->getName(); 366cdf0e10cSrcweir ::rtl::OUString aLocation = sfUri->getParameter( 367cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "location" ) ); 368cdf0e10cSrcweir 369cdf0e10cSrcweir sal_Int32 nIndex = 0; 370cdf0e10cSrcweir ::rtl::OUString aLibrary = aDescription.getToken( 0, (sal_Unicode)'.', nIndex ); 371cdf0e10cSrcweir ::rtl::OUString aModule; 372cdf0e10cSrcweir if ( nIndex != -1 ) 373cdf0e10cSrcweir aModule = aDescription.getToken( 0, (sal_Unicode)'.', nIndex ); 374cdf0e10cSrcweir ::rtl::OUString aMethod; 375cdf0e10cSrcweir if ( nIndex != -1 ) 376cdf0e10cSrcweir aMethod = aDescription.getToken( 0, (sal_Unicode)'.', nIndex ); 377cdf0e10cSrcweir 378cdf0e10cSrcweir if ( aLibrary.getLength() != 0 && aModule.getLength() != 0 && aMethod.getLength() != 0 && aLocation.getLength() != 0 ) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir BasicManager* pBasicMgr = NULL; 381cdf0e10cSrcweir if ( aLocation.equals( ::rtl::OUString::createFromAscii("document") ) ) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir pBasicMgr = m_pDocBasicManager; 384cdf0e10cSrcweir } 385cdf0e10cSrcweir else if ( aLocation.equals( ::rtl::OUString::createFromAscii("application") ) ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir pBasicMgr = m_pAppBasicManager; 388cdf0e10cSrcweir } 389cdf0e10cSrcweir 390cdf0e10cSrcweir if ( pBasicMgr ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir StarBASIC* pBasic = pBasicMgr->GetLib( aLibrary ); 393cdf0e10cSrcweir if ( !pBasic ) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir sal_uInt16 nId = pBasicMgr->GetLibId( aLibrary ); 396cdf0e10cSrcweir if ( nId != LIB_NOTFOUND ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir pBasicMgr->LoadLib( nId ); 399cdf0e10cSrcweir pBasic = pBasicMgr->GetLib( aLibrary ); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir } 402cdf0e10cSrcweir if ( pBasic ) 403cdf0e10cSrcweir { 404cdf0e10cSrcweir SbModule* pModule = pBasic->FindModule( aModule ); 405cdf0e10cSrcweir if ( pModule ) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir SbxArray* pMethods = pModule->GetMethods(); 408cdf0e10cSrcweir if ( pMethods ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Find( aMethod, SbxCLASS_METHOD ) ); 411cdf0e10cSrcweir if ( pMethod && !pMethod->IsHidden() ) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir if ( m_pDocBasicManager == pBasicMgr ) 414cdf0e10cSrcweir xScript = new BasicScriptImpl( aDescription, pMethod, *m_pDocBasicManager, m_xInvocationContext ); 415cdf0e10cSrcweir else 416cdf0e10cSrcweir xScript = new BasicScriptImpl( aDescription, pMethod ); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir } 419cdf0e10cSrcweir } 420cdf0e10cSrcweir } 421cdf0e10cSrcweir } 422cdf0e10cSrcweir } 423cdf0e10cSrcweir 424cdf0e10cSrcweir if ( !xScript.is() ) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir ::rtl::OUStringBuffer aMessage; 427cdf0e10cSrcweir aMessage.appendAscii( "The following Basic script could not be found:\n" ); 428cdf0e10cSrcweir aMessage.appendAscii( "library: '" ).append( aLibrary ).appendAscii( "'\n" ); 429cdf0e10cSrcweir aMessage.appendAscii( "module: '" ).append( aModule ).appendAscii( "'\n" ); 430cdf0e10cSrcweir aMessage.appendAscii( "method: '" ).append( aMethod ).appendAscii( "'\n" ); 431cdf0e10cSrcweir aMessage.appendAscii( "location: '" ).append( aLocation ).appendAscii( "'\n" ); 432cdf0e10cSrcweir throw provider::ScriptFrameworkErrorException( 433cdf0e10cSrcweir aMessage.makeStringAndClear(), 434cdf0e10cSrcweir Reference< XInterface >(), 435cdf0e10cSrcweir scriptURI, OUSTR("Basic"), 436cdf0e10cSrcweir provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT ); 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir return xScript; 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir // ----------------------------------------------------------------------------- 443cdf0e10cSrcweir // XBrowseNode 444cdf0e10cSrcweir // ----------------------------------------------------------------------------- 445cdf0e10cSrcweir getName()446cdf0e10cSrcweir ::rtl::OUString BasicProviderImpl::getName( ) throw (RuntimeException) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir // TODO 449cdf0e10cSrcweir 450cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 451cdf0e10cSrcweir 452cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "Basic" ); 453cdf0e10cSrcweir } 454cdf0e10cSrcweir 455cdf0e10cSrcweir // ----------------------------------------------------------------------------- 456cdf0e10cSrcweir getChildNodes()457cdf0e10cSrcweir Sequence< Reference< browse::XBrowseNode > > BasicProviderImpl::getChildNodes( ) throw (RuntimeException) 458cdf0e10cSrcweir { 459cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 460cdf0e10cSrcweir 461cdf0e10cSrcweir Reference< script::XLibraryContainer > xLibContainer; 462cdf0e10cSrcweir BasicManager* pBasicManager = NULL; 463cdf0e10cSrcweir 464cdf0e10cSrcweir if ( m_bIsAppScriptCtx ) 465cdf0e10cSrcweir { 466cdf0e10cSrcweir xLibContainer = m_xLibContainerApp; 467cdf0e10cSrcweir pBasicManager = m_pAppBasicManager; 468cdf0e10cSrcweir } 469cdf0e10cSrcweir else 470cdf0e10cSrcweir { 471cdf0e10cSrcweir xLibContainer = m_xLibContainerDoc; 472cdf0e10cSrcweir pBasicManager = m_pDocBasicManager; 473cdf0e10cSrcweir } 474cdf0e10cSrcweir 475cdf0e10cSrcweir Sequence< Reference< browse::XBrowseNode > > aChildNodes; 476cdf0e10cSrcweir 477cdf0e10cSrcweir if ( pBasicManager && xLibContainer.is() ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir Sequence< ::rtl::OUString > aLibNames = xLibContainer->getElementNames(); 480cdf0e10cSrcweir sal_Int32 nLibCount = aLibNames.getLength(); 481cdf0e10cSrcweir const ::rtl::OUString* pLibNames = aLibNames.getConstArray(); 482cdf0e10cSrcweir aChildNodes.realloc( nLibCount ); 483cdf0e10cSrcweir Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray(); 484cdf0e10cSrcweir sal_Int32 childsFound = 0; 485cdf0e10cSrcweir 486cdf0e10cSrcweir for ( sal_Int32 i = 0 ; i < nLibCount ; ++i ) 487cdf0e10cSrcweir { 488cdf0e10cSrcweir bool bCreate = false; 489cdf0e10cSrcweir if ( m_bIsAppScriptCtx ) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir bool bShared = isLibraryShared( xLibContainer, pLibNames[i] ); 492cdf0e10cSrcweir if ( ( m_bIsUserCtx && !bShared ) || ( !m_bIsUserCtx && bShared ) ) 493cdf0e10cSrcweir bCreate = true; 494cdf0e10cSrcweir } 495cdf0e10cSrcweir else 496cdf0e10cSrcweir { 497cdf0e10cSrcweir bCreate = true; 498cdf0e10cSrcweir } 499cdf0e10cSrcweir if ( bCreate ) 500cdf0e10cSrcweir { 501cdf0e10cSrcweir pChildNodes[childsFound++] = static_cast< browse::XBrowseNode* >( new BasicLibraryNodeImpl( 502cdf0e10cSrcweir m_xContext, m_sScriptingContext, pBasicManager, xLibContainer, pLibNames[i], m_bIsAppScriptCtx ) ); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir if ( childsFound != nLibCount ) 507cdf0e10cSrcweir aChildNodes.realloc( childsFound ); 508cdf0e10cSrcweir } 509cdf0e10cSrcweir 510cdf0e10cSrcweir return aChildNodes; 511cdf0e10cSrcweir } 512cdf0e10cSrcweir 513cdf0e10cSrcweir // ----------------------------------------------------------------------------- 514cdf0e10cSrcweir hasChildNodes()515cdf0e10cSrcweir sal_Bool BasicProviderImpl::hasChildNodes( ) throw (RuntimeException) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 518cdf0e10cSrcweir 519cdf0e10cSrcweir sal_Bool bReturn = sal_False; 520cdf0e10cSrcweir Reference< script::XLibraryContainer > xLibContainer; 521cdf0e10cSrcweir if ( m_bIsAppScriptCtx ) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir xLibContainer = m_xLibContainerApp; 524cdf0e10cSrcweir } 525cdf0e10cSrcweir else 526cdf0e10cSrcweir { 527cdf0e10cSrcweir xLibContainer = m_xLibContainerDoc; 528cdf0e10cSrcweir } 529cdf0e10cSrcweir if ( xLibContainer.is() ) 530cdf0e10cSrcweir bReturn = xLibContainer->hasElements(); 531cdf0e10cSrcweir 532cdf0e10cSrcweir return bReturn; 533cdf0e10cSrcweir } 534cdf0e10cSrcweir 535cdf0e10cSrcweir // ----------------------------------------------------------------------------- 536cdf0e10cSrcweir getType()537cdf0e10cSrcweir sal_Int16 BasicProviderImpl::getType( ) throw (RuntimeException) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 540cdf0e10cSrcweir 541cdf0e10cSrcweir return browse::BrowseNodeTypes::CONTAINER; 542cdf0e10cSrcweir } 543cdf0e10cSrcweir 544cdf0e10cSrcweir // ============================================================================= 545cdf0e10cSrcweir // component operations 546cdf0e10cSrcweir // ============================================================================= 547cdf0e10cSrcweir create_BasicProviderImpl(Reference<XComponentContext> const & xContext)548cdf0e10cSrcweir static Reference< XInterface > SAL_CALL create_BasicProviderImpl( 549cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 550cdf0e10cSrcweir SAL_THROW( () ) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir return static_cast< lang::XTypeProvider * >( new BasicProviderImpl( xContext ) ); 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir // ----------------------------------------------------------------------------- 556cdf0e10cSrcweir 557cdf0e10cSrcweir static struct ::cppu::ImplementationEntry s_component_entries [] = 558cdf0e10cSrcweir { 559cdf0e10cSrcweir { 560cdf0e10cSrcweir create_BasicProviderImpl, getImplementationName_BasicProviderImpl, 561cdf0e10cSrcweir getSupportedServiceNames_BasicProviderImpl, ::cppu::createSingleComponentFactory, 562cdf0e10cSrcweir 0, 0 563cdf0e10cSrcweir }, 564cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 } 565cdf0e10cSrcweir }; 566cdf0e10cSrcweir 567cdf0e10cSrcweir // ----------------------------------------------------------------------------- 568cdf0e10cSrcweir 569cdf0e10cSrcweir //......................................................................... 570cdf0e10cSrcweir } // namespace basprov 571cdf0e10cSrcweir //......................................................................... 572cdf0e10cSrcweir 573cdf0e10cSrcweir 574cdf0e10cSrcweir // ============================================================================= 575cdf0e10cSrcweir // component exports 576cdf0e10cSrcweir // ============================================================================= 577cdf0e10cSrcweir 578cdf0e10cSrcweir extern "C" 579cdf0e10cSrcweir { component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment ** ppEnv)580cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( 581cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir (void)ppEnv; 584cdf0e10cSrcweir 585cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir component_getFactory(const sal_Char * pImplName,lang::XMultiServiceFactory * pServiceManager,registry::XRegistryKey * pRegistryKey)588cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( 589cdf0e10cSrcweir const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager, 590cdf0e10cSrcweir registry::XRegistryKey * pRegistryKey ) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir return ::cppu::component_getFactoryHelper( 593cdf0e10cSrcweir pImplName, pServiceManager, pRegistryKey, ::basprov::s_component_entries ); 594cdf0e10cSrcweir } 595cdf0e10cSrcweir } 596