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