xref: /trunk/main/scripting/source/storage/ScriptStorage.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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     //-------------------------------------------------------------------------
89     virtual ~ScriptStorage() SAL_THROW( () );
90     //=========================================================================
91 
92     // XServiceInfo impl
93     //=========================================================================
94     virtual ::rtl::OUString SAL_CALL getImplementationName();
95     //-------------------------------------------------------------------------
96     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString & ServiceName );
97     //-------------------------------------------------------------------------
98     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
99     //-------------------------------------------------------------------------
100     static css::uno::Sequence< ::rtl::OUString > SAL_CALL
101         getSupportedServiceNames_Static();
102     //=========================================================================
103 
104     // XInitialization impl
105     //=========================================================================
106     virtual void SAL_CALL
107         initialize( css::uno::Sequence< css::uno::Any > const & args );
108     //=========================================================================
109 
110     //XScriptInfoAccess
111     //=========================================================================
112     /**
113      * Get the logical names for this storage
114      *
115      * @return sequence < ::rtl::OUString >
116      *      The logical names
117      */
118     virtual css::uno::Sequence< ::rtl::OUString >
119         SAL_CALL getScriptLogicalNames();
120 
121     //=========================================================================
122     /**
123      * Get the implementations for a given URI
124      *
125      * @param queryURI
126      *      The URI to get the implementations for
127      *
128      * @return sequence < XScriptInfo >
129      *      The URIs of the implementations
130      */
131     virtual css::uno::Sequence< css::uno::Reference< dcsssf::storage::XScriptInfo > >
132         SAL_CALL getImplementations(
133             const ::rtl::OUString& queryURI );
134 
135     //=========================================================================
136     /**
137      * Get all script implementations
138      *
139      *
140      * @return sequence < XScriptInfo >
141      *      script implementations
142      */
143     virtual css::uno::Sequence< css::uno::Reference< dcsssf::storage::XScriptInfo > >
144         SAL_CALL getAllImplementations();
145 
146     //=========================================================================
147 
148     /**
149      * Save the scripts stored in the ScriptStorage into the corresponding
150      * area (document or application)
151      */
152     void SAL_CALL save();
153     //=========================================================================
154 
155     /**
156      * Refresh the ScriptStorage from the data stored in the corresponding area
157      * (document or application).
158      */
159     void SAL_CALL refresh();
160     //=========================================================================
161 
162 private:
163 
164     css::uno::Reference< css::uno::XComponentContext > m_xContext;
165     css::uno::Reference< css::ucb::XSimpleFileAccess > m_xSimpleFileAccess;
166     css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
167 
168     ::std::vector < ::rtl::OUString >  mv_logicalNames;
169     static ScriptLanguages_hash* mh_scriptLangs;
170     ScriptData_hash mh_implementations;
171     ScriptOutput_hash mh_parcels;
172     sal_Int32 m_scriptStorageID;
173     ::rtl::OUString m_stringUri;
174 
175     osl::Mutex m_mutex;
176     bool m_bInitialised;
177 
178     void updateMaps( const Datas_vec & vScriptDatas );
179     void writeMetadataHeader(
180         css::uno::Reference < css::xml::sax::XExtendedDocumentHandler > & xExDocHandler );
181     void create ();
182     void createForFilesystem ( const ::rtl::OUString & scriptLanguage );
183     ::rtl::OUString getFileExtension ( const ::rtl::OUString & stringUri );
184 
185 }; // class ScriptingStorage
186 
187 } // namespace scripting_impl
188 
189 #endif
190