1*6998d047SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6998d047SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6998d047SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6998d047SAndrew Rist * distributed with this work for additional information 6*6998d047SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6998d047SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6998d047SAndrew Rist * "License"); you may not use this file except in compliance 9*6998d047SAndrew Rist * with the License. You may obtain a copy of the License at 10*6998d047SAndrew Rist * 11*6998d047SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6998d047SAndrew Rist * 13*6998d047SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6998d047SAndrew Rist * software distributed under the License is distributed on an 15*6998d047SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6998d047SAndrew Rist * KIND, either express or implied. See the License for the 17*6998d047SAndrew Rist * specific language governing permissions and limitations 18*6998d047SAndrew Rist * under the License. 19*6998d047SAndrew Rist * 20*6998d047SAndrew Rist *************************************************************/ 21*6998d047SAndrew Rist 22*6998d047SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir #ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_ 26cdf0e10cSrcweir #define _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_STORAGE_SCRIPTSTORAGEMANAGER_HXX_ 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <hash_map> 29cdf0e10cSrcweir #include <map> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <osl/mutex.hxx> 32cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 35cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 36cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 37cdf0e10cSrcweir #include <com/sun/star/security/AccessControlException.hpp> 38cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp> 41cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptStorageRefresh.hpp> 42cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp> 43cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/security/XScriptSecurity.hpp> 44cdf0e10cSrcweir #include "ScriptSecurityManager.hxx" 45cdf0e10cSrcweir 46cdf0e10cSrcweir 47cdf0e10cSrcweir namespace scripting_impl 48cdf0e10cSrcweir { 49cdf0e10cSrcweir // for simplification 50cdf0e10cSrcweir #define css ::com::sun::star 51cdf0e10cSrcweir #define dcsssf ::drafts::com::sun::star::script::framework 52cdf0e10cSrcweir 53cdf0e10cSrcweir // Define a map used to store the ScriptingStorages key;d by ID 54cdf0e10cSrcweir typedef ::std::map < sal_Int32, css::uno::Reference < css::uno::XInterface > > 55cdf0e10cSrcweir ScriptStorage_map; 56cdf0e10cSrcweir 57cdf0e10cSrcweir typedef ::std::hash_map < ::rtl::OUString, sal_Int32, ::rtl::OUStringHash> 58cdf0e10cSrcweir StorageId_hash; 59cdf0e10cSrcweir 60cdf0e10cSrcweir class ScriptStorageManager : public 61cdf0e10cSrcweir ::cppu::WeakImplHelper4 < dcsssf::storage::XScriptStorageManager, 62cdf0e10cSrcweir dcsssf::security::XScriptSecurity, css::lang::XServiceInfo, 63cdf0e10cSrcweir css::lang::XEventListener > 64cdf0e10cSrcweir { 65cdf0e10cSrcweir public: 66cdf0e10cSrcweir explicit ScriptStorageManager( 67cdf0e10cSrcweir const css::uno::Reference< css::uno::XComponentContext > & xContext ) 68cdf0e10cSrcweir SAL_THROW ( ( css::uno::RuntimeException ) ); 69cdf0e10cSrcweir 70cdf0e10cSrcweir 71cdf0e10cSrcweir ~ScriptStorageManager() SAL_THROW ( () ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir // XServiceInfo implementation 74cdf0e10cSrcweir //====================================================================== 75cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() 76cdf0e10cSrcweir throw( css::uno::RuntimeException ); 77cdf0e10cSrcweir //---------------------------------------------------------------------- 78cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 79cdf0e10cSrcweir throw( css::uno::RuntimeException ); 80cdf0e10cSrcweir //---------------------------------------------------------------------- 81cdf0e10cSrcweir virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() 82cdf0e10cSrcweir throw( css::uno::RuntimeException ); 83cdf0e10cSrcweir //====================================================================== 84cdf0e10cSrcweir 85cdf0e10cSrcweir //XScriptStorageManager 86cdf0e10cSrcweir //====================================================================== 87cdf0e10cSrcweir /** 88cdf0e10cSrcweir create a ScriptStorage using the XSimpleFileAccess passed as an 89cdf0e10cSrcweir argument, and return a ID for getting the associated ScriptStorage 90cdf0e10cSrcweir 91cdf0e10cSrcweir @params xSFA 92cdf0e10cSrcweir an implementation of XSimpleFileAccess that knows its own base URL 93cdf0e10cSrcweir and can thus take URLs relative to that base. 94cdf0e10cSrcweir 95cdf0e10cSrcweir @returns an unsigned short ScriptStorage ID, which can be used in the 96cdf0e10cSrcweir getScriptStorage method 97cdf0e10cSrcweir */ 98cdf0e10cSrcweir virtual sal_Int32 SAL_CALL createScriptStorage( 99cdf0e10cSrcweir const css::uno::Reference< css::ucb::XSimpleFileAccess > & xSFA ) 100cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 101cdf0e10cSrcweir //---------------------------------------------------------------------- 102cdf0e10cSrcweir /** 103cdf0e10cSrcweir create a ScriptStorage using the XSimpleFileAccess, and a string URL 104cdf0e10cSrcweir and return a ID for getting the associated ScriptStorage 105cdf0e10cSrcweir 106cdf0e10cSrcweir @params xSFA 107cdf0e10cSrcweir a standard implementation of XSimpleFileAccess 108cdf0e10cSrcweir 109cdf0e10cSrcweir @params stringURI 110cdf0e10cSrcweir a string URI to the head of the script storage 111cdf0e10cSrcweir 112cdf0e10cSrcweir @returns an unsigned short ScriptStorage ID, which can be used in the 113cdf0e10cSrcweir getScriptStorage method 114cdf0e10cSrcweir */ 115cdf0e10cSrcweir virtual sal_Int32 SAL_CALL 116cdf0e10cSrcweir createScriptStorageWithURI( 117cdf0e10cSrcweir const css::uno::Reference< css::ucb::XSimpleFileAccess >& xSFA, 118cdf0e10cSrcweir const ::rtl::OUString& stringURI ) 119cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 120cdf0e10cSrcweir //---------------------------------------------------------------------- 121cdf0e10cSrcweir /** 122cdf0e10cSrcweir get a ScriptStorage component using its scriptStorageID 123cdf0e10cSrcweir 124cdf0e10cSrcweir @params scriptStorageID 125cdf0e10cSrcweir the usigned short returned by one of the methods above. ID=0 is 126cdf0e10cSrcweir reserved for the application/share scripts, and ID=1 is reserved 127cdf0e10cSrcweir for the application/user scripts 128cdf0e10cSrcweir 129cdf0e10cSrcweir @returns an XInterface to a component that implements the ScriptStorage 130cdf0e10cSrcweir service 131cdf0e10cSrcweir */ 132cdf0e10cSrcweir virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getScriptStorage( 133cdf0e10cSrcweir sal_Int32 scriptStorageID ) 134cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 135cdf0e10cSrcweir 136cdf0e10cSrcweir /** 137cdf0e10cSrcweir get a ScriptStorage ID using storage URI 138cdf0e10cSrcweir 139cdf0e10cSrcweir @param scriptStorageURI 140cdf0e10cSrcweir the file URL for the document will retrieve storage id for the document, special treatment is reserved for the strings "USER"and "SHARE" which 141cdf0e10cSrcweir retrieve storage id for application/user application/share areas respectively. 142cdf0e10cSrcweir 143cdf0e10cSrcweir 144cdf0e10cSrcweir @returns as long ScriptStorage ID (-1 if no storage exists), which can be used in getScriptStorage method. 145cdf0e10cSrcweir 146cdf0e10cSrcweir */ 147cdf0e10cSrcweir 148cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getScriptStorageID( const ::rtl::OUString& scriptStorageURI ) 149cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 150cdf0e10cSrcweir 151cdf0e10cSrcweir /** 152cdf0e10cSrcweir refresh a storage component using its URI 153cdf0e10cSrcweir 154cdf0e10cSrcweir @param StringURI 155cdf0e10cSrcweir 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. 156cdf0e10cSrcweir 157cdf0e10cSrcweir */ 158cdf0e10cSrcweir 159cdf0e10cSrcweir virtual void SAL_CALL refreshScriptStorage(const ::rtl::OUString & stringURI) 160cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 161cdf0e10cSrcweir //====================================================================== 162cdf0e10cSrcweir 163cdf0e10cSrcweir //XScriptSecurity 164cdf0e10cSrcweir //====================================================================== 165cdf0e10cSrcweir //---------------------------------------------------------------------- 166cdf0e10cSrcweir /** 167cdf0e10cSrcweir the language independent interface for invocation 168cdf0e10cSrcweir 169cdf0e10cSrcweir @param scriptURI 170cdf0e10cSrcweir a string containing the script URI 171cdf0e10cSrcweir 172cdf0e10cSrcweir @returns 173cdf0e10cSrcweir the value returned from the function being invoked 174cdf0e10cSrcweir 175cdf0e10cSrcweir @throws IllegalArgumentException 176cdf0e10cSrcweir if there is no matching script name 177cdf0e10cSrcweir 178cdf0e10cSrcweir */ 179cdf0e10cSrcweir virtual void SAL_CALL ScriptStorageManager::checkPermission( 180cdf0e10cSrcweir const rtl::OUString & scriptStorageURI, 181cdf0e10cSrcweir const rtl::OUString & permissionRequest ) 182cdf0e10cSrcweir throw ( css::uno::RuntimeException, css::lang::IllegalArgumentException, 183cdf0e10cSrcweir css::security::AccessControlException ); 184cdf0e10cSrcweir //====================================================================== 185cdf0e10cSrcweir 186cdf0e10cSrcweir //XEventListener 187cdf0e10cSrcweir //====================================================================== 188cdf0e10cSrcweir 189cdf0e10cSrcweir virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) 190cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir private: 193cdf0e10cSrcweir ScriptStorageManager( const ScriptStorageManager & ); 194cdf0e10cSrcweir ScriptStorageManager& operator= ( const ScriptStorageManager & ); 195cdf0e10cSrcweir 196cdf0e10cSrcweir void removeScriptDocURIHashEntry( const ::rtl::OUString & origURI ); 197cdf0e10cSrcweir 198cdf0e10cSrcweir // to obtain other services if needed 199cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > m_xContext; 200cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 201cdf0e10cSrcweir ::osl::Mutex m_mutex; 202cdf0e10cSrcweir ScriptStorage_map m_ScriptStorageMap; 203cdf0e10cSrcweir StorageId_hash m_StorageIdOrigURIHash; 204cdf0e10cSrcweir sal_Int32 m_count; 205cdf0e10cSrcweir scripting_securitymgr::ScriptSecurityManager m_securityMgr; 206cdf0e10cSrcweir 207cdf0e10cSrcweir void setupAppStorage( const css::uno::Reference< css::util::XMacroExpander > & xME, 208cdf0e10cSrcweir const ::rtl::OUString & storageStr, 209cdf0e10cSrcweir const ::rtl::OUString & appStr) 210cdf0e10cSrcweir SAL_THROW ( ( css::uno::RuntimeException ) ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir sal_Int32 setupAnyStorage( 213cdf0e10cSrcweir const css::uno::Reference< css::ucb::XSimpleFileAccess> & xSFA, 214cdf0e10cSrcweir const ::rtl::OUString & storageStr, 215cdf0e10cSrcweir const ::rtl::OUString & origStringURI ) 216cdf0e10cSrcweir SAL_THROW ( ( css::uno::RuntimeException ) ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir }; 219cdf0e10cSrcweir } // scripting_impl 220cdf0e10cSrcweir 221cdf0e10cSrcweir #endif //_COM_SUN_STAR_SCRIPTING_STORAGE_SCRIPTSTORAGEMANAGER_HXX_ 222