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