merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / scripting / source / storage / ScriptStorageManager.hxx
blob32d10bb09db0c4a934a5a0bb875d29e64527b146
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_
31 #define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_
33 #include <hash_map>
34 #include <map>
36 #include <osl/mutex.hxx>
37 #include <cppuhelper/implbase4.hxx>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XEventListener.hpp>
41 #include <com/sun/star/lang/IllegalArgumentException.hpp>
42 #include <com/sun/star/security/AccessControlException.hpp>
43 #include <com/sun/star/uno/RuntimeException.hpp>
45 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
46 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageRefresh.hpp>
47 #include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp>
48 #include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp>
49 #include "ScriptSecurityManager.hxx"
52 namespace scripting_impl
54 // for simplification
55 #define css ::com::sun::star
56 #define dcsssf ::drafts::com::sun::star::script::framework
58 // Define a map used to store the ScriptingStorages key;d by ID
59 typedef ::std::map < sal_Int32, css::uno::Reference < css::uno::XInterface > >
60 ScriptStorage_map;
62 typedef ::std::hash_map < ::rtl::OUString, sal_Int32, ::rtl::OUStringHash>
63 StorageId_hash;
65 class ScriptStorageManager : public
66 ::cppu::WeakImplHelper4 < dcsssf::storage::XScriptStorageManager,
67 dcsssf::security::XScriptSecurity, css::lang::XServiceInfo,
68 css::lang::XEventListener >
70 public:
71 explicit ScriptStorageManager(
72 const css::uno::Reference< css::uno::XComponentContext > & xContext )
73 SAL_THROW ( ( css::uno::RuntimeException ) );
76 ~ScriptStorageManager() SAL_THROW ( () );
78 // XServiceInfo implementation
79 //======================================================================
80 virtual ::rtl::OUString SAL_CALL getImplementationName()
81 throw( css::uno::RuntimeException );
82 //----------------------------------------------------------------------
83 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
84 throw( css::uno::RuntimeException );
85 //----------------------------------------------------------------------
86 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
87 throw( css::uno::RuntimeException );
88 //======================================================================
90 //XScriptStorageManager
91 //======================================================================
92 /**
93 create a ScriptStorage using the XSimpleFileAccess passed as an
94 argument, and return a ID for getting the associated ScriptStorage
96 @params xSFA
97 an implementation of XSimpleFileAccess that knows its own base URL
98 and can thus take URLs relative to that base.
100 @returns an unsigned short ScriptStorage ID, which can be used in the
101 getScriptStorage method
103 virtual sal_Int32 SAL_CALL createScriptStorage(
104 const css::uno::Reference< css::ucb::XSimpleFileAccess > & xSFA )
105 throw ( css::uno::RuntimeException );
106 //----------------------------------------------------------------------
108 create a ScriptStorage using the XSimpleFileAccess, and a string URL
109 and return a ID for getting the associated ScriptStorage
111 @params xSFA
112 a standard implementation of XSimpleFileAccess
114 @params stringURI
115 a string URI to the head of the script storage
117 @returns an unsigned short ScriptStorage ID, which can be used in the
118 getScriptStorage method
120 virtual sal_Int32 SAL_CALL
121 createScriptStorageWithURI(
122 const css::uno::Reference< css::ucb::XSimpleFileAccess >& xSFA,
123 const ::rtl::OUString& stringURI )
124 throw ( css::uno::RuntimeException );
125 //----------------------------------------------------------------------
127 get a ScriptStorage component using its scriptStorageID
129 @params scriptStorageID
130 the usigned short returned by one of the methods above. ID=0 is
131 reserved for the application/share scripts, and ID=1 is reserved
132 for the application/user scripts
134 @returns an XInterface to a component that implements the ScriptStorage
135 service
137 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getScriptStorage(
138 sal_Int32 scriptStorageID )
139 throw ( css::uno::RuntimeException );
142 get a ScriptStorage ID using storage URI
144 @param scriptStorageURI
145 the file URL for the document will retrieve storage id for the document, special treatment is reserved for the strings "USER"and "SHARE" which
146 retrieve storage id for application/user application/share areas respectively.
149 @returns as long ScriptStorage ID (-1 if no storage exists), which can be used in getScriptStorage method.
153 virtual sal_Int32 SAL_CALL getScriptStorageID( const ::rtl::OUString& scriptStorageURI )
154 throw (::com::sun::star::uno::RuntimeException);
157 refresh a storage component using its URI
159 @param StringURI
160 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.
164 virtual void SAL_CALL refreshScriptStorage(const ::rtl::OUString & stringURI)
165 throw ( css::uno::RuntimeException );
166 //======================================================================
168 //XScriptSecurity
169 //======================================================================
170 //----------------------------------------------------------------------
172 the language independent interface for invocation
174 @param scriptURI
175 a string containing the script URI
177 @returns
178 the value returned from the function being invoked
180 @throws IllegalArgumentException
181 if there is no matching script name
184 virtual void SAL_CALL ScriptStorageManager::checkPermission(
185 const rtl::OUString & scriptStorageURI,
186 const rtl::OUString & permissionRequest )
187 throw ( css::uno::RuntimeException, css::lang::IllegalArgumentException,
188 css::security::AccessControlException );
189 //======================================================================
191 //XEventListener
192 //======================================================================
194 virtual void SAL_CALL disposing( const css::lang::EventObject& Source )
195 throw ( css::uno::RuntimeException );
197 private:
198 ScriptStorageManager( const ScriptStorageManager & );
199 ScriptStorageManager& operator= ( const ScriptStorageManager & );
201 void removeScriptDocURIHashEntry( const ::rtl::OUString & origURI );
203 // to obtain other services if needed
204 css::uno::Reference< css::uno::XComponentContext > m_xContext;
205 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
206 ::osl::Mutex m_mutex;
207 ScriptStorage_map m_ScriptStorageMap;
208 StorageId_hash m_StorageIdOrigURIHash;
209 sal_Int32 m_count;
210 scripting_securitymgr::ScriptSecurityManager m_securityMgr;
212 void setupAppStorage( const css::uno::Reference< css::util::XMacroExpander > & xME,
213 const ::rtl::OUString & storageStr,
214 const ::rtl::OUString & appStr)
215 SAL_THROW ( ( css::uno::RuntimeException ) );
217 sal_Int32 setupAnyStorage(
218 const css::uno::Reference< css::ucb::XSimpleFileAccess> & xSFA,
219 const ::rtl::OUString & storageStr,
220 const ::rtl::OUString & origStringURI )
221 SAL_THROW ( ( css::uno::RuntimeException ) );
224 } // scripting_impl
226 #endif //_COM_SUN_STAR_SCRIPTING_STORAGE_SCRIPTSTORAGEMANAGER_HXX_
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */