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