1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <vector>
#include <stdlib.h>
#include <cppuhelper/implementationentry.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/security/AccessControlException.hpp>
#include <util/util.hxx>
#include <util/scriptingconstants.hxx>
#include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
#include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp>
#include "ScriptNameResolverImpl.hxx"
#include "ScriptRuntimeManager.hxx"
using namespace ::rtl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::drafts::com::sun::star::script::framework;
namespace scripting_runtimemgr
{
const sal_Char* const LANGUAGE_TO_RESOLVE_ON[] = { "All" }; // should be configurable
OUString nrs_implName(RTL_CONSTASCII_USTRINGPARAM(
"drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" ));
OUString nrs_serviceName(RTL_CONSTASCII_USTRINGPARAM(
"drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" ));
Sequence< OUString > nrs_serviceNames = Sequence< OUString >( &nrs_serviceName, 1 );
const char* const SCRIPTSTORAGEMANAGER_SERVICE =
"/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager";
extern ::rtl_StandardModuleCount s_moduleCount;
// define storages to search
static ::std::vector< sal_Int32 >* m_pSearchIDs = NULL;
//*************************************************************************
ScriptNameResolverImpl::ScriptNameResolverImpl(
const Reference< XComponentContext > & xContext ) :
m_xContext( xContext, UNO_SET_THROW )
{
OSL_TRACE( "< ScriptNameResolverImpl ctor called >" );
validateXRef( m_xContext, "ScriptNameResolverImpl::ScriptNameResolverImpl: invalid context" );
m_xMultiComFac.set( m_xContext->getServiceManager(), UNO_SET_THROW );
if( !m_pSearchIDs )
{
osl::Guard< osl::Mutex > aGuard( m_mutex );
if( !m_pSearchIDs )
{
scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
scripting_constants::ScriptingConstantsPool::instance();
m_pSearchIDs = new ::std::vector< sal_Int32 >();
m_pSearchIDs->push_back( scriptingConstantsPool.DOC_STORAGE_ID_NOT_SET );
m_pSearchIDs->push_back( scriptingConstantsPool.USER_STORAGE_ID );
m_pSearchIDs->push_back( scriptingConstantsPool.SHARED_STORAGE_ID );
}
}
s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt );
}
//*************************************************************************
ScriptNameResolverImpl::~ScriptNameResolverImpl()
{
OSL_TRACE( "< ScriptNameResolverImpl dtor called >" );
s_moduleCount.modCnt.release( &s_moduleCount.modCnt );
}
//*************************************************************************
Reference< storage::XScriptInfo > ScriptNameResolverImpl::resolve(
const ::rtl::OUString & scriptURI, Any& invocationCtx )
throw ( lang::IllegalArgumentException, script::CannotConvertException, RuntimeException )
{
Reference< storage::XScriptInfo > resolvedName;
Reference< beans::XPropertySet > xPropSetScriptingContext;
scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
scripting_constants::ScriptingConstantsPool::instance();
OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - start" );
if ( sal_False == ( invocationCtx >>= xPropSetScriptingContext ) )
{
throw RuntimeException( OUSTR(
"ScriptNameResolverImpl::resolve : unable to get XScriptingContext from param" ),
Reference< XInterface > () );
}
Any any;
OUString docUri;
sal_Int32 filesysScriptStorageID = -1;
Reference < storage::XScriptStorageManager > xScriptStorageMgr;
sal_Int32 docSid;
try
{
any = xPropSetScriptingContext->getPropertyValue(
scriptingConstantsPool.DOC_URI );
OSL_TRACE( "ScriptNameResolverImpl::resolve: in resolve - got anyUri" );
if ( sal_False == ( any >>= docUri ) )
{
throw RuntimeException( OUSTR(
"ScriptNameResolverImpl::resolve : unable to get doc Uri from xPropSetScriptingContext" ),
Reference< XInterface > () );
}
any = xPropSetScriptingContext->getPropertyValue(
scriptingConstantsPool.DOC_STORAGE_ID );
if ( sal_False == ( any >>= docSid ) )
{
throw RuntimeException( OUSTR(
"ScriptNameResolverImpl::resolve : unable to get doc storage id from xPropSetScriptingContext" ),
Reference< XInterface > () );
}
}
catch ( const Exception & e )
{
OUString temp = OUSTR(
"ScriptNameResolverImpl::resolve : problem with getPropertyValue" );
throw RuntimeException( temp.concat( e.Message ),
Reference< XInterface > () );
}
#ifdef _DEBUG
catch ( ... )
{
throw RuntimeException( OUSTR(
"ScriptNameResolverImpl::resolve Unknown Exception caught - RuntimeException rethrown" ),
Reference< XInterface > () );
}
#endif
::rtl::OString docUriO(
::rtl::OUStringToOString( docUri , RTL_TEXTENCODING_ASCII_US ) );
OSL_TRACE(
"ScriptNameResolverImpl::resolve: *** >>> DOC URI: %s, doc sid is %d\n",
docUriO.pData->buffer, docSid );
OSL_TRACE( "ScriptNameResolverImpl::resolve Starting..." );
OUString docString(RTL_CONSTASCII_USTRINGPARAM("location=document"));
OUString userString(RTL_CONSTASCII_USTRINGPARAM("location=user"));
OUString shareString(RTL_CONSTASCII_USTRINGPARAM("location=share"));
OUString filesysString(RTL_CONSTASCII_USTRINGPARAM("location=filesystem"));
// initialise vector with doc, user and share
// m_pSearchIDs is initialised as follows,
// m_pSearchIDs [ 0 ] empty
// m_pSearchIDs [ 1 ] user storage id
// m_pSearchIDs [ 2 ] share " "
::std::vector< sal_Int32 > m_vSearchIDs = *m_pSearchIDs;
m_vSearchIDs[ 0 ] = docSid;
if ( scriptURI.indexOf( docString ) != -1 )
{
OSL_TRACE("Full resolution available, search document");
// search in document
m_vSearchIDs.resize( 1 );
}
else if ( scriptURI.indexOf( userString ) != -1 )
{
OSL_TRACE("Full resolution available, search user");
// search in user
m_vSearchIDs[ 0 ] = ( *m_pSearchIDs )[ 1 ];
m_vSearchIDs.resize( 1 );
}
else if ( scriptURI.indexOf( shareString ) != -1 )
{
OSL_TRACE("Full resolution available, search share");
// search in share
m_vSearchIDs[ 0 ] = ( *m_pSearchIDs )[ 2 ];
m_vSearchIDs.resize( 1 );
}
else if ( scriptURI.indexOf( filesysString ) != -1 )
{
OSL_TRACE("Full resolution available, create & search filesystem");
OUString filesysURL;
try
{
filesysURL = getFilesysURL( scriptURI );
}
catch ( const lang::IllegalArgumentException & e )
{
OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: " );
throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
}
Reference< XInterface > xInterface(
m_xMultiComFac->createInstanceWithContext(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.ucb.SimpleFileAccess" )),
m_xContext
),
UNO_SET_THROW
);
Reference < ucb::XSimpleFileAccess > xSimpleFileAccess = Reference <
ucb::XSimpleFileAccess > ( xInterface, UNO_QUERY_THROW );
// do we need to encode this? hope not.
OSL_TRACE( ">>>> About to create storage for %s",
::rtl::OUStringToOString( filesysURL,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
// ask storage manager to create storage
try
{
// need to get the ScriptStorageManager
xScriptStorageMgr.set( m_xContext->getValueByName(
scriptingConstantsPool.SCRIPTSTORAGEMANAGER_SERVICE ), UNO_QUERY_THROW );
filesysScriptStorageID =
xScriptStorageMgr->createScriptStorageWithURI(
xSimpleFileAccess, filesysURL );
OSL_TRACE( ">>>> Created storage %d - for %s ",
filesysScriptStorageID, ::rtl::OUStringToOString(
filesysURL, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
}
catch ( const RuntimeException & e )
{
OUString temp = OUSTR( "ScriptNameResolverImpl::resolve: " );
throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
}
m_vSearchIDs[ 0 ] = filesysScriptStorageID;
m_vSearchIDs.resize( 1 );
}
else
{
OSL_TRACE("Only partial uri available, search doc, user & share");
// is this illegal or do we search in a default way
// if we get to here a uri has been passed in that has:
// a) not got a location specified
// b) an illegal location
// detect illegal location
if ( scriptURI.indexOf( OUString(RTL_CONSTASCII_USTRINGPARAM("location=")) ) != -1 )
{
OSL_TRACE(
"ScriptNameResolver::resolve, throwing IllegalArgException" );
throw lang::IllegalArgumentException(
OUSTR( "invalid URI: " ).concat( scriptURI ),
Reference < XInterface > (), 1 );
}
// leave vSearchIDs take care of the search...
}
::std::vector< sal_Int32 >::const_iterator iter;
::std::vector< sal_Int32 >::const_iterator iterEnd = m_vSearchIDs.end();
for ( iter = m_vSearchIDs.begin() ; iter != iterEnd; ++iter )
{
try
{
OSL_TRACE( "** about to resolve from storage using id %d from vector of size %d",
*iter, m_vSearchIDs.size() );
if ( ( resolvedName = resolveURIFromStorageID( *iter, docUri, scriptURI ) ).is() )
{
OSL_TRACE( "found match in uri from storage %d", *iter );
xPropSetScriptingContext->setPropertyValue(
scriptingConstantsPool.RESOLVED_STORAGE_ID, makeAny(*iter) );
break;
}
}
catch ( css::security::AccessControlException & )
{
// no execute permission
OSL_TRACE( "ScriptNameResolverImpl::resolve : AccessControlException " );
continue;
}
catch ( const beans::UnknownPropertyException & e )
{
OUString temp = OUSTR(
"ScriptNameResolverImpl::resolve : UnknownPropertyException" );
throw RuntimeException( temp.concat( e.Message ),
Reference< XInterface > () );
}
catch ( const beans::PropertyVetoException & e )
{
OUString temp = OUSTR(
"ScriptNameResolverImpl::resolve : PropertyVetoException " );
throw RuntimeException( temp.concat( e.Message ),
Reference< XInterface > () );
}
catch ( const lang::IllegalArgumentException & e )
{
OUString temp = OUSTR(
"ScriptNameResolverImpl::resolve : IllegalArgumentException " );
throw lang::IllegalArgumentException( temp.concat( e.Message ),
Reference< XInterface > (), e.ArgumentPosition );
}
catch ( const lang::WrappedTargetException & e )
{
OUString temp = OUSTR(
"ScriptNameResolverImpl::resolve : WrappedTargetException " );
throw RuntimeException( temp.concat( e.Message ),
Reference< XInterface > () );
}
catch ( const Exception & e )
{
OSL_TRACE(
"Exception thrown by storage %d, failed to match uri: %s",
*iter,
::rtl::OUStringToOString( e.Message,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
OUString temp = OUSTR(
"ScriptNameResolverImpl::resolve : unknown exception" );
throw RuntimeException( temp.concat( e.Message ),
Reference< XInterface > () );
}
#ifdef _DEBUG
catch ( ... )
{
OSL_TRACE(
"unknown exception thrown by storage %d, failed to match uri",
*iter );
OUString temp = OUSTR(
"ScriptNameResolverImpl::resolve Unknown exception caught - RuntimeException rethrown" );
throw RuntimeException( temp,
Reference< XInterface > () );
}
#endif
}
if ( !resolvedName.is() )
{
if( filesysScriptStorageID > 2 )
{
// get the filesys storage and dispose of it
Reference< XInterface > xScriptStorage( xScriptStorageMgr->getScriptStorage( filesysScriptStorageID ), UNO_SET_THROW );
Reference< storage::XScriptInfoAccess > xScriptInfoAccess = Reference<
storage::XScriptInfoAccess > ( xScriptStorage, UNO_QUERY_THROW );
Sequence< Reference< storage::XScriptInfo > > results =
xScriptInfoAccess->getAllImplementations( );
Reference < lang::XEventListener > xEL_ScriptStorageMgr( xScriptStorageMgr ,UNO_QUERY_THROW );
lang::EventObject event( results[ 0 ] );
xEL_ScriptStorageMgr->disposing( event );
}
throw lang::IllegalArgumentException( OUSTR(
"ScriptNameResolverImpl::resolve: no script found for uri=" ).concat( scriptURI ),
Reference< XInterface > (), 0 );
}
return resolvedName;
}
//*************************************************************************
OUString SAL_CALL
ScriptNameResolverImpl::getImplementationName( )
throw( RuntimeException )
{
return nrs_implName;
}
//*************************************************************************
sal_Bool SAL_CALL
ScriptNameResolverImpl::supportsService( const OUString& serviceName )
throw( RuntimeException )
{
OUString const * pNames = nrs_serviceNames.getConstArray();
for ( sal_Int32 nPos = nrs_serviceNames.getLength(); nPos--; )
{
if ( serviceName.equals( pNames[ nPos ] ) )
{
return sal_True;
}
}
return sal_False;
}
//*************************************************************************
Reference< storage::XScriptInfo >
ScriptNameResolverImpl::resolveURIFromStorageID
( sal_Int32 sid, const ::rtl::OUString & docURI,
const ::rtl::OUString& scriptURI )
SAL_THROW ( ( lang::IllegalArgumentException, css::security::AccessControlException, RuntimeException ) )
{
Reference< storage::XScriptInfo > resolvedScriptInfo;
scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
scripting_constants::ScriptingConstantsPool::instance();
if ( sid == scriptingConstantsPool.DOC_STORAGE_ID_NOT_SET )
{
OSL_TRACE( "@@@@ **** ScriptNameResolverImpl::resolve DOC_STORAGE_ID_NOT_SET" );
return resolvedScriptInfo;
}
try
{
OUString permissionURI = docURI;
OUString filesysString(RTL_CONSTASCII_USTRINGPARAM("location=filesystem"));
if ( scriptURI.indexOf( filesysString ) != -1 )
{
// in the case of filesys scripts we're checking whether the
// location of the script, rather than the location of the document,
// has execute permission
try
{
permissionURI = getFilesysURL( scriptURI );
}
catch ( const lang::IllegalArgumentException & e )
{
OUString temp = OUSTR( "ScriptNameResolverImpl::resolveFromURI: " );
throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
}
}
Reference< storage::XScriptInfoAccess > storage( getStorageInstance( sid, permissionURI ), UNO_SET_THROW );
Sequence< Reference< storage::XScriptInfo > > results =
storage->getImplementations( scriptURI );
const sal_Int32 length = results.getLength();
if ( !length )
{
return resolvedScriptInfo;
}
OSL_TRACE( "ScriptNameResolverImpl::resolve Got some results..." );
// if we get results, just return first in list,
// storage has already matched language, function name etc. if
// that information was in the uri
resolvedScriptInfo = results[ 0 ];
}
catch ( const css::security::AccessControlException & ace )
{
OUString temp = OUSTR(
"ScriptRuntimeManager::resolveURIFromStorageID AccessControlException: " );
throw css::security::AccessControlException( temp.concat( ace.Message ),
Reference< XInterface > (),
ace.LackingPermission );
}
catch ( const lang::IllegalArgumentException & iae )
{
OUString temp = OUSTR(
"ScriptRuntimeManager::resolveURIFromStorageID IllegalArgumentException: " );
throw lang::IllegalArgumentException( temp.concat( iae.Message ),
Reference< XInterface > (),
iae.ArgumentPosition );
}
catch ( const RuntimeException & re )
{
OUString temp = OUSTR(
"ScriptRuntimeManager::resolveURIFromStorageID RuntimeException: " );
throw RuntimeException( temp.concat( re.Message ),
Reference< XInterface > () );
}
catch ( const Exception & e )
{
OUString temp = OUSTR(
"ScriptNameResolverImpl::resolveURIFromStorageID : Exception caught - RuntimeException rethrown" );
throw RuntimeException( temp.concat( e.Message ),
Reference< XInterface > () );
}
#ifdef _DEBUG
catch ( ... )
{
throw RuntimeException( OUSTR(
"ScriptNameResolverImpl::resolveURIFromStorageID Unknown exception caught - RuntimeException rethrown" ),
Reference< XInterface > () );
}
#endif
return resolvedScriptInfo;
}
//*************************************************************************
Reference< storage::XScriptInfoAccess >
ScriptNameResolverImpl::getStorageInstance( sal_Int32 sid,
const ::rtl::OUString & permissionURI ) SAL_THROW ( ( RuntimeException, css::security::AccessControlException, lang::IllegalArgumentException ) )
{
Reference< storage::XScriptInfoAccess > xScriptInfoAccess;
try
{
Reference< XInterface > xInterface( m_xContext->getValueByName(
OUString::createFromAscii( SCRIPTSTORAGEMANAGER_SERVICE ) ), UNO_QUERY_THROW );
// check that we have permissions for this storage
Reference< ::drafts::com::sun::star::script::framework::security::XScriptSecurity > xScriptSecurity( xInterface, UNO_QUERY_THROW );
scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
scripting_constants::ScriptingConstantsPool::instance();
// if we dealing with a document storage (ie. not user or share
// we need to check the permission
if( ( sid != scriptingConstantsPool.USER_STORAGE_ID ) &&
( sid != scriptingConstantsPool.SHARED_STORAGE_ID ) )
{
xScriptSecurity->checkPermission( permissionURI,
OUString(RTL_CONSTASCII_USTRINGPARAM("execute")) );
// if we get here, the checkPermission hasn't thrown an
// AccessControlException, ie. permission has been granted
OSL_TRACE( "ScriptNameResolverImpl::getStorageInstance: got execute permission for ID=%d", sid );
}
Reference< storage::XScriptStorageManager > xScriptStorageManager( xInterface, UNO_QUERY_THROW );
Reference< XInterface > xScriptStorage( ScriptStorageManager->getScriptStorage( sid ), UNO_SET_THROW );
xScriptInfoAccess.set( xScriptStorage, UNO_QUERY_THROW );
}
catch ( const lang::IllegalArgumentException & e )
{
OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
throw lang::IllegalArgumentException( temp.concat( e.Message ),
Reference< XInterface >(), e.ArgumentPosition );
}
catch ( const css::security::AccessControlException & e )
{
OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: AccessControlException " );
throw css::security::AccessControlException( temp.concat( e.Message ), Reference< XInterface >(), e.LackingPermission );
}
catch ( const RuntimeException & re )
{
OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
throw RuntimeException( temp.concat( re.Message ), Reference< XInterface >() );
}
catch ( const Exception & e )
{
OUString temp = OUSTR( "ScriptNameResolverImpl::getStorageInstance: " );
throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
}
return xScriptInfoAccess;
}
//*************************************************************************
OUString
ScriptNameResolverImpl::getFilesysURL( const OUString & scriptURI )
throw( lang::IllegalArgumentException )
{
OUString filePath;
OUString fileName;
OUString filesysString(RTL_CONSTASCII_USTRINGPARAM("location=filesystem"));
sal_Int32 locationPos = scriptURI.indexOf( filesysString );
// expect location=filesys:file:///foo/bar/myscript.bsh etc
// except the file url at this point is encoded
// so we should be ok searching for the '&'
sal_Int32 filesysStrLen = filesysString.getLength() + 1;
sal_Int32 endOfLocn = scriptURI.indexOf( '&', locationPos );
if (endOfLocn == -1 )
{
filePath = scriptURI.copy( locationPos + filesysString.getLength() + 1 );
}
else
{
filePath = scriptURI.copy( locationPos + filesysStrLen,
endOfLocn - locationPos - filesysStrLen );
}
//file name shoul also be encoded so again ok to search for '&'
OUString functionKey(RTL_CONSTASCII_USTRINGPARAM("function="));
sal_Int32 functionKeyLength = functionKey.getLength();
sal_Int32 functionNamePos = scriptURI.indexOf( functionKey );
if ( functionNamePos > 0 )
{
sal_Int32 endOfFn = scriptURI.indexOf( '&', functionNamePos );
if ( endOfFn == -1 )
{
fileName = scriptURI.copy( functionNamePos + functionKeyLength );
}
else
{
fileName = scriptURI.copy( functionNamePos + functionKeyLength,
endOfFn - functionNamePos - functionKeyLength );
}
}
else
{
// we need to throw
OUString temp = OUSTR( "ScriptNameResolverImpl::getFilesysURL: error getting the filesysURL" );
throw lang::IllegalArgumentException( temp, Reference< XInterface >(), 0 );
}
filePath+=fileName;
OSL_TRACE( "ScriptNameResolverImpl::getFilesysURL: filesys URL = %s",
::rtl::OUStringToOString( filePath,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
return filePath;
}
//*************************************************************************
Sequence<OUString> SAL_CALL
ScriptNameResolverImpl::getSupportedServiceNames( )
throw( RuntimeException )
{
return nrs_serviceNames;
}
//*************************************************************************
Reference< XInterface > SAL_CALL scriptnri_create(
Reference< XComponentContext > const & xComponentContext )
SAL_THROW( ( Exception ) )
{
return ( cppu::OWeakObject * ) new ScriptNameResolverImpl( xComponentContext );
}
//*************************************************************************
Sequence< OUString > scriptnri_getSupportedServiceNames() SAL_THROW(())
{
return nrs_serviceNames;
}
//*************************************************************************
OUString scriptnri_getImplementationName() SAL_THROW(())
{
return nrs_implName;
}
} // namespace scripting_runtimemgr
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|