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 
24 #ifndef __FRAMEWORK_CLASSES_FILTERCACHEDATA_HXX_
25 #define __FRAMEWORK_CLASSES_FILTERCACHEDATA_HXX_
26 
27 /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
28                with solaris headers ...
29 */
30 #include <hash_map>
31 #include <vector>
32 #include <iterator>
33 
34 //_________________________________________________________________________________________________________________
35 //	my own includes
36 //_________________________________________________________________________________________________________________
37 #include <classes/checkediterator.hxx>
38 #include <classes/wildcard.hxx>
39 #include <classes/converter.hxx>
40 #include <threadhelp/threadhelpbase.hxx>
41 #include <macros/xinterface.hxx>
42 #include <macros/debug.hxx>
43 #include <general.h>
44 
45 //_________________________________________________________________________________________________________________
46 //	interface includes
47 //_________________________________________________________________________________________________________________
48 #include <com/sun/star/uno/Sequence.hxx>
49 #include <com/sun/star/uno/Any.hxx>
50 #include <com/sun/star/uno/Reference.hxx>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 #include <com/sun/star/util/XChangesListener.hpp>
54 #include <com/sun/star/util/XChangesNotifier.hpp>
55 
56 //_________________________________________________________________________________________________________________
57 //	other includes
58 //_________________________________________________________________________________________________________________
59 #include <unotools/configitem.hxx>
60 #include <cppuhelper/weak.hxx>
61 #include <rtl/ustring.hxx>
62 #include <rtl/logfile.hxx>
63 
64 //_________________________________________________________________________________________________________________
65 //	namespace
66 //_________________________________________________________________________________________________________________
67 
68 namespace framework{
69 
70 //_________________________________________________________________________________________________________________
71 //	exported const
72 //_________________________________________________________________________________________________________________
73 
74 #define PACKAGENAME_TYPEDETECTION_STANDARD          DECLARE_ASCII("Office.TypeDetection"                            )   /// Names of our configuration files.
75 #define PACKAGENAME_TYPEDETECTION_ADDITIONAL        DECLARE_ASCII("Office.TypeDetectionAdditional"                  )
76 #define CFG_PATH_SEPERATOR                          DECLARE_ASCII("/"                                               )   /// seperator for configuration pathes
77 #define PROPERTY_SEPERATOR                          sal_Unicode(',')                                                    /// seperator for own formated property strings of types and filters
78 #define LIST_SEPERATOR                              sal_Unicode(';')                                                    /// seperator for own formated lists as part of our own formated type- or filter-string
79 #define LOCALE_FALLBACK                             DECLARE_ASCII("en-US"                                           )   /// fallback, if configuration can't give us current set locale ...
80 #define DEFAULT_FILTERCACHE_VERSION                 6                                                                   /// these implmentation of FilterCache support different version of TypeDetection.xml! This define the current set default one.
81 
82 #define DEFAULT_FILTERCACHE_MODE                    CONFIG_MODE_DELAYED_UPDATE | CONFIG_MODE_ALL_LOCALES                                          /// ConfigItems could run in different modes: supported values are ... { CONFIG_MODE_IMMEDIATE_UPDATE, CONFIG_MODE_DELAYED_UPDATE, CONFIG_MODE_ALL_LOCALES }
83 //#define DEFAULT_FILTERCACHE_MODE                    CONFIG_MODE_DELAYED_UPDATE                                          /// ConfigItems could run in different modes: supported values are ... { CONFIG_MODE_IMMEDIATE_UPDATE, CONFIG_MODE_DELAYED_UPDATE, CONFIG_MODE_ALL_LOCALES }
84 
85 #define CFG_ENCODING_OPEN                           DECLARE_ASCII("[\'"                                             )   /// used to start encoding of set names
86 #define CFG_ENCODING_CLOSE                          DECLARE_ASCII("\']"                                             )   /// used to finish encoding of set names
87 
88 //*****************************************************************************************************************
89 // We know some default values ...
90 //*****************************************************************************************************************
91 #define NAME_DEFAULTDETECTOR                        DECLARE_ASCII("com.sun.star.comp.office.FilterDetect"           )
92 #define NAME_GENERICLOADER                          DECLARE_ASCII("com.sun.star.comp.office.FrameLoader"            )
93 #define UINAME_GENERICLOADER                        DECLARE_ASCII("com.sun.star.comp.office.FrameLoader"            )
94 #define TYPELIST_DEFAULTDETECTOR                    DECLARE_ASCII("*"                                               )
95 #define TYPELIST_GENERICLOADER                      DECLARE_ASCII("*"                                               )
96 
97 //*****************************************************************************************************************
98 // This are all supported set-names of our filter configuration.
99 //*****************************************************************************************************************
100 #define SUBLIST_TYPES                               DECLARE_ASCII("Types"                                           )
101 #define SUBLIST_FILTERS                             DECLARE_ASCII("Filters"                                         )
102 #define SUBLIST_DETECTSERVICES                      DECLARE_ASCII("DetectServices"                                  )
103 #define SUBLIST_FRAMELOADERS                        DECLARE_ASCII("FrameLoaders"                                    )
104 #define SUBLIST_CONTENTHANDLERS                     DECLARE_ASCII("ContentHandlers"                                 )
105 #define SUBLIST_DEFAULTS                            DECLARE_ASCII("Defaults"                                        )
106 
107 #define TEMPLATENAME_TYPE                           DECLARE_ASCII("Type"                                            )
108 #define TEMPLATENAME_FILTER                         DECLARE_ASCII("Filter"                                          )
109 #define TEMPLATENAME_DETECTSERVICE                  DECLARE_ASCII("DetectService"                                   )
110 #define TEMPLATENAME_FRAMELOADER                    DECLARE_ASCII("FrameLoader"                                     )
111 #define TEMPLATENAME_CONTENTHANDLER                 DECLARE_ASCII("ContentHandler"                                  )
112 
113 //*****************************************************************************************************************
114 // These defines declare all supported names of configuration key names.
115 // They are not sorted and could be shared by different base configuration items.
116 //*****************************************************************************************************************
117 #define SUBKEY_PREFERRED                            DECLARE_ASCII("Preferred"                                       )
118 #define SUBKEY_INSTALLED                            DECLARE_ASCII("Installed"                                       )
119 #define SUBKEY_NAME                                 DECLARE_ASCII("Name"                                            )
120 #define SUBKEY_UINAME                               DECLARE_ASCII("UIName"                                          )
121 #define SUBKEY_MEDIATYPE                            DECLARE_ASCII("MediaType"                                       )
122 #define SUBKEY_CLIPBOARDFORMAT                      DECLARE_ASCII("ClipboardFormat"                                 )
123 #define SUBKEY_URLPATTERN                           DECLARE_ASCII("URLPattern"                                      )
124 #define SUBKEY_EXTENSIONS                           DECLARE_ASCII("Extensions"                                      )
125 #define SUBKEY_DOCUMENTICONID                       DECLARE_ASCII("DocumentIconID"                                  )
126 #define SUBKEY_TYPE                                 DECLARE_ASCII("Type"                                            )
127 #define SUBKEY_DOCUMENTSERVICE                      DECLARE_ASCII("DocumentService"                                 )
128 #define SUBKEY_FILTERSERVICE                        DECLARE_ASCII("FilterService"                                   )
129 #define SUBKEY_FLAGS                                DECLARE_ASCII("Flags"                                           )
130 #define SUBKEY_USERDATA                             DECLARE_ASCII("UserData"                                        )
131 #define SUBKEY_FILEFORMATVERSION                    DECLARE_ASCII("FileFormatVersion"                               )
132 #define SUBKEY_TEMPLATENAME                         DECLARE_ASCII("TemplateName"                                    )
133 #define SUBKEY_TYPES                                DECLARE_ASCII("Types"                                           )
134 #define SUBKEY_ORDER                                DECLARE_ASCII("Order"                                           )
135 #define SUBKEY_DEFAULTDETECTOR                      DECLARE_ASCII("DetectService"                                   )
136 #define SUBKEY_GENERICLOADER                        DECLARE_ASCII("FrameLoader"                                     )
137 #define SUBKEY_DATA                                 DECLARE_ASCII("Data"                                            )
138 #define SUBKEY_UICOMPONENT                          DECLARE_ASCII("UIComponent"                                     )
139 
140 //*****************************************************************************************************************
141 // These defines declare all supported property names for our name container interface.
142 // They are not sorted by using ... and could be shared by different methods and access operations.
143 //*****************************************************************************************************************
144 #define PROPERTY_NAME                               DECLARE_ASCII("Name"                                            )
145 #define PROPERTY_PREFERRED                          DECLARE_ASCII("Preferred"                                       )
146 #define PROPERTY_INSTALLED                          DECLARE_ASCII("Installed"                                       )
147 #define PROPERTY_UINAME                             DECLARE_ASCII("UIName"                                          )
148 #define PROPERTY_UINAMES                            DECLARE_ASCII("UINames"                                         )
149 #define PROPERTY_MEDIATYPE                          DECLARE_ASCII("MediaType"                                       )
150 #define PROPERTY_CLIPBOARDFORMAT                    DECLARE_ASCII("ClipboardFormat"                                 )
151 #define PROPERTY_URLPATTERN                         DECLARE_ASCII("URLPattern"                                      )
152 #define PROPERTY_EXTENSIONS                         DECLARE_ASCII("Extensions"                                      )
153 #define PROPERTY_DOCUMENTICONID                     DECLARE_ASCII("DocumentIconID"                                  )
154 #define PROPERTY_TYPE                               DECLARE_ASCII("Type"                                            )
155 #define PROPERTY_DOCUMENTSERVICE                    DECLARE_ASCII("DocumentService"                                 )
156 #define PROPERTY_FILTERSERVICE                      DECLARE_ASCII("FilterService"                                   )
157 #define PROPERTY_FLAGS                              DECLARE_ASCII("Flags"                                           )
158 #define PROPERTY_USERDATA                           DECLARE_ASCII("UserData"                                        )
159 #define PROPERTY_FILEFORMATVERSION                  DECLARE_ASCII("FileFormatVersion"                               )
160 #define PROPERTY_TEMPLATENAME                       DECLARE_ASCII("TemplateName"                                    )
161 #define PROPERTY_TYPES                              DECLARE_ASCII("Types"                                           )
162 #define PROPERTY_ORDER                              DECLARE_ASCII("Order"                                           )
163 #define PROPERTY_UICOMPONENT                        DECLARE_ASCII("UIComponent"                                     )
164 
165 //_________________________________________________________________________________________________________________
166 //	exported definitions
167 //_________________________________________________________________________________________________________________
168 
169 enum EModifyState
170 {
171     E_UNTOUCHED ,
172     E_ADDED     ,
173     E_CHANGED   ,
174     E_REMOVED
175 };
176 
177 enum EFilterPackage
178 {
179     E_STANDARD  ,
180     E_ADDITIONAL
181 };
182 
183 //*****************************************************************************************************************
184 // These struct define a type, which present the type of a file.
185 // He is used for easy filter detection without file stream detection!
186 // The internal name is the keyname of an item with these structure in our hash map or our configuration set!
187 //*****************************************************************************************************************
188 struct FileType
189 {
190 	//-------------------------------------------------------------------------------------------------------------
191 	// public methods
192 	//-------------------------------------------------------------------------------------------------------------
193 	public:
194 
FileTypeframework::FileType195 		inline				 FileType	(								) { impl_clear();				}
FileTypeframework::FileType196 		inline				 FileType	(	const	FileType&	rCopy	) { impl_copy( rCopy );			}
~FileTypeframework::FileType197 		inline				~FileType	(								) { impl_clear();				}
operator =framework::FileType198 		inline FileType&	operator=	(	const	FileType&	rCopy	) { return impl_copy( rCopy );	}
freeframework::FileType199 		inline void			free		(								) { impl_clear();				}
200 
201 	//-------------------------------------------------------------------------------------------------------------
202 	// private methods
203 	//-------------------------------------------------------------------------------------------------------------
204 	private:
205 
impl_clearframework::FileType206 		inline void impl_clear()
207 		{
208             bPreferred          = sal_False         ;
209 			sName				= ::rtl::OUString()	;
210 			sMediaType			= ::rtl::OUString()	;
211 			sClipboardFormat	= ::rtl::OUString()	;
212 			nDocumentIconID		= 0					;
213 			lUINames.free	();
214 			lURLPattern.free();
215 			lExtensions.free();
216 		}
217 
impl_copyframework::FileType218 		inline FileType& impl_copy( const FileType& rCopy )
219 		{
220 			bPreferred			= rCopy.bPreferred		;
221 			sName				= rCopy.sName			;
222 			lUINames			= rCopy.lUINames		;
223 			sMediaType			= rCopy.sMediaType		;
224 			sClipboardFormat	= rCopy.sClipboardFormat;
225 			nDocumentIconID		= rCopy.nDocumentIconID	;
226 			lURLPattern			= rCopy.lURLPattern		;
227 			lExtensions			= rCopy.lExtensions		;
228 			return (*this);
229 		}
230 
231 	//-------------------------------------------------------------------------------------------------------------
232 	// public member
233 	//-------------------------------------------------------------------------------------------------------------
234 	public:
235 
236 		sal_Bool			bPreferred			;
237 		::rtl::OUString		sName				;
238         OUStringHashMap     lUINames            ;
239 		::rtl::OUString		sMediaType			;
240 		::rtl::OUString		sClipboardFormat	;
241 		sal_Int32			nDocumentIconID		;
242         OUStringList        lURLPattern         ;
243         OUStringList        lExtensions         ;
244 };
245 
246 //*****************************************************************************************************************
247 // These struct describe a filter which is registered for one type.
248 // He hold information about services which present the document himself (like a item) and a filter service which
249 // filter a file in these document.
250 // The internal name is the keyname of an item with these structure in our hash map or our configuration set!
251 //*****************************************************************************************************************
252 struct Filter
253 {
254 	//-------------------------------------------------------------------------------------------------------------
255 	// public methods
256 	//-------------------------------------------------------------------------------------------------------------
257 	public:
258 
Filterframework::Filter259 		inline			 Filter		(							) { impl_clear();				}
Filterframework::Filter260 		inline			 Filter		(	const	Filter&	rCopy	) { impl_copy( rCopy );			}
~Filterframework::Filter261 		inline			~Filter		(							) { impl_clear();				}
operator =framework::Filter262 		inline Filter&	operator=	(	const	Filter&	rCopy	) { return impl_copy( rCopy );	}
freeframework::Filter263 		inline void		free		(							) { impl_clear();				}
264 
265 	//-------------------------------------------------------------------------------------------------------------
266 	// private methods
267 	//-------------------------------------------------------------------------------------------------------------
268 	private:
269 
impl_clearframework::Filter270 		inline void impl_clear()
271 		{
272             nOrder              = 0                ;
273             sName               = ::rtl::OUString();
274             sType               = ::rtl::OUString();
275             sDocumentService    = ::rtl::OUString();
276             sFilterService      = ::rtl::OUString();
277             sUIComponent        = ::rtl::OUString();
278             nFlags              = 0                ;
279             nFileFormatVersion  = 0                ;
280             sTemplateName       = ::rtl::OUString();
281 			lUINames.free	();
282 			lUserData.free	();
283 		}
284 
impl_copyframework::Filter285 		inline Filter& impl_copy( const Filter& rCopy )
286 		{
287             nOrder              = rCopy.nOrder              ;
288 			sName				= rCopy.sName				;
289 			sType				= rCopy.sType				;
290 			lUINames			= rCopy.lUINames			;
291 			sDocumentService	= rCopy.sDocumentService	;
292 			sFilterService		= rCopy.sFilterService		;
293             sUIComponent        = rCopy.sUIComponent        ;
294 			nFlags				= rCopy.nFlags				;
295 			nFileFormatVersion	= rCopy.nFileFormatVersion	;
296 			sTemplateName		= rCopy.sTemplateName		;
297 			lUserData			= rCopy.lUserData			;
298 			return (*this);
299 		}
300 
301 	//-------------------------------------------------------------------------------------------------------------
302 	// public member
303 	//-------------------------------------------------------------------------------------------------------------
304 	public:
305 
306         sal_Int32           nOrder              ;
307         ::rtl::OUString     sName               ;
308 		::rtl::OUString		sType				;
309         OUStringHashMap     lUINames            ;
310 		::rtl::OUString		sDocumentService	;
311 		::rtl::OUString		sFilterService		;
312         ::rtl::OUString     sUIComponent        ;
313 		sal_Int32			nFlags				;
314         OUStringList        lUserData           ;
315 		sal_Int32			nFileFormatVersion	;
316 		::rtl::OUString		sTemplateName		;
317 };
318 
319 //*****************************************************************************************************************
320 // Programmer can register his own services for an content detection of different types.
321 // The implementation or service name of these is the keyname of an item with these structure
322 // in our hash map or our configuration set!
323 //*****************************************************************************************************************
324 struct Detector
325 {
326 	//-------------------------------------------------------------------------------------------------------------
327 	// public methods
328 	//-------------------------------------------------------------------------------------------------------------
329 	public:
330 
Detectorframework::Detector331 		inline			 	 Detector	(								) { impl_clear();				}
Detectorframework::Detector332 		inline			 	 Detector	(	const	Detector&	rCopy	) { impl_copy( rCopy );			}
~Detectorframework::Detector333 		inline				~Detector	(								) { impl_clear();				}
operator =framework::Detector334 		inline Detector&	operator=	(	const	Detector&	rCopy	) { return impl_copy( rCopy );	}
freeframework::Detector335 		inline void			free		(								) { impl_clear();				}
336 
337 	//-------------------------------------------------------------------------------------------------------------
338 	// private methods
339 	//-------------------------------------------------------------------------------------------------------------
340 	private:
341 
impl_clearframework::Detector342 		inline void impl_clear()
343 		{
344             sName = ::rtl::OUString();
345 			lTypes.free();
346 		}
347 
impl_copyframework::Detector348 		inline Detector& impl_copy( const Detector& rCopy )
349 		{
350             sName  = rCopy.sName  ;
351             lTypes = rCopy.lTypes ;
352 			return (*this);
353 		}
354 
355 	//-------------------------------------------------------------------------------------------------------------
356 	// public member
357 	//-------------------------------------------------------------------------------------------------------------
358 	public:
359 
360         ::rtl::OUString     sName       ;
361         OUStringList        lTypes      ;
362 };
363 
364 //*****************************************************************************************************************
365 // Programmer can register his own services for loading documents in a frame.
366 // The implementation or service name of these is the keyname of an item with these structure
367 // in our hash map or our configuration set!
368 //*****************************************************************************************************************
369 struct Loader
370 {
371 	//-------------------------------------------------------------------------------------------------------------
372 	// public methods
373 	//-------------------------------------------------------------------------------------------------------------
374 	public:
375 
Loaderframework::Loader376 		inline		  	 Loader		(							) { impl_clear();				}
Loaderframework::Loader377 		inline		  	 Loader		(	const	Loader&	rCopy	) { impl_copy( rCopy );			}
~Loaderframework::Loader378 		inline		 	~Loader		(							) { impl_clear();				}
operator =framework::Loader379 		inline Loader&	operator=	(	const	Loader&	rCopy	) { return impl_copy( rCopy );	}
freeframework::Loader380 		inline void	 	free		(							) { impl_clear();				}
381 
382 	//-------------------------------------------------------------------------------------------------------------
383 	// private methods
384 	//-------------------------------------------------------------------------------------------------------------
385 	private:
386 
impl_clearframework::Loader387 		inline void impl_clear()
388 		{
389             sName = ::rtl::OUString();
390 			lUINames.free	();
391 			lTypes.free		();
392 		}
393 
impl_copyframework::Loader394 		inline Loader& impl_copy( const Loader& rCopy )
395 		{
396             sName       = rCopy.sName       ;
397 			lUINames	= rCopy.lUINames	;
398 			lTypes		= rCopy.lTypes		;
399 			return (*this);
400 		}
401 
402 	//-------------------------------------------------------------------------------------------------------------
403 	// public member
404 	//-------------------------------------------------------------------------------------------------------------
405 	public:
406 
407 		::rtl::OUString	sName		;
408         OUStringHashMap lUINames    ;
409         OUStringList    lTypes      ;
410 };
411 
412 //*****************************************************************************************************************
413 // Programmer can register his own services to handle a FileType and intercept dispatches.
414 // Don't forget: It's not a FrameLoader - it's a ContentHandler! (normaly without any UI)
415 //*****************************************************************************************************************
416 struct ContentHandler
417 {
418 	//-------------------------------------------------------------------------------------------------------------
419 	// public methods
420 	//-------------------------------------------------------------------------------------------------------------
421 	public:
422 
ContentHandlerframework::ContentHandler423         inline                   ContentHandler(                              ) { impl_clear();               }
ContentHandlerframework::ContentHandler424         inline                   ContentHandler( const ContentHandler& rCopy  ) { impl_copy( rCopy );         }
~ContentHandlerframework::ContentHandler425         inline                  ~ContentHandler(                              ) { impl_clear();               }
operator =framework::ContentHandler426         inline ContentHandler&   operator=     ( const ContentHandler& rCopy  ) { return impl_copy( rCopy );  }
freeframework::ContentHandler427         inline void              free          (                              ) { impl_clear();               }
428 
429 	//-------------------------------------------------------------------------------------------------------------
430 	// private methods
431 	//-------------------------------------------------------------------------------------------------------------
432 	private:
433 
impl_clearframework::ContentHandler434 		inline void impl_clear()
435 		{
436             sName = ::rtl::OUString();
437             lTypes.free();
438 		}
439 
impl_copyframework::ContentHandler440         inline ContentHandler& impl_copy( const ContentHandler& rCopy )
441 		{
442             sName  = rCopy.sName ;
443             lTypes = rCopy.lTypes;
444 			return (*this);
445 		}
446 
447 	//-------------------------------------------------------------------------------------------------------------
448 	// public member
449 	//-------------------------------------------------------------------------------------------------------------
450 	public:
451 
452         ::rtl::OUString     sName   ;
453         OUStringList        lTypes  ;
454 };
455 
456 //*****************************************************************************************************************
457 // We need different hash maps for different tables of our configuration management.
458 // Follow maps convert <names> to <properties> of type, filter, detector, loader ...
459 // and could be used in a generic way
460 //*****************************************************************************************************************
461 template< class HashType >
462 class SetNodeHash : public ::std::hash_map< ::rtl::OUString                    ,
463                                             HashType                           ,
464                                             rtl::OUStringHash                  ,
465                                             ::std::equal_to< ::rtl::OUString > >
466 {
467     //-------------------------------------------------------------------------------------------------------------
468     // interface
469     //-------------------------------------------------------------------------------------------------------------
470 	public:
471         //---------------------------------------------------------------------------------------------------------
472         // The only way to free ALL memory realy!
473         //---------------------------------------------------------------------------------------------------------
free()474         inline void free()
475         {
476             SetNodeHash().swap( *this );
477             lAddedItems.free  ();
478             lChangedItems.free();
479             lRemovedItems.free();
480         }
481 
482         //---------------------------------------------------------------------------------------------------------
483         // Append changed, added or removed items to special lists
484         // Neccessary for saving changes
485         //---------------------------------------------------------------------------------------------------------
486         void appendChange( const ::rtl::OUString& sName  ,
487                                  EModifyState     eState );
488 
489     //-------------------------------------------------------------------------------------------------------------
490     // member
491     //-------------------------------------------------------------------------------------------------------------
492     public:
493         OUStringList  lAddedItems    ;
494         OUStringList  lChangedItems  ;
495         OUStringList  lRemovedItems  ;
496 };
497 
498 //*****************************************************************************************************************
499 // Use these hashes to implement different tables which assign types to frame loader or detect services.
500 // It's an optimism to find registered services faster!
501 // The preferred hash maps file extensions to preferred types to find these ones faster.
502 //*****************************************************************************************************************
503 class PerformanceHash   :   public  ::std::hash_map<    ::rtl::OUString                     ,
504                                                         OUStringList                        ,
505                                                         rtl::OUStringHash                    ,
506 														::std::equal_to< ::rtl::OUString >	>
507 {
508 	public:
509         //---------------------------------------------------------------------------------------------------------
510         //  try to free all used memory REALY!
511         //---------------------------------------------------------------------------------------------------------
free()512         inline void free()
513         {
514             PerformanceHash().swap( *this );
515         }
516 
517         //---------------------------------------------------------------------------------------------------------
518         //  normaly a complete string must match our hash key values ...
519         //  But sometimes we need a search by using these key values as pattern!
520         //  The in/out parameter "pStepper" is used to return a pointer to found element in hash ...
521         //  and could be used for further searches again, which should be started at next element!
522         //  We stop search at the end of hash. You can start it again by setting it to the begin by himself.
523         //---------------------------------------------------------------------------------------------------------
findPatternKey(const::rtl::OUString & sSearchValue,const_iterator & pStepper)524         inline sal_Bool findPatternKey( const ::rtl::OUString& sSearchValue ,
525                                               const_iterator&  pStepper     )
526         {
527             sal_Bool bFound = sal_False;
528 
529             // If this is the forst call - start search on first element.
530             // Otherwise start search on further elements!
531             if( pStepper != begin() )
532             {
533                 ++pStepper;
534             }
535 
536             while(
537                     ( pStepper != end()     )   &&
538                     ( bFound   == sal_False )
539                 )
540             {
541                 bFound = Wildcard::match( sSearchValue, pStepper->first );
542                 // If element was found - break loop by setting right return value
543                 // and don't change "pStepper". He must point to found element!
544                 // Otherwise step to next one.
545                 if( bFound == sal_False )
546                     ++pStepper;
547             }
548             return bFound;
549         }
550 };
551 
552 //*****************************************************************************************************************
553 // Define easy usable types
554 //*****************************************************************************************************************
555 typedef SetNodeHash< FileType >                                     FileTypeHash                ;
556 typedef SetNodeHash< Filter >                                       FilterHash                  ;
557 typedef SetNodeHash< Detector >                                     DetectorHash                ;
558 typedef SetNodeHash< Loader >                                       LoaderHash                  ;
559 typedef SetNodeHash< ContentHandler >                               ContentHandlerHash          ;
560 typedef OUStringHashMap                                             PreferredHash               ;
561 typedef OUStringList                                                OrderList                   ;
562 
563 typedef CheckedIterator< OUStringList >                             CheckedStringListIterator   ;
564 typedef CheckedIterator< FileTypeHash >                             CheckedTypeIterator         ;
565 typedef CheckedIterator< PerformanceHash >                          CheckedPerformanceIterator  ;
566 
567 typedef ::std::vector< FilterHash::const_iterator >                 FilterQuery                 ;
568 
569 //*****************************************************************************************************************
570 // Use private static data container to hold all values of configuration!
571 //*****************************************************************************************************************
572 class DataContainer : private ThreadHelpBase
573 {
574     public:
575 
576     /** @short  identifies different sets of the TypeDetection configuration package.
577 
578         @descr  Most functions on top of this configuration package are the same ...
579                 but must be executed on different places inside ths configuration structures.
580                 These enum values can be used ate some interface methods to specify, which
581                 configuration set should be used.
582                 Further it must be possible to start the same action for more then one cfg type.
583                 That's why these values must be interpreted as flags. Means: it's values must be
584                 in range [2^n]!
585       */
586     enum ECFGType
587     {
588         E_TYPE           =  1,
589         E_FILTER         =  2,
590         E_DETECTSERVICE  =  4,
591         E_FRAMELOADER    =  8,
592         E_CONTENTHANDLER = 16,
593 
594         E_ALL            = E_TYPE | E_FILTER | E_DETECTSERVICE | E_FRAMELOADER | E_CONTENTHANDLER
595     };
596 
597     public:
598 
599         DataContainer();
600 
601         void        startListener();
602         void        stopListener ();
603 
604         sal_Bool    isModified();
605 
606         LockHelper& getSyncronizer();
607         void        free();
608 
609         sal_Bool isValidOrRepairable       () const;
610         sal_Bool validateAndRepair         ();
611         sal_Bool validateAndRepairTypes    ();
612         sal_Bool validateAndRepairFilter   ();
613         sal_Bool validateAndRepairDetectors();
614         sal_Bool validateAndRepairLoader   ();
615         sal_Bool validateAndRepairHandler  ();
616 
617         sal_Bool existsType           ( const ::rtl::OUString& sName );
618         sal_Bool existsFilter         ( const ::rtl::OUString& sName );
619         sal_Bool existsDetector       ( const ::rtl::OUString& sName );
620         sal_Bool existsLoader         ( const ::rtl::OUString& sName );
621         sal_Bool existsContentHandler ( const ::rtl::OUString& sName );
622 
623         void addType              ( const FileType&        aType    , sal_Bool bSetModified );
624         void addFilter            ( const Filter&          aFilter  , sal_Bool bSetModified );
625         void addDetector          ( const Detector&        aDetector, sal_Bool bSetModified );
626         void addLoader            ( const Loader&          aLoader  , sal_Bool bSetModified );
627         void addContentHandler    ( const ContentHandler&  aHandler , sal_Bool bSetModified );
628 
629         void replaceType          ( const FileType&        aType    , sal_Bool bSetModified );
630         void replaceFilter        ( const Filter&          aFilter  , sal_Bool bSetModified );
631         void replaceDetector      ( const Detector&        aDetector, sal_Bool bSetModified );
632         void replaceLoader        ( const Loader&          aLoader  , sal_Bool bSetModified );
633         void replaceContentHandler( const ContentHandler&  aHandler , sal_Bool bSetModified );
634 
635         void removeType           ( const ::rtl::OUString& sName    , sal_Bool bSetModified );
636         void removeFilter         ( const ::rtl::OUString& sName    , sal_Bool bSetModified );
637         void removeDetector       ( const ::rtl::OUString& sName    , sal_Bool bSetModified );
638         void removeLoader         ( const ::rtl::OUString& sName    , sal_Bool bSetModified );
639         void removeContentHandler ( const ::rtl::OUString& sName    , sal_Bool bSetModified );
640 
641         static void             convertFileTypeToPropertySequence          ( const FileType&                                           aSource         ,
642                                                                                    css::uno::Sequence< css::beans::PropertyValue >&    lDestination    ,
643                                                                              const ::rtl::OUString&                                    sCurrentLocale  );
644         static void             convertFilterToPropertySequence            ( const Filter&                                             aSource         ,
645                                                                                    css::uno::Sequence< css::beans::PropertyValue >&    lDestination    ,
646                                                                              const ::rtl::OUString&                                    sCurrentLocale  );
647         static void             convertDetectorToPropertySequence          ( const Detector&                                           aSource         ,
648                                                                                    css::uno::Sequence< css::beans::PropertyValue >&    lDestination    );
649         static void             convertLoaderToPropertySequence            ( const Loader&                                             aSource         ,
650                                                                                    css::uno::Sequence< css::beans::PropertyValue >&    lDestination    ,
651                                                                              const ::rtl::OUString&                                    sCurrentLocale  );
652         static void             convertContentHandlerToPropertySequence    ( const ContentHandler&                                     aSource         ,
653                                                                                    css::uno::Sequence< css::beans::PropertyValue >&    lDestination    );
654         static void             convertPropertySequenceToFilter            ( const css::uno::Sequence< css::beans::PropertyValue >&    lSource         ,
655                                                                                    Filter&                                             aDestination    ,
656                                                                              const ::rtl::OUString&                                    sCurrentLocale  );
657         static void             convertPropertySequenceToFileType          ( const css::uno::Sequence< css::beans::PropertyValue >&    lSource         ,
658                                                                                    FileType&                                           aDestination    ,
659                                                                              const ::rtl::OUString&                                    sCurrentLocale  );
660         static void             convertPropertySequenceToDetector          ( const css::uno::Sequence< css::beans::PropertyValue >&    lSource         ,
661                                                                                    Detector&                                           aDestination    );
662         static void             convertPropertySequenceToLoader            ( const css::uno::Sequence< css::beans::PropertyValue >&    lSource         ,
663                                                                                    Loader&                                             aDestination    ,
664                                                                              const ::rtl::OUString&                                    sCurrentLocale  );
665         static void             convertPropertySequenceToContentHandler    ( const css::uno::Sequence< css::beans::PropertyValue >&    lSource         ,
666                                                                                    ContentHandler&                                     aDestination    ,
667                                                                              const ::rtl::OUString&                                    sCurrentLocale  );
668         static void             extractLocalizedStrings                    ( const ::rtl::OUString&                                    sCurrentLocale  ,
669                                                                              const css::uno::Any&                                      aCFGValue       ,
670                                                                                    OUStringHashMap&                                       lLocales        );
671         static void             packLocalizedStrings                       (       sal_Int16                                           nMode           ,
672                                                                              const ::rtl::OUString&                                    sCurrentLocale  ,
673                                                                                    css::uno::Any&                                      aCFGValue       ,
674                                                                              const OUStringHashMap&                                       lLocales        );
675         static ::rtl::OUString  getLocalelizedString                       ( const OUStringHashMap&                                       lLocales        ,
676                                                                              const ::rtl::OUString&                                    sLocale         );
677         static void             setLocalelizedString                       (       OUStringHashMap&                                       lLocales        ,
678                                                                              const ::rtl::OUString&                                    sLocale         ,
679                                                                              const ::rtl::OUString&                                    sValue          );
680         static void             correctExtensions                          (       OUStringList&                                       lExtensions     );
681 
682     public:
683 
684         FileTypeHash            m_aTypeCache                ;     /// hold all informations about registered file types
685         FilterHash              m_aFilterCache              ;     /// hold all informations about registered filters
686         DetectorHash            m_aDetectorCache            ;     /// hold all informations about registered detect services
687         LoaderHash              m_aLoaderCache              ;     /// hold all informations about registered loader services
688         ContentHandlerHash      m_aContentHandlerCache      ;     /// hold all informations about registered content handler services
689         PerformanceHash         m_aFastFilterCache          ;     /// hold all registered filter for a special file type
690         PerformanceHash         m_aFastDetectorCache        ;     /// hold all registered detect services for a special file type
691         PerformanceHash         m_aFastLoaderCache          ;     /// hold all registered loader services for a special file type
692         PerformanceHash         m_aFastContentHandlerCache  ;     /// hold all registered content handler services for a special file type
693         PreferredHash           m_aPreferredTypesCache      ;     /// assignment of extensions to preferred types for it
694         Loader                  m_aGenericLoader            ;     /// informations about our default frame loader
695         ::rtl::OUString         m_sLocale                   ;     /// current set locale of configuration to handle right UIName from set of all UINames!
696         sal_Bool                m_bTypesModified            ;
697         sal_Bool                m_bFiltersModified          ;
698         sal_Bool                m_bDetectorsModified        ;
699         sal_Bool                m_bLoadersModified          ;
700         sal_Bool                m_bHandlersModified         ;
701 };
702 
703 /*-************************************************************************************************************//**
704     @short          capsulate configuration access for fiter configuration
705     @descr          We use the ConfigItem mechanism to read/write values from/to configuration.
706                     This implementation could be used to handle standard AND additional filter configurations in the same way.
707                     We set a data container pointer for filling or reading ... this class use it temp.
708                     After successfuly calling of read(), we can use filled container directly or merge it with an existing one.
709                     After successfuly calling of write() all values of given data container are flushed to our configuration.
710 
711 	@implements		-
712     @base           ConfigItem
713 
714 	@devstatus		ready to use
715     @threadsafe     no
716 *//*-*************************************************************************************************************/
717 class FilterCFGAccess : public ::utl::ConfigItem
718 {
719     //-------------------------------------------------------------------------------------------------------------
720     //  interface
721     //-------------------------------------------------------------------------------------------------------------
722     public:
723                                     FilterCFGAccess ( const ::rtl::OUString& sPath                                  ,
724                                                             sal_Int32        nVersion = DEFAULT_FILTERCACHE_VERSION ,
725                                                             sal_Int16        nMode    = DEFAULT_FILTERCACHE_MODE    ); // open configuration
726         virtual                     ~FilterCFGAccess(                                                               );
727 
728         void                        read            (       DataContainer&   rData                                  ,
729                                                             DataContainer::ECFGType         eType                   ); // read values from configuration into given struct
730         void                        write           (       DataContainer&   rData                                  ,
731                                                             DataContainer::ECFGType         eType                   ); // write values from given struct to configuration
732 
733         static   ::rtl::OUString    encodeTypeData  ( const FileType&        aType                                  ); // build own formated string of type properties
734         static   void               decodeTypeData  ( const ::rtl::OUString& sData                                  ,
735                                                             FileType&        aType                                  );
736         static   ::rtl::OUString    encodeFilterData( const Filter&          aFilter                                ); // build own formated string of filter properties
737         static   void               decodeFilterData( const ::rtl::OUString& sData                                  ,
738                                                             Filter&          aFilter                                );
739         static   ::rtl::OUString    encodeStringList( const OUStringList&    lList                                  ); // build own formated string of OUStringList
740         static   OUStringList       decodeStringList( const ::rtl::OUString& sValue                                 );
741 
742         void             setProductName                             (       OUStringHashMap&                                       lUINames        );
743         void             resetProductName                           (       OUStringHashMap&                                       lUINames        );
744 
745     //-------------------------------------------------------------------------------------------------------------
746     //  internal helper
747     //-------------------------------------------------------------------------------------------------------------
748     private:
749         void impl_initKeyCounts        (                                            );    // set right key counts, which are used at reading/writing of set node properties
750         void impl_removeNodes          (       OUStringList&        rChangesList    ,     // helper to remove list of set nodes
751                                          const ::rtl::OUString&     sTemplateType   ,
752                                          const ::rtl::OUString&     sSetName        );
753 
754         void impl_loadTypes            ( DataContainer&             rData           );    // helper to load configuration parts
755         void impl_loadFilters          ( DataContainer&             rData           );
756         void impl_loadDetectors        ( DataContainer&             rData           );
757         void impl_loadLoaders          ( DataContainer&             rData           );
758         void impl_loadContentHandlers  ( DataContainer&             rData           );
759         void impl_loadDefaults         ( DataContainer&             rData           );
760 
761         void impl_saveTypes            ( DataContainer&             rData           );    // helper to save configuration parts
762         void impl_saveFilters          ( DataContainer&             rData           );
763         void impl_saveDetectors        ( DataContainer&             rData           );
764         void impl_saveLoaders          ( DataContainer&             rData           );
765         void impl_saveContentHandlers  ( DataContainer&             rData           );
766 
767     //-------------------------------------------------------------------------------------------------------------
768     //  debug checks
769     //-------------------------------------------------------------------------------------------------------------
770     private:
771         static sal_Bool implcp_ctor ( const ::rtl::OUString& sPath    ,     // methods to check incoming parameter on our interface methods!
772                                             sal_Int32        nVersion ,
773                                             sal_Int16        nMode    );
774         static sal_Bool implcp_read ( const DataContainer&   rData    );
775         static sal_Bool implcp_write( const DataContainer&   rData    );
776 
777     //-------------------------------------------------------------------------------------------------------------
778     //  member
779     //-------------------------------------------------------------------------------------------------------------
780     private:
781         EFilterPackage  m_ePackage                     ;   // ... not realy used yet! should split configuration in STANDARD and ADDITIONAL filter
782         sal_Int32       m_nVersion                     ;   // file format version of configuration! (neccessary for "xml2xcd" transformation!)
783         sal_Int32       m_nKeyCountTypes               ;   // follow key counts present count of configuration properties for types/filters ... and depends from m_nVersion - must be set right!
784         sal_Int32       m_nKeyCountFilters             ;
785         sal_Int32       m_nKeyCountDetectors           ;
786         sal_Int32       m_nKeyCountLoaders             ;
787         sal_Int32       m_nKeyCountContentHandlers     ;
788         ::rtl::OUString m_sProductName                 ;
789         ::rtl::OUString m_sFormatVersion               ;
790 };
791 /*DRAFT
792 class FilterCFGListener : public  css::util::XChangesListener
793                         , private ThreadHelpBase
794                         , public  ::cppu::OWeakObject
795 {
796     public:
797 
798         enum ECFGType
799         {
800             E_TYPE          ,
801             E_FILTER        ,
802             E_LOADER        ,
803             E_DETECTOR      ,
804             E_CONTENTHANDLER
805         };
806 
807     private:
808 
809         // read only access to the configuration, where we are regsieterd as changes listener.
810         css::uno::Reference< css::uno::XInterface > m_xCFG;
811 
812         // indicates, for which type of configuration item we listen.
813         ECFGType m_eType;
814 
815         DataContainer* m_pData;
816 
817         // we must know, if we are already registered as listener or not.
818         //    That can be usefull to supress double registration calls ...
819         //    which may will force double call backs in our disposing method!
820         //    Such superflous calls can be dangerous.
821         sal_Bool m_bListening;
822 
823     public:
824 
825         DECLARE_XINTERFACE
826 
827         FilterCFGListener( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
828                                  ECFGType                                                eType ,
829                                  DataContainer*                                          pData );
830 
831         void startListening();
832         void stopListening ();
833 
834         virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& aEvent ) throw(css::uno::RuntimeException);
835         virtual void SAL_CALL disposing      ( const css::lang::EventObject&  aEvent ) throw(css::uno::RuntimeException);
836 
837     private:
838 
839         FileType       impl_readType    ( const css::uno::Reference< css::uno::XInterface >& xNode );
840         Filter         impl_readFilter  ( const css::uno::Reference< css::uno::XInterface >& xNode );
841         Detector       impl_readDetector( const css::uno::Reference< css::uno::XInterface >& xNode );
842         Loader         impl_readLoader  ( const css::uno::Reference< css::uno::XInterface >& xNode );
843         ContentHandler impl_readHandler ( const css::uno::Reference< css::uno::XInterface >& xNode );
844 };
845 */
846 
847 }       //  namespace framework
848 
849 #endif  //  #ifndef __FRAMEWORK_CLASSES_FILTERCACHEDATA_HXX_
850