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