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 #ifndef __SCRIPTING_STORAGE_SCRIPTSTORAGE_HXX_ 28*cdf0e10cSrcweir #define __SCRIPTING_STORAGE_SCRIPTSTORAGE_HXX_ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <vector> 31*cdf0e10cSrcweir #include <hash_map> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <osl/mutex.hxx> 34*cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx> // helper for component factory 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptInfoAccess.hpp> 45*cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptStorageExport.hpp> 46*cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptStorageRefresh.hpp> 47*cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir namespace scripting_impl 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir // for simplification 52*cdf0e10cSrcweir #define css ::com::sun::star 53*cdf0e10cSrcweir #define dcsssf ::drafts::com::sun::star::script::framework 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir //Typedefs 56*cdf0e10cSrcweir //============================================================================= 57*cdf0e10cSrcweir typedef ::std::vector< ScriptData > Datas_vec; 58*cdf0e10cSrcweir //----------------------------------------------------------------------------- 59*cdf0e10cSrcweir // function name -> ScriptData 60*cdf0e10cSrcweir typedef ::std::hash_map < ::rtl::OUString, ScriptData, ::rtl::OUStringHash, 61*cdf0e10cSrcweir ::std::equal_to< ::rtl::OUString > > ScriptFunction_hash; 62*cdf0e10cSrcweir //----------------------------------------------------------------------------- 63*cdf0e10cSrcweir // language -> hash of function name -> ScriptData 64*cdf0e10cSrcweir typedef ::std::hash_map < ::rtl::OUString, ScriptFunction_hash, 65*cdf0e10cSrcweir ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > 66*cdf0e10cSrcweir ScriptData_hash; 67*cdf0e10cSrcweir //----------------------------------------------------------------------------- 68*cdf0e10cSrcweir typedef ::std::hash_map < ::rtl::OUString, 69*cdf0e10cSrcweir css::uno::Reference< css::xml::sax::XExtendedDocumentHandler >, 70*cdf0e10cSrcweir ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > 71*cdf0e10cSrcweir ScriptOutput_hash; 72*cdf0e10cSrcweir //----------------------------------------------------------------------------- 73*cdf0e10cSrcweir typedef ::std::hash_map < ::rtl::OUString, 74*cdf0e10cSrcweir ::rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > 75*cdf0e10cSrcweir ScriptLanguages_hash; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //============================================================================= 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir class ScriptStorage : public 80*cdf0e10cSrcweir ::cppu::WeakImplHelper5< 81*cdf0e10cSrcweir css::lang::XServiceInfo, 82*cdf0e10cSrcweir css::lang::XInitialization, 83*cdf0e10cSrcweir dcsssf::storage::XScriptInfoAccess, 84*cdf0e10cSrcweir dcsssf::storage::XScriptStorageExport, 85*cdf0e10cSrcweir dcsssf::storage::XScriptStorageRefresh > 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir public: 88*cdf0e10cSrcweir //Constructors and Destructors 89*cdf0e10cSrcweir //========================================================================= 90*cdf0e10cSrcweir explicit ScriptStorage( 91*cdf0e10cSrcweir const css::uno::Reference< css::uno::XComponentContext > & xContext ) 92*cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 93*cdf0e10cSrcweir //------------------------------------------------------------------------- 94*cdf0e10cSrcweir virtual ~ScriptStorage() SAL_THROW( () ); 95*cdf0e10cSrcweir //========================================================================= 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // XServiceInfo impl 98*cdf0e10cSrcweir //========================================================================= 99*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() 100*cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 101*cdf0e10cSrcweir //------------------------------------------------------------------------- 102*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString & ServiceName ) 103*cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 104*cdf0e10cSrcweir //------------------------------------------------------------------------- 105*cdf0e10cSrcweir virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() 106*cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 107*cdf0e10cSrcweir //------------------------------------------------------------------------- 108*cdf0e10cSrcweir static css::uno::Sequence< ::rtl::OUString > SAL_CALL 109*cdf0e10cSrcweir getSupportedServiceNames_Static(); 110*cdf0e10cSrcweir //========================================================================= 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // XInitialization impl 113*cdf0e10cSrcweir //========================================================================= 114*cdf0e10cSrcweir virtual void SAL_CALL 115*cdf0e10cSrcweir initialize( css::uno::Sequence< css::uno::Any > const & args ) 116*cdf0e10cSrcweir throw ( css::uno::RuntimeException, css::uno::Exception ); 117*cdf0e10cSrcweir //========================================================================= 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir //XScriptInfoAccess 120*cdf0e10cSrcweir //========================================================================= 121*cdf0e10cSrcweir /** 122*cdf0e10cSrcweir * Get the logical names for this storage 123*cdf0e10cSrcweir * 124*cdf0e10cSrcweir * @return sequence < ::rtl::OUString > 125*cdf0e10cSrcweir * The logical names 126*cdf0e10cSrcweir */ 127*cdf0e10cSrcweir virtual css::uno::Sequence< ::rtl::OUString > 128*cdf0e10cSrcweir SAL_CALL getScriptLogicalNames() 129*cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir //========================================================================= 132*cdf0e10cSrcweir /** 133*cdf0e10cSrcweir * Get the implementations for a given URI 134*cdf0e10cSrcweir * 135*cdf0e10cSrcweir * @param queryURI 136*cdf0e10cSrcweir * The URI to get the implementations for 137*cdf0e10cSrcweir * 138*cdf0e10cSrcweir * @return sequence < XScriptInfo > 139*cdf0e10cSrcweir * The URIs of the implementations 140*cdf0e10cSrcweir */ 141*cdf0e10cSrcweir virtual css::uno::Sequence< css::uno::Reference< dcsssf::storage::XScriptInfo > > 142*cdf0e10cSrcweir SAL_CALL getImplementations( 143*cdf0e10cSrcweir const ::rtl::OUString& queryURI ) 144*cdf0e10cSrcweir throw ( css::lang::IllegalArgumentException, css::uno::RuntimeException ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir //========================================================================= 147*cdf0e10cSrcweir /** 148*cdf0e10cSrcweir * Get all script implementations 149*cdf0e10cSrcweir * 150*cdf0e10cSrcweir * 151*cdf0e10cSrcweir * @return sequence < XScriptInfo > 152*cdf0e10cSrcweir * script implementations 153*cdf0e10cSrcweir */ 154*cdf0e10cSrcweir virtual css::uno::Sequence< css::uno::Reference< dcsssf::storage::XScriptInfo > > 155*cdf0e10cSrcweir SAL_CALL getAllImplementations() 156*cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir //========================================================================= 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir /** 161*cdf0e10cSrcweir * Save the scripts stored in the ScriptStorage into the corresponding 162*cdf0e10cSrcweir * area (document or application) 163*cdf0e10cSrcweir */ 164*cdf0e10cSrcweir void SAL_CALL save() 165*cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 166*cdf0e10cSrcweir //========================================================================= 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir /** 169*cdf0e10cSrcweir * Refresh the ScriptStorage from the data stored in the corresponding area 170*cdf0e10cSrcweir * (document or application). 171*cdf0e10cSrcweir */ 172*cdf0e10cSrcweir void SAL_CALL refresh() 173*cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 174*cdf0e10cSrcweir //========================================================================= 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir private: 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > m_xContext; 179*cdf0e10cSrcweir css::uno::Reference< css::ucb::XSimpleFileAccess > m_xSimpleFileAccess; 180*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir ::std::vector < ::rtl::OUString > mv_logicalNames; 183*cdf0e10cSrcweir static ScriptLanguages_hash* mh_scriptLangs; 184*cdf0e10cSrcweir ScriptData_hash mh_implementations; 185*cdf0e10cSrcweir ScriptOutput_hash mh_parcels; 186*cdf0e10cSrcweir sal_Int32 m_scriptStorageID; 187*cdf0e10cSrcweir ::rtl::OUString m_stringUri; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir osl::Mutex m_mutex; 190*cdf0e10cSrcweir bool m_bInitialised; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir void updateMaps( const Datas_vec & vScriptDatas ); 193*cdf0e10cSrcweir void writeMetadataHeader( 194*cdf0e10cSrcweir css::uno::Reference < css::xml::sax::XExtendedDocumentHandler > & xExDocHandler ); 195*cdf0e10cSrcweir void create () 196*cdf0e10cSrcweir throw (css::uno::RuntimeException, css::uno::Exception); 197*cdf0e10cSrcweir void createForFilesystem ( const ::rtl::OUString & scriptLanguage ) 198*cdf0e10cSrcweir throw (css::uno::RuntimeException, css::uno::Exception); 199*cdf0e10cSrcweir ::rtl::OUString getFileExtension ( const ::rtl::OUString & stringUri ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir }; // class ScriptingStorage 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir } // namespace scripting_impl 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir #endif 206