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: ScriptStorage.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"
33 #include <osl/file.hxx>
35 #include <cppuhelper/implementationentry.hxx>
36 #include <com/sun/star/lang/IllegalArgumentException.hpp>
37 #include <com/sun/star/ucb/CommandAbortedException.hpp>
38 #include <com/sun/star/io/XActiveDataSource.hpp>
39 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
40 #include <com/sun/star/container/XNameAccess.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/beans/PropertyValue.hpp>
44 #include <util/util.hxx>
45 #include <rtl/uri.hxx>
48 #include "ScriptData.hxx"
49 #include "ScriptInfo.hxx"
50 #include "ScriptStorage.hxx"
51 #include "ScriptElement.hxx"
52 #include "ScriptMetadataImporter.hxx"
53 #include "ScriptURI.hxx"
55 using namespace ::rtl
;
56 using namespace ::cppu
;
57 using namespace ::com::sun::star
;
58 using namespace ::com::sun::star::uno
;
59 using namespace ::drafts::com::sun::star::script::framework
;
61 namespace scripting_impl
64 ScriptLanguages_hash
* ScriptStorage::mh_scriptLangs
= NULL
;
66 const sal_Char
* const SERVICE_NAME
=
67 "drafts.com.sun.star.script.framework.storage.ScriptStorage";
68 const sal_Char
* const IMPL_NAME
=
69 "drafts.com.sun.star.script.framework.storage.ScriptStorage";
71 const sal_Char
* const SCRIPT_DIR
= "/Scripts";
72 const sal_Char
* const SCRIPT_PARCEL
= "/parcel-descriptor.xml";
73 const sal_Char
* const SCRIPT_PARCEL_NAME_ONLY
= "parcel-descriptor";
75 static OUString ss_implName
= OUString::createFromAscii( IMPL_NAME
);
76 static OUString ss_serviceName
= OUString::createFromAscii( SERVICE_NAME
);
77 static Sequence
< OUString
> ss_serviceNames
=
78 Sequence
< OUString
>( &ss_serviceName
, 1 );
80 const sal_uInt16 NUMBER_STORAGE_INITIALIZE_ARGS
= 3;
82 //extern ::rtl_StandardModuleCount s_moduleCount;
86 //*************************************************************************
87 ScriptStorage::ScriptStorage( const Reference
<
88 XComponentContext
> & xContext
)
89 throw ( RuntimeException
)
90 : m_xContext( xContext
), m_bInitialised( false )
92 OSL_TRACE( "< ScriptStorage ctor called >\n" );
94 validateXRef( m_xContext
,
95 "ScriptStorage::ScriptStorage : cannot get component context" );
97 m_xMgr
= m_xContext
->getServiceManager();
99 "ScriptStorage::ScriptStorage : cannot get service manager" );
101 if( !mh_scriptLangs
)
103 ::osl::MutexGuard
guard( ::osl::Mutex::getGlobalMutex() );
104 if( !mh_scriptLangs
)
106 mh_scriptLangs
= new ScriptLanguages_hash();
107 Reference
< XInterface
> xInterface
=
108 m_xMgr
->createInstanceWithContext(
109 OUString::createFromAscii(
110 "com.sun.star.configuration.ConfigurationProvider" )
112 validateXRef( xInterface
,
113 "ScriptStorage::ScriptStorage: cannot get ConfigurationProvider" );
114 // create an instance of the ConfigurationAccess for accessing the
115 // scripting runtime settings
116 Reference
< lang::XMultiServiceFactory
> xConfigProvFactory
=
117 Reference
< lang::XMultiServiceFactory
>
118 ( xInterface
, UNO_QUERY_THROW
);
119 validateXRef( xConfigProvFactory
,
120 "ScriptStorage::ScriptStorage: cannot get XMultiServiceFactory interface from ConfigurationProvider" );
121 beans::PropertyValue configPath
;
122 configPath
.Name
= ::rtl::OUString::createFromAscii( "nodepath" );
123 configPath
.Value
<<= ::rtl::OUString::createFromAscii( "org.openoffice.Office.Scripting/ScriptRuntimes" );
124 Sequence
< Any
> aargs( 1 );
125 aargs
[ 0 ] <<= configPath
;
127 xInterface
= xConfigProvFactory
->createInstanceWithArguments(
128 OUString::createFromAscii(
129 "com.sun.star.configuration.ConfigurationAccess"),
131 validateXRef( xInterface
,
132 "ScriptStorage::ScriptStorage: cannot get ConfigurationAccess" );
133 Reference
< container::XNameAccess
> xNameAccess
=
134 Reference
< container::XNameAccess
> ( xInterface
,
136 validateXRef( xNameAccess
,
137 "ScriptStorage::ScriptStorage: cannot get ConfigurationAccess" );
138 Sequence
< OUString
> names
= xNameAccess
->getElementNames();
139 for( int i
= 0 ; i
< names
.getLength() ; i
++ )
141 OSL_TRACE( "Getting propertyset for Lang=%s",
142 ::rtl::OUStringToOString( names
[i
], RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
143 Reference
< beans::XPropertySet
> xPropSet
=
144 Reference
< beans::XPropertySet
>( xNameAccess
->getByName(names
[i
]),
146 validateXRef( xPropSet
,
147 "ScriptStorage::ScriptStorage: cannot get XPropertySet for name" );
148 Any aProp
= xPropSet
->getPropertyValue(
149 OUString::createFromAscii( "SupportedFileExtensions") );
150 Sequence
< OUString
> extns
;
151 if( sal_False
== ( aProp
>>= extns
) )
153 throw RuntimeException(
154 OUSTR( "ScriptStorage:ScriptStorage: can't get runtime extensions" ),
155 Reference
< XInterface
> () );
157 for( int j
= 0 ; j
< extns
.getLength() ; j
++ )
159 OSL_TRACE( "Adding Lang=%s, Extn=%s\n",
160 ::rtl::OUStringToOString( names
[i
], RTL_TEXTENCODING_ASCII_US
).pData
->buffer
,
161 ::rtl::OUStringToOString( extns
[j
], RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
162 (*mh_scriptLangs
)[ extns
[j
] ] =
168 // s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt );
171 //*************************************************************************
172 ScriptStorage::~ScriptStorage() SAL_THROW( () )
174 OSL_TRACE( "< ScriptStorage dtor called >\n" );
175 // s_moduleCount.modCnt.release( &s_moduleCount.modCnt );
178 //*************************************************************************
180 ScriptStorage::initialize( const Sequence
<Any
> & args
)
181 throw ( RuntimeException
, Exception
)
183 OSL_TRACE( "Entering ScriptStorage::initialize\n" );
185 // Should not be renitialised
186 if ( m_bInitialised
)
188 throw RuntimeException(
189 OUSTR( "ScriptStorage::initalize already initialized" ),
190 Reference
<XInterface
> () );
193 { // Protect member variable writes
194 ::osl::Guard
< osl::Mutex
> aGuard( m_mutex
);
197 if ( args
.getLength() != NUMBER_STORAGE_INITIALIZE_ARGS
)
199 OSL_TRACE( "ScriptStorage::initialize: got wrong number of args\n" );
200 throw RuntimeException(
201 OUSTR( "Invalid number of arguments provided!" ),
202 Reference
< XInterface
>() );
205 if ( sal_False
== ( args
[ 0 ] >>= m_xSimpleFileAccess
) )
207 throw RuntimeException(
208 OUSTR( "Invalid XSimpleFileAccess argument provided!" ),
209 Reference
< XInterface
>() );
212 if ( sal_False
== ( args
[ 1 ] >>= m_scriptStorageID
) )
214 throw RuntimeException(
215 OUSTR( "Invalid ScriptStorage ID argument provided!" ),
216 Reference
< XInterface
>() );
219 if ( sal_False
== ( args
[ 2 ] >>= m_stringUri
) )
221 throw RuntimeException(
222 OUSTR( "Invalid String Uri argument provided!" ),
223 Reference
< XInterface
>() );
225 } // End - Protect member variable writes
227 OSL_TRACE( "uri: %s\n", ::rtl::OUStringToOString(
228 m_stringUri
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
232 // need to check for what???
233 // what we have is a URI for the filesystem or document
234 // we need to check of the last element in the path has an
235 // extension that is associated with a script (eg. .bsh, .js etc)
236 OUString fileExtension
= getFileExtension( m_stringUri
);
237 // and see if this is in our scripts map
238 ScriptLanguages_hash::iterator h_it
= mh_scriptLangs
->find( fileExtension
);
239 if ( h_it
!= mh_scriptLangs
->end() )
241 createForFilesystem( fileExtension
);
248 catch ( RuntimeException
& re
)
250 OSL_TRACE( "caught com::sun::star::uno::RuntimeException in ScriptStorage::initialize" );
251 throw RuntimeException(
252 OUSTR( "ScriptStorage::initalize RuntimeException: " ).concat( re
.Message
),
253 Reference
< XInterface
> () );
255 catch ( Exception
& ue
)
257 OSL_TRACE( "caught com::sun::star::uno::Exception in ScriptStorage::initialize" );
258 throw RuntimeException(
259 OUSTR( "ScriptStorage::initalize Exception: " ).concat( ue
.Message
),
260 Reference
< XInterface
> () );
265 OSL_TRACE( "caught unknown Exception in ScriptStorage::initialize" );
266 throw RuntimeException(
267 OUSTR( "ScriptStorage::initalize unknown exception: " ),
268 Reference
< XInterface
> () );
272 OSL_TRACE( "Parsed the XML\n" );
274 m_bInitialised
= true;
278 ScriptStorage::create()
279 throw ( RuntimeException
, Exception
)
281 ::osl::Guard
< osl::Mutex
> aGuard( m_mutex
);
284 // clear existing hashmap - rebuilding from scratch to avoid having
285 // to search for deleted elements on refresh
286 mh_implementations
.clear();
288 OUString
xStringUri(m_stringUri
);
290 ScriptMetadataImporter
* SMI
= new ScriptMetadataImporter( m_xContext
);
291 Reference
< xml::sax::XExtendedDocumentHandler
> xSMI( SMI
);
293 validateXRef( xSMI
, "ScriptStorage::create: failed to obtain valid XExtendedDocumentHandler" );
295 xStringUri
= xStringUri
.concat( ::rtl::OUString::createFromAscii(
298 // No Scripts directory - just return
299 if ( ! m_xSimpleFileAccess
->isFolder( xStringUri
) )
301 OSL_TRACE( "ScriptStorage::initialize: no Scripts dir for this storage - install problem\n" );
305 // get the list of language folders under the Scripts directory
306 Sequence
< ::rtl::OUString
> languageDirs
=
307 m_xSimpleFileAccess
->getFolderContents( xStringUri
, true );
309 Reference
< io::XInputStream
> xInput
;
310 sal_Int32 languageDirsLength
= languageDirs
.getLength();
311 for ( sal_Int32 i
= 0; i
< languageDirsLength
; ++i
)
313 OSL_TRACE( "contains: %s\n", ::rtl::OUStringToOString(
314 languageDirs
[ i
], RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
316 if ( ! m_xSimpleFileAccess
->isFolder( languageDirs
[ i
] ) )
321 //get the list of parcel folders for each language folder
323 Sequence
< ::rtl::OUString
> parcelDirs
=
324 m_xSimpleFileAccess
->getFolderContents( languageDirs
[ i
], true );
326 sal_Int32 parcelDirsLength
= parcelDirs
.getLength();
327 for ( sal_Int32 j
= 0; j
< parcelDirsLength
; ++j
)
329 OSL_TRACE( "contains: %s\n",
330 ::rtl::OUStringToOString( parcelDirs
[ j
],
331 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
333 OUString parcelFile
= parcelDirs
[ j
].concat(
334 ::rtl::OUString::createFromAscii( SCRIPT_PARCEL
) );
336 // Do not have a valid parcel.xml
337 if ( !m_xSimpleFileAccess
->exists( parcelFile
) ||
338 m_xSimpleFileAccess
->isFolder( parcelFile
) )
342 OSL_TRACE( "parcel file: %s\n",
343 ::rtl::OUStringToOString( parcelFile
,
344 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
346 xInput
= m_xSimpleFileAccess
->openFileRead( parcelFile
);
347 // Failed to get input stream
353 OSL_TRACE( "Parse the metadata \n" );
354 Datas_vec vScriptDatas
;
357 SMI
->parseMetaData( xInput
, parcelDirs
[ j
], vScriptDatas
);
359 catch ( xml::sax::SAXException
& saxe
)
363 xInput
->closeInput();
366 "caught com::sun::star::xml::sax::SAXException in ScriptStorage::create %s",
367 ::rtl::OUStringToOString( saxe
.Message
,
368 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
372 catch ( io::IOException
& ioe
)
376 xInput
->closeInput();
379 "caught com::sun::star::io::IOException in ScriptStorage::create" );
382 xInput
->closeInput();
384 updateMaps( vScriptDatas
);
388 catch ( io::IOException
& ioe
)
390 //From ScriptMetadata Importer
391 OSL_TRACE( "caught com::sun::star::io::IOException in ScriptStorage::create" );
392 throw RuntimeException(
393 OUSTR( "ScriptStorage::create IOException: " ).concat( ioe
.Message
),
394 Reference
< XInterface
> () );
397 catch ( ucb::CommandAbortedException
& cae
)
399 OSL_TRACE( "caught com::sun::star::ucb::CommandAbortedException in ScriptStorage::create" );
400 throw RuntimeException(
402 "ScriptStorage::create CommandAbortedException: " ).concat( cae
.Message
),
403 Reference
< XInterface
> () );
405 catch ( RuntimeException
& re
)
407 OSL_TRACE( "caught com::sun::star::uno::RuntimeException in ScriptStorage::create" );
408 throw RuntimeException(
409 OUSTR( "ScriptStorage::create RuntimeException: " ).concat( re
.Message
),
410 Reference
< XInterface
> () );
412 catch ( Exception
& ue
)
414 OSL_TRACE( "caught com::sun::star::uno::Exception in ScriptStorage::create" );
415 throw RuntimeException(
416 OUSTR( "ScriptStorage::create Exception: " ).concat( ue
.Message
),
417 Reference
< XInterface
> () );
422 OSL_TRACE( "caught unknown Exception in ScriptStorage::create" );
423 throw RuntimeException(
424 OUSTR( "ScriptStorage::initalize unknown exception: " ),
425 Reference
< XInterface
> () );
429 OSL_TRACE( "Parsed the XML\n" );
431 m_bInitialised
= true;
434 //*************************************************************************
435 // private method to create the usual data structures for scripts located
436 // on the filesystem.
437 // parcelURI = the path to the script
438 // functionName = the full filename with extension
439 // logicalName = the filename without the extension
441 ScriptStorage::createForFilesystem( const OUString
& fileExtension
)
442 throw ( RuntimeException
, Exception
)
444 // need to decode as file urls are encoded
445 OUString xStringUri
= ::rtl::Uri::decode( m_stringUri
,
446 rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_ASCII_US
);
448 // no x-platform issues here as we are dealing with URLs
449 sal_Int32 lastFileSep
= xStringUri
.lastIndexOf( '/' );
450 // the char just after the filesep
452 sal_Int32 lastFileExt
= xStringUri
.lastIndexOf( fileExtension
);
453 OUString searchString
= OUString::createFromAscii( "://" );
454 sal_Int32 searchStringLength
= searchString
.getLength();
455 sal_Int32 startPath
= xStringUri
.indexOf( searchString
);
456 sal_Int32 uriLength
= xStringUri
.getLength();
457 OUString fileNameNoExt
= xStringUri
.copy( lastFileSep
,
458 lastFileExt
- lastFileSep
- 1 );
459 OUString fileName
= xStringUri
.copy( lastFileSep
, uriLength
- lastFileSep
);
460 OUString filePath
= xStringUri
.copy( startPath
+ searchStringLength
,
461 lastFileSep
- startPath
- searchStringLength
);
462 OUString filePathWithName
= xStringUri
.copy( startPath
+ searchStringLength
,
463 uriLength
- startPath
- searchStringLength
);
465 ScriptData scriptData
;
466 scriptData
.language
= mh_scriptLangs
->find( fileExtension
)->second
;
467 OSL_TRACE( "\t language = %s", ::rtl::OUStringToOString(
468 scriptData
.language
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
470 // do we need to encode this?
471 scriptData
.functionname
= fileName
;
472 OSL_TRACE( "\t functionName = %s", ::rtl::OUStringToOString(
473 scriptData
.functionname
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
474 //scriptData.functionname = ::rtl::Uri::encode( fileName,
475 //rtl_UriCharClassUricNoSlash, rtl_UriEncodeCheckEscapes,
476 //RTL_TEXTENCODING_ASCII_US );
478 scriptData
.parcelURI
= filePath
;
479 OSL_TRACE( "\t parcelURI = %s", ::rtl::OUStringToOString(
480 scriptData
.parcelURI
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
481 scriptData
.logicalname
= fileNameNoExt
;
482 OSL_TRACE( "\t logicalName = %s", ::rtl::OUStringToOString(
483 scriptData
.logicalname
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
485 // and now push onto the usual structures
486 ScriptFunction_hash sfh
;
487 sfh
[ scriptData
.functionname
] = scriptData
;
488 mh_implementations
[ scriptData
.language
] = sfh
;
489 m_bInitialised
= true;
492 //*************************************************************************
493 // private method to return the file extension, eg. bsh, js etc
495 ScriptStorage::getFileExtension( const OUString
& stringUri
)
497 OUString fileExtension
;
498 sal_Int32 lastDot
= stringUri
.lastIndexOf( '.' );
500 sal_Int32 stringUriLength
= stringUri
.getLength();
501 fileExtension
= stringUri
.copy( lastDot
+1 , stringUriLength
- lastDot
- 1 );
505 fileExtension
= OUString::createFromAscii("");
507 return fileExtension
;
510 //*************************************************************************
511 // private method for updating hashmaps
513 ScriptStorage::updateMaps( const Datas_vec
& vScriptDatas
)
516 Datas_vec::const_iterator it_end
= vScriptDatas
.end();
517 // step through the vector of ScripImplInfos returned from parse
518 for ( Datas_vec::const_iterator it
= vScriptDatas
.begin() ; it
!= it_end
; ++it
)
520 //find the Datas_vec for this logical name
521 ScriptData_hash::iterator h_it
= mh_implementations
.find( it
->language
);
523 if ( h_it
== mh_implementations
.end() )
525 //if it's null, need to create a new Datas_vec
527 "updateMaps: new language: %s\n", rtl::OUStringToOString(
528 it
->language
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
530 "updateMaps: adding functionname: %s\n", rtl::OUStringToOString(
531 it
->functionname
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
533 ScriptFunction_hash sfh
;
534 sfh
[ it
->functionname
] = *it
;
535 mh_implementations
[ it
->language
] = sfh
;
540 "updateMaps: adding functionname: %s\n", rtl::OUStringToOString(
541 it
->functionname
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
542 OSL_TRACE( " language name: %s\n",
543 rtl::OUStringToOString( it
->functionname
,
544 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
546 h_it
->second
[ it
->functionname
] = *it
;
551 //*************************************************************************
552 // XScriptStorageExport::save
554 ScriptStorage::save()
555 throw ( RuntimeException
)
557 ::osl::Guard
< osl::Mutex
> aGuard( m_mutex
);
558 Reference
< io::XActiveDataSource
> xSource
;
559 Reference
< io::XOutputStream
> xOS
;
561 // xScriptInvocation = Reference<XScriptInvocation>(xx, UNO_QUERY_THROW);
562 Reference
< xml::sax::XExtendedDocumentHandler
> xHandler
;
564 OUString parcel_suffix
= OUString::createFromAscii( SCRIPT_PARCEL
);
565 OUString ou_parcel
= OUString(
566 RTL_CONSTASCII_USTRINGPARAM( SCRIPT_PARCEL_NAME_ONLY
) );
570 ScriptData_hash::iterator it_end
= mh_implementations
.end();
571 for ( ScriptData_hash::iterator it
= mh_implementations
.begin() ; it
!= it_end
; ++it
)
573 ::rtl::OUString logName
= it
->first
;
574 ScriptFunction_hash::iterator it_sfh_end
= it
->second
.end();
575 for ( ScriptFunction_hash::iterator it_sfh
= it
->second
.begin();
576 it_sfh
!= it_sfh_end
; ++it_sfh
)
578 ScriptOutput_hash::const_iterator it_parcels
=
579 mh_parcels
.find( it_sfh
->second
.parcelURI
);
580 if ( it_parcels
== mh_parcels
.end() )
582 //create new outputstream
583 OUString parcel_xml_path
= it_sfh
->second
.parcelURI
.concat(
585 m_xSimpleFileAccess
->kill( parcel_xml_path
);
586 xOS
= m_xSimpleFileAccess
->openFileWrite( parcel_xml_path
);
588 OSL_TRACE( "saving: %s\n", rtl::OUStringToOString(
589 it_sfh
->second
.parcelURI
.concat( OUString::createFromAscii(
591 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
593 Reference
< XInterface
> xInterface
=
594 m_xMgr
->createInstanceWithContext(
595 OUString::createFromAscii( "com.sun.star.xml.sax.Writer" ),
597 validateXRef( xInterface
, "ScriptStorage::save: cannot get sax.Writer" );
598 xHandler
= Reference
<xml::sax::XExtendedDocumentHandler
>(
599 xInterface
, UNO_QUERY_THROW
);
600 xSource
= Reference
< io::XActiveDataSource
>(
601 xHandler
, UNO_QUERY_THROW
);
602 xSource
->setOutputStream( xOS
);
604 writeMetadataHeader( xHandler
);
606 mh_parcels
[ it_sfh
->second
.parcelURI
] = xHandler
;
610 xHandler
= it_parcels
->second
;
613 ScriptElement
* pSE
= new ScriptElement( it_sfh
->second
);
614 // this is to get pSE released correctly
615 Reference
< xml::sax::XAttributeList
> xal( pSE
);
616 pSE
->dump( xHandler
);
620 ScriptOutput_hash::const_iterator out_it_end
= mh_parcels
.end();
622 for ( ScriptOutput_hash::const_iterator out_it
= mh_parcels
.begin();
623 out_it
!= out_it_end
; ++out_it
)
625 out_it
->second
->ignorableWhitespace( ::rtl::OUString() );
626 out_it
->second
->endDocument();
627 xSource
.set( out_it
->second
, UNO_QUERY
);
628 Reference
< io::XOutputStream
> xOS
= xSource
->getOutputStream();
633 // clear the hash map, as all output streams have been closed.
634 // need to re-create on next save
637 // *** TODO - other exception handling IO etc.
638 catch ( RuntimeException
& re
)
640 OSL_TRACE( "caught com::sun::star::uno::RuntimeException in ScriptStorage::save" );
641 throw RuntimeException(
642 OUSTR( "ScriptStorage::save RuntimeException: " ).concat(
644 Reference
< XInterface
> () );
648 //*************************************************************************
650 ScriptStorage::refresh()
651 throw (RuntimeException
)
653 OSL_TRACE("** => ScriptStorage: in refresh()\n");
655 // guard against concurrent refreshes
656 ::osl::Guard
< ::osl::Mutex
> aGuard( m_mutex
);
663 catch ( RuntimeException
& re
)
665 OSL_TRACE( "caught com::sun::star::uno::RuntimeException in ScriptStorage::refresh" );
666 throw RuntimeException(
667 OUSTR( "ScriptStorage::refresh RuntimeException: " ).concat( re
.Message
),
668 Reference
< XInterface
> () );
670 catch ( Exception
& ue
)
672 OSL_TRACE( "caught com::sun::star::uno::Exception in ScriptStorage::refresh" );
673 throw RuntimeException(
674 OUSTR( "ScriptStorage::refresh Exception: " ).concat( ue
.Message
),
675 Reference
< XInterface
> () );
679 //*************************************************************************
681 ScriptStorage::writeMetadataHeader(
682 Reference
<xml::sax::XExtendedDocumentHandler
> & xHandler
)
684 xHandler
->startDocument();
685 OUString
aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM(
686 "<!DOCTYPE parcel SYSTEM \"scripting.dtd\">" ) );
687 xHandler
->unknown( aDocTypeStr
);
688 xHandler
->ignorableWhitespace( OUString() );
692 //*************************************************************************
693 Sequence
< ::rtl::OUString
>
694 ScriptStorage::getScriptLogicalNames()
695 throw ( RuntimeException
)
697 Sequence
< ::rtl::OUString
> results
;
698 // comment out the rest, and ultimately remove method
699 /*ScriptInfo_hash::iterator h_it = mh_implementations.begin();
700 ScriptInfo_hash::iterator h_itEnd = mh_implementations.end();
701 if ( h_it == h_itEnd )
703 OSL_TRACE( "ScriptStorage::getImplementations: EMPTY STORAGE");
706 results.realloc( mh_implementations.size() );
708 //find the implementations for the given logical name
712 ::osl::Guard< osl::Mutex > aGuard( m_mutex );
714 for ( sal_Int32 count = 0; h_it != h_itEnd ; ++h_it )
716 ::rtl::OUString logicalName = h_it->first;
717 OSL_TRACE( "Adding %s at index %d ", ::rtl::OUStringToOString(
718 logicalName, RTL_TEXTENCODING_ASCII_US ).pData->buffer, count);
719 results[ count++ ] = logicalName;
723 catch ( RuntimeException & re )
725 throw RuntimeException(
726 OUSTR( "ScriptStorage::getScriptLogicalNames RuntimeException: " ).concat( re.Message ),
727 Reference< XInterface > () );
729 catch ( Exception & e )
731 throw RuntimeException( OUSTR(
732 "ScriptStorage::getScriptLogicalNames Exception: " ).concat(
733 e.Message ), Reference< XInterface > () );
738 //*************************************************************************
739 Sequence
< Reference
< storage::XScriptInfo
> >
740 ScriptStorage::getImplementations( const ::rtl::OUString
& queryURI
)
741 throw ( lang::IllegalArgumentException
,
744 ::osl::Guard
< osl::Mutex
> aGuard( m_mutex
);
745 // format is script:://[function_name]?language=[languge]&location=[location]
746 // LogicalName is now not used anymore, further more the ScriptURI class
747 // will be retired also and a new UNO service will be used. Additionally the
748 // parcel-description will also need to be modified to remove logical name
749 // ScriprtMetaDataImporter has been modified to ignore the Logical name
750 // definined in the parcel-desc.xml. As an interim temp solution the Datas_vec
751 // structure that is returned from ScriptMetDataImporter sets the logicalname
752 // to the function name. ScriptURI class has been changed in the same way.
754 Sequence
< Reference
< storage::XScriptInfo
> > results
;
755 ScriptURI
scriptURI( queryURI
);
756 OSL_TRACE( "getting impl for language %s, function name: %s",
757 ::rtl::OUStringToOString( scriptURI
.getLanguage(),
758 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
,
759 ::rtl::OUStringToOString( scriptURI
.getFunctionName(),
760 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
761 ScriptData_hash::iterator h_itEnd
= mh_implementations
.end();
762 ScriptData_hash::iterator h_it
= mh_implementations
.begin();
763 if ( h_it
== h_itEnd
)
765 OSL_TRACE( "ScriptStorage::getImplementations: EMPTY STORAGE" );
769 //find the implementations for the given language
770 h_it
= mh_implementations
.find( scriptURI
.getLanguage() );
772 if ( h_it
== h_itEnd
)
774 OSL_TRACE( "ScriptStorage::getImplementations: no impls found for %s",
775 ::rtl::OUStringToOString( scriptURI
.getLanguage(),
776 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
780 //find the implementations for the given language
781 ScriptFunction_hash::const_iterator it_datas
= h_it
->second
.find(
782 scriptURI
.getLogicalName() );
783 ScriptFunction_hash::const_iterator it_datas_end
= h_it
->second
.end();
785 if ( it_datas
== it_datas_end
)
787 OSL_TRACE( "ScriptStorage::getImplementations: no impls found for %s",
788 ::rtl::OUStringToOString( scriptURI
.getFunctionName(),
789 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
793 results
.realloc( 1 );
794 ScriptData scriptData
= it_datas
->second
;
795 OSL_TRACE( "ScriptStorage::getImplementations: impls found for %s",
796 ::rtl::OUStringToOString( scriptData
.functionname
,
797 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
798 Reference
< storage::XScriptInfo
> xScriptInfo
=
799 new ScriptInfo ( scriptData
, m_scriptStorageID
);
800 results
[ 0 ] = xScriptInfo
;
805 //*************************************************************************
806 Sequence
< Reference
< storage::XScriptInfo
> > SAL_CALL
807 ScriptStorage::getAllImplementations() throw ( RuntimeException
)
809 ::osl::Guard
< osl::Mutex
> aGuard( m_mutex
);
810 Sequence
< Reference
< storage::XScriptInfo
> > results
;
811 ScriptData_hash::iterator h_itEnd
= mh_implementations
.end();
812 ScriptData_hash::iterator h_it
= mh_implementations
.begin();
813 if ( h_it
== h_itEnd
)
815 OSL_TRACE( "ScriptStorage::getImplementations: EMPTY STORAGE" );
820 //iterate through each logical name and gather each implementation
822 for ( sal_Int32 count
= 0; h_it
!= h_itEnd
; ++h_it
)
824 results
.realloc( h_it
->second
.size() + count
);
825 OSL_TRACE( "Adding implementations for %s",
826 ::rtl::OUStringToOString( h_it
->first
,
827 RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
828 ScriptFunction_hash::const_iterator it_sfh
= h_it
->second
.begin();
829 ScriptFunction_hash::const_iterator it_sfh_end
= h_it
->second
.end();
830 OSL_TRACE( "Adding %d to sequence of impls ", h_it
->second
.size() );
831 for ( ; it_sfh
!= it_sfh_end
; ++it_sfh
)
833 Reference
< storage::XScriptInfo
> xScriptInfo
= new ScriptInfo (
834 it_sfh
->second
, m_scriptStorageID
);
836 results
[ count
++ ] = xScriptInfo
;
843 //*************************************************************************
844 OUString SAL_CALL
ScriptStorage::getImplementationName( )
845 throw( RuntimeException
)
850 //*************************************************************************
851 sal_Bool SAL_CALL
ScriptStorage::supportsService( const OUString
& serviceName
)
852 throw( RuntimeException
)
854 OUString
const * pNames
= ss_serviceNames
.getConstArray();
855 for ( sal_Int32 nPos
= ss_serviceNames
.getLength(); nPos
--; )
857 if ( serviceName
.equals( pNames
[ nPos
] ) )
865 //*************************************************************************
866 Sequence
<OUString
> SAL_CALL
ScriptStorage::getSupportedServiceNames( )
867 throw( RuntimeException
)
869 return ss_serviceNames
;
872 } // namespace scripting_impl
875 namespace scripting_runtimemgr
878 //*************************************************************************
879 Reference
<XInterface
> SAL_CALL
ss_create(
880 const Reference
< XComponentContext
> & xCompC
)
882 return ( cppu::OWeakObject
* ) new ::scripting_impl::ScriptStorage( xCompC
);
885 //*************************************************************************
886 Sequence
<OUString
> ss_getSupportedServiceNames( )
889 return ::scripting_impl::ss_serviceNames
;
892 //*************************************************************************
893 OUString
ss_getImplementationName( )
896 return ::scripting_impl::ss_implName
;