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

Generated by: LCOV version 1.10