2002-09-20 13:37:46 +00:00
/*************************************************************************
*
2008-04-11 09:46:17 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2002-09-20 13:37:46 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2002-09-20 13:37:46 +00:00
*
2008-04-11 09:46:17 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2002-09-20 13:37:46 +00:00
*
2008-04-11 09:46:17 +00:00
* This file is part of OpenOffice . org .
2002-09-20 13:37:46 +00:00
*
2008-04-11 09:46:17 +00:00
* 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 .
2002-09-20 13:37:46 +00:00
*
2008-04-11 09:46:17 +00:00
* 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 ) .
2002-09-20 13:37:46 +00:00
*
2008-04-11 09:46:17 +00:00
* 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 .
2002-09-20 13:37:46 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# 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>
2003-03-04 11:33:34 +00:00
# include <com/sun/star/lang/IllegalArgumentException.hpp>
# include <com/sun/star/security/AccessControlException.hpp>
2002-09-20 13:37:46 +00:00
# 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-03-12 14:54:18 +00:00
virtual void 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 )
2003-03-04 11:33:34 +00:00
throw ( css : : uno : : RuntimeException , css : : lang : : IllegalArgumentException ,
css : : security : : AccessControlException ) ;
2003-01-27 16:18:27 +00:00
//======================================================================
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_