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: ScriptNameResolverImpl.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"
37 #include <cppuhelper/implementationentry.hxx>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/security/AccessControlException.hpp>
41 #include <util/util.hxx>
42 #include <util/scriptingconstants.hxx>
44 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
45 #include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp>
47 #include "ScriptNameResolverImpl.hxx"
48 #include "ScriptRuntimeManager.hxx"
50 using namespace ::rtl
;
51 using namespace ::com::sun::star
;
52 using namespace ::com::sun::star::uno
;
53 using namespace ::drafts::com::sun::star::script::framework
;
55 namespace scripting_runtimemgr
58 const sal_Char
* const LANGUAGE_TO_RESOLVE_ON
[] = { "All" }; // should be configurable
59 OUString nrs_implName
= OUString::createFromAscii(
60 "drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" );
61 OUString nrs_serviceName
= OUString::createFromAscii(
62 "drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" );
63 Sequence
< OUString
> nrs_serviceNames
= Sequence
< OUString
>( &nrs_serviceName
, 1 );
65 const char* const SCRIPTSTORAGEMANAGER_SERVICE
=
66 "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager";
68 extern ::rtl_StandardModuleCount s_moduleCount
;
70 // define storages to search
71 static ::std::vector
< sal_Int32
>* m_pSearchIDs
= NULL
;
73 //*************************************************************************
74 ScriptNameResolverImpl::ScriptNameResolverImpl(
75 const Reference
< XComponentContext
> & xContext
) :
76 m_xContext( xContext
)
78 OSL_TRACE( "< ScriptNameResolverImpl ctor called >\n" );
79 validateXRef( m_xContext
, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid context" );
80 m_xMultiComFac
= m_xContext
->getServiceManager();
82 validateXRef( m_xMultiComFac
, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid XMultiComponentFactory " );
86 osl::Guard
< osl::Mutex
> aGuard( m_mutex
);
89 scripting_constants::ScriptingConstantsPool
& scriptingConstantsPool
=
90 scripting_constants::ScriptingConstantsPool::instance();
91 m_pSearchIDs
= new ::std::vector
< sal_Int32
>();
92 m_pSearchIDs
->push_back( scriptingConstantsPool
.DOC_STORAGE_ID_NOT_SET
);
93 m_pSearchIDs
->push_back( scriptingConstantsPool
.USER_STORAGE_ID
);
94 m_pSearchIDs
->push_back( scriptingConstantsPool
.SHARED_STORAGE_ID
);
98 s_moduleCount
.modCnt
.acquire( &s_moduleCount
.modCnt
);
101 //*************************************************************************
102 ScriptNameResolverImpl::~ScriptNameResolverImpl()
104 OSL_TRACE( "< ScriptNameResolverImpl dtor called >\n" );
105 s_moduleCount
.modCnt
.release( &s_moduleCount
.modCnt
);
108 //*************************************************************************
109 Reference
< storage::XScriptInfo
> ScriptNameResolverImpl::resolve(
110 const ::rtl::OUString
& scriptURI
, Any
& invocationCtx
)
111 throw ( lang::IllegalArgumentException
, script::CannotConvertException
, RuntimeException
)
114 Reference
< storage::XScriptInfo
> resolvedName
;
115 Reference
< beans::XPropertySet
> xPropSetScriptingContext
;
116 scripting_constants::ScriptingConstantsPool
& scriptingConstantsPool
=
117 scripting_constants::ScriptingConstantsPool::instance();
119 OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - start" );
121 if ( sal_False
== ( invocationCtx
>>= xPropSetScriptingContext
) )
123 throw RuntimeException( OUSTR(
124 "ScriptNameResolverImpl::resolve : unable to get XScriptingContext from param" ),
125 Reference
< XInterface
> () );
130 sal_Int32 filesysScriptStorageID
= -1;
131 Reference
< storage::XScriptStorageManager
> xScriptStorageMgr
;
135 any
= xPropSetScriptingContext
->getPropertyValue(
136 scriptingConstantsPool
.DOC_URI
);
137 OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - got anyUri" );
138 if ( sal_False
== ( any
>>= docUri
) )
140 throw RuntimeException( OUSTR(
141 "ScriptNameResolverImpl::resolve : unable to get doc Uri from xPropSetScriptingContext" ),
142 Reference
< XInterface
> () );
144 any
= xPropSetScriptingContext
->getPropertyValue(
145 scriptingConstantsPool
.DOC_STORAGE_ID
);
146 if ( sal_False
== ( any
>>= docSid
) )
148 throw RuntimeException( OUSTR(
149 "ScriptNameResolverImpl::resolve : unable to get doc storage id from xPropSetScriptingContext" ),
150 Reference
< XInterface
> () );
153 catch ( Exception
& e
)
155 OUString temp
= OUSTR(
156 "ScriptNameResolverImpl::resolve : problem with getPropertyValue" );
157 throw RuntimeException( temp
.concat( e
.Message
),
158 Reference
< XInterface
> () );
163 throw RuntimeException( OUSTR(
164 "ScriptNameResolverImpl::resolve Unknown Exception caught - RuntimeException rethrown" ),
165 Reference
< XInterface
> () );
170 ::rtl::OString
docUriO(
171 ::rtl::OUStringToOString( docUri
, RTL_TEXTENCODING_ASCII_US
) );
173 "ScriptNameResolverImpl::resolve: *** >>> DOC URI: %s, doc sid is %d\n",
174 docUriO
.pData
->buffer
, docSid
);
177 OSL_TRACE( "ScriptNameResolverImpl::resolve Starting..." );
178 OUString docString
= OUString::createFromAscii( "location=document" );
179 OUString userString
= OUString::createFromAscii( "location=user" );
180 OUString shareString
= OUString::createFromAscii( "location=share" );
181 OUString filesysString
= OUString::createFromAscii( "location=filesystem" );
183 // initialise vector with doc, user and share
185 // m_pSearchIDs is initialised as follows,
186 // m_pSearchIDs [ 0 ] empty
187 // m_pSearchIDs [ 1 ] user storage id
188 // m_pSearchIDs [ 2 ] share " "
190 ::std::vector
< sal_Int32
> m_vSearchIDs
= *m_pSearchIDs
;
191 m_vSearchIDs
[ 0 ] = docSid
;
193 if ( scriptURI
.indexOf( docString
) != -1 )
195 OSL_TRACE("Full resolution available, search document");
196 // search in document
197 m_vSearchIDs
.resize( 1 );
199 else if ( scriptURI
.indexOf( userString
) != -1 )
201 OSL_TRACE("Full resolution available, search user");
203 m_vSearchIDs
[ 0 ] = ( *m_pSearchIDs
)[ 1 ];
204 m_vSearchIDs
.resize( 1 );
206 else if ( scriptURI
.indexOf( shareString
) != -1 )
208 OSL_TRACE("Full resolution available, search share");
210 m_vSearchIDs
[ 0 ] = ( *m_pSearchIDs
)[ 2 ];
211 m_vSearchIDs
.resize( 1 );
213 else if ( scriptURI
.indexOf( filesysString
) != -1 )
215 OSL_TRACE("Full resolution available, create & search filesystem");
219 filesysURL
= getFilesysURL( scriptURI
);
221 catch ( lang::IllegalArgumentException
& e
)
223 OUString temp
= OUSTR( "ScriptNameResolverImpl::resolve: " );
224 throw RuntimeException( temp
.concat( e
.Message
), Reference
< XInterface
>() );
226 Reference
< XInterface
> xInterface
= m_xMultiComFac
->createInstanceWithContext(
227 ::rtl::OUString::createFromAscii(
228 "com.sun.star.ucb.SimpleFileAccess" ), m_xContext
);
229 validateXRef( xInterface
,
230 "ScriptProvider::initialise: cannot get SimpleFileAccess Service\n" );
231 Reference
< ucb::XSimpleFileAccess
> xSimpleFileAccess
= Reference
<
232 ucb::XSimpleFileAccess
> ( xInterface
, UNO_QUERY_THROW
);
234 // do we need to encode this? hope not.
235 OSL_TRACE( ">>>> About to create storage for %s",
236 ::rtl::OUStringToOString( filesysURL
,
237 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
238 // ask storage manager to create storage
241 // need to get the ScriptStorageManager
242 Any a
= m_xContext
->getValueByName(
243 scriptingConstantsPool
.SCRIPTSTORAGEMANAGER_SERVICE
);
244 if ( sal_False
== ( a
>>= xScriptStorageMgr
) )
246 OUString temp
= OUSTR( "ScriptNameResolverImpl::resolve: failed to get ScriptStorageManager" );
247 throw RuntimeException( temp
, Reference
< XInterface
>() );
250 validateXRef( xScriptStorageMgr
, "Cannot get ScriptStorageManager" );
251 filesysScriptStorageID
=
252 xScriptStorageMgr
->createScriptStorageWithURI(
253 xSimpleFileAccess
, filesysURL
);
254 OSL_TRACE( ">>>> Created storage %d - for %s ",
255 filesysScriptStorageID
, ::rtl::OUStringToOString(
256 filesysURL
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
258 catch ( RuntimeException
& e
)
260 OUString temp
= OUSTR( "ScriptNameResolverImpl::resolve: " );
261 throw RuntimeException( temp
.concat( e
.Message
), Reference
< XInterface
>() );
263 m_vSearchIDs
[ 0 ] = filesysScriptStorageID
;
264 m_vSearchIDs
.resize( 1 );
268 OSL_TRACE("Only partial uri available, search doc, user & share");
269 // is this illegal or do we search in a default way
270 // if we get to here a uri has been passed in that has:
271 // a) not got a location specified
272 // b) an illegal location
274 // detect illegal location
275 if ( scriptURI
.indexOf( OUString::createFromAscii( "location=" ) ) != -1 )
278 "ScriptNameResolver::resolve, throwing IllegalArgException" );
279 throw lang::IllegalArgumentException(
280 OUSTR( "invalid URI: " ).concat( scriptURI
),
281 Reference
< XInterface
> (), 1 );
284 // leave vSearchIDs take care of the search...
287 ::std::vector
< sal_Int32
>::const_iterator iter
;
288 ::std::vector
< sal_Int32
>::const_iterator iterEnd
= m_vSearchIDs
.end();
290 for ( iter
= m_vSearchIDs
.begin() ; iter
!= iterEnd
; ++iter
)
294 OSL_TRACE( "** about to resolve from storage using id %d from vector of size %d",
295 *iter
, m_vSearchIDs
.size() );
296 if ( ( resolvedName
= resolveURIFromStorageID( *iter
, docUri
, scriptURI
) ).is() )
298 OSL_TRACE( "found match in uri from storage %d", *iter
);
299 xPropSetScriptingContext
->setPropertyValue(
300 scriptingConstantsPool
.RESOLVED_STORAGE_ID
, makeAny(*iter
) );
305 catch ( css::security::AccessControlException
& e
)
307 // no execute permission
308 OSL_TRACE( "ScriptNameResolverImpl::resolve : AccessControlException " );
311 catch ( beans::UnknownPropertyException
& e
)
313 OUString temp
= OUSTR(
314 "ScriptNameResolverImpl::resolve : UnknownPropertyException" );
315 throw RuntimeException( temp
.concat( e
.Message
),
316 Reference
< XInterface
> () );
318 catch ( beans::PropertyVetoException
& e
)
320 OUString temp
= OUSTR(
321 "ScriptNameResolverImpl::resolve : PropertyVetoException " );
322 throw RuntimeException( temp
.concat( e
.Message
),
323 Reference
< XInterface
> () );
325 catch ( lang::IllegalArgumentException
& e
)
327 OUString temp
= OUSTR(
328 "ScriptNameResolverImpl::resolve : IllegalArgumentException " );
329 throw lang::IllegalArgumentException( temp
.concat( e
.Message
),
330 Reference
< XInterface
> (), e
.ArgumentPosition
);
332 catch ( lang::WrappedTargetException
& e
)
334 OUString temp
= OUSTR(
335 "ScriptNameResolverImpl::resolve : WrappedTargetException " );
336 throw RuntimeException( temp
.concat( e
.Message
),
337 Reference
< XInterface
> () );
339 catch ( Exception
& e
)
342 "Exception thrown by storage %d, failed to match uri: %s",
344 ::rtl::OUStringToOString( e
.Message
,
345 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
346 OUString temp
= OUSTR(
347 "ScriptNameResolverImpl::resolve : unknown exception" );
348 throw RuntimeException( temp
.concat( e
.Message
),
349 Reference
< XInterface
> () );
355 "unknown exception thrown by storage %d, failed to match uri",
357 OUString temp
= OUSTR(
358 "ScriptNameResolverImpl::resolve Unknown exception caught - RuntimeException rethrown" );
359 throw RuntimeException( temp
,
360 Reference
< XInterface
> () );
365 if ( !resolvedName
.is() )
367 if( filesysScriptStorageID
> 2 )
369 // get the filesys storage and dispose of it
370 Reference
< XInterface
> xScriptStorage
=
371 xScriptStorageMgr
->getScriptStorage( filesysScriptStorageID
);
372 validateXRef( xScriptStorage
,
373 "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" );
374 Reference
< storage::XScriptInfoAccess
> xScriptInfoAccess
= Reference
<
375 storage::XScriptInfoAccess
> ( xScriptStorage
, UNO_QUERY_THROW
);
376 validateXRef( xScriptInfoAccess
,
377 "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptInfoAccess" );
378 Sequence
< Reference
< storage::XScriptInfo
> > results
=
379 xScriptInfoAccess
->getAllImplementations( );
380 Reference
< lang::XEventListener
> xEL_ScriptStorageMgr
=
381 Reference
< lang::XEventListener
>
382 ( xScriptStorageMgr
,UNO_QUERY_THROW
);
383 validateXRef( xEL_ScriptStorageMgr
, "ScriptNameResolverImpl::resolve: can't get ScriptStorageManager XEventListener interface when trying to dispose of filesystem storage" );
384 lang::EventObject
event( results
[ 0 ] );
385 xEL_ScriptStorageMgr
->disposing( event
);
387 throw lang::IllegalArgumentException( OUSTR(
388 "ScriptNameResolverImpl::resolve: no script found for uri=" ).concat( scriptURI
),
389 Reference
< XInterface
> (), 0 );
394 //*************************************************************************
396 ScriptNameResolverImpl::getImplementationName( )
397 throw( RuntimeException
)
402 //*************************************************************************
404 ScriptNameResolverImpl::supportsService( const OUString
& serviceName
)
405 throw( RuntimeException
)
407 OUString
const * pNames
= nrs_serviceNames
.getConstArray();
408 for ( sal_Int32 nPos
= nrs_serviceNames
.getLength(); nPos
--; )
410 if ( serviceName
.equals( pNames
[ nPos
] ) )
418 //*************************************************************************
420 Reference
< storage::XScriptInfo
>
421 ScriptNameResolverImpl::resolveURIFromStorageID
422 ( sal_Int32 sid
, const ::rtl::OUString
& docURI
,
423 const ::rtl::OUString
& scriptURI
)
424 SAL_THROW ( ( lang::IllegalArgumentException
, css::security::AccessControlException
, RuntimeException
) )
426 Reference
< storage::XScriptInfo
> resolvedScriptInfo
;
427 scripting_constants::ScriptingConstantsPool
& scriptingConstantsPool
=
428 scripting_constants::ScriptingConstantsPool::instance();
429 if ( sid
== scriptingConstantsPool
.DOC_STORAGE_ID_NOT_SET
)
431 OSL_TRACE( "@@@@ **** ScriptNameResolverImpl::resolve DOC_STORAGE_ID_NOT_SET" );
432 return resolvedScriptInfo
;
436 OUString permissionURI
= docURI
;
437 OUString filesysString
= OUString::createFromAscii( "location=filesystem" );
438 if ( scriptURI
.indexOf( filesysString
) != -1 )
440 // in the case of filesys scripts we're checking whether the
441 // location of the script, rather than the location of the document,
442 // has execute permission
445 permissionURI
= getFilesysURL( scriptURI
);
447 catch ( lang::IllegalArgumentException
& e
)
449 OUString temp
= OUSTR( "ScriptNameResolverImpl::resolveFromURI: " );
450 throw RuntimeException( temp
.concat( e
.Message
), Reference
< XInterface
>() );
453 Reference
< storage::XScriptInfoAccess
> storage
= getStorageInstance( sid
, permissionURI
);
454 validateXRef( storage
,
455 "ScriptNameResolverImpl::resolveURIFromStorageID: cannot get XScriptInfoAccess" );
456 Sequence
< Reference
< storage::XScriptInfo
> > results
=
457 storage
->getImplementations( scriptURI
);
459 const sal_Int32 length
= results
.getLength();
463 return resolvedScriptInfo
;
466 OSL_TRACE( "ScriptNameResolverImpl::resolve Got some results..." );
467 // if we get results, just return first in list,
468 // storage has already matched language, function name etc. if
469 // that information was in the uri
470 resolvedScriptInfo
= results
[ 0 ];
472 catch ( css::security::AccessControlException
& ace
)
474 OUString temp
= OUSTR(
475 "ScriptRuntimeManager::resolveURIFromStorageID AccessControlException: " );
476 throw css::security::AccessControlException( temp
.concat( ace
.Message
),
477 Reference
< XInterface
> (),
478 ace
.LackingPermission
);
480 catch ( lang::IllegalArgumentException
& iae
)
482 OUString temp
= OUSTR(
483 "ScriptRuntimeManager::resolveURIFromStorageID IllegalArgumentException: " );
484 throw lang::IllegalArgumentException( temp
.concat( iae
.Message
),
485 Reference
< XInterface
> (),
486 iae
.ArgumentPosition
);
488 catch ( RuntimeException
& re
)
490 OUString temp
= OUSTR(
491 "ScriptRuntimeManager::resolveURIFromStorageID RuntimeException: " );
492 throw RuntimeException( temp
.concat( re
.Message
),
493 Reference
< XInterface
> () );
495 catch ( Exception
& e
)
497 OUString temp
= OUSTR(
498 "ScriptNameResolverImpl::resolveURIFromStorageID : Exception caught - RuntimeException rethrown" );
499 throw RuntimeException( temp
.concat( e
.Message
),
500 Reference
< XInterface
> () );
505 throw RuntimeException( OUSTR(
506 "ScriptNameResolverImpl::resolveURIFromStorageID Unknown exception caught - RuntimeException rethrown" ),
507 Reference
< XInterface
> () );
510 return resolvedScriptInfo
;
512 //*************************************************************************
514 Reference
< storage::XScriptInfoAccess
>
516 ScriptNameResolverImpl::getStorageInstance( sal_Int32 sid
,
517 const ::rtl::OUString
& permissionURI
) SAL_THROW ( ( RuntimeException
, css::security::AccessControlException
, lang::IllegalArgumentException
) )
519 Reference
< storage::XScriptInfoAccess
> xScriptInfoAccess
;
522 Reference
< XInterface
> xInterface
;
524 Any a
= m_xContext
->getValueByName(
525 OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE
) );
526 if ( sal_False
== ( a
>>= xInterface
) )
528 throw RuntimeException(
529 OUSTR( "ScriptNameResolverImpl::getStorageInstance: could not obtain ScriptStorageManager singleton" ),
530 Reference
< XInterface
>() );
532 validateXRef( xInterface
,
533 "ScriptNameResolverImpl::getStorageInstance: cannot get Storage service" );
534 // check that we have permissions for this storage
535 Reference
< dcsssf::security::XScriptSecurity
> xScriptSecurity( xInterface
, UNO_QUERY_THROW
);
536 validateXRef( xScriptSecurity
,
537 "ScriptNameResolverImpl::getStorageInstance: cannot get Script Security service" );
538 scripting_constants::ScriptingConstantsPool
& scriptingConstantsPool
=
539 scripting_constants::ScriptingConstantsPool::instance();
540 // if we dealing with a document storage (ie. not user or share
541 // we need to check the permission
542 if( ( sid
!= scriptingConstantsPool
.USER_STORAGE_ID
) &&
543 ( sid
!= scriptingConstantsPool
.SHARED_STORAGE_ID
) )
545 xScriptSecurity
->checkPermission( permissionURI
,
546 OUString::createFromAscii( "execute" ) );
547 // if we get here, the checkPermission hasn't thrown an
548 // AccessControlException, ie. permission has been granted
549 OSL_TRACE( "ScriptNameResolverImpl::getStorageInstance: got execute permission for ID=%d", sid
);
551 Reference
< storage::XScriptStorageManager
> xScriptStorageManager( xInterface
, UNO_QUERY_THROW
);
552 validateXRef( xScriptStorageManager
,
553 "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage Manager service" );
554 Reference
< XInterface
> xScriptStorage
=
555 xScriptStorageManager
->getScriptStorage( sid
);
556 validateXRef( xScriptStorage
,
557 "ScriptNameResolverImpl::getStorageInstance: cannot get Script Storage service" );
558 xScriptInfoAccess
= Reference
<
559 storage::XScriptInfoAccess
> ( xScriptStorage
, UNO_QUERY_THROW
);
561 catch ( lang::IllegalArgumentException
& e
)
563 OUString temp
= OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
564 throw lang::IllegalArgumentException( temp
.concat( e
.Message
),
565 Reference
< XInterface
>(), e
.ArgumentPosition
);
567 catch ( css::security::AccessControlException
& e
)
569 OUString temp
= OUSTR( "ScriptNameResolverImpl::getStorageInstance: AccessControlException " );
570 throw css::security::AccessControlException( temp
.concat( e
.Message
), Reference
< XInterface
>(), e
.LackingPermission
);
572 catch ( RuntimeException
& re
)
574 OUString temp
= OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
575 throw RuntimeException( temp
.concat( re
.Message
), Reference
< XInterface
>() );
577 catch ( Exception
& e
)
579 OUString temp
= OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
580 throw RuntimeException( temp
.concat( e
.Message
), Reference
< XInterface
>() );
582 return xScriptInfoAccess
;
584 //*************************************************************************
586 ScriptNameResolverImpl::getFilesysURL( const OUString
& scriptURI
)
587 throw( lang::IllegalArgumentException
)
591 OUString filesysString
= OUString::createFromAscii( "location=filesystem" );
592 sal_Int32 locationPos
= scriptURI
.indexOf( filesysString
);
593 // expect location=filesys:file:///foo/bar/myscript.bsh etc
594 // except the file url at this point is encoded
595 // so we should be ok searching for the '&'
596 sal_Int32 filesysStrLen
= filesysString
.getLength() + 1;
597 sal_Int32 endOfLocn
= scriptURI
.indexOf( '&', locationPos
);
598 if (endOfLocn
== -1 )
600 filePath
= scriptURI
.copy( locationPos
+ filesysString
.getLength() + 1 );
604 filePath
= scriptURI
.copy( locationPos
+ filesysStrLen
,
605 endOfLocn
- locationPos
- filesysStrLen
);
607 //file name shoul also be encoded so again ok to search for '&'
608 OUString functionKey
= OUString::createFromAscii( "function=" );
609 sal_Int32 functionKeyLength
= functionKey
.getLength();
610 sal_Int32 functionNamePos
= scriptURI
.indexOf( functionKey
);
611 if ( functionNamePos
> 0 )
613 sal_Int32 endOfFn
= scriptURI
.indexOf( '&', functionNamePos
);
616 fileName
= scriptURI
.copy( functionNamePos
+ functionKeyLength
);
620 fileName
= scriptURI
.copy( functionNamePos
+ functionKeyLength
,
621 endOfFn
- functionNamePos
- functionKeyLength
);
627 OUString temp
= OUSTR( "ScriptNameResolverImpl::getFilesysURL: error getting the filesysURL" );
628 throw lang::IllegalArgumentException( temp
, Reference
< XInterface
>(), 0 );
631 OSL_TRACE( "ScriptNameResolverImpl::getFilesysURL: filesys URL = %s",
632 ::rtl::OUStringToOString( filePath
,
633 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
636 //*************************************************************************
637 Sequence
<OUString
> SAL_CALL
638 ScriptNameResolverImpl::getSupportedServiceNames( )
639 throw( RuntimeException
)
641 return nrs_serviceNames
;
644 //*************************************************************************
645 Reference
< XInterface
> SAL_CALL
scriptnri_create(
646 Reference
< XComponentContext
> const & xComponentContext
)
647 SAL_THROW( ( Exception
) )
649 return ( cppu::OWeakObject
* ) new ScriptNameResolverImpl( xComponentContext
);
652 //*************************************************************************
653 Sequence
< OUString
> scriptnri_getSupportedServiceNames() SAL_THROW( () )
655 return nrs_serviceNames
;
658 //*************************************************************************
659 OUString
scriptnri_getImplementationName() SAL_THROW( () )
663 } // namespace scripting_runtimemgr