update dev300-m58
[ooovba.git] / framework / inc / classes / filtercache.hxx
blob2d375f913e7f4a7e1ef29fabe56a42ab656c88fd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filtercache.hxx,v $
10 * $Revision: 1.33 $
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 ************************************************************************/
31 /*TODO
32 - late init
33 - order by number!
34 - insert default detector and loader as last ones in hashes ... don't hold it as an extra member!
35 => CheckedIterator will be obsolete!
38 #ifndef __FRAMEWORK_CLASSES_FILTERCACHE_HXX_
39 #define __FRAMEWORK_CLASSES_FILTERCACHE_HXX_
41 //_________________________________________________________________________________________________________________
42 // my own includes
43 //_________________________________________________________________________________________________________________
45 #include <classes/filtercachedata.hxx>
46 #include <threadhelp/threadhelpbase.hxx>
48 #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONBASE_HXX_
49 #include <threadhelp/transactionbase.hxx>
50 #endif
51 #include <general.h>
52 #include <queries.h>
54 //_________________________________________________________________________________________________________________
55 // interface includes
56 //_________________________________________________________________________________________________________________
57 #include <com/sun/star/uno/Reference.hxx>
58 #include <com/sun/star/uno/Sequence.hxx>
59 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
60 #include <com/sun/star/registry/XRegistryKey.hpp>
61 #include <com/sun/star/beans/PropertyValue.hpp>
62 #include <com/sun/star/container/ElementExistException.hpp>
63 #include <com/sun/star/container/NoSuchElementException.hpp>
65 //_________________________________________________________________________________________________________________
66 // other includes
67 //_________________________________________________________________________________________________________________
68 #include <rtl/ustring.hxx>
70 #ifdef ENABLE_GENERATEFILTERCACHE
71 #ifndef _RTL_USTRBUF_HXX_
72 #include <rtl/ustrbuf.hxx>
73 #endif
74 #endif
76 //_________________________________________________________________________________________________________________
77 // namespace
78 //_________________________________________________________________________________________________________________
80 namespace framework{
82 //_________________________________________________________________________________________________________________
83 // exported const
84 //_________________________________________________________________________________________________________________
86 //_________________________________________________________________________________________________________________
87 // exported definitions
88 //_________________________________________________________________________________________________________________
90 /*-************************************************************************************************************//**
91 @short cache for all filter and type information
92 @descr Frameloader- and filterfactory need some informations about our current registered filters and types.
93 For better performance its neccessary to cache all needed values.
95 @implements -
96 @base ThreadHelpBase
97 TransactionBase
99 @devstatus ready to use
100 @threadsafe yes
101 *//*-*************************************************************************************************************/
103 class FilterCache : private ThreadHelpBase
104 , private TransactionBase
106 public:
108 //-------------------------------------------------------------------------------------------------------------
109 // public methods
110 //-------------------------------------------------------------------------------------------------------------
112 public:
114 //---------------------------------------------------------------------------------------------------------
115 // constructor / destructor
116 //---------------------------------------------------------------------------------------------------------
118 FilterCache( sal_Int32 nVersion = DEFAULT_FILTERCACHE_VERSION,
119 sal_Int16 nMode = DEFAULT_FILTERCACHE_MODE );
121 /*-****************************************************************************************************//**
122 @short standard destructor to delete instance
123 @descr This will clear the cache if last owner release it.
125 @seealso -
127 @param -
128 @return -
130 @onerror -
131 *//*-*****************************************************************************************************/
133 virtual ~FilterCache();
135 void flush( DataContainer::ECFGType eType );
137 /*-****************************************************************************************************//**
138 @short get the current state of the cache
139 @descr Call this methods to get information about the state of the current cache.
141 @seealso -
143 @param -
144 @return -
145 @return -
147 @onerror -
148 *//*-*****************************************************************************************************/
150 sal_Bool isValidOrRepairable() const;
151 sal_Bool hasTypes () const;
152 sal_Bool hasFilters () const;
153 sal_Bool hasDetectors () const;
154 sal_Bool hasLoaders () const;
155 sal_Bool hasContentHandlers () const;
157 /*-****************************************************************************************************//**
158 @short search routines to find items which match given parameter
159 @descr Mostly we search for a type first and get all informations about filter, detector and loader
160 services from the other configuration tables which are registered for this type.
161 These operations support a FindFirst/Next mechanism.
162 If you call search...( ... nStartEntry=0 ... ) we search for
163 the first entry. If these return a value different from <empty> you can work with these value.
164 If found value isn't the right one - you can call search method again.
165 DONT'T CHANGE THE VALUE OF "rStartEntry" between two search calls!
166 You can use returned value as parameter for getBy...Name() functions of this implementation too!
168 @attention returned type name is an internal name
169 returned filter name is an internal name
170 returned loader name is an implementation name of a service
171 returned detector name is an implementation name of a service
173 @seealso -
175 @param "sResult", name of found type, filter, ...
176 @return true, if search was successful,
177 false, otherwise.
179 @onerror We return false.
180 *//*-*****************************************************************************************************/
182 sal_Bool searchType ( const ::rtl::OUString& sURL ,
183 const ::rtl::OUString& sMediaType ,
184 const ::rtl::OUString& sClipboardFormat ,
185 CheckedTypeIterator& aStartEntry ,
186 ::rtl::OUString& sResult ) const;
188 sal_Bool searchFilterForType ( const ::rtl::OUString& sInternalTypeName ,
189 CheckedStringListIterator& aStartEntry ,
190 ::rtl::OUString& sResult ) const;
192 sal_Bool searchDetectorForType ( const ::rtl::OUString& sInternalTypeName ,
193 CheckedStringListIterator& aStartEntry ,
194 ::rtl::OUString& sResult ) const;
196 sal_Bool searchLoaderForType ( const ::rtl::OUString& sInternalTypeName ,
197 CheckedStringListIterator& aStartEntry ,
198 ::rtl::OUString& sResult ) const;
200 sal_Bool searchContentHandlerForType ( const ::rtl::OUString& sInternalTypeName ,
201 CheckedStringListIterator& aStartEntry ,
202 ::rtl::OUString& sResult ) const;
204 /*-****************************************************************************************************//**
205 @short get all properties of a cache entry by given name
206 @descr If you need additional informations about our internal cache values
207 you can use these methods to get a list of all cached config values
208 and subkeys of specified entry.
210 @seealso -
212 @param "sName", name of suspected entry in cache
213 @return A structure with valid information if item exists! An empty Any otherwise.
215 @onerror We return an empty Any.
216 *//*-*****************************************************************************************************/
218 css::uno::Sequence< ::rtl::OUString > getAllTypeNames () const;
219 css::uno::Sequence< ::rtl::OUString > getAllFilterNames () const;
220 css::uno::Sequence< ::rtl::OUString > getAllDetectorNames () const; // without default detector!
221 css::uno::Sequence< ::rtl::OUString > getAllLoaderNames () const; // without default loader!
222 css::uno::Sequence< ::rtl::OUString > getAllContentHandlerNames () const;
223 css::uno::Sequence< ::rtl::OUString > getAllDetectorNamesWithDefault () const; // default detector is last one!
224 css::uno::Sequence< ::rtl::OUString > getAllLoaderNamesWithDefault () const; // default loader is last one!
225 ::rtl::OUString getDefaultLoader () const;
227 css::uno::Sequence< css::beans::PropertyValue > getTypeProperties ( const ::rtl::OUString& sName ) const;
228 css::uno::Sequence< css::beans::PropertyValue > getFilterProperties ( const ::rtl::OUString& sName ) const;
229 css::uno::Sequence< css::beans::PropertyValue > getDetectorProperties ( const ::rtl::OUString& sName ) const;
230 css::uno::Sequence< css::beans::PropertyValue > getLoaderProperties ( const ::rtl::OUString& sName ) const;
231 css::uno::Sequence< css::beans::PropertyValue > getContentHandlerProperties ( const ::rtl::OUString& sName ) const;
233 FileType getType ( const ::rtl::OUString& sName ) const;
234 Filter getFilter ( const ::rtl::OUString& sName ) const;
235 Detector getDetector ( const ::rtl::OUString& sName ) const;
236 Loader getLoader ( const ::rtl::OUString& sName ) const;
237 ContentHandler getContentHandler ( const ::rtl::OUString& sName ) const;
239 sal_Bool existsType ( const ::rtl::OUString& sName ) const;
240 sal_Bool existsFilter ( const ::rtl::OUString& sName ) const;
241 sal_Bool existsDetector ( const ::rtl::OUString& sName ) const;
242 sal_Bool existsLoader ( const ::rtl::OUString& sName ) const;
243 sal_Bool existsContentHandler ( const ::rtl::OUString& sName ) const;
245 /*-****************************************************************************************************//**
246 @short support special query modes
247 @descr Our owner services need sometimes a special mode to query for subsets of our configuration!
248 They give us a special query string - we return right values.
250 @seealso file queries.h
251 @seealso class FilterFactory
252 @seealso class FrameLoaderFactory
253 @seealso class TypeDetection
255 @param "sName", name of query
256 @return A structure with valid information!
258 @onerror We return an empty result set.
259 *//*-*****************************************************************************************************/
261 css::uno::Any queryFilters( const ::rtl::OUString& sQuery ) const;
263 /*-****************************************************************************************************//**
264 @short support registration of elements in current configuration
265 @descr Use this methods to add or remove items in our configuration files.
266 We use the globale configuration to do that ... in fat office "share/config/registry/..."!
268 *** structure of type properties **********************************************************
270 PropertyValue.Name PropertyValue.Value Description
271 ---------------------------------------------------------------------------------------
274 *** structure of filter properties ********************************************************
276 PropertyValue.Name PropertyValue.Value Description
277 ---------------------------------------------------------------------------------------
278 "Name" [string] internal name
279 "Type" [string] registered for these type
280 "UIName" [string] localized name for UI (valid for current locale at runtime!)
281 "UINames" [stringlist] assignment of all supported localized names to right locales
282 "DocumentService" [string] uno servicename of document services
283 "FilterService" [string] uno servicename of filter implementation
284 "Flags" [long] describe filter
285 "UserData" [stringlist] additional user data (format not fixed!)
286 "FileFormatVersion" [long] version numbher of supported files
287 "TemplateName" [string] name of template
289 *** structure of detector properties ******************************************************
291 PropertyValue.Name PropertyValue.Value Description
292 ---------------------------------------------------------------------------------------
295 *** structure of loader properties ********************************************************
297 PropertyValue.Name PropertyValue.Value Description
298 ---------------------------------------------------------------------------------------
301 @seealso -
303 @param "sName" , name of type, filter ...
304 @param "lProperties" , values of new type, filter
305 @return state of operation as bool
307 @onerror We return false then.
308 *//*-*****************************************************************************************************/
310 sal_Bool addFilter ( const ::rtl::OUString& sName ,
311 const css::uno::Sequence< css::beans::PropertyValue >& lProperties ,
312 sal_Bool bException ) throw(css::container::ElementExistException ,
313 css::registry::InvalidRegistryException);
314 sal_Bool replaceFilter( const ::rtl::OUString& sName ,
315 const css::uno::Sequence< css::beans::PropertyValue >& lProperties ,
316 sal_Bool bException ) throw(css::container::NoSuchElementException ,
317 css::registry::InvalidRegistryException);
318 sal_Bool removeFilter ( const ::rtl::OUString& sName ,
319 sal_Bool bException ) throw(css::container::NoSuchElementException ,
320 css::registry::InvalidRegistryException);
322 sal_Bool addType ( const ::rtl::OUString& sName ,
323 const css::uno::Sequence< css::beans::PropertyValue >& lProperties ,
324 sal_Bool bException ) throw(css::container::ElementExistException ,
325 css::registry::InvalidRegistryException);
326 sal_Bool replaceType ( const ::rtl::OUString& sName ,
327 const css::uno::Sequence< css::beans::PropertyValue >& lProperties ,
328 sal_Bool bException ) throw(css::container::NoSuchElementException ,
329 css::registry::InvalidRegistryException);
330 sal_Bool removeType ( const ::rtl::OUString& sName ,
331 sal_Bool bException ) throw(css::container::NoSuchElementException ,
332 css::registry::InvalidRegistryException);
334 sal_Bool addDetector ( const ::rtl::OUString& sName ,
335 const css::uno::Sequence< css::beans::PropertyValue >& lProperties ,
336 sal_Bool bException ) throw(css::container::ElementExistException ,
337 css::registry::InvalidRegistryException);
338 sal_Bool replaceDetector( const ::rtl::OUString& sName ,
339 const css::uno::Sequence< css::beans::PropertyValue >& lProperties ,
340 sal_Bool bException ) throw(css::container::NoSuchElementException ,
341 css::registry::InvalidRegistryException);
342 sal_Bool removeDetector ( const ::rtl::OUString& sName ,
343 sal_Bool bException ) throw(css::container::NoSuchElementException ,
344 css::registry::InvalidRegistryException);
346 sal_Bool validateAndRepair();
347 sal_Bool validateAndRepairTypes();
348 sal_Bool validateAndRepairFilter();
349 sal_Bool validateAndRepairDetectors();
350 sal_Bool validateAndRepairLoader();
351 sal_Bool validateAndRepairHandler();
353 //-------------------------------------------------------------------------------------------------------------
354 // protected methods
355 //-------------------------------------------------------------------------------------------------------------
357 protected:
359 //-------------------------------------------------------------------------------------------------------------
360 // private methods
361 //-------------------------------------------------------------------------------------------------------------
363 private:
365 //-------------------------------------------------------------------------------------------------------------
366 // debug methods
367 //-------------------------------------------------------------------------------------------------------------
369 /*-****************************************************************************************************//**
370 @short debug-method to check incoming parameter of some other mehods of this class
371 @descr The following methods are used to check parameters for other methods
372 of this class. The return value is used directly for an ASSERT(...).
374 @seealso ASSERT in implementation!
376 @param references to checking variables
377 @return sal_False ,on invalid parameter
378 @return sal_True ,otherwise
380 @onerror -
381 *//*-*****************************************************************************************************/
383 #ifdef ENABLE_ASSERTIONS
385 private:
387 static sal_Bool implcp_searchType ( const ::rtl::OUString& sURL ,
388 const ::rtl::OUString* pMediaType ,
389 const ::rtl::OUString* pClipboardFormat ,
390 const CheckedTypeIterator& aStartEntry ,
391 const ::rtl::OUString& sResult );
392 static sal_Bool implcp_searchFilterForType ( const ::rtl::OUString& sInternalTypeName ,
393 const CheckedStringListIterator& aStartEntry ,
394 const ::rtl::OUString& sResult );
395 static sal_Bool implcp_searchDetectorForType ( const ::rtl::OUString& sInternalTypeName ,
396 const CheckedStringListIterator& aStartEntry ,
397 const ::rtl::OUString& sResult );
398 static sal_Bool implcp_searchLoaderForType ( const ::rtl::OUString& sInternalTypeName ,
399 const CheckedStringListIterator& aStartEntry ,
400 const ::rtl::OUString& sResult );
401 static sal_Bool implcp_searchContentHandlerForType ( const ::rtl::OUString& sInternalTypeName ,
402 const CheckedStringListIterator& aStartEntry ,
403 const ::rtl::OUString& sResult );
404 static sal_Bool implcp_getTypeProperties ( const ::rtl::OUString& sName );
405 static sal_Bool implcp_getFilterProperties ( const ::rtl::OUString& sName );
406 static sal_Bool implcp_getDetectorProperties ( const ::rtl::OUString& sName );
407 static sal_Bool implcp_getLoaderProperties ( const ::rtl::OUString& sName );
408 static sal_Bool implcp_getContentHandlerProperties ( const ::rtl::OUString& sName );
409 static sal_Bool implcp_getType ( const ::rtl::OUString& sName );
410 static sal_Bool implcp_getFilter ( const ::rtl::OUString& sName );
411 static sal_Bool implcp_getDetector ( const ::rtl::OUString& sName );
412 static sal_Bool implcp_getLoader ( const ::rtl::OUString& sName );
413 static sal_Bool implcp_getContentHandler ( const ::rtl::OUString& sName );
414 static sal_Bool implcp_existsType ( const ::rtl::OUString& sName );
415 static sal_Bool implcp_existsFilter ( const ::rtl::OUString& sName );
416 static sal_Bool implcp_existsDetector ( const ::rtl::OUString& sName );
417 static sal_Bool implcp_existsLoader ( const ::rtl::OUString& sName );
418 static sal_Bool implcp_existsContentHandler ( const ::rtl::OUString& sName );
419 static sal_Bool implcp_addFilter ( const ::rtl::OUString& sName ,
420 const css::uno::Sequence< css::beans::PropertyValue >& lProperties );
421 static sal_Bool implcp_replaceFilter ( const ::rtl::OUString& sName ,
422 const css::uno::Sequence< css::beans::PropertyValue >& lProperties );
423 static sal_Bool implcp_removeFilter ( const ::rtl::OUString& sName );
424 static sal_Bool implcp_queryFilters ( const ::rtl::OUString& sQuery );
426 #endif // #ifdef ENABLE_ASSERTIONS
428 #ifdef ENABLE_COMPONENT_SELF_CHECK
430 private:
432 void impldbg_dumpCache();
434 #endif // ENABLE_COMPONENT_SELF_CHECK
436 //-------------------------------------------------------------------------------------------------------------
437 // private variables
438 //-------------------------------------------------------------------------------------------------------------
439 private:
441 static sal_Int32 m_nRefCount ;
442 static DataContainer* m_pData ;
443 static sal_Int32 m_nVersion ;
444 static sal_Int16 m_nMode ;
446 }; // class FilterCache
448 } // namespace framework
450 #endif // #ifndef __FRAMEWORK_CLASSES_FILTERCACHE_HXX_