1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef __SCRIPTING_STORAGE_SCRIPTSTORAGE_HXX_ 28 #define __SCRIPTING_STORAGE_SCRIPTSTORAGE_HXX_ 29 30 #include <vector> 31 #include <hash_map> 32 33 #include <osl/mutex.hxx> 34 #include <cppuhelper/implbase5.hxx> // helper for component factory 35 36 #include <com/sun/star/uno/XComponentContext.hpp> 37 #include <com/sun/star/lang/XServiceInfo.hpp> 38 #include <com/sun/star/lang/XInitialization.hpp> 39 #include <com/sun/star/io/XInputStream.hpp> 40 #include <com/sun/star/io/XOutputStream.hpp> 41 #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 42 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 43 44 #include <drafts/com/sun/star/script/framework/storage/XScriptInfoAccess.hpp> 45 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageExport.hpp> 46 #include <drafts/com/sun/star/script/framework/storage/XScriptStorageRefresh.hpp> 47 #include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp> 48 49 namespace scripting_impl 50 { 51 // for simplification 52 #define css ::com::sun::star 53 #define dcsssf ::drafts::com::sun::star::script::framework 54 55 //Typedefs 56 //============================================================================= 57 typedef ::std::vector< ScriptData > Datas_vec; 58 //----------------------------------------------------------------------------- 59 // function name -> ScriptData 60 typedef ::std::hash_map < ::rtl::OUString, ScriptData, ::rtl::OUStringHash, 61 ::std::equal_to< ::rtl::OUString > > ScriptFunction_hash; 62 //----------------------------------------------------------------------------- 63 // language -> hash of function name -> ScriptData 64 typedef ::std::hash_map < ::rtl::OUString, ScriptFunction_hash, 65 ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > 66 ScriptData_hash; 67 //----------------------------------------------------------------------------- 68 typedef ::std::hash_map < ::rtl::OUString, 69 css::uno::Reference< css::xml::sax::XExtendedDocumentHandler >, 70 ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > 71 ScriptOutput_hash; 72 //----------------------------------------------------------------------------- 73 typedef ::std::hash_map < ::rtl::OUString, 74 ::rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > 75 ScriptLanguages_hash; 76 77 //============================================================================= 78 79 class ScriptStorage : public 80 ::cppu::WeakImplHelper5< 81 css::lang::XServiceInfo, 82 css::lang::XInitialization, 83 dcsssf::storage::XScriptInfoAccess, 84 dcsssf::storage::XScriptStorageExport, 85 dcsssf::storage::XScriptStorageRefresh > 86 { 87 public: 88 //Constructors and Destructors 89 //========================================================================= 90 explicit ScriptStorage( 91 const css::uno::Reference< css::uno::XComponentContext > & xContext ) 92 throw ( css::uno::RuntimeException ); 93 //------------------------------------------------------------------------- 94 virtual ~ScriptStorage() SAL_THROW( () ); 95 //========================================================================= 96 97 // XServiceInfo impl 98 //========================================================================= 99 virtual ::rtl::OUString SAL_CALL getImplementationName() 100 throw ( css::uno::RuntimeException ); 101 //------------------------------------------------------------------------- 102 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString & ServiceName ) 103 throw ( css::uno::RuntimeException ); 104 //------------------------------------------------------------------------- 105 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() 106 throw ( css::uno::RuntimeException ); 107 //------------------------------------------------------------------------- 108 static css::uno::Sequence< ::rtl::OUString > SAL_CALL 109 getSupportedServiceNames_Static(); 110 //========================================================================= 111 112 // XInitialization impl 113 //========================================================================= 114 virtual void SAL_CALL 115 initialize( css::uno::Sequence< css::uno::Any > const & args ) 116 throw ( css::uno::RuntimeException, css::uno::Exception ); 117 //========================================================================= 118 119 //XScriptInfoAccess 120 //========================================================================= 121 /** 122 * Get the logical names for this storage 123 * 124 * @return sequence < ::rtl::OUString > 125 * The logical names 126 */ 127 virtual css::uno::Sequence< ::rtl::OUString > 128 SAL_CALL getScriptLogicalNames() 129 throw ( css::uno::RuntimeException ); 130 131 //========================================================================= 132 /** 133 * Get the implementations for a given URI 134 * 135 * @param queryURI 136 * The URI to get the implementations for 137 * 138 * @return sequence < XScriptInfo > 139 * The URIs of the implementations 140 */ 141 virtual css::uno::Sequence< css::uno::Reference< dcsssf::storage::XScriptInfo > > 142 SAL_CALL getImplementations( 143 const ::rtl::OUString& queryURI ) 144 throw ( css::lang::IllegalArgumentException, css::uno::RuntimeException ); 145 146 //========================================================================= 147 /** 148 * Get all script implementations 149 * 150 * 151 * @return sequence < XScriptInfo > 152 * script implementations 153 */ 154 virtual css::uno::Sequence< css::uno::Reference< dcsssf::storage::XScriptInfo > > 155 SAL_CALL getAllImplementations() 156 throw ( css::uno::RuntimeException ); 157 158 //========================================================================= 159 160 /** 161 * Save the scripts stored in the ScriptStorage into the corresponding 162 * area (document or application) 163 */ 164 void SAL_CALL save() 165 throw ( css::uno::RuntimeException ); 166 //========================================================================= 167 168 /** 169 * Refresh the ScriptStorage from the data stored in the corresponding area 170 * (document or application). 171 */ 172 void SAL_CALL refresh() 173 throw ( css::uno::RuntimeException ); 174 //========================================================================= 175 176 private: 177 178 css::uno::Reference< css::uno::XComponentContext > m_xContext; 179 css::uno::Reference< css::ucb::XSimpleFileAccess > m_xSimpleFileAccess; 180 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 181 182 ::std::vector < ::rtl::OUString > mv_logicalNames; 183 static ScriptLanguages_hash* mh_scriptLangs; 184 ScriptData_hash mh_implementations; 185 ScriptOutput_hash mh_parcels; 186 sal_Int32 m_scriptStorageID; 187 ::rtl::OUString m_stringUri; 188 189 osl::Mutex m_mutex; 190 bool m_bInitialised; 191 192 void updateMaps( const Datas_vec & vScriptDatas ); 193 void writeMetadataHeader( 194 css::uno::Reference < css::xml::sax::XExtendedDocumentHandler > & xExDocHandler ); 195 void create () 196 throw (css::uno::RuntimeException, css::uno::Exception); 197 void createForFilesystem ( const ::rtl::OUString & scriptLanguage ) 198 throw (css::uno::RuntimeException, css::uno::Exception); 199 ::rtl::OUString getFileExtension ( const ::rtl::OUString & stringUri ); 200 201 }; // class ScriptingStorage 202 203 } // namespace scripting_impl 204 205 #endif 206