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 
28 #ifndef __FRAMEWORK_SERVICES_FRAMELOADERFACTORY_HXX_
29 #define __FRAMEWORK_SERVICES_FRAMELOADERFACTORY_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	my own includes
33 //_________________________________________________________________________________________________________________
34 
35 #include <classes/filtercache.hxx>
36 #include <threadhelp/threadhelpbase.hxx>
37 #include <macros/generic.hxx>
38 #include <macros/debug.hxx>
39 #include <macros/xinterface.hxx>
40 #include <macros/xtypeprovider.hxx>
41 #include <macros/xserviceinfo.hxx>
42 #include <general.h>
43 
44 //_________________________________________________________________________________________________________________
45 //	interface includes
46 //_________________________________________________________________________________________________________________
47 #include <com/sun/star/beans/PropertyValue.hpp>
48 #include <com/sun/star/lang/XInitialization.hpp>
49 #include <com/sun/star/lang/WrappedTargetException.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <com/sun/star/container/NoSuchElementException.hpp>
52 #include <com/sun/star/io/XInputStream.hpp>
53 
54 //_________________________________________________________________________________________________________________
55 //	other includes
56 //_________________________________________________________________________________________________________________
57 #include <cppuhelper/implbase3.hxx>
58 
59 //_________________________________________________________________________________________________________________
60 //	namespace
61 //_________________________________________________________________________________________________________________
62 
63 namespace framework{
64 
65 //_________________________________________________________________________________________________________________
66 //	exported const
67 //_________________________________________________________________________________________________________________
68 
69 //_________________________________________________________________________________________________________________
70 //	exported definitions
71 //_________________________________________________________________________________________________________________
72 
73 struct tIMPLExtractedArguments
74 {
75 	::rtl::OUString									sMimeType			;
76 	sal_Int32										nFlags				;
77 	::rtl::OUString									sFilterName			;
78 	sal_Int32										nClipboardFormat	;
79 	::rtl::OUString									sDetectService		;
80 	css::uno::Reference< css::io::XInputStream >	xInputStream		;
81 
82 	sal_Int32										nValidMask			;
83 };
84 
85 /*-************************************************************************************************************//**
86 	@short		factory to create frameloader-objects
87 	@descr		These class can be used to create new loader for specified contents.
88 				We use cached values of the registry to lay down, wich frameloader match
89 				a given URL or filtername. To do this, we use the XMultiServiceFactory-interface.
90 
91 	@ATTENTION	In a specialmode of these implementation we support a simple filterdetection.
92 				But there is no special interface. You must call some existing methods in another context!
93 				see createInstanceWithArguments() fo rfurther informations!
94 
95 	@implements	XInterface
96 				XTypeProvider
97 				XServiceInfo
98 				XMultiServiceFactory
99 				XNameAccess
100 				XElementAccess
101 	@base		ThreadHelpBase
102 				OWeakObject
103 
104 	@devstatus	deprecated
105 *//*-*************************************************************************************************************/
106 
107 class FrameLoaderFactory	:	public ThreadHelpBase							,		// Struct for right initalization of mutex member! Mst first of baseclasses
108 								public ::cppu::WeakImplHelper3< ::com::sun::star::lang::XServiceInfo,::com::sun::star::lang::XMultiServiceFactory,::com::sun::star::container::XNameAccess >
109 {
110 	//-------------------------------------------------------------------------------------------------------------
111 	//	public methods
112 	//-------------------------------------------------------------------------------------------------------------
113 
114 	public:
115 
116 		//---------------------------------------------------------------------------------------------------------
117 		//	constructor / destructor
118 		//---------------------------------------------------------------------------------------------------------
119 
120 		/*-****************************************************************************************************//**
121 			@short		standard constructor
122 			@descr		Initialize a new instance and fill the registrycache with values.
123 						To do this - xFactory must be valid!
124 
125 			@seealso	class RegistryCache
126 			@seealso	member m_aRegistryCache
127 
128 			@param		"xFactory", factory which has created us.
129 			@return		-
130 
131 			@onerror	An ASSERTION is thrown in debug version, if xFactory is invalid or cache can't filled.
132 		*//*-*****************************************************************************************************/
133 
134 	 	FrameLoaderFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
135 
136 		/*-****************************************************************************************************//**
137 			@short		standard destructor to delete instance
138 			@descr		We use it to clear ouer cache.
139 
140 			@seealso	class RegistryCache
141 
142 			@param		-
143 			@return		-
144 
145 			@onerror	-
146 		*//*-*****************************************************************************************************/
147 
148 		virtual ~FrameLoaderFactory();
149 
150 		//---------------------------------------------------------------------------------------------------------
151 		//	XInterface, XTypeProvider, XServiceInfo
152 		//---------------------------------------------------------------------------------------------------------
153 
154 		DECLARE_XSERVICEINFO
155 
156 		//---------------------------------------------------------------------------------------------------------
157 		//	XMultiServiceFactory
158 		//---------------------------------------------------------------------------------------------------------
159 
160 		/*-****************************************************************************************************//**
161 			@short		create a new frameloder (without arguments!)
162 			@descr		We search for an agreement between given type name and our cache-content.
163 						If we found some information, we create the registered frameloader for these type.
164 						Otherwise - we return NULL.
165 						We search from begin to end of internal loader list!
166 
167 			@seealso	method impl_createFrameLoader()
168 			@seealso	method createInstanceWithArguments()
169 
170 			@param		"sTypeName", type name of a document to filter, open or save.
171 			@return		A reference to a new created frameloader.
172 
173 			@onerror	A null reference is returned.
174 		*//*-*****************************************************************************************************/
175 
176 		virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& sTypeName ) throw(	css::uno::Exception			,
177 																																css::uno::RuntimeException	);
178 
179 		/*-****************************************************************************************************//**
180 			@short		create a new frameloder
181 			@descr		We search for an agreement between given type name and our cache-content.
182 						If we found some information, we create the registered frameloader for these type.
183 						Otherwise - we return NULL.
184 						You can give us some optional arguments to influence our search!
185 
186 			@seealso	method impl_createFrameLoader()
187 			@seealso	method createInstance()
188 
189 			@param		"sTypeName", type name of a document to filter, open or save.
190 			@param		"seqArguments", list of optional arguments for initializing of new frameloader.
191 			@return		A reference to a new created frameloader.
192 
193 			@onerror	A null reference is returned.
194 		*//*-*****************************************************************************************************/
195 
196     	virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(	const	::rtl::OUString&						sTypeName	,
197 																									const	css::uno::Sequence< css::uno::Any >&	seqArguments) throw(	css::uno::Exception		,
198 																									  																		css::uno::RuntimeException);
199 
200 		/*-****************************************************************************************************//**
201 			@short		not supported
202 			@descr		Please use XNameAcces instead of these!
203 
204 			@seealso	-
205 
206 			@param		-
207 			@return		-
208 
209 			@onerror	-
210 		*//*-*****************************************************************************************************/
211 
212     	virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames() throw( css::uno::RuntimeException );
213 
214 		//---------------------------------------------------------------------------------------------------------
215 		//	XNameAccess
216 		//---------------------------------------------------------------------------------------------------------
217 
218 		/*-****************************************************************************************************//**
219 			@short		return properties of registered frame loader specified by his implementation name
220 			@descr		Use these method to get all informations about our internal loader cache
221 						and a special frame loader.
222 						We return a Sequence< PropertyValue > in an Any packed as result.
223 
224 						structure of return value:
225 							[0].Name	=	"Types"
226 							[0].Value	=	list of supported types of these loader as [sequence< oustring >]
227 
228 							[1].Name	=	"UIName"
229 							[1].Value	=	localized name of loader as [string]
230 
231 			@seealso	method getElementNames()
232 			@seealso	method hasByName()
233 
234 			@param		"sName", the name of searched frame loader (use getElementNames() to get it!)
235 			@return		A Sequence< PropertyValue > packed in an Any.
236 
237 			@onerror	If given name not exist a NoSuchElementException is thrown.
238 		*//*-*****************************************************************************************************/
239 
240     	virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& sName ) throw(	css::container::NoSuchElementException	,
241 																						css::lang::WrappedTargetException		,
242 																						css::uno::RuntimeException				);
243 
244 		/*-****************************************************************************************************//**
245 			@short		return list of all well known loader names from configuration
246 			@descr		Use these method to get all names of well known loader.
247 						You can use it to get the properties of a loader by calling getByName()!
248 
249 			@seealso	method getByName()
250 			@seealso	method hasByName()
251 
252 			@param		-
253 			@return		A list of well known loader. Is static at runtime!
254 
255 			@onerror	No error should occure.
256 		*//*-*****************************************************************************************************/
257 
258     	virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw( css::uno::RuntimeException );
259 
260 		/*-****************************************************************************************************//**
261 			@short		check if searched frame loader exist in configuration
262 			@descr		Normaly nobody need these method realy (use getElementNames() in combination with getByName()).
263 						We guarantee correctness of these mechanism. There is no reason to check for existing elements then ...
264 						but if you have an unknwon name and has no fun to search it in returned sequence ...
265 						you can call these ...
266 
267 			@seealso	method getByName()
268 			@seealso	method getElementNames()
269 
270 			@param		"sName", implementation name of searched frame loader
271 			@return		sal_True if loader exist, sal_False otherwise.
272 
273 			@onerror	No error should occure.
274 		*//*-*****************************************************************************************************/
275 
276     	virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& sName ) throw( css::uno::RuntimeException );
277 
278 		//---------------------------------------------------------------------------------------------------------
279 		//	XElementAccess
280 		//---------------------------------------------------------------------------------------------------------
281 
282 		/*-****************************************************************************************************//**
283 			@short		return the type of retrun value of method XNameAccess::getByName()
284 			@descr		In these implementation its a Sequence< PropertyValue > everytime!
285 
286 			@seealso	description of interface XNameAccess
287 
288 			@param		-
289 			@return		Type of Sequence< PropertyValue >.
290 
291 			@onerror	No error should occure.
292 		*//*-*****************************************************************************************************/
293 
294 		virtual css::uno::Type SAL_CALL getElementType() throw( css::uno::RuntimeException );
295 
296 		/*-****************************************************************************************************//**
297 			@short		return state if informations about frame loader available
298 			@descr		If these method return false - no information could'nt read from configuration ...
299 						I think nothing will work then. Normaly we return sal_True!
300 
301 			@seealso	class FilterCache!
302 
303 			@param		-
304 			@return		sal_True if information available, sal_False otherwise.
305 
306 			@onerror	No error should occure.
307 		*//*-*****************************************************************************************************/
308 
309     	virtual sal_Bool SAL_CALL hasElements() throw( css::uno::RuntimeException );
310 
311 	//-------------------------------------------------------------------------------------------------------------
312 	//	protected methods
313 	//-------------------------------------------------------------------------------------------------------------
314 
315 	protected:
316 
317 	//-------------------------------------------------------------------------------------------------------------
318 	//	private methods
319 	//-------------------------------------------------------------------------------------------------------------
320 
321 	private:
322 
323 		/*-****************************************************************************************************//**
324 			@short		try to set configuration properties at created loader
325 			@descr		We support the old async. loader interface ( XFrameLoader ) and the new one XSynchronousFrameLoader.
326 						The new one should implement a property set on which we can set his configuration values!
327 						We try to cast given loader to these interface - if it's exist we set the values - otherwise not!
328 
329 			@seealso	service FrameLoader
330 			@seealso	service SynchronousFrameLoader
331 
332 			@param		"xLoader" loader with generic XInterface! (We don't know before which service type is used!)
333 			@param		"pLoaderInfo" configuration structure of these loader.
334 			@return		-
335 
336 			@onerror	No error should occure.
337 		*//*-*****************************************************************************************************/
338 
339 		void impl_initializeLoader( css::uno::Reference< css::uno::XInterface >& xLoader, const Loader& pLoaderInfo );
340 
341 	//-------------------------------------------------------------------------------------------------------------
342 	//	debug methods
343 	//	(should be private everyway!)
344 	//-------------------------------------------------------------------------------------------------------------
345 
346 		/*-****************************************************************************************************//**
347 			@short		debug-method to check incoming parameter of some other mehods of this class
348 			@descr		The following methods are used to check parameters for other methods
349 						of this class. The return value is used directly for an ASSERT(...).
350 
351 			@seealso	ASSERTs in implementation!
352 
353 			@param		references to checking variables
354 			@return		sal_False ,on invalid parameter
355 			@return		sal_True  ,otherwise
356 
357 			@onerror	-
358 		*//*-*****************************************************************************************************/
359 
360 
361 	#ifdef ENABLE_ASSERTIONS
362 
363 	private:
364 
365 	 	static sal_Bool impldbg_checkParameter_FrameLoaderFactory			(	const	css::uno::Reference< css::lang::XMultiServiceFactory >&	xFactory	);
366 		static sal_Bool impldbg_checkParameter_createInstance				(	const	::rtl::OUString&										sTypeName	);
367     	static sal_Bool impldbg_checkParameter_createInstanceWithArguments	(	const	::rtl::OUString&										sTypeName	,
368 																				const	css::uno::Sequence< css::uno::Any >&					seqArguments);
369     	static sal_Bool impldbg_checkParameter_getByName					(	const	::rtl::OUString&										sName		);
370     	static sal_Bool impldbg_checkParameter_hasByName					(	const	::rtl::OUString&										sName		);
371 
372 	#endif	//	#ifdef ENABLE_ASSERTIONS
373 
374 	//-------------------------------------------------------------------------------------------------------------
375 	//	private variables
376 	//	(should be private everyway!)
377 	//-------------------------------------------------------------------------------------------------------------
378 
379 	private:
380 
381 		css::uno::Reference< css::lang::XMultiServiceFactory >		m_xFactory			;
382 		FilterCache													m_aCache			;
383 
384 };		//	class FrameLoaderFactory
385 
386 }		//	namespace framework
387 
388 #endif	//	#ifndef __FRAMEWORK_SERVICES_FRAMELOADERFACTORY_HXX_
389