merge the formfield patch from ooo-build
[ooovba.git] / scripting / source / storage / ScriptStorageManager.hxx
blob13bfeae3922dece83ae1e71088d2327789e9bbe3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScriptStorageManager.hxx,v $
10 * $Revision: 1.19 $
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 ************************************************************************/
32 #ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_
33 #define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_
35 #include <hash_map>
36 #include <map>
38 #include <osl/mutex.hxx>
39 #include <cppuhelper/implbase4.hxx>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XEventListener.hpp>
43 #include <com/sun/star/lang/IllegalArgumentException.hpp>
44 #include <com/sun/star/security/AccessControlException.hpp>
45 #include <com/sun/star/uno/RuntimeException.hpp>
47 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
48 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageRefresh.hpp>
49 #include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp>
50 #include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp>
51 #include "ScriptSecurityManager.hxx"
54 namespace scripting_impl
56 // for simplification
57 #define css ::com::sun::star
58 #define dcsssf ::drafts::com::sun::star::script::framework
60 // Define a map used to store the ScriptingStorages key;d by ID
61 typedef ::std::map < sal_Int32, css::uno::Reference < css::uno::XInterface > >
62 ScriptStorage_map;
64 typedef ::std::hash_map < ::rtl::OUString, sal_Int32, ::rtl::OUStringHash>
65 StorageId_hash;
67 class ScriptStorageManager : public
68 ::cppu::WeakImplHelper4 < dcsssf::storage::XScriptStorageManager,
69 dcsssf::security::XScriptSecurity, css::lang::XServiceInfo,
70 css::lang::XEventListener >
72 public:
73 explicit ScriptStorageManager(
74 const css::uno::Reference< css::uno::XComponentContext > & xContext )
75 SAL_THROW ( ( css::uno::RuntimeException ) );
78 ~ScriptStorageManager() SAL_THROW ( () );
80 // XServiceInfo implementation
81 //======================================================================
82 virtual ::rtl::OUString SAL_CALL getImplementationName()
83 throw( css::uno::RuntimeException );
84 //----------------------------------------------------------------------
85 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
86 throw( css::uno::RuntimeException );
87 //----------------------------------------------------------------------
88 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
89 throw( css::uno::RuntimeException );
90 //======================================================================
92 //XScriptStorageManager
93 //======================================================================
94 /**
95 create a ScriptStorage using the XSimpleFileAccess passed as an
96 argument, and return a ID for getting the associated ScriptStorage
98 @params xSFA
99 an implementation of XSimpleFileAccess that knows its own base URL
100 and can thus take URLs relative to that base.
102 @returns an unsigned short ScriptStorage ID, which can be used in the
103 getScriptStorage method
105 virtual sal_Int32 SAL_CALL createScriptStorage(
106 const css::uno::Reference< css::ucb::XSimpleFileAccess > & xSFA )
107 throw ( css::uno::RuntimeException );
108 //----------------------------------------------------------------------
110 create a ScriptStorage using the XSimpleFileAccess, and a string URL
111 and return a ID for getting the associated ScriptStorage
113 @params xSFA
114 a standard implementation of XSimpleFileAccess
116 @params stringURI
117 a string URI to the head of the script storage
119 @returns an unsigned short ScriptStorage ID, which can be used in the
120 getScriptStorage method
122 virtual sal_Int32 SAL_CALL
123 createScriptStorageWithURI(
124 const css::uno::Reference< css::ucb::XSimpleFileAccess >& xSFA,
125 const ::rtl::OUString& stringURI )
126 throw ( css::uno::RuntimeException );
127 //----------------------------------------------------------------------
129 get a ScriptStorage component using its scriptStorageID
131 @params scriptStorageID
132 the usigned short returned by one of the methods above. ID=0 is
133 reserved for the application/share scripts, and ID=1 is reserved
134 for the application/user scripts
136 @returns an XInterface to a component that implements the ScriptStorage
137 service
139 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getScriptStorage(
140 sal_Int32 scriptStorageID )
141 throw ( css::uno::RuntimeException );
144 get a ScriptStorage ID using storage URI
146 @param scriptStorageURI
147 the file URL for the document will retrieve storage id for the document, special treatment is reserved for the strings "USER"and "SHARE" which
148 retrieve storage id for application/user application/share areas respectively.
151 @returns as long ScriptStorage ID (-1 if no storage exists), which can be used in getScriptStorage method.
155 virtual sal_Int32 SAL_CALL getScriptStorageID( const ::rtl::OUString& scriptStorageURI )
156 throw (::com::sun::star::uno::RuntimeException);
159 refresh a storage component using its URI
161 @param StringURI
162 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.
166 virtual void SAL_CALL refreshScriptStorage(const ::rtl::OUString & stringURI)
167 throw ( css::uno::RuntimeException );
168 //======================================================================
170 //XScriptSecurity
171 //======================================================================
172 //----------------------------------------------------------------------
174 the language independent interface for invocation
176 @param scriptURI
177 a string containing the script URI
179 @returns
180 the value returned from the function being invoked
182 @throws IllegalArgumentException
183 if there is no matching script name
186 virtual void SAL_CALL ScriptStorageManager::checkPermission(
187 const rtl::OUString & scriptStorageURI,
188 const rtl::OUString & permissionRequest )
189 throw ( css::uno::RuntimeException, css::lang::IllegalArgumentException,
190 css::security::AccessControlException );
191 //======================================================================
193 //XEventListener
194 //======================================================================
196 virtual void SAL_CALL disposing( const css::lang::EventObject& Source )
197 throw ( css::uno::RuntimeException );
199 private:
200 ScriptStorageManager( const ScriptStorageManager & );
201 ScriptStorageManager& operator= ( const ScriptStorageManager & );
203 void removeScriptDocURIHashEntry( const ::rtl::OUString & origURI );
205 // to obtain other services if needed
206 css::uno::Reference< css::uno::XComponentContext > m_xContext;
207 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
208 ::osl::Mutex m_mutex;
209 ScriptStorage_map m_ScriptStorageMap;
210 StorageId_hash m_StorageIdOrigURIHash;
211 sal_Int32 m_count;
212 scripting_securitymgr::ScriptSecurityManager m_securityMgr;
214 void setupAppStorage( const css::uno::Reference< css::util::XMacroExpander > & xME,
215 const ::rtl::OUString & storageStr,
216 const ::rtl::OUString & appStr)
217 SAL_THROW ( ( css::uno::RuntimeException ) );
219 sal_Int32 setupAnyStorage(
220 const css::uno::Reference< css::ucb::XSimpleFileAccess> & xSFA,
221 const ::rtl::OUString & storageStr,
222 const ::rtl::OUString & origStringURI )
223 SAL_THROW ( ( css::uno::RuntimeException ) );
226 } // scripting_impl
228 #endif //_COM_SUN_STAR_SCRIPTING_STORAGE_SCRIPTSTORAGEMANAGER_HXX_