LCOV - code coverage report
Current view: top level - scripting/source/basprov - basprov.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 106 222 47.7 %
Date: 2012-08-25 Functions: 9 17 52.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 129 476 27.1 %

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

Generated by: LCOV version 1.10