LCOV - code coverage report
Current view: top level - scripting/source/provider - MasterScriptProvider.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 100 298 33.6 %
Date: 2014-11-03 Functions: 12 32 37.5 %
Legend: Lines: hit not hit

          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             : 
      21             : #include <comphelper/documentinfo.hxx>
      22             : 
      23             : #include <cppuhelper/implementationentry.hxx>
      24             : #include <cppuhelper/exc_hlp.hxx>
      25             : #include <cppuhelper/factory.hxx>
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : #include <tools/diagnose_ex.h>
      28             : 
      29             : #include <com/sun/star/frame/XModel.hpp>
      30             : #include <com/sun/star/lang/EventObject.hpp>
      31             : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      32             : #include <com/sun/star/document/XScriptInvocationContext.hpp>
      33             : 
      34             : #include <com/sun/star/uri/XUriReference.hpp>
      35             : #include <com/sun/star/uri/UriReferenceFactory.hpp>
      36             : #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
      37             : 
      38             : #include <com/sun/star/deployment/XPackage.hpp>
      39             : #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
      40             : #include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
      41             : #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
      42             : 
      43             : #include <util/scriptingconstants.hxx>
      44             : #include <util/MiscUtils.hxx>
      45             : 
      46             : #include "ActiveMSPList.hxx"
      47             : #include "MasterScriptProvider.hxx"
      48             : #include "URIHelper.hxx"
      49             : 
      50             : using namespace ::com::sun::star;
      51             : using namespace ::com::sun::star::uno;
      52             : using namespace ::com::sun::star::script;
      53             : using namespace ::com::sun::star::document;
      54             : using namespace ::sf_misc;
      55             : 
      56             : namespace func_provider
      57             : {
      58             : 
      59           0 : bool endsWith( const OUString& target,
      60             :     const OUString& item )
      61             : {
      62           0 :     sal_Int32 index = 0;
      63           0 :     if (  ( index = target.indexOf( item ) ) != -1  &&
      64           0 :        ( index == ( target.getLength() - item.getLength() ) ) )
      65             :     {
      66           0 :         return true;
      67             :     }
      68           0 :     return false;
      69             : }
      70             : 
      71             : /* should be available in some central location. */
      72             : 
      73             : // XScriptProvider implementation
      74             : 
      75             : 
      76          58 : MasterScriptProvider::MasterScriptProvider( const Reference< XComponentContext > & xContext ) throw ( RuntimeException ):
      77             :         m_xContext( xContext ), m_bIsValid( false ), m_bInitialised( false ),
      78          58 :         m_bIsPkgMSP( false ), m_pPCache( 0 )
      79             : {
      80          58 :     ENSURE_OR_THROW( m_xContext.is(), "MasterScriptProvider::MasterScriptProvider: No context available\n" );
      81          58 :     m_xMgr = m_xContext->getServiceManager();
      82          58 :     ENSURE_OR_THROW( m_xMgr.is(), "MasterScriptProvider::MasterScriptProvider: No service manager available\n" );
      83          58 :     m_bIsValid = true;
      84          58 : }
      85             : 
      86             : 
      87         174 : MasterScriptProvider::~MasterScriptProvider()
      88             : {
      89          58 :     if ( m_pPCache )
      90             :     {
      91          58 :         delete m_pPCache;
      92             :     }
      93          58 :     m_pPCache = 0;
      94         116 : }
      95             : 
      96             : 
      97          58 : void SAL_CALL MasterScriptProvider::initialize( const Sequence < Any >& args )
      98             : throw ( Exception, RuntimeException, std::exception )
      99             : {
     100          58 :     if ( m_bInitialised )
     101          58 :         return;
     102             : 
     103          58 :     m_bIsValid = false;
     104             : 
     105          58 :     sal_Int32 len = args.getLength();
     106          58 :     if ( len > 1  )
     107             :     {
     108             :         throw RuntimeException(
     109           0 :             "MasterScriptProvider::initialize: invalid number of arguments" );
     110             :     }
     111             : 
     112          58 :     Sequence< Any > invokeArgs( len );
     113             : 
     114          58 :     if ( len != 0 )
     115             :     {
     116             :         // check if first parameter is a string
     117             :         // if it is, this implies that this is a MSP created
     118             :         // with a user or share ctx ( used for browse functionality )
     119             : 
     120          58 :         if ( args[ 0 ] >>= m_sCtxString )
     121             :         {
     122          58 :             invokeArgs[ 0  ] = args[ 0 ];
     123          58 :             if ( m_sCtxString.startsWith( "vnd.sun.star.tdoc" ) )
     124             :             {
     125          58 :                 m_xModel =  MiscUtils::tDocUrlToModel( m_sCtxString );
     126             :             }
     127             :         }
     128           0 :         else if ( args[ 0 ] >>= m_xInvocationContext )
     129             :         {
     130           0 :             m_xModel.set( m_xInvocationContext->getScriptContainer(), UNO_QUERY_THROW );
     131             :         }
     132             :         else
     133             :         {
     134           0 :             args[ 0 ] >>= m_xModel;
     135             :         }
     136             : 
     137          58 :         if ( m_xModel.is() )
     138             :         {
     139             :             // from the arguments, we were able to deduce a model. That alone doesn't
     140             :             // suffice, we also need an XEmbeddedScripts which actually indicates support
     141             :             // for embeddeding scripts
     142          58 :             Reference< XEmbeddedScripts > xScripts( m_xModel, UNO_QUERY );
     143          58 :             if ( !xScripts.is() )
     144             :             {
     145             :                 throw lang::IllegalArgumentException(
     146             :                     OUString( "The given document does not support embedding scripts into it, and cannot be associated with such a document."
     147             :                      ),
     148             :                     *this,
     149             :                     1
     150           0 :                 );
     151             :             }
     152             : 
     153             :             try
     154             :             {
     155          58 :                 m_sCtxString =  MiscUtils::xModelToTdocUrl( m_xModel, m_xContext );
     156             :             }
     157           0 :             catch ( const Exception& )
     158             :             {
     159           0 :                 Any aError( ::cppu::getCaughtException() );
     160             : 
     161           0 :                 OUStringBuffer buf;
     162           0 :                 buf.appendAscii( "MasterScriptProvider::initialize: caught " );
     163           0 :                 buf.append     ( aError.getValueTypeName() );
     164           0 :                 buf.appendAscii( ":" );
     165             : 
     166           0 :                 Exception aException; aError >>= aException;
     167           0 :                 buf.append     ( aException.Message );
     168           0 :                 throw lang::WrappedTargetException( buf.makeStringAndClear(), *this, aError );
     169             :             }
     170             : 
     171          58 :             if ( m_xInvocationContext.is() && m_xInvocationContext != m_xModel )
     172           0 :                 invokeArgs[ 0 ] <<= m_xInvocationContext;
     173             :             else
     174          58 :                 invokeArgs[ 0 ] <<= m_sCtxString;
     175             :         }
     176             : 
     177          58 :         OUString pkgSpec = "uno_packages";
     178          58 :         sal_Int32 indexOfPkgSpec = m_sCtxString.lastIndexOf( pkgSpec );
     179             : 
     180             :         // if contex string ends with "uno_packages"
     181          58 :         if ( indexOfPkgSpec > -1 && m_sCtxString.match( pkgSpec, indexOfPkgSpec ) )
     182             :         {
     183           0 :             m_bIsPkgMSP = true;
     184             :         }
     185             :         else
     186             :         {
     187          58 :             m_bIsPkgMSP = false;
     188          58 :         }
     189             :     }
     190             :     else // no args
     191             :     {
     192             :         // use either scriping context or maybe zero args?
     193           0 :         invokeArgs = Sequence< Any >( 0 ); // no arguments
     194             :     }
     195          58 :     m_sAargs = invokeArgs;
     196             :     // don't create pkg mgr MSP for documents, not supported
     197          58 :     if ( !m_bIsPkgMSP && !m_xModel.is() )
     198             :     {
     199           0 :         createPkgProvider();
     200             :     }
     201             : 
     202          58 :     m_bInitialised = true;
     203          58 :     m_bIsValid = true;
     204             : }
     205             : 
     206             : 
     207             : 
     208           0 : void MasterScriptProvider::createPkgProvider()
     209             : {
     210             :     try
     211             :     {
     212           0 :         Any location;
     213           0 :         OUString sPkgCtx =  m_sCtxString.concat( ":uno_packages" );
     214           0 :         location <<= sPkgCtx;
     215             : 
     216             :         Reference< provider::XScriptProviderFactory > xFac =
     217           0 :             provider::theMasterScriptProviderFactory::get( m_xContext );
     218             : 
     219             :         m_xMSPPkg.set(
     220           0 :             xFac->createScriptProvider( location ), UNO_QUERY_THROW );
     221             : 
     222             :     }
     223           0 :     catch ( const Exception& e )
     224             :     {
     225             :         (void)e;
     226             :         OSL_TRACE("Exception creating MasterScriptProvider for uno_packages in context %s: %s",
     227             :                 OUStringToOString( m_sCtxString,
     228             :                     RTL_TEXTENCODING_ASCII_US ).pData->buffer,
     229             :                 OUStringToOString( e.Message,
     230             :                     RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     231             :     }
     232           0 : }
     233             : 
     234             : 
     235             : Reference< provider::XScript >
     236         154 : MasterScriptProvider::getScript( const OUString& scriptURI )
     237             : throw ( provider::ScriptFrameworkErrorException,
     238             :         RuntimeException, std::exception )
     239             : {
     240         154 :     if ( !isValid() )
     241             :     {
     242             :         throw provider::ScriptFrameworkErrorException(
     243             :             "MasterScriptProvider not initialised", Reference< XInterface >(),
     244             :             scriptURI, "",
     245           0 :             provider::ScriptFrameworkErrorType::UNKNOWN );
     246             :     }
     247             : 
     248             :     // need to get the language from the string
     249             : 
     250         154 :     Reference< uri::XUriReferenceFactory > xFac ( uri::UriReferenceFactory::create( m_xContext )  );
     251             : 
     252             :     Reference<  uri::XUriReference > uriRef(
     253         308 :         xFac->parse( scriptURI ), UNO_QUERY );
     254             : 
     255         308 :     Reference < uri::XVndSunStarScriptUrl > sfUri( uriRef, UNO_QUERY );
     256             : 
     257         154 :     if ( !uriRef.is() || !sfUri.is() )
     258             :     {
     259           0 :         OUString errorMsg = "Incorrect format for Script URI: ";
     260           0 :         errorMsg = errorMsg.concat( scriptURI );
     261             :         throw provider::ScriptFrameworkErrorException(
     262             :             errorMsg, Reference< XInterface >(),
     263             :             scriptURI, "",
     264           0 :             provider::ScriptFrameworkErrorType::UNKNOWN );
     265             :     }
     266             : 
     267         308 :     OUString langKey("language");
     268         308 :     OUString locKey("location");
     269             : 
     270         616 :     if ( sfUri->hasParameter( langKey ) == sal_False ||
     271         616 :          sfUri->hasParameter( locKey ) == sal_False ||
     272         616 :          ( sfUri->getName().isEmpty()  ) )
     273             :     {
     274           0 :         OUString errorMsg = "Incorrect format for Script URI: ";
     275           0 :         errorMsg = errorMsg.concat( scriptURI );
     276             :         throw provider::ScriptFrameworkErrorException(
     277             :             errorMsg, Reference< XInterface >(),
     278             :             scriptURI, "",
     279           0 :             provider::ScriptFrameworkErrorType::UNKNOWN );
     280             :     }
     281             : 
     282         308 :     OUString language = sfUri->getParameter( langKey );
     283         308 :     OUString location = sfUri->getParameter( locKey );
     284             : 
     285             :     // if script us located in uno pkg
     286         154 :     sal_Int32 index = -1;
     287         308 :     OUString pkgTag(":uno_packages");
     288             :     // for languages other than basic,  scripts located in uno packages
     289             :     // are merged into the user/share location context.
     290             :     // For other languages the location attribute in script url has the form
     291             :     // location = [user|share]:uno_packages or location :uno_pacakges/xxxx.uno.pkg
     292             :     // we need to extract the value of location part from the
     293             :     // location attribute of the script, if the script is located in an
     294             :     // uno package then that is the location part up to and including
     295             :     // ":uno_packages", if the script is not in an uno package then the
     296             :     // normal value is used e.g. user or share.
     297             :     // The value extracted will be used to determine if the script is
     298             :     // located in the same location context as this MSP.
     299             :     // For Basic, the language script provider can handle the execution of a
     300             :     // script in any location context
     301         154 :     if ( ( index = location.indexOf( pkgTag ) ) > -1 )
     302             :     {
     303           0 :         location = location.copy( 0, index + pkgTag.getLength() );
     304             :     }
     305             : 
     306         154 :     Reference< provider::XScript > xScript;
     307             : 
     308             :     // If the script location is in the same location context as this
     309             :     // MSP then delate to the lanaguage provider controlled by this MSP
     310             :     // ** Special case is BASIC, all calls to getScript will be handled
     311             :     // by the language script provider in the current location context
     312             :     // even if its different
     313         616 :     if  (   (   location.equals( "document" )
     314         154 :             &&  m_xModel.is()
     315             :             )
     316           0 :             ||  ( endsWith( m_sCtxString, location ) )
     317         616 :             ||  ( language.equals( "Basic" ) )
     318             :          )
     319             :     {
     320         154 :         Reference< provider::XScriptProvider > xScriptProvider;
     321         308 :         OUStringBuffer buf( 80 );
     322         154 :         buf.appendAscii( "com.sun.star.script.provider.ScriptProviderFor");
     323         154 :         buf.append( language );
     324         308 :         OUString serviceName = buf.makeStringAndClear();
     325         154 :         if ( providerCache() )
     326             :         {
     327             :             try
     328             :             {
     329             :                 xScriptProvider.set(
     330             :                     providerCache()->getProvider( serviceName ),
     331         154 :                     UNO_QUERY_THROW );
     332             :             }
     333           0 :             catch( const Exception& e )
     334             :             {
     335             :                 throw provider::ScriptFrameworkErrorException(
     336             :                     e.Message, Reference< XInterface >(),
     337           0 :                     sfUri->getName(), language,
     338           0 :                     provider::ScriptFrameworkErrorType::NOTSUPPORTED );
     339             :             }
     340             :         }
     341             :         else
     342             :         {
     343             :             throw provider::ScriptFrameworkErrorException(
     344             :                 "No LanguageProviders detected",
     345             :                 Reference< XInterface >(),
     346           0 :                 sfUri->getName(), language,
     347           0 :                 provider::ScriptFrameworkErrorType::NOTSUPPORTED );
     348             :         }
     349         308 :         xScript=xScriptProvider->getScript( scriptURI );
     350             :     }
     351             :     else
     352             :     {
     353             :         Reference< provider::XScriptProviderFactory > xFac_ =
     354           0 :             provider::theMasterScriptProviderFactory::get( m_xContext );
     355             : 
     356             :         Reference< provider::XScriptProvider > xSP(
     357           0 :             xFac_->createScriptProvider( makeAny( location ) ), UNO_QUERY_THROW );
     358           0 :         xScript = xSP->getScript( scriptURI );
     359             :     }
     360             : 
     361         308 :     return xScript;
     362             : }
     363             : 
     364             : 
     365             : 
     366             : ProviderCache*
     367         308 : MasterScriptProvider::providerCache()
     368             : {
     369         308 :     if ( !m_pPCache )
     370             :     {
     371          58 :         ::osl::MutexGuard aGuard( m_mutex );
     372          58 :         if ( !m_pPCache )
     373             :         {
     374          58 :             OUString serviceName1 = "com.sun.star.script.provider.ScriptProviderForBasic";
     375         116 :             Sequence< OUString > blacklist(1);
     376          58 :             blacklist[ 0 ] = serviceName1;
     377             : 
     378          58 :             if ( !m_bIsPkgMSP )
     379             :             {
     380          58 :                 m_pPCache = new ProviderCache( m_xContext, m_sAargs );
     381             :             }
     382             :             else
     383             :             {
     384           0 :                 m_pPCache = new ProviderCache( m_xContext, m_sAargs, blacklist );
     385          58 :             }
     386          58 :         }
     387             :     }
     388         308 :     return m_pPCache;
     389             : }
     390             : 
     391             : 
     392             : 
     393             : OUString SAL_CALL
     394           0 : MasterScriptProvider::getName()
     395             :         throw ( css::uno::RuntimeException, std::exception )
     396             : {
     397           0 :     if ( !isPkgProvider() )
     398             :     {
     399           0 :         OUString sCtx = getContextString();
     400           0 :         if ( sCtx.startsWith( "vnd.sun.star.tdoc" ) )
     401             :         {
     402           0 :             Reference< frame::XModel > xModel = m_xModel;
     403           0 :             if ( !xModel.is() )
     404             :             {
     405           0 :                 xModel = MiscUtils::tDocUrlToModel( sCtx );
     406             :             }
     407             : 
     408           0 :             m_sNodeName = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
     409             :         }
     410             :         else
     411             :         {
     412           0 :             m_sNodeName = parseLocationName( getContextString() );
     413           0 :         }
     414             :     }
     415             :     else
     416             :     {
     417           0 :         m_sNodeName = "uno_packages";
     418             :     }
     419           0 :     return m_sNodeName;
     420             : }
     421             : 
     422             : 
     423             : Sequence< Reference< browse::XBrowseNode > > SAL_CALL
     424           0 : MasterScriptProvider::getChildNodes()
     425             :         throw ( css::uno::RuntimeException, std::exception )
     426             : {
     427           0 :     Sequence< Reference< provider::XScriptProvider > > providers = getAllProviders();
     428             : 
     429           0 :     Reference< provider::XScriptProvider > pkgProv = getPkgProvider();
     430           0 :     sal_Int32 size = providers.getLength();
     431           0 :     bool hasPkgs = pkgProv.is();
     432           0 :     if ( hasPkgs  )
     433             :     {
     434           0 :         size++;
     435             :     }
     436           0 :     Sequence<  Reference< browse::XBrowseNode > > children( size );
     437           0 :     sal_Int32 provIndex = 0;
     438           0 :     for ( ; provIndex < providers.getLength(); provIndex++ )
     439             :     {
     440           0 :         children[ provIndex ] = Reference< browse::XBrowseNode >( providers[ provIndex ], UNO_QUERY );
     441             :     }
     442             : 
     443           0 :     if ( hasPkgs  )
     444             :     {
     445           0 :         children[ provIndex ] = Reference< browse::XBrowseNode >( pkgProv, UNO_QUERY );
     446             : 
     447             :     }
     448             : 
     449           0 :     return children;
     450             : }
     451             : 
     452             : 
     453             : sal_Bool SAL_CALL
     454           0 : MasterScriptProvider::hasChildNodes()
     455             :         throw ( css::uno::RuntimeException, std::exception )
     456             : {
     457           0 :     return sal_True;
     458             : }
     459             : 
     460             : 
     461             : sal_Int16 SAL_CALL
     462           0 : MasterScriptProvider::getType()
     463             :         throw ( css::uno::RuntimeException, std::exception )
     464             : {
     465           0 :     return browse::BrowseNodeTypes::CONTAINER;
     466             : }
     467             : 
     468             : 
     469             : 
     470             : OUString
     471           0 : MasterScriptProvider::parseLocationName( const OUString& location )
     472             : {
     473             :     // strip out the last leaf of location name
     474             :     // e.g. file://dir1/dir2/Blah.sxw - > Blah.sxw
     475           0 :     OUString temp = location;
     476           0 :     INetURLObject aURLObj( temp );
     477           0 :     if ( !aURLObj.HasError() )
     478           0 :         temp = aURLObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
     479           0 :     return temp;
     480             : }
     481             : 
     482             : 
     483             : // Register Package
     484             : void SAL_CALL
     485           0 : MasterScriptProvider::insertByName( const OUString& aName, const Any& aElement ) throw ( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, css::uno::RuntimeException, std::exception)
     486             : {
     487           0 :     if ( !m_bIsPkgMSP )
     488             :     {
     489           0 :         if ( m_xMSPPkg.is() )
     490             :         {
     491           0 :             Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY );
     492           0 :             if ( !xCont.is() )
     493             :             {
     494             :                 throw RuntimeException(
     495           0 :                     "PackageMasterScriptProvider doesn't implement XNameContainer" );
     496             :             }
     497           0 :             xCont->insertByName( aName, aElement );
     498             :         }
     499             :         else
     500             :         {
     501           0 :             throw RuntimeException( "PackageMasterScriptProvider is unitialised" );
     502             :         }
     503             : 
     504             :     }
     505             :     else
     506             :     {
     507           0 :         Reference< deployment::XPackage > xPkg( aElement, UNO_QUERY );
     508           0 :         if ( !xPkg.is() )
     509             :         {
     510             :             throw lang::IllegalArgumentException( "Couldn't convert to XPackage",
     511           0 :                                                       Reference < XInterface > (), 2 );
     512             :         }
     513           0 :         if ( aName.isEmpty() )
     514             :         {
     515             :             throw lang::IllegalArgumentException( "Name not set!!",
     516           0 :                                                       Reference < XInterface > (), 1 );
     517             :         }
     518             :         // TODO for library pacakge parse the language, for the moment will try
     519             :         // to get each provider to process the new Package, the first one the succeeds
     520             :         // will terminate processing
     521           0 :         if ( !providerCache() )
     522             :         {
     523             :             throw RuntimeException(
     524             :                 "insertByName cannot instantiate "
     525           0 :                 "child script providers." );
     526             :         }
     527             :         Sequence < Reference< provider::XScriptProvider > > xSProviders =
     528           0 :             providerCache()->getAllProviders();
     529           0 :         sal_Int32 index = 0;
     530             : 
     531           0 :         for ( ; index < xSProviders.getLength(); index++ )
     532             :         {
     533           0 :             Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
     534           0 :             if ( !xCont.is() )
     535             :             {
     536           0 :                 continue;
     537             :             }
     538             :             try
     539             :             {
     540           0 :                 xCont->insertByName( aName, aElement );
     541           0 :                 break;
     542             :             }
     543           0 :             catch ( Exception& e )
     544             :             {
     545             :                 SAL_INFO(
     546             :                     "scripting.provider", "ignoring Exception " << e.Message);
     547             :             }
     548             : 
     549           0 :         }
     550           0 :         if ( index == xSProviders.getLength() )
     551             :         {
     552             :             // No script providers could process the package
     553           0 :             OUString message = "Failed to register package for ";
     554           0 :             message = message.concat( aName );
     555             :             throw lang::IllegalArgumentException( message,
     556           0 :                 Reference < XInterface > (), 2 );
     557           0 :         }
     558             :    }
     559           0 : }
     560             : 
     561             : 
     562             : // Revoke Package
     563             : void SAL_CALL
     564           0 : MasterScriptProvider::removeByName( const OUString& Name ) throw ( container::NoSuchElementException, lang::WrappedTargetException, RuntimeException, std::exception)
     565             : {
     566           0 :     if ( !m_bIsPkgMSP )
     567             :     {
     568           0 :         if ( m_xMSPPkg.is() )
     569             :         {
     570           0 :             Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY );
     571           0 :             if ( !xCont.is() )
     572             :             {
     573             :                 throw RuntimeException(
     574           0 :                     "PackageMasterScriptProvider doesn't implement XNameContainer" );
     575             :             }
     576           0 :             xCont->removeByName( Name );
     577             :         }
     578             :         else
     579             :         {
     580           0 :             throw RuntimeException( "PackageMasterScriptProvider is unitialised" );
     581             :         }
     582             : 
     583             :    }
     584             :    else
     585             :    {
     586           0 :         if ( Name.isEmpty() )
     587             :         {
     588             :             throw lang::IllegalArgumentException( "Name not set!!",
     589           0 :                                                       Reference < XInterface > (), 1 );
     590             :         }
     591             :         // TODO for Script library pacakge url parse the language,
     592             :         // for the moment will just try to get each provider to process remove/revoke
     593             :         // request, the first one the succeeds will terminate processing
     594             : 
     595           0 :         if ( !providerCache() )
     596             :         {
     597             :             throw RuntimeException(
     598             :                 "removeByName() cannot instantiate "
     599           0 :                 "child script providers." );
     600             :         }
     601             :         Sequence < Reference< provider::XScriptProvider > > xSProviders =
     602           0 :             providerCache()->getAllProviders();
     603           0 :         sal_Int32 index = 0;
     604           0 :         for ( ; index < xSProviders.getLength(); index++ )
     605             :         {
     606           0 :             Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
     607           0 :             if ( !xCont.is() )
     608             :             {
     609           0 :                 continue;
     610             :             }
     611             :             try
     612             :             {
     613           0 :                 xCont->removeByName( Name );
     614           0 :                 break;
     615             :             }
     616           0 :             catch ( Exception& )
     617             :             {
     618             :             }
     619             : 
     620           0 :         }
     621           0 :         if ( index == xSProviders.getLength() )
     622             :         {
     623             :             // No script providers could process the package
     624           0 :             OUString message = "Failed to revoke package for ";
     625           0 :             message = message.concat( Name );
     626             :             throw lang::IllegalArgumentException( message,
     627           0 :                                                       Reference < XInterface > (), 1 );
     628           0 :         }
     629             : 
     630             :     }
     631           0 : }
     632             : 
     633             : 
     634             : void SAL_CALL
     635           0 : MasterScriptProvider::replaceByName( const OUString& aName, const Any& aElement ) throw ( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, RuntimeException, std::exception)
     636             : {
     637             :     (void)aName;
     638             :     (void)aElement;
     639             : 
     640             :     // TODO needs implementing
     641             :     if ( true )
     642             :     {
     643           0 :         throw RuntimeException( "replaceByName not implemented!!!!" );
     644             :     }
     645             : }
     646             : 
     647             : Any SAL_CALL
     648           0 : MasterScriptProvider::getByName( const OUString& aName ) throw ( container::NoSuchElementException, lang::WrappedTargetException, RuntimeException, std::exception)
     649             : {
     650             :     (void)aName;
     651             : 
     652             :     // TODO needs to be implemented
     653           0 :     Any result;
     654             :     if ( true )
     655             :     {
     656           0 :         throw RuntimeException( "getByName not implemented!!!!" );
     657             :     }
     658             :     return result;
     659             : }
     660             : 
     661             : sal_Bool SAL_CALL
     662           2 : MasterScriptProvider::hasByName( const OUString& aName ) throw (RuntimeException, std::exception)
     663             : {
     664           2 :     bool result = false;
     665           2 :     if ( !m_bIsPkgMSP )
     666             :     {
     667           2 :         if ( m_xMSPPkg.is() )
     668             :         {
     669           0 :             Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY );
     670           0 :             if ( !xCont.is() )
     671             :             {
     672             :                 throw RuntimeException(
     673           0 :                     "PackageMasterScriptProvider doesn't implement XNameContainer" );
     674             :             }
     675             : 
     676           0 :             result = xCont->hasByName( aName );
     677             :         }
     678             :         // If this is a document provider then we shouldn't
     679             :         // have a PackageProvider
     680           2 :         else if (!m_xModel.is())
     681             :         {
     682           0 :             throw RuntimeException( "PackageMasterScriptProvider is unitialised" );
     683             :         }
     684             : 
     685             :    }
     686             :    else
     687             :    {
     688           0 :         if ( aName.isEmpty() )
     689             :         {
     690             :             throw lang::IllegalArgumentException( "Name not set!!",
     691           0 :                                                       Reference < XInterface > (), 1 );
     692             :         }
     693             :         // TODO for Script library pacakge url parse the language,
     694             :         // for the moment will just try to get each provider to see if the
     695             :         // package exists in any provider, first one that succeed will
     696             :         // terminate the loop
     697             : 
     698           0 :         if ( !providerCache() )
     699             :         {
     700             :             throw RuntimeException(
     701             :                 "removeByName() cannot instantiate "
     702           0 :                 "child script providers." );
     703             :         }
     704             :         Sequence < Reference< provider::XScriptProvider > > xSProviders =
     705           0 :             providerCache()->getAllProviders();
     706           0 :         for ( sal_Int32 index = 0; index < xSProviders.getLength(); index++ )
     707             :         {
     708           0 :             Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
     709           0 :             if ( !xCont.is() )
     710             :             {
     711           0 :                 continue;
     712             :             }
     713             :             try
     714             :             {
     715           0 :                 result = xCont->hasByName( aName );
     716           0 :                 if ( result )
     717             :                 {
     718           0 :                     break;
     719             :                 }
     720             :             }
     721           0 :             catch ( Exception& )
     722             :             {
     723             :             }
     724             : 
     725           0 :         }
     726             :     }
     727           2 :     return result;
     728             : }
     729             : 
     730             : 
     731             : Sequence< OUString > SAL_CALL
     732           0 : MasterScriptProvider::getElementNames(  ) throw ( RuntimeException, std::exception)
     733             : {
     734             :     // TODO needs implementing
     735           0 :     Sequence< OUString >  names;
     736             :     if ( true )
     737             :     {
     738           0 :         throw RuntimeException( "getElementNames not implemented!!!!" );
     739             :     }
     740             :     return names;
     741             : }
     742             : 
     743             : Type SAL_CALL
     744           0 : MasterScriptProvider::getElementType(  ) throw ( RuntimeException, std::exception)
     745             : {
     746             :     // TODO needs implementing
     747           0 :     Type t;
     748           0 :     return t;
     749             : }
     750             : 
     751           0 : sal_Bool SAL_CALL MasterScriptProvider::hasElements(  ) throw ( RuntimeException, std::exception)
     752             : {
     753             :     // TODO needs implementing
     754             :     if ( true )
     755             :     {
     756           0 :         throw RuntimeException( "hasElements not implemented!!!!" );
     757             :     }
     758             :     return false;
     759             : }
     760             : 
     761             : 
     762             : Sequence< Reference< provider::XScriptProvider > > SAL_CALL
     763           0 : MasterScriptProvider::getAllProviders() throw ( css::uno::RuntimeException )
     764             : {
     765           0 :     if ( providerCache() )
     766             :     {
     767           0 :         return providerCache()->getAllProviders();
     768             :     }
     769             :     else
     770             :     {
     771             :         OUString errorMsg(
     772           0 :             "MasterScriptProvider::getAllProviders, cache not initialised");
     773           0 :         throw RuntimeException( errorMsg.concat( errorMsg ) );
     774             :     }
     775             : }
     776             : 
     777             : 
     778             : 
     779           0 : OUString SAL_CALL MasterScriptProvider::getImplementationName( )
     780             : throw( RuntimeException, std::exception )
     781             : {
     782           0 :     return OUString( "com.sun.star.script.provider.MasterScriptProvider"  );
     783             : }
     784             : 
     785           0 : sal_Bool SAL_CALL MasterScriptProvider::supportsService( const OUString& serviceName )
     786             : throw( RuntimeException, std::exception )
     787             : {
     788           0 :     return cppu::supportsService(this, serviceName);
     789             : }
     790             : 
     791             : 
     792           0 : Sequence< OUString > SAL_CALL MasterScriptProvider::getSupportedServiceNames( )
     793             : throw( RuntimeException, std::exception )
     794             : {
     795           0 :     OUString names[3];
     796             : 
     797           0 :     names[0] = "com.sun.star.script.provider.MasterScriptProvider";
     798           0 :     names[1] = "com.sun.star.script.browse.BrowseNode";
     799           0 :     names[2] = "com.sun.star.script.provider.ScriptProvider";
     800             : 
     801           0 :     return Sequence< OUString >( names, 3 );
     802             : }
     803             : 
     804             : } // namespace func_provider
     805             : 
     806             : 
     807             : namespace scripting_runtimemgr
     808             : {
     809             : 
     810          58 : Reference< XInterface > SAL_CALL sp_create(
     811             :     const Reference< XComponentContext > & xCompC )
     812             : {
     813          58 :     return ( cppu::OWeakObject * ) new ::func_provider::MasterScriptProvider( xCompC );
     814             : }
     815             : 
     816             : 
     817           8 : Sequence< OUString > sp_getSupportedServiceNames( )
     818             : {
     819          32 :     OUString names[3];
     820             : 
     821           8 :     names[0] = "com.sun.star.script.provider.MasterScriptProvider";
     822           8 :     names[1] = "com.sun.star.script.browse.BrowseNode";
     823           8 :     names[2] = "com.sun.star.script.provider.ScriptProvider";
     824             : 
     825          32 :     return Sequence< OUString >( names, 3 );
     826             : }
     827             : 
     828             : 
     829          18 : OUString sp_getImplementationName( )
     830             : {
     831          18 :     return OUString( "com.sun.star.script.provider.MasterScriptProvider"  );
     832             : }
     833             : 
     834             : // ***** registration or ScriptingFrameworkURIHelper
     835           0 : Reference< XInterface > SAL_CALL urihelper_create(
     836             :     const Reference< XComponentContext > & xCompC )
     837             : {
     838             :     return ( cppu::OWeakObject * )
     839           0 :         new ::func_provider::ScriptingFrameworkURIHelper( xCompC );
     840             : }
     841             : 
     842           0 : Sequence< OUString > urihelper_getSupportedServiceNames( )
     843             : {
     844             :     OUString serviceNameList[] = {
     845             :         OUString(
     846           0 :             "com.sun.star.script.provider.ScriptURIHelper" ) };
     847             : 
     848             :     Sequence< OUString > serviceNames = Sequence <
     849           0 :         OUString > ( serviceNameList, 1 );
     850             : 
     851           0 :     return serviceNames;
     852             : }
     853             : 
     854          18 : OUString urihelper_getImplementationName( )
     855             : {
     856             :     return OUString(
     857          18 :         "com.sun.star.script.provider.ScriptURIHelper");
     858             : }
     859             : 
     860             : static const struct cppu::ImplementationEntry s_entries [] =
     861             :     {
     862             :         {
     863             :             sp_create, sp_getImplementationName,
     864             :             sp_getSupportedServiceNames, cppu::createSingleComponentFactory,
     865             :             0, 0
     866             :         },
     867             :         {
     868             :             urihelper_create,
     869             :             urihelper_getImplementationName,
     870             :             urihelper_getSupportedServiceNames,
     871             :             cppu::createSingleComponentFactory,
     872             :             0, 0
     873             :         },
     874             :         {
     875             :             func_provider::mspf_create, func_provider::mspf_getImplementationName,
     876             :             func_provider::mspf_getSupportedServiceNames, cppu::createSingleComponentFactory,
     877             :             0, 0
     878             :         },
     879             :         {
     880             :             browsenodefactory::bnf_create, browsenodefactory::bnf_getImplementationName,
     881             :             browsenodefactory::bnf_getSupportedServiceNames, cppu::createSingleComponentFactory,
     882             :             0, 0
     883             :         },
     884             :         { 0, 0, 0, 0, 0, 0 }
     885             :     };
     886             : }
     887             : 
     888             : 
     889             : //#### EXPORTED ##############################################################
     890             : 
     891             : 
     892             : extern "C"
     893             : {
     894             :     /**
     895             :      * This function is called to get service factories for an implementation.
     896             :      *
     897             :      * @param pImplName       name of implementation
     898             :      * @param pServiceManager a service manager, need for component creation
     899             :      * @param pRegistryKey    the registry key for this component, need for persistent
     900             :      *                        data
     901             :      * @return a component factory
     902             :      */
     903          18 :     SAL_DLLPUBLIC_EXPORT void * SAL_CALL scriptframe_component_getFactory(
     904             :         const sal_Char * pImplName,
     905             :         void * pServiceManager,
     906             :         void * pRegistryKey )
     907             :     {
     908             :         return ::cppu::component_getFactoryHelper( pImplName, pServiceManager,
     909          18 :             pRegistryKey, ::scripting_runtimemgr::s_entries );
     910             :     }
     911             : }
     912             : 
     913             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10