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