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