merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / scripting / source / runtimemgr / ScriptNameResolverImpl.cxx
blob5a45a29b731b020880bb2b956ceb8556700ceffb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_scripting.hxx"
32 #include <vector>
33 #include <stdlib.h>
35 #include <cppuhelper/implementationentry.hxx>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/security/AccessControlException.hpp>
39 #include <util/util.hxx>
40 #include <util/scriptingconstants.hxx>
42 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
43 #include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp>
45 #include "ScriptNameResolverImpl.hxx"
46 #include "ScriptRuntimeManager.hxx"
48 using namespace ::rtl;
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::drafts::com::sun::star::script::framework;
53 namespace scripting_runtimemgr
56 const sal_Char* const LANGUAGE_TO_RESOLVE_ON[] = { "All" }; // should be configurable
57 OUString nrs_implName = OUString::createFromAscii(
58 "drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" );
59 OUString nrs_serviceName = OUString::createFromAscii(
60 "drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" );
61 Sequence< OUString > nrs_serviceNames = Sequence< OUString >( &nrs_serviceName, 1 );
63 const char* const SCRIPTSTORAGEMANAGER_SERVICE =
64 "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager";
66 extern ::rtl_StandardModuleCount s_moduleCount;
68 // define storages to search
69 static ::std::vector< sal_Int32 >* m_pSearchIDs = NULL;
71 //*************************************************************************
72 ScriptNameResolverImpl::ScriptNameResolverImpl(
73 const Reference< XComponentContext > & xContext ) :
74 m_xContext( xContext )
76 OSL_TRACE( "< ScriptNameResolverImpl ctor called >\n" );
77 validateXRef( m_xContext, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid context" );
78 m_xMultiComFac = m_xContext->getServiceManager();
80 validateXRef( m_xMultiComFac, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid XMultiComponentFactory " );
82 if( !m_pSearchIDs )
84 osl::Guard< osl::Mutex > aGuard( m_mutex );
85 if( !m_pSearchIDs )
87 scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
88 scripting_constants::ScriptingConstantsPool::instance();
89 m_pSearchIDs = new ::std::vector< sal_Int32 >();
90 m_pSearchIDs->push_back( scriptingConstantsPool.DOC_STORAGE_ID_NOT_SET );
91 m_pSearchIDs->push_back( scriptingConstantsPool.USER_STORAGE_ID );
92 m_pSearchIDs->push_back( scriptingConstantsPool.SHARED_STORAGE_ID );
96 s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt );
99 //*************************************************************************
100 ScriptNameResolverImpl::~ScriptNameResolverImpl()
102 OSL_TRACE( "< ScriptNameResolverImpl dtor called >\n" );
103 s_moduleCount.modCnt.release( &s_moduleCount.modCnt );
106 //*************************************************************************
107 Reference< storage::XScriptInfo > ScriptNameResolverImpl::resolve(
108 const ::rtl::OUString & scriptURI, Any& invocationCtx )
109 throw ( lang::IllegalArgumentException, script::CannotConvertException, RuntimeException )
112 Reference< storage::XScriptInfo > resolvedName;
113 Reference< beans::XPropertySet > xPropSetScriptingContext;
114 scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
115 scripting_constants::ScriptingConstantsPool::instance();
117 OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - start" );
119 if ( sal_False == ( invocationCtx >>= xPropSetScriptingContext ) )
121 throw RuntimeException( OUSTR(
122 "ScriptNameResolverImpl::resolve : unable to get XScriptingContext from param" ),
123 Reference< XInterface > () );
126 Any any;
127 OUString docUri;
128 sal_Int32 filesysScriptStorageID = -1;
129 Reference < storage::XScriptStorageManager > xScriptStorageMgr;
130 sal_Int32 docSid;
133 any = xPropSetScriptingContext->getPropertyValue(
134 scriptingConstantsPool.DOC_URI );
135 OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - got anyUri" );
136 if ( sal_False == ( any >>= docUri ) )
138 throw RuntimeException( OUSTR(
139 "ScriptNameResolverImpl::resolve : unable to get doc Uri from xPropSetScriptingContext" ),
140 Reference< XInterface > () );
142 any = xPropSetScriptingContext->getPropertyValue(
143 scriptingConstantsPool.DOC_STORAGE_ID );
144 if ( sal_False == ( any >>= docSid ) )
146 throw RuntimeException( OUSTR(
147 "ScriptNameResolverImpl::resolve : unable to get doc storage id from xPropSetScriptingContext" ),
148 Reference< XInterface > () );
151 catch ( Exception & e )
153 OUString temp = OUSTR(
154 "ScriptNameResolverImpl::resolve : problem with getPropertyValue" );
155 throw RuntimeException( temp.concat( e.Message ),
156 Reference< XInterface > () );
158 #ifdef _DEBUG
159 catch ( ... )
161 throw RuntimeException( OUSTR(
162 "ScriptNameResolverImpl::resolve Unknown Exception caught - RuntimeException rethrown" ),
163 Reference< XInterface > () );
165 #endif
168 ::rtl::OString docUriO(
169 ::rtl::OUStringToOString( docUri , RTL_TEXTENCODING_ASCII_US ) );
170 OSL_TRACE(
171 "ScriptNameResolverImpl::resolve: *** >>> DOC URI: %s, doc sid is %d\n",
172 docUriO.pData->buffer, docSid );
175 OSL_TRACE( "ScriptNameResolverImpl::resolve Starting..." );
176 OUString docString = OUString::createFromAscii( "location=document" );
177 OUString userString = OUString::createFromAscii( "location=user" );
178 OUString shareString = OUString::createFromAscii( "location=share" );
179 OUString filesysString = OUString::createFromAscii( "location=filesystem" );
181 // initialise vector with doc, user and share
183 // m_pSearchIDs is initialised as follows,
184 // m_pSearchIDs [ 0 ] empty
185 // m_pSearchIDs [ 1 ] user storage id
186 // m_pSearchIDs [ 2 ] share " "
188 ::std::vector< sal_Int32 > m_vSearchIDs = *m_pSearchIDs;
189 m_vSearchIDs[ 0 ] = docSid;
191 if ( scriptURI.indexOf( docString ) != -1 )
193 OSL_TRACE("Full resolution available, search document");
194 // search in document
195 m_vSearchIDs.resize( 1 );
197 else if ( scriptURI.indexOf( userString ) != -1 )
199 OSL_TRACE("Full resolution available, search user");
200 // search in user
201 m_vSearchIDs[ 0 ] = ( *m_pSearchIDs )[ 1 ];
202 m_vSearchIDs.resize( 1 );
204 else if ( scriptURI.indexOf( shareString ) != -1 )
206 OSL_TRACE("Full resolution available, search share");
207 // search in share
208 m_vSearchIDs[ 0 ] = ( *m_pSearchIDs )[ 2 ];
209 m_vSearchIDs.resize( 1 );
211 else if ( scriptURI.indexOf( filesysString ) != -1 )
213 OSL_TRACE("Full resolution available, create & search filesystem");
214 OUString filesysURL;
217 filesysURL = getFilesysURL( scriptURI );
219 catch ( lang::IllegalArgumentException & e )
221 OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: " );
222 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
224 Reference< XInterface > xInterface = m_xMultiComFac->createInstanceWithContext(
225 ::rtl::OUString::createFromAscii(
226 "com.sun.star.ucb.SimpleFileAccess" ), m_xContext );
227 validateXRef( xInterface,
228 "ScriptProvider::initialise: cannot get SimpleFileAccess Service\n" );
229 Reference < ucb::XSimpleFileAccess > xSimpleFileAccess = Reference <
230 ucb::XSimpleFileAccess > ( xInterface, UNO_QUERY_THROW );
232 // do we need to encode this? hope not.
233 OSL_TRACE( ">>>> About to create storage for %s",
234 ::rtl::OUStringToOString( filesysURL,
235 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
236 // ask storage manager to create storage
239 // need to get the ScriptStorageManager
240 Any a = m_xContext->getValueByName(
241 scriptingConstantsPool.SCRIPTSTORAGEMANAGER_SERVICE );
242 if ( sal_False == ( a >>= xScriptStorageMgr ) )
244 OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: failed to get ScriptStorageManager" );
245 throw RuntimeException( temp, Reference< XInterface >() );
246 // need to throw
248 validateXRef( xScriptStorageMgr, "Cannot get ScriptStorageManager" );
249 filesysScriptStorageID =
250 xScriptStorageMgr->createScriptStorageWithURI(
251 xSimpleFileAccess, filesysURL );
252 OSL_TRACE( ">>>> Created storage %d - for %s ",
253 filesysScriptStorageID, ::rtl::OUStringToOString(
254 filesysURL, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
256 catch ( RuntimeException & e )
258 OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: " );
259 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
261 m_vSearchIDs[ 0 ] = filesysScriptStorageID;
262 m_vSearchIDs.resize( 1 );
264 else
266 OSL_TRACE("Only partial uri available, search doc, user & share");
267 // is this illegal or do we search in a default way
268 // if we get to here a uri has been passed in that has:
269 // a) not got a location specified
270 // b) an illegal location
272 // detect illegal location
273 if ( scriptURI.indexOf( OUString::createFromAscii( "location=" ) ) != -1 )
275 OSL_TRACE(
276 "ScriptNameResolver::resolve, throwing IllegalArgException" );
277 throw lang::IllegalArgumentException(
278 OUSTR( "invalid URI: " ).concat( scriptURI ),
279 Reference < XInterface > (), 1 );
282 // leave vSearchIDs take care of the search...
285 ::std::vector< sal_Int32 >::const_iterator iter;
286 ::std::vector< sal_Int32 >::const_iterator iterEnd = m_vSearchIDs.end();
288 for ( iter = m_vSearchIDs.begin() ; iter != iterEnd; ++iter )
292 OSL_TRACE( "** about to resolve from storage using id %d from vector of size %d",
293 *iter, m_vSearchIDs.size() );
294 if ( ( resolvedName = resolveURIFromStorageID( *iter, docUri, scriptURI ) ).is() )
296 OSL_TRACE( "found match in uri from storage %d", *iter );
297 xPropSetScriptingContext->setPropertyValue(
298 scriptingConstantsPool.RESOLVED_STORAGE_ID, makeAny(*iter) );
299 break;
303 catch ( css::security::AccessControlException & e )
305 // no execute permission
306 OSL_TRACE( "ScriptNameResolverImpl::resolve : AccessControlException " );
307 continue;
309 catch ( beans::UnknownPropertyException & e )
311 OUString temp = OUSTR(
312 "ScriptNameResolverImpl::resolve : UnknownPropertyException" );
313 throw RuntimeException( temp.concat( e.Message ),
314 Reference< XInterface > () );
316 catch ( beans::PropertyVetoException & e )
318 OUString temp = OUSTR(
319 "ScriptNameResolverImpl::resolve : PropertyVetoException " );
320 throw RuntimeException( temp.concat( e.Message ),
321 Reference< XInterface > () );
323 catch ( lang::IllegalArgumentException & e )
325 OUString temp = OUSTR(
326 "ScriptNameResolverImpl::resolve : IllegalArgumentException " );
327 throw lang::IllegalArgumentException( temp.concat( e.Message ),
328 Reference< XInterface > (), e.ArgumentPosition );
330 catch ( lang::WrappedTargetException & e )
332 OUString temp = OUSTR(
333 "ScriptNameResolverImpl::resolve : WrappedTargetException " );
334 throw RuntimeException( temp.concat( e.Message ),
335 Reference< XInterface > () );
337 catch ( Exception & e )
339 OSL_TRACE(
340 "Exception thrown by storage %d, failed to match uri: %s",
341 *iter,
342 ::rtl::OUStringToOString( e.Message,
343 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
344 OUString temp = OUSTR(
345 "ScriptNameResolverImpl::resolve : unknown exception" );
346 throw RuntimeException( temp.concat( e.Message ),
347 Reference< XInterface > () );
349 #ifdef _DEBUG
350 catch ( ... )
352 OSL_TRACE(
353 "unknown exception thrown by storage %d, failed to match uri",
354 *iter );
355 OUString temp = OUSTR(
356 "ScriptNameResolverImpl::resolve Unknown exception caught - RuntimeException rethrown" );
357 throw RuntimeException( temp,
358 Reference< XInterface > () );
360 #endif
363 if ( !resolvedName.is() )
365 if( filesysScriptStorageID > 2 )
367 // get the filesys storage and dispose of it
368 Reference< XInterface > xScriptStorage =
369 xScriptStorageMgr->getScriptStorage( filesysScriptStorageID );
370 validateXRef( xScriptStorage,
371 "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" );
372 Reference< storage::XScriptInfoAccess > xScriptInfoAccess = Reference<
373 storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW );
374 validateXRef( xScriptInfoAccess,
375 "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptInfoAccess" );
376 Sequence< Reference< storage::XScriptInfo > > results =
377 xScriptInfoAccess->getAllImplementations( );
378 Reference < lang::XEventListener > xEL_ScriptStorageMgr =
379 Reference< lang::XEventListener >
380 ( xScriptStorageMgr ,UNO_QUERY_THROW );
381 validateXRef( xEL_ScriptStorageMgr, "ScriptNameResolverImpl::resolve: can't get ScriptStorageManager XEventListener interface when trying to dispose of filesystem storage" );
382 lang::EventObject event( results[ 0 ] );
383 xEL_ScriptStorageMgr->disposing( event );
385 throw lang::IllegalArgumentException( OUSTR(
386 "ScriptNameResolverImpl::resolve: no script found for uri=" ).concat( scriptURI ),
387 Reference< XInterface > (), 0 );
389 return resolvedName;
392 //*************************************************************************
393 OUString SAL_CALL
394 ScriptNameResolverImpl::getImplementationName( )
395 throw( RuntimeException )
397 return nrs_implName;
400 //*************************************************************************
401 sal_Bool SAL_CALL
402 ScriptNameResolverImpl::supportsService( const OUString& serviceName )
403 throw( RuntimeException )
405 OUString const * pNames = nrs_serviceNames.getConstArray();
406 for ( sal_Int32 nPos = nrs_serviceNames.getLength(); nPos--; )
408 if ( serviceName.equals( pNames[ nPos ] ) )
410 return sal_True;
413 return sal_False;
416 //*************************************************************************
418 Reference< storage::XScriptInfo >
419 ScriptNameResolverImpl::resolveURIFromStorageID
420 ( sal_Int32 sid, const ::rtl::OUString & docURI,
421 const ::rtl::OUString& scriptURI )
422 SAL_THROW ( ( lang::IllegalArgumentException, css::security::AccessControlException, RuntimeException ) )
424 Reference< storage::XScriptInfo > resolvedScriptInfo;
425 scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
426 scripting_constants::ScriptingConstantsPool::instance();
427 if ( sid == scriptingConstantsPool.DOC_STORAGE_ID_NOT_SET )
429 OSL_TRACE( "@@@@ **** ScriptNameResolverImpl::resolve DOC_STORAGE_ID_NOT_SET" );
430 return resolvedScriptInfo;
434 OUString permissionURI = docURI;
435 OUString filesysString = OUString::createFromAscii( "location=filesystem" );
436 if ( scriptURI.indexOf( filesysString ) != -1 )
438 // in the case of filesys scripts we're checking whether the
439 // location of the script, rather than the location of the document,
440 // has execute permission
443 permissionURI = getFilesysURL( scriptURI );
445 catch ( lang::IllegalArgumentException & e )
447 OUString temp = OUSTR( "ScriptNameResolverImpl::resolveFromURI: " );
448 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
451 Reference< storage::XScriptInfoAccess > storage = getStorageInstance( sid, permissionURI );
452 validateXRef( storage,
453 "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptInfoAccess" );
454 Sequence< Reference< storage::XScriptInfo > > results =
455 storage->getImplementations( scriptURI );
457 const sal_Int32 length = results.getLength();
459 if ( !length )
461 return resolvedScriptInfo;
464 OSL_TRACE( "ScriptNameResolverImpl::resolve Got some results..." );
465 // if we get results, just return first in list,
466 // storage has already matched language, function name etc. if
467 // that information was in the uri
468 resolvedScriptInfo = results[ 0 ];
470 catch ( css::security::AccessControlException & ace )
472 OUString temp = OUSTR(
473 "ScriptRuntimeManager::resolveURIFromStorageID AccessControlException: " );
474 throw css::security::AccessControlException( temp.concat( ace.Message ),
475 Reference< XInterface > (),
476 ace.LackingPermission );
478 catch ( lang::IllegalArgumentException & iae )
480 OUString temp = OUSTR(
481 "ScriptRuntimeManager::resolveURIFromStorageID IllegalArgumentException: " );
482 throw lang::IllegalArgumentException( temp.concat( iae.Message ),
483 Reference< XInterface > (),
484 iae.ArgumentPosition );
486 catch ( RuntimeException & re )
488 OUString temp = OUSTR(
489 "ScriptRuntimeManager::resolveURIFromStorageID RuntimeException: " );
490 throw RuntimeException( temp.concat( re.Message ),
491 Reference< XInterface > () );
493 catch ( Exception & e )
495 OUString temp = OUSTR(
496 "ScriptNameResolverImpl::resolveURIFromStorageID : Exception caught - RuntimeException rethrown" );
497 throw RuntimeException( temp.concat( e.Message ),
498 Reference< XInterface > () );
500 #ifdef _DEBUG
501 catch ( ... )
503 throw RuntimeException( OUSTR(
504 "ScriptNameResolverImpl::resolveURIFromStorageID Unknown exception caught - RuntimeException rethrown" ),
505 Reference< XInterface > () );
507 #endif
508 return resolvedScriptInfo;
510 //*************************************************************************
512 Reference< storage::XScriptInfoAccess >
514 ScriptNameResolverImpl::getStorageInstance( sal_Int32 sid,
515 const ::rtl::OUString & permissionURI ) SAL_THROW ( ( RuntimeException, css::security::AccessControlException, lang::IllegalArgumentException ) )
517 Reference< storage::XScriptInfoAccess > xScriptInfoAccess;
520 Reference< XInterface > xInterface;
522 Any a = m_xContext->getValueByName(
523 OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) );
524 if ( sal_False == ( a >>= xInterface ) )
526 throw RuntimeException(
527 OUSTR( "ScriptNameResolverImpl::getStorageInstance: could not obtain ScriptStorageManager singleton" ),
528 Reference< XInterface >() );
530 validateXRef( xInterface,
531 "ScriptNameResolverImpl::getStorageInstance: cannot get Storage service" );
532 // check that we have permissions for this storage
533 Reference< dcsssf::security::XScriptSecurity > xScriptSecurity( xInterface, UNO_QUERY_THROW );
534 validateXRef( xScriptSecurity,
535 "ScriptNameResolverImpl::getStorageInstance: cannot get Script Security service" );
536 scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
537 scripting_constants::ScriptingConstantsPool::instance();
538 // if we dealing with a document storage (ie. not user or share
539 // we need to check the permission
540 if( ( sid != scriptingConstantsPool.USER_STORAGE_ID ) &&
541 ( sid != scriptingConstantsPool.SHARED_STORAGE_ID ) )
543 xScriptSecurity->checkPermission( permissionURI,
544 OUString::createFromAscii( "execute" ) );
545 // if we get here, the checkPermission hasn't thrown an
546 // AccessControlException, ie. permission has been granted
547 OSL_TRACE( "ScriptNameResolverImpl::getStorageInstance: got execute permission for ID=%d", sid );
549 Reference< storage::XScriptStorageManager > xScriptStorageManager( xInterface, UNO_QUERY_THROW );
550 validateXRef( xScriptStorageManager,
551 "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage Manager service" );
552 Reference< XInterface > xScriptStorage =
553 xScriptStorageManager->getScriptStorage( sid );
554 validateXRef( xScriptStorage,
555 "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" );
556 xScriptInfoAccess = Reference<
557 storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW );
559 catch ( lang::IllegalArgumentException & e )
561 OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
562 throw lang::IllegalArgumentException( temp.concat( e.Message ),
563 Reference< XInterface >(), e.ArgumentPosition );
565 catch ( css::security::AccessControlException & e )
567 OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: AccessControlException " );
568 throw css::security::AccessControlException( temp.concat( e.Message ), Reference< XInterface >(), e.LackingPermission );
570 catch ( RuntimeException & re )
572 OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
573 throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
575 catch ( Exception & e )
577 OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
578 throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
580 return xScriptInfoAccess;
582 //*************************************************************************
583 OUString
584 ScriptNameResolverImpl::getFilesysURL( const OUString & scriptURI )
585 throw( lang::IllegalArgumentException )
587 OUString filePath;
588 OUString fileName;
589 OUString filesysString = OUString::createFromAscii( "location=filesystem" );
590 sal_Int32 locationPos = scriptURI.indexOf( filesysString );
591 // expect location=filesys:file:///foo/bar/myscript.bsh etc
592 // except the file url at this point is encoded
593 // so we should be ok searching for the '&'
594 sal_Int32 filesysStrLen = filesysString.getLength() + 1;
595 sal_Int32 endOfLocn = scriptURI.indexOf( '&', locationPos );
596 if (endOfLocn == -1 )
598 filePath = scriptURI.copy( locationPos + filesysString.getLength() + 1 );
600 else
602 filePath = scriptURI.copy( locationPos + filesysStrLen,
603 endOfLocn - locationPos - filesysStrLen );
605 //file name shoul also be encoded so again ok to search for '&'
606 OUString functionKey = OUString::createFromAscii( "function=" );
607 sal_Int32 functionKeyLength = functionKey.getLength();
608 sal_Int32 functionNamePos = scriptURI.indexOf( functionKey );
609 if ( functionNamePos > 0 )
611 sal_Int32 endOfFn = scriptURI.indexOf( '&', functionNamePos );
612 if ( endOfFn == -1 )
614 fileName = scriptURI.copy( functionNamePos + functionKeyLength );
616 else
618 fileName = scriptURI.copy( functionNamePos + functionKeyLength,
619 endOfFn - functionNamePos - functionKeyLength );
622 else
624 // we need to throw
625 OUString temp = OUSTR( "ScriptNameResolverImpl::getFilesysURL: error getting the filesysURL" );
626 throw lang::IllegalArgumentException( temp, Reference< XInterface >(), 0 );
628 filePath+=fileName;
629 OSL_TRACE( "ScriptNameResolverImpl::getFilesysURL: filesys URL = %s",
630 ::rtl::OUStringToOString( filePath,
631 RTL_TEXTENCODING_ASCII_US ).pData->buffer );
632 return filePath;
634 //*************************************************************************
635 Sequence<OUString> SAL_CALL
636 ScriptNameResolverImpl::getSupportedServiceNames( )
637 throw( RuntimeException )
639 return nrs_serviceNames;
642 //*************************************************************************
643 Reference< XInterface > SAL_CALL scriptnri_create(
644 Reference< XComponentContext > const & xComponentContext )
645 SAL_THROW( ( Exception ) )
647 return ( cppu::OWeakObject * ) new ScriptNameResolverImpl( xComponentContext );
650 //*************************************************************************
651 Sequence< OUString > scriptnri_getSupportedServiceNames() SAL_THROW( () )
653 return nrs_serviceNames;
656 //*************************************************************************
657 OUString scriptnri_getImplementationName() SAL_THROW( () )
659 return nrs_implName;
661 } // namespace scripting_runtimemgr
663 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */