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