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

Generated by: LCOV version 1.10