1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MasterScriptProvider.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_scripting.hxx"
34 #include <comphelper/documentinfo.hxx>
36 #include <cppuhelper/implementationentry.hxx>
37 #include <cppuhelper/exc_hlp.hxx>
38 #include <cppuhelper/factory.hxx>
39 #include <com/sun/star/frame/XModel.hpp>
40 #include <com/sun/star/lang/EventObject.hpp>
41 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
42 #include <com/sun/star/document/XScriptInvocationContext.hpp>
44 #include <com/sun/star/uri/XUriReference.hpp>
45 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
46 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
48 #include <com/sun/star/deployment/XPackage.hpp>
49 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
50 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
51 #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
53 #include <util/scriptingconstants.hxx>
54 #include <util/util.hxx>
55 #include <util/MiscUtils.hxx>
57 #include "ActiveMSPList.hxx"
58 #include "MasterScriptProvider.hxx"
59 #include "URIHelper.hxx"
61 using namespace ::com::sun::star
;
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::script
;
64 using namespace ::com::sun::star::document
;
65 using namespace ::sf_misc
;
66 using namespace ::scripting_util
;
68 namespace func_provider
70 //*************************************************************************
71 // Definitions for MasterScriptProviderFactory global methods.
72 //*************************************************************************
74 ::rtl::OUString SAL_CALL
mspf_getImplementationName() ;
75 Reference
< XInterface
> SAL_CALL
mspf_create( Reference
< XComponentContext
> const & xComponentContext
);
76 Sequence
< ::rtl::OUString
> SAL_CALL
mspf_getSupportedServiceNames();
79 bool endsWith( const ::rtl::OUString
& target
,
80 const ::rtl::OUString
& item
)
83 if ( ( index
= target
.indexOf( item
) ) != -1 &&
84 ( index
== ( target
.getLength() - item
.getLength() ) ) )
90 //::rtl_StandardModuleCount s_moduleCount = MODULE_COUNT_INIT;
92 /* should be available in some central location. */
93 //*************************************************************************
94 // XScriptProvider implementation
96 //*************************************************************************
97 MasterScriptProvider::MasterScriptProvider( const Reference
< XComponentContext
> & xContext
) throw ( RuntimeException
):
98 m_xContext( xContext
), m_bIsValid( false ), m_bInitialised( false ),
99 m_bIsPkgMSP( false ), m_pPCache( 0 )
101 validateXRef( m_xContext
, "MasterScriptProvider::MasterScriptProvider: No context available\n" );
102 m_xMgr
= m_xContext
->getServiceManager();
103 validateXRef( m_xMgr
,
104 "MasterScriptProvider::MasterScriptProvider: No service manager available\n" );
108 //*************************************************************************
109 MasterScriptProvider::~MasterScriptProvider()
111 //s_moduleCount.modCnt.release( &s_moduleCount.modCnt );
119 //*************************************************************************
120 void SAL_CALL
MasterScriptProvider::initialize( const Sequence
< Any
>& args
)
121 throw ( Exception
, RuntimeException
)
123 if ( m_bInitialised
)
128 sal_Int32 len
= args
.getLength();
131 throw RuntimeException(
132 OUSTR( "MasterScriptProvider::initialize: invalid number of arguments" ),
133 Reference
< XInterface
>() );
136 Sequence
< Any
> invokeArgs( len
);
140 // check if first parameter is a string
141 // if it is, this implies that this is a MSP created
142 // with a user or share ctx ( used for browse functionality )
144 if ( args
[ 0 ] >>= m_sCtxString
)
146 invokeArgs
[ 0 ] = args
[ 0 ];
147 if ( m_sCtxString
.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.tdoc" ) ) == 0 )
149 m_xModel
= MiscUtils::tDocUrlToModel( m_sCtxString
);
152 else if ( args
[ 0 ] >>= m_xInvocationContext
)
154 m_xModel
.set( m_xInvocationContext
->getScriptContainer(), UNO_QUERY_THROW
);
158 args
[ 0 ] >>= m_xModel
;
163 // from the arguments, we were able to deduce a model. That alone doesn't
164 // suffice, we also need an XEmbeddedScripts which actually indicates support
165 // for embeddeding scripts
166 Reference
< XEmbeddedScripts
> xScripts( m_xModel
, UNO_QUERY
);
167 if ( !xScripts
.is() )
169 throw lang::IllegalArgumentException(
170 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
171 "The given document does not support embedding scripts into it, and cannot be associated with such a document."
180 m_sCtxString
= MiscUtils::xModelToTdocUrl( m_xModel
, m_xContext
);
182 catch ( const Exception
& )
184 Any
aError( ::cppu::getCaughtException() );
186 ::rtl::OUStringBuffer buf
;
187 buf
.appendAscii( "MasterScriptProvider::initialize: caught " );
188 buf
.append ( aError
.getValueTypeName() );
189 buf
.appendAscii( ":" );
191 Exception aException
; aError
>>= aException
;
192 buf
.append ( aException
.Message
);
193 throw lang::WrappedTargetException( buf
.makeStringAndClear(), *this, aError
);
196 if ( m_xInvocationContext
.is() && m_xInvocationContext
!= m_xModel
)
197 invokeArgs
[ 0 ] <<= m_xInvocationContext
;
199 invokeArgs
[ 0 ] <<= m_sCtxString
;
202 ::rtl::OUString pkgSpec
= OUSTR("uno_packages");
203 sal_Int32 indexOfPkgSpec
= m_sCtxString
.lastIndexOf( pkgSpec
);
205 // if contex string ends with "uno_packages"
206 if ( indexOfPkgSpec
> -1 && ( m_sCtxString
.match( pkgSpec
, indexOfPkgSpec
) == sal_True
) )
208 m_bIsPkgMSP
= sal_True
;
212 m_bIsPkgMSP
= sal_False
;
217 // use either scriping context or maybe zero args?
218 invokeArgs
= Sequence
< Any
>( 0 ); // no arguments
220 m_sAargs
= invokeArgs
;
221 // don't create pkg mgr MSP for documents, not supported
222 if ( m_bIsPkgMSP
== sal_False
&& !m_xModel
.is() )
227 m_bInitialised
= true;
232 //*************************************************************************
233 void MasterScriptProvider::createPkgProvider()
237 ::rtl::OUString loc
= m_sCtxString
;
239 ::rtl::OUString sPkgCtx
= m_sCtxString
.concat( OUSTR(":uno_packages") );
240 location
<<= sPkgCtx
;
242 Reference
< provider::XScriptProviderFactory
> xFac(
243 m_xContext
->getValueByName(
244 OUSTR( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory") ), UNO_QUERY_THROW
);
247 xFac
->createScriptProvider( location
), UNO_QUERY_THROW
);
250 catch ( Exception
& e
)
253 OSL_TRACE("Exception creating MasterScriptProvider for uno_packages in context %s: %s",
254 ::rtl::OUStringToOString( m_sCtxString
,
255 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
,
256 ::rtl::OUStringToOString( e
.Message
,
257 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
261 //*************************************************************************
262 Reference
< provider::XScript
>
263 MasterScriptProvider::getScript( const ::rtl::OUString
& scriptURI
)
264 throw ( provider::ScriptFrameworkErrorException
,
269 throw provider::ScriptFrameworkErrorException(
270 OUSTR( "MasterScriptProvider not initialised" ), Reference
< XInterface
>(),
271 scriptURI
, OUSTR(""),
272 provider::ScriptFrameworkErrorType::UNKNOWN
);
275 // need to get the language from the string
277 Reference
< uri::XUriReferenceFactory
> xFac (
278 m_xMgr
->createInstanceWithContext( rtl::OUString::createFromAscii(
279 "com.sun.star.uri.UriReferenceFactory"), m_xContext
) , UNO_QUERY
);
282 ::rtl::OUString message
= ::rtl::OUString::createFromAscii("Failed to instantiate UriReferenceFactory");
283 throw provider::ScriptFrameworkErrorException(
284 message
, Reference
< XInterface
>(),
285 scriptURI
, ::rtl::OUString(),
286 provider::ScriptFrameworkErrorType::UNKNOWN
);
289 Reference
< uri::XUriReference
> uriRef(
290 xFac
->parse( scriptURI
), UNO_QUERY
);
292 Reference
< uri::XVndSunStarScriptUrl
> sfUri( uriRef
, UNO_QUERY
);
294 if ( !uriRef
.is() || !sfUri
.is() )
296 ::rtl::OUString errorMsg
= OUSTR( "Incorrect format for Script URI: " );
297 errorMsg
= errorMsg
.concat( scriptURI
);
298 throw provider::ScriptFrameworkErrorException(
299 errorMsg
, Reference
< XInterface
>(),
300 scriptURI
, OUSTR(""),
301 provider::ScriptFrameworkErrorType::UNKNOWN
);
304 ::rtl::OUString langKey
= ::rtl::OUString::createFromAscii( "language" );
305 ::rtl::OUString locKey
= ::rtl::OUString::createFromAscii( "location" );
307 if ( sfUri
->hasParameter( langKey
) == sal_False
||
308 sfUri
->hasParameter( locKey
) == sal_False
||
309 ( sfUri
->getName().getLength() == 0 ) )
311 ::rtl::OUString errorMsg
= OUSTR( "Incorrect format for Script URI: " );
312 errorMsg
= errorMsg
.concat( scriptURI
);
313 throw provider::ScriptFrameworkErrorException(
314 errorMsg
, Reference
< XInterface
>(),
315 scriptURI
, OUSTR(""),
316 provider::ScriptFrameworkErrorType::UNKNOWN
);
319 ::rtl::OUString language
= sfUri
->getParameter( langKey
);
320 ::rtl::OUString location
= sfUri
->getParameter( locKey
);
322 // if script us located in uno pkg
323 sal_Int32 index
= -1;
324 ::rtl::OUString pkgTag
=
325 ::rtl::OUString::createFromAscii( ":uno_packages" );
326 // for languages other than basic, scripts located in uno packages
327 // are merged into the user/share location context.
328 // For other languages the location attribute in script url has the form
329 // location = [user|share]:uno_packages or location :uno_pacakges/xxxx.uno.pkg
330 // we need to extract the value of location part from the
331 // location attribute of the script, if the script is located in an
332 // uno package then that is the location part up to and including
333 // ":uno_packages", if the script is not in an uno package then the
334 // normal value is used e.g. user or share.
335 // The value extracted will be used to determine if the script is
336 // located in the same location context as this MSP.
337 // For Basic, the language script provider can handle the execution of a
338 // script in any location context
339 if ( ( index
= location
.indexOf( pkgTag
) ) > -1 )
341 location
= location
.copy( 0, index
+ pkgTag
.getLength() );
344 Reference
< provider::XScript
> xScript
;
346 // If the script location is in the same location context as this
347 // MSP then delate to the lanaguage provider controlled by this MSP
348 // ** Special case is BASIC, all calls to getScript will be handled
349 // by the language script provider in the current location context
350 // even if its different
351 if ( ( location
.equals( OUSTR( "document" ) )
354 || ( endsWith( m_sCtxString
, location
) )
355 || ( language
.equals( OUSTR( "Basic" ) ) )
358 Reference
< provider::XScriptProvider
> xScriptProvider
;
359 ::rtl::OUStringBuffer
buf( 80 );
360 buf
.appendAscii( "com.sun.star.script.provider.ScriptProviderFor");
361 buf
.append( language
);
362 ::rtl::OUString serviceName
= buf
.makeStringAndClear();
363 if ( providerCache() )
368 providerCache()->getProvider( serviceName
),
371 catch( const Exception
& e
)
373 throw provider::ScriptFrameworkErrorException(
374 e
.Message
, Reference
< XInterface
>(),
375 sfUri
->getName(), language
,
376 provider::ScriptFrameworkErrorType::NOTSUPPORTED
);
381 throw provider::ScriptFrameworkErrorException(
382 OUSTR( "No LanguageProviders detected" ),
383 Reference
< XInterface
>(),
384 sfUri
->getName(), language
,
385 provider::ScriptFrameworkErrorType::NOTSUPPORTED
);
387 xScript
=xScriptProvider
->getScript( scriptURI
);
391 Reference
< provider::XScriptProviderFactory
> xFac_(
392 m_xContext
->getValueByName(
393 OUSTR( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory") ), UNO_QUERY_THROW
);
395 Reference
< provider::XScriptProvider
> xSP(
396 xFac_
->createScriptProvider( makeAny( location
) ), UNO_QUERY_THROW
);
397 xScript
= xSP
->getScript( scriptURI
);
402 //*************************************************************************
404 MasterScriptProvider::isValid()
409 //*************************************************************************
411 MasterScriptProvider::providerCache()
415 ::osl::MutexGuard
aGuard( m_mutex
);
418 ::rtl::OUString serviceName1
= OUSTR("com.sun.star.script.provider.ScriptProviderForBasic");
419 Sequence
< ::rtl::OUString
> blacklist(1);
420 blacklist
[ 0 ] = serviceName1
;
424 m_pPCache
= new ProviderCache( m_xContext
, m_sAargs
);
428 m_pPCache
= new ProviderCache( m_xContext
, m_sAargs
, blacklist
);
436 //*************************************************************************
437 ::rtl::OUString SAL_CALL
438 MasterScriptProvider::getName()
439 throw ( css::uno::RuntimeException
)
441 if ( !isPkgProvider() )
443 ::rtl::OUString sCtx
= getContextString();
444 if ( sCtx
.indexOf( OUSTR( "vnd.sun.star.tdoc" ) ) == 0 )
446 Reference
< frame::XModel
> xModel
= m_xModel
;
449 xModel
= MiscUtils::tDocUrlToModel( sCtx
);
452 m_sNodeName
= ::comphelper::DocumentInfo::getDocumentTitle( xModel
);
456 m_sNodeName
= parseLocationName( getContextString() );
461 m_sNodeName
= OUSTR("uno_packages");
466 //*************************************************************************
467 Sequence
< Reference
< browse::XBrowseNode
> > SAL_CALL
468 MasterScriptProvider::getChildNodes()
469 throw ( css::uno::RuntimeException
)
471 Sequence
< Reference
< provider::XScriptProvider
> > providers
= getAllProviders();
473 Reference
< provider::XScriptProvider
> pkgProv
= getPkgProvider();
474 sal_Int32 size
= providers
.getLength();
475 bool hasPkgs
= pkgProv
.is();
480 Sequence
< Reference
< browse::XBrowseNode
> > children( size
);
481 sal_Int32 provIndex
= 0;
482 for ( ; provIndex
< providers
.getLength(); provIndex
++ )
484 children
[ provIndex
] = Reference
< browse::XBrowseNode
>( providers
[ provIndex
], UNO_QUERY
);
489 children
[ provIndex
] = Reference
< browse::XBrowseNode
>( pkgProv
, UNO_QUERY
);
496 //*************************************************************************
498 MasterScriptProvider::hasChildNodes()
499 throw ( css::uno::RuntimeException
)
504 //*************************************************************************
506 MasterScriptProvider::getType()
507 throw ( css::uno::RuntimeException
)
509 return browse::BrowseNodeTypes::CONTAINER
;
512 //*************************************************************************
515 MasterScriptProvider::parseLocationName( const ::rtl::OUString
& location
)
517 // strip out the last leaf of location name
518 // e.g. file://dir1/dir2/Blah.sxw - > Blah.sxw
519 ::rtl::OUString temp
= location
;
520 INetURLObject
aURLObj( temp
);
521 if ( !aURLObj
.HasError() )
522 temp
= aURLObj
.getName( INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
526 //*************************************************************************
529 MasterScriptProvider::insertByName( const ::rtl::OUString
& aName
, const Any
& aElement
) throw ( lang::IllegalArgumentException
, container::ElementExistException
, lang::WrappedTargetException
, css::uno::RuntimeException
)
533 if ( m_xMSPPkg
.is() )
535 Reference
< container::XNameContainer
> xCont( m_xMSPPkg
, UNO_QUERY
);
538 throw RuntimeException(
539 OUSTR("PackageMasterScriptProvider doesn't implement XNameContainer"),
540 Reference
< XInterface
>() );
542 xCont
->insertByName( aName
, aElement
);
546 throw RuntimeException( OUSTR("PackageMasterScriptProvider is unitialised"),
547 Reference
< XInterface
>() );
553 Reference
< deployment::XPackage
> xPkg( aElement
, UNO_QUERY
);
556 throw lang::IllegalArgumentException( OUSTR("Couldn't convert to XPackage"),
557 Reference
< XInterface
> (), 2 );
559 if ( !aName
.getLength() )
561 throw lang::IllegalArgumentException( OUSTR("Name not set!!"),
562 Reference
< XInterface
> (), 1 );
564 // TODO for library pacakge parse the language, for the moment will try
565 // to get each provider to process the new Package, the first one the succeeds
566 // will terminate processing
567 if ( !providerCache() )
569 throw RuntimeException(
570 OUSTR("insertByName cannot instantiate "
571 "child script providers."),
572 Reference
< XInterface
>() );
574 Sequence
< Reference
< provider::XScriptProvider
> > xSProviders
=
575 providerCache()->getAllProviders();
578 for ( ; index
< xSProviders
.getLength(); index
++ )
580 Reference
< container::XNameContainer
> xCont( xSProviders
[ index
], UNO_QUERY
);
587 xCont
->insertByName( aName
, aElement
);
595 if ( index
== xSProviders
.getLength() )
597 // No script providers could process the package
598 ::rtl::OUString message
= OUSTR("Failed to register package for ");
599 message
= message
.concat( aName
);
600 throw lang::IllegalArgumentException( message
,
601 Reference
< XInterface
> (), 2 );
606 //*************************************************************************
609 MasterScriptProvider::removeByName( const ::rtl::OUString
& Name
) throw ( container::NoSuchElementException
, lang::WrappedTargetException
, RuntimeException
)
613 if ( m_xMSPPkg
.is() )
615 Reference
< container::XNameContainer
> xCont( m_xMSPPkg
, UNO_QUERY
);
618 throw RuntimeException(
619 OUSTR("PackageMasterScriptProvider doesn't implement XNameContainer"),
620 Reference
< XInterface
>() );
622 xCont
->removeByName( Name
);
626 throw RuntimeException( OUSTR("PackageMasterScriptProvider is unitialised"),
627 Reference
< XInterface
>() );
633 if ( !Name
.getLength() )
635 throw lang::IllegalArgumentException( OUSTR("Name not set!!"),
636 Reference
< XInterface
> (), 1 );
638 // TODO for Script library pacakge url parse the language,
639 // for the moment will just try to get each provider to process remove/revoke
640 // request, the first one the succeeds will terminate processing
642 if ( !providerCache() )
644 throw RuntimeException(
645 OUSTR("removeByName() cannot instantiate "
646 "child script providers."),
647 Reference
< XInterface
>() );
649 Sequence
< Reference
< provider::XScriptProvider
> > xSProviders
=
650 providerCache()->getAllProviders();
652 for ( ; index
< xSProviders
.getLength(); index
++ )
654 Reference
< container::XNameContainer
> xCont( xSProviders
[ index
], UNO_QUERY
);
661 xCont
->removeByName( Name
);
669 if ( index
== xSProviders
.getLength() )
671 // No script providers could process the package
672 ::rtl::OUString message
= OUSTR("Failed to revoke package for ");
673 message
= message
.concat( Name
);
674 throw lang::IllegalArgumentException( message
,
675 Reference
< XInterface
> (), 1 );
681 //*************************************************************************
683 MasterScriptProvider::replaceByName( const ::rtl::OUString
& aName
, const Any
& aElement
) throw ( lang::IllegalArgumentException
, container::NoSuchElementException
, lang::WrappedTargetException
, RuntimeException
)
688 // TODO needs implementing
691 throw RuntimeException( OUSTR("replaceByName not implemented!!!!") ,
692 Reference
< XInterface
>() );
695 //*************************************************************************
697 MasterScriptProvider::getByName( const ::rtl::OUString
& aName
) throw ( container::NoSuchElementException
, lang::WrappedTargetException
, RuntimeException
)
701 // TODO needs to be implemented
705 throw RuntimeException( OUSTR("getByName not implemented!!!!") ,
706 Reference
< XInterface
>() );
710 //*************************************************************************
712 MasterScriptProvider::hasByName( const ::rtl::OUString
& aName
) throw (RuntimeException
)
714 sal_Bool result
= sal_False
;
717 if ( m_xMSPPkg
.is() )
719 Reference
< container::XNameContainer
> xCont( m_xMSPPkg
, UNO_QUERY
);
722 throw RuntimeException(
723 OUSTR("PackageMasterScriptProvider doesn't implement XNameContainer"),
724 Reference
< XInterface
>() );
727 result
= xCont
->hasByName( aName
);
731 throw RuntimeException( OUSTR("PackageMasterScriptProvider is unitialised"),
732 Reference
< XInterface
>() );
738 if ( !aName
.getLength() )
740 throw lang::IllegalArgumentException( OUSTR("Name not set!!"),
741 Reference
< XInterface
> (), 1 );
743 // TODO for Script library pacakge url parse the language,
744 // for the moment will just try to get each provider to see if the
745 // package exists in any provider, first one that succeed will
746 // terminate the loop
748 if ( !providerCache() )
750 throw RuntimeException(
751 OUSTR("removeByName() cannot instantiate "
752 "child script providers."),
753 Reference
< XInterface
>() );
755 Sequence
< Reference
< provider::XScriptProvider
> > xSProviders
=
756 providerCache()->getAllProviders();
757 for ( sal_Int32 index
= 0; index
< xSProviders
.getLength(); index
++ )
759 Reference
< container::XNameContainer
> xCont( xSProviders
[ index
], UNO_QUERY
);
766 result
= xCont
->hasByName( aName
);
767 if ( result
== sal_True
)
781 //*************************************************************************
782 Sequence
< ::rtl::OUString
> SAL_CALL
783 MasterScriptProvider::getElementNames( ) throw ( RuntimeException
)
785 // TODO needs implementing
786 Sequence
< ::rtl::OUString
> names
;
789 throw RuntimeException( OUSTR("getElementNames not implemented!!!!") ,
790 Reference
< XInterface
>() );
794 //*************************************************************************
796 MasterScriptProvider::getElementType( ) throw ( RuntimeException
)
798 // TODO needs implementing
802 //*************************************************************************
803 sal_Bool SAL_CALL
MasterScriptProvider::hasElements( ) throw ( RuntimeException
)
805 // TODO needs implementing
808 throw RuntimeException( OUSTR("hasElements not implemented!!!!") ,
809 Reference
< XInterface
>() );
814 //*************************************************************************
815 Sequence
< Reference
< provider::XScriptProvider
> > SAL_CALL
816 MasterScriptProvider::getAllProviders() throw ( css::uno::RuntimeException
)
818 if ( providerCache() )
820 return providerCache()->getAllProviders();
824 ::rtl::OUString errorMsg
= ::rtl::OUString::createFromAscii(
825 "MasterScriptProvider::getAllProviders, cache not initialised");
826 throw RuntimeException( errorMsg
.concat( errorMsg
),
827 Reference
< XInterface
>() );
832 //*************************************************************************
833 ::rtl::OUString SAL_CALL
MasterScriptProvider::getImplementationName( )
834 throw( RuntimeException
)
836 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
837 "com.sun.star.script.provider.MasterScriptProvider" ) );
840 //*************************************************************************
841 sal_Bool SAL_CALL
MasterScriptProvider::supportsService( const ::rtl::OUString
& serviceName
)
842 throw( RuntimeException
)
844 Sequence
< ::rtl::OUString
> serviceNames( getSupportedServiceNames() );
845 ::rtl::OUString
const * pNames
= serviceNames
.getConstArray();
846 for ( sal_Int32 nPos
= serviceNames
.getLength(); nPos
--; )
848 if ( serviceName
.equals( pNames
[ nPos
] ) )
856 //*************************************************************************
857 Sequence
< ::rtl::OUString
> SAL_CALL
MasterScriptProvider::getSupportedServiceNames( )
858 throw( RuntimeException
)
860 ::rtl::OUString names
[3];
862 names
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
863 "com.sun.star.script.provider.MasterScriptProvider" ) );
864 names
[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
865 "com.sun.star.script.browse.BrowseNode" ) );
866 names
[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
867 "com.sun.star.script.provider.ScriptProvider" ) );
869 return Sequence
< ::rtl::OUString
>( names
, 3 );
872 } // namespace func_provider
875 namespace browsenodefactory
877 ::rtl::OUString SAL_CALL
bnf_getImplementationName() ;
878 Reference
< XInterface
> SAL_CALL
bnf_create( Reference
< XComponentContext
> const & xComponentContext
);
879 Sequence
< ::rtl::OUString
> SAL_CALL
bnf_getSupportedServiceNames();
882 namespace scripting_runtimemgr
884 //*************************************************************************
885 Reference
< XInterface
> SAL_CALL
sp_create(
886 const Reference
< XComponentContext
> & xCompC
)
888 return ( cppu::OWeakObject
* ) new ::func_provider::MasterScriptProvider( xCompC
);
891 //*************************************************************************
892 Sequence
< ::rtl::OUString
> sp_getSupportedServiceNames( )
895 ::rtl::OUString names
[3];
897 names
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
898 "com.sun.star.script.provider.MasterScriptProvider" ) );
899 names
[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
900 "com.sun.star.script.browse.BrowseNode" ) );
901 names
[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
902 "com.sun.star.script.provider.ScriptProvider" ) );
904 return Sequence
< ::rtl::OUString
>( names
, 3 );
907 //*************************************************************************
908 ::rtl::OUString
sp_getImplementationName( )
911 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
912 "com.sun.star.script.provider.MasterScriptProvider" ) );
915 // ***** registration or ScriptingFrameworkURIHelper
916 Reference
< XInterface
> SAL_CALL
urihelper_create(
917 const Reference
< XComponentContext
> & xCompC
)
919 return ( cppu::OWeakObject
* )
920 new ::func_provider::ScriptingFrameworkURIHelper( xCompC
);
923 Sequence
< ::rtl::OUString
> urihelper_getSupportedServiceNames( )
926 ::rtl::OUString serviceNameList
[] = {
927 ::rtl::OUString::createFromAscii(
928 "com.sun.star.script.provider.ScriptURIHelper" ) };
930 Sequence
< ::rtl::OUString
> serviceNames
= Sequence
<
931 ::rtl::OUString
> ( serviceNameList
, 1 );
936 ::rtl::OUString
urihelper_getImplementationName( )
939 return ::rtl::OUString::createFromAscii(
940 "com.sun.star.script.provider.ScriptURIHelper");
943 static struct cppu::ImplementationEntry s_entries
[] =
946 sp_create
, sp_getImplementationName
,
947 sp_getSupportedServiceNames
, cppu::createSingleComponentFactory
,
952 urihelper_getImplementationName
,
953 urihelper_getSupportedServiceNames
,
954 cppu::createSingleComponentFactory
,
958 func_provider::mspf_create
, func_provider::mspf_getImplementationName
,
959 func_provider::mspf_getSupportedServiceNames
, cppu::createSingleComponentFactory
,
963 browsenodefactory::bnf_create
, browsenodefactory::bnf_getImplementationName
,
964 browsenodefactory::bnf_getSupportedServiceNames
, cppu::createSingleComponentFactory
,
971 //############################################################################
972 //#### EXPORTED ##############################################################
973 //############################################################################
976 * Gives the environment this component belongs to.
980 SAL_DLLPUBLIC_EXPORT
void SAL_CALL
component_getImplementationEnvironment(
981 const sal_Char
** ppEnvTypeName
, uno_Environment
** ppEnv
)
984 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
988 * This function creates an implementation section in the registry and another subkey
990 * for each supported service.
991 * @param pServiceManager the service manager
992 * @param pRegistryKey the registry key
994 SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
component_writeInfo(
995 lang::XMultiServiceFactory
* pServiceManager
,
996 registry::XRegistryKey
* pRegistryKey
)
998 if (::cppu::component_writeInfoHelper( pServiceManager
, pRegistryKey
,
999 ::scripting_runtimemgr::s_entries
))
1003 // MasterScriptProviderFactory Mangager singleton
1004 registry::XRegistryKey
* pKey
=
1005 reinterpret_cast< registry::XRegistryKey
* >(pRegistryKey
);
1007 Reference
< registry::XRegistryKey
>xKey
= pKey
->createKey(
1008 OUSTR("com.sun.star.script.provider.MasterScriptProviderFactory/UNO/SINGLETONS/com.sun.star.script.provider.theMasterScriptProviderFactory"));
1009 xKey
->setStringValue( OUSTR("com.sun.star.script.provider.MasterScriptProviderFactory") );
1010 // BrowseNodeFactory Mangager singleton
1011 xKey
= pKey
->createKey(
1012 OUSTR("com.sun.star.script.browse.BrowseNodeFactory/UNO/SINGLETONS/com.sun.star.script.browse.theBrowseNodeFactory"));
1013 xKey
->setStringValue( OUSTR("com.sun.star.script.browse.BrowseNodeFactory") );
1024 * This function is called to get service factories for an implementation.
1026 * @param pImplName name of implementation
1027 * @param pServiceManager a service manager, need for component creation
1028 * @param pRegistryKey the registry key for this component, need for persistent
1030 * @return a component factory
1032 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
component_getFactory(
1033 const sal_Char
* pImplName
,
1034 lang::XMultiServiceFactory
* pServiceManager
,
1035 registry::XRegistryKey
* pRegistryKey
)
1037 return ::cppu::component_getFactoryHelper( pImplName
, pServiceManager
,
1038 pRegistryKey
, ::scripting_runtimemgr::s_entries
);