2002-09-20 13:37:46 +00:00
/*************************************************************************
*
* $ RCSfile : ScriptStorageManager . hxx , v $
*
2003-02-12 15:21:43 +00:00
* $ Revision : 1.15 $
2002-09-20 13:37:46 +00:00
*
2003-02-12 15:21:43 +00:00
* last change : $ Author : npower $ $ Date : 2003 - 02 - 12 16 : 21 : 43 $
2002-09-20 13:37:46 +00:00
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc . , October , 2000
*
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2000 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 , as published by the Free Software Foundation .
*
* This library 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 for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston ,
* MA 02111 - 1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 ( the " License " ) ; You may not use this file
* except in compliance with the License . You may obtain a copy of the
* License at http : //www.openoffice.org/license.html.
*
* Software provided under this License is provided on an " AS IS " basis ,
* WITHOUT WARRANTY OF ANY KIND , EITHER EXPRESSED OR IMPLIED , INCLUDING ,
* WITHOUT LIMITATION , WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS ,
* MERCHANTABLE , FIT FOR A PARTICULAR PURPOSE , OR NON - INFRINGING .
* See the License for the specific provisions governing your rights and
* obligations concerning the Software .
*
* The Initial Developer of the Original Code is : Sun Microsystems , Inc .
*
* Copyright : 2000 by Sun Microsystems , Inc .
*
* All Rights Reserved .
*
* Contributor ( s ) : _______________________________________
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_
# define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_
# include <hash_map>
2002-11-06 15:26:40 +00:00
# include <map>
2002-09-20 13:37:46 +00:00
2002-09-27 11:16:30 +00:00
# include <osl/mutex.hxx>
2003-01-27 16:18:27 +00:00
# include <cppuhelper/implbase4.hxx>
2002-09-20 13:37:46 +00:00
# include <com/sun/star/lang/XServiceInfo.hpp>
# include <com/sun/star/lang/XEventListener.hpp>
# include <com/sun/star/uno/RuntimeException.hpp>
2002-09-27 11:16:30 +00:00
2002-09-20 13:37:46 +00:00
# include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
2003-01-27 16:18:27 +00:00
# include <drafts/com/sun/star/script/framework/storage/XScriptStorageRefresh.hpp>
# include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp>
# include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp>
# include "ScriptSecurityManager.hxx"
2002-09-20 13:37:46 +00:00
namespace scripting_impl
{
2002-10-01 09:45:14 +00:00
// for simplification
# define css ::com::sun::star
# define dcsssf ::drafts::com::sun::star::script::framework
2002-09-20 13:37:46 +00:00
2002-11-06 15:26:40 +00:00
// Define a map used to store the ScriptingStorages key;d by ID
typedef : : std : : map < sal_Int32 , css : : uno : : Reference < css : : uno : : XInterface > >
ScriptStorage_map ;
2002-09-27 11:16:30 +00:00
2002-11-01 12:58:33 +00:00
typedef : : std : : hash_map < : : rtl : : OUString , sal_Int32 , : : rtl : : OUStringHash >
StorageId_hash ;
2002-10-01 09:45:14 +00:00
class ScriptStorageManager : public
2003-01-27 16:18:27 +00:00
: : cppu : : WeakImplHelper4 < dcsssf : : storage : : XScriptStorageManager ,
dcsssf : : security : : XScriptSecurity , css : : lang : : XServiceInfo ,
css : : lang : : XEventListener >
2002-09-20 13:37:46 +00:00
{
public :
2002-09-27 11:16:30 +00:00
explicit ScriptStorageManager (
2002-10-01 09:45:14 +00:00
const css : : uno : : Reference < css : : uno : : XComponentContext > & xContext )
SAL_THROW ( ( css : : uno : : RuntimeException ) ) ;
2002-09-27 13:14:14 +00:00
2002-09-20 13:37:46 +00:00
2002-09-27 11:16:30 +00:00
~ ScriptStorageManager ( ) SAL_THROW ( ( ) ) ;
2002-09-20 13:37:46 +00:00
// XServiceInfo implementation
//======================================================================
2002-10-01 09:45:14 +00:00
virtual : : rtl : : OUString SAL_CALL getImplementationName ( )
2002-10-24 11:00:40 +00:00
throw ( css : : uno : : RuntimeException ) ;
2002-09-20 13:37:46 +00:00
//----------------------------------------------------------------------
2002-10-01 09:45:14 +00:00
virtual sal_Bool SAL_CALL supportsService ( const : : rtl : : OUString & ServiceName )
2002-10-24 11:00:40 +00:00
throw ( css : : uno : : RuntimeException ) ;
2002-09-20 13:37:46 +00:00
//----------------------------------------------------------------------
2002-10-01 09:45:14 +00:00
virtual css : : uno : : Sequence < : : rtl : : OUString > SAL_CALL getSupportedServiceNames ( )
2002-10-24 11:00:40 +00:00
throw ( css : : uno : : RuntimeException ) ;
2002-09-20 13:37:46 +00:00
//======================================================================
//XScriptStorageManager
//======================================================================
/**
create a ScriptStorage using the XSimpleFileAccess passed as an
argument , and return a ID for getting the associated ScriptStorage
@ params xSFA
an implementation of XSimpleFileAccess that knows its own base URL
and can thus take URLs relative to that base .
@ returns an unsigned short ScriptStorage ID , which can be used in the
getScriptStorage method
*/
2002-10-17 09:04:15 +00:00
virtual sal_Int32 SAL_CALL createScriptStorage (
2002-10-01 09:45:14 +00:00
const css : : uno : : Reference < css : : ucb : : XSimpleFileAccess > & xSFA )
2002-10-24 11:00:40 +00:00
throw ( css : : uno : : RuntimeException ) ;
2002-09-20 13:37:46 +00:00
//----------------------------------------------------------------------
/**
create a ScriptStorage using the XSimpleFileAccess , and a string URL
and return a ID for getting the associated ScriptStorage
@ params xSFA
a standard implementation of XSimpleFileAccess
@ params stringURI
a string URI to the head of the script storage
@ returns an unsigned short ScriptStorage ID , which can be used in the
getScriptStorage method
*/
2002-10-17 09:04:15 +00:00
virtual sal_Int32 SAL_CALL
2002-09-27 11:16:30 +00:00
createScriptStorageWithURI (
2002-10-01 09:45:14 +00:00
const css : : uno : : Reference < css : : ucb : : XSimpleFileAccess > & xSFA ,
2002-09-27 11:16:30 +00:00
const : : rtl : : OUString & stringURI )
2002-10-24 11:00:40 +00:00
throw ( css : : uno : : RuntimeException ) ;
2002-09-20 13:37:46 +00:00
//----------------------------------------------------------------------
/**
get a ScriptStorage component using its scriptStorageID
@ params scriptStorageID
the usigned short returned by one of the methods above . ID = 0 is
reserved for the application / share scripts , and ID = 1 is reserved
for the application / user scripts
@ returns an XInterface to a component that implements the ScriptStorage
service
*/
2002-10-01 09:45:14 +00:00
virtual css : : uno : : Reference < css : : uno : : XInterface > SAL_CALL getScriptStorage (
2002-10-17 09:04:15 +00:00
sal_Int32 scriptStorageID )
2002-10-24 11:00:40 +00:00
throw ( css : : uno : : RuntimeException ) ;
2002-11-01 12:58:33 +00:00
2003-02-12 15:21:43 +00:00
/**
get a ScriptStorage ID using storage URI
@ param scriptStorageURI
the file URL for the document will retrieve storage id for the document , special treatment is reserved for the strings " USER " and " SHARE " which
retrieve storage id for application / user application / share areas respectively .
@ returns as long ScriptStorage ID ( - 1 if no storage exists ) , which can be used in getScriptStorage method .
*/
virtual sal_Int32 SAL_CALL getScriptStorageID ( const : : rtl : : OUString & scriptStorageURI )
throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
/**
refresh a storage component using its URI
@ param StringURI
URI of storage area , for documents , url to document eg , file : ///home/user/ADocument.sxw To refresh the storage for user or share area, use USER or SHARE respectively instead or a url.
*/
2002-11-01 12:58:33 +00:00
virtual void SAL_CALL refreshScriptStorage ( const : : rtl : : OUString & stringURI )
throw ( css : : uno : : RuntimeException ) ;
2002-09-20 13:37:46 +00:00
//======================================================================
2003-01-27 16:18:27 +00:00
//XScriptSecurity
//======================================================================
//----------------------------------------------------------------------
/**
the language independent interface for invocation
@ param scriptURI
a string containing the script URI
@ returns
the value returned from the function being invoked
@ throws IllegalArgumentException
if there is no matching script name
*/
2003-02-12 13:59:01 +00:00
virtual sal_Bool SAL_CALL ScriptStorageManager : : checkPermission (
2003-01-28 16:09:27 +00:00
const rtl : : OUString & scriptStorageURI ,
2003-01-27 16:18:27 +00:00
const rtl : : OUString & permissionRequest )
throw ( css : : uno : : RuntimeException ) ;
//======================================================================
2002-09-20 13:37:46 +00:00
//XEventListener
//======================================================================
2003-01-16 17:50:55 +00:00
2002-10-01 09:45:14 +00:00
virtual void SAL_CALL disposing ( const css : : lang : : EventObject & Source )
2002-10-24 11:00:40 +00:00
throw ( css : : uno : : RuntimeException ) ;
2002-09-27 11:16:30 +00:00
private :
2002-10-24 11:00:40 +00:00
ScriptStorageManager ( const ScriptStorageManager & ) ;
ScriptStorageManager & operator = ( const ScriptStorageManager & ) ;
2002-09-27 11:16:30 +00:00
2003-01-16 17:50:55 +00:00
void removeScriptDocURIHashEntry ( const : : rtl : : OUString & origURI ) ;
2002-09-27 11:16:30 +00:00
// to obtain other services if needed
2002-10-01 09:45:14 +00:00
css : : uno : : Reference < css : : uno : : XComponentContext > m_xContext ;
css : : uno : : Reference < css : : lang : : XMultiComponentFactory > m_xMgr ;
: : osl : : Mutex m_mutex ;
2002-11-06 15:26:40 +00:00
ScriptStorage_map m_ScriptStorageMap ;
2003-01-16 17:50:55 +00:00
StorageId_hash m_StorageIdOrigURIHash ;
2002-10-17 09:04:15 +00:00
sal_Int32 m_count ;
2003-01-27 16:18:27 +00:00
scripting_securitymgr : : ScriptSecurityManager m_securityMgr ;
2002-09-27 11:16:30 +00:00
2002-10-01 09:45:14 +00:00
void setupAppStorage ( const css : : uno : : Reference < css : : util : : XMacroExpander > & xME ,
2003-01-16 17:50:55 +00:00
const : : rtl : : OUString & storageStr ,
const : : rtl : : OUString & appStr )
2002-10-01 09:45:14 +00:00
SAL_THROW ( ( css : : uno : : RuntimeException ) ) ;
2002-09-27 11:16:30 +00:00
2002-10-17 09:04:15 +00:00
sal_Int32 setupAnyStorage (
2002-10-01 09:45:14 +00:00
const css : : uno : : Reference < css : : ucb : : XSimpleFileAccess > & xSFA ,
2003-01-16 17:50:55 +00:00
const : : rtl : : OUString & storageStr ,
const : : rtl : : OUString & origStringURI )
2002-10-01 09:45:14 +00:00
SAL_THROW ( ( css : : uno : : RuntimeException ) ) ;
2002-09-27 11:16:30 +00:00
2002-09-20 13:37:46 +00:00
} ;
} // scripting_impl
# endif //_COM_SUN_STAR_SCRIPTING_STORAGE_SCRIPTSTORAGEMANAGER_HXX_