1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_unotools.hxx"
30 #ifndef GCC
31 #endif
32 
33 //_________________________________________________________________________________________________________________
34 //	includes
35 //_________________________________________________________________________________________________________________
36 
37 #include <unotools/moduleoptions.hxx>
38 #include <comphelper/sequenceashashmap.hxx>
39 #include <unotools/configmgr.hxx>
40 #include <unotools/configitem.hxx>
41 #include <unotools/processfactory.hxx>
42 #include <osl/diagnose.h>
43 #include <rtl/ustrbuf.hxx>
44 
45 #include <rtl/logfile.hxx>
46 #include <com/sun/star/uno/Any.hxx>
47 #include <com/sun/star/uno/Sequence.hxx>
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #include <com/sun/star/container/XNameAccess.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/document/XTypeDetection.hpp>
53 #include <com/sun/star/util/XStringSubstitution.hpp>
54 
55 #include "itemholder1.hxx"
56 
57 //_________________________________________________________________________________________________________________
58 //	namespaces
59 //_________________________________________________________________________________________________________________
60 
61 #ifndef css
62 namespace css = ::com::sun::star;
63 #endif
64 
65 //_________________________________________________________________________________________________________________
66 //	const
67 //_________________________________________________________________________________________________________________
68 
69 /*-************************************************************************************************************//**
70     @descr          These values are used to define neccessary keys from our configuration management to support
71                     all functionality of these implementation.
72 					It's a fast way to make changes if some keys change his name or location!
73 
74                     Property handle are neccessary to specify right position in return list of configuration
75 					for asked values. We ask it with a list of properties to get his values. The returned list
76                     has the same order like our given name list!
77                     e.g.:
78                             NAMELIST[ PROPERTYHANDLE_xxx ] => VALUELIST[ PROPERTYHANDLE_xxx ]
79 *//*-*************************************************************************************************************/
80 #define ROOTNODE_FACTORIES                  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Setup/Office/Factories"        ))
81 #define PATHSEPERATOR                       ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"                             ))
82 
83 // Attention: The property "ooSetupFactoryEmptyDocumentURL" is read from configuration but not used! There is
84 //            special code that uses hard coded strings to return them.
85 #define PROPERTYNAME_SHORTNAME              ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryShortName"       ))
86 #define PROPERTYNAME_TEMPLATEFILE           ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryTemplateFile"    ))
87 #define PROPERTYNAME_WINDOWATTRIBUTES       ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryWindowAttributes"))
88 #define PROPERTYNAME_EMPTYDOCUMENTURL       ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryEmptyDocumentURL"))
89 #define PROPERTYNAME_DEFAULTFILTER          ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryDefaultFilter"   ))
90 #define PROPERTYNAME_ICON                   ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryIcon"            ))
91 
92 #define PROPERTYHANDLE_SHORTNAME            0
93 #define PROPERTYHANDLE_TEMPLATEFILE         1
94 #define PROPERTYHANDLE_WINDOWATTRIBUTES     2
95 #define PROPERTYHANDLE_EMPTYDOCUMENTURL     3
96 #define PROPERTYHANDLE_DEFAULTFILTER        4
97 #define PROPERTYHANDLE_ICON                 5
98 
99 #define PROPERTYCOUNT                       6
100 
101 #define FACTORYNAME_WRITER                  ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument"                ))
102 #define FACTORYNAME_WRITERWEB               ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.WebDocument"                 ))
103 #define FACTORYNAME_WRITERGLOBAL            ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.GlobalDocument"              ))
104 #define FACTORYNAME_CALC                    ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument"        ))
105 #define FACTORYNAME_DRAW                    ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocument"          ))
106 #define FACTORYNAME_IMPRESS                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument"))
107 #define FACTORYNAME_MATH                    ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.formula.FormulaProperties"        ))
108 #define FACTORYNAME_CHART                   ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.ChartDocument"             ))
109 #define FACTORYNAME_DATABASE                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.OfficeDatabaseDocument"       ))
110 #define FACTORYNAME_STARTMODULE             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.StartModule"                ))
111 
112 #define FACTORYCOUNT                        10
113 
114 /*-************************************************************************************************************//**
115     @descr  This struct hold information about one factory. We declare a complete array which can hold infos
116             for all well known factories. Values of enum "EFactory" (see header!) are directly used as index!
117             So we can support a fast access on these informations.
118 *//*-*************************************************************************************************************/
119 struct FactoryInfo
120 {
121     public:
122         //---------------------------------------------------------------------------------------------------------
123         // initialize empty struct
124         FactoryInfo()
125         {
126             free();
127             // @@@ should be supplied from outside!
128             xSMgr = ::utl::getProcessServiceFactory();
129         }
130 
131         //---------------------------------------------------------------------------------------------------------
132         // easy way to reset struct member!
133         void free()
134         {
135             bInstalled                  = sal_False         ;
136             sFactory                    = ::rtl::OUString() ;
137             sShortName                  = ::rtl::OUString() ;
138             sTemplateFile               = ::rtl::OUString() ;
139             sWindowAttributes           = ::rtl::OUString() ;
140             sEmptyDocumentURL           = ::rtl::OUString() ;
141             sDefaultFilter              = ::rtl::OUString() ;
142             nIcon                       = 0                 ;
143             bChangedTemplateFile        = sal_False         ;
144             bChangedWindowAttributes    = sal_False         ;
145             bChangedEmptyDocumentURL    = sal_False         ;
146             bChangedDefaultFilter       = sal_False         ;
147             bChangedIcon                = sal_False         ;
148             bDefaultFilterReadonly      = sal_False         ;
149         }
150 
151         //---------------------------------------------------------------------------------------------------------
152         // returns list of properties, which has changed only!
153         // We use given value of sNodeBase to build full qualified pathes ...
154         // Last sign of it must be "/". Beacuse we use it directly, without any additional things!
155         css::uno::Sequence< css::beans::PropertyValue > getChangedProperties( const ::rtl::OUString& sNodeBase )
156         {
157             // a) reserve memory for max. count of changed properties
158             // b) add names and values of changed ones only and count it
159             // c) resize return list by using count
160             css::uno::Sequence< css::beans::PropertyValue > lProperties   ( 4 );
161             sal_Int8                                        nRealyChanged = 0  ;
162 
163             if( bChangedTemplateFile == sal_True )
164             {
165                 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_TEMPLATEFILE;
166 
167                 if ( sTemplateFile.getLength() > 0 )
168                 {
169                     lProperties[nRealyChanged].Value
170                         <<= getStringSubstitution()
171                             ->reSubstituteVariables( sTemplateFile );
172                 }
173                 else
174                 {
175                     lProperties[nRealyChanged].Value <<= sTemplateFile;
176                 }
177 
178                 ++nRealyChanged;
179             }
180             if( bChangedWindowAttributes == sal_True )
181             {
182                 lProperties[nRealyChanged].Name    = sNodeBase + PROPERTYNAME_WINDOWATTRIBUTES;
183                 lProperties[nRealyChanged].Value <<= sWindowAttributes;
184                 ++nRealyChanged;
185             }
186             if( bChangedEmptyDocumentURL == sal_True )
187             {
188                 lProperties[nRealyChanged].Name    = sNodeBase + PROPERTYNAME_EMPTYDOCUMENTURL;
189                 lProperties[nRealyChanged].Value <<= sEmptyDocumentURL;
190                 ++nRealyChanged;
191             }
192             if( bChangedDefaultFilter == sal_True )
193             {
194                 lProperties[nRealyChanged].Name    = sNodeBase + PROPERTYNAME_DEFAULTFILTER;
195                 lProperties[nRealyChanged].Value <<= sDefaultFilter;
196                 ++nRealyChanged;
197             }
198             if( bChangedIcon == sal_True )
199             {
200                 lProperties[nRealyChanged].Name    = sNodeBase + PROPERTYNAME_ICON;
201                 lProperties[nRealyChanged].Value <<= nIcon;
202                 ++nRealyChanged;
203             }
204 
205             // Don't forget to reset changed flags! Otherwise we save it again and again and ...
206             bChangedTemplateFile        = sal_False         ;
207             bChangedWindowAttributes    = sal_False         ;
208             bChangedEmptyDocumentURL    = sal_False         ;
209             bChangedDefaultFilter       = sal_False         ;
210             bChangedIcon                = sal_False         ;
211 
212             lProperties.realloc( nRealyChanged );
213             return lProperties;
214         }
215 
216         //---------------------------------------------------------------------------------------------------------
217         // We must support setting AND marking of changed values.
218         // That's why we can't make our member public. We must use get/set/init methods
219         // to control access on it!
220         sal_Bool            getInstalled        () const { return bInstalled;         };
221         ::rtl::OUString     getFactory          () const { return sFactory;           };
222         ::rtl::OUString     getShortName        () const { return sShortName;         };
223         ::rtl::OUString     getTemplateFile     () const { return sTemplateFile;      };
224         ::rtl::OUString     getWindowAttributes () const { return sWindowAttributes;  };
225         ::rtl::OUString     getEmptyDocumentURL () const { return sEmptyDocumentURL;  };
226         ::rtl::OUString     getDefaultFilter    () const { return sDefaultFilter;     };
227         sal_Bool            isDefaultFilterReadonly() const { return bDefaultFilterReadonly; }
228         sal_Int32           getIcon             () const { return nIcon;              };
229 
230         //---------------------------------------------------------------------------------------------------------
231         // If you call set-methods - we check for changes of valkues and mark it.
232         // But if you whish to set it without that ... you must initialize it!
233         void initInstalled        ( sal_Bool               bNewInstalled        ) { bInstalled        = bNewInstalled        ; }
234         void initFactory          ( const ::rtl::OUString& sNewFactory          ) { sFactory          = sNewFactory          ; }
235         void initShortName        ( const ::rtl::OUString& sNewShortName        ) { sShortName        = sNewShortName        ; }
236         void initWindowAttributes ( const ::rtl::OUString& sNewWindowAttributes ) { sWindowAttributes = sNewWindowAttributes ; }
237         void initEmptyDocumentURL ( const ::rtl::OUString& sNewEmptyDocumentURL ) { sEmptyDocumentURL = sNewEmptyDocumentURL ; }
238         void initDefaultFilter    ( const ::rtl::OUString& sNewDefaultFilter    ) { sDefaultFilter    = sNewDefaultFilter    ; }
239         void setDefaultFilterReadonly( const sal_Bool bVal){bDefaultFilterReadonly = bVal;}
240         void initIcon             ( sal_Int32              nNewIcon             ) { nIcon             = nNewIcon             ; }
241 
242         //---------------------------------------------------------------------------------------------------------
243         void initTemplateFile( const ::rtl::OUString& sNewTemplateFile )
244         {
245             if ( sNewTemplateFile.getLength() > 0 )
246             {
247                 sTemplateFile
248                     = getStringSubstitution()
249                         ->substituteVariables( sNewTemplateFile, sal_False );
250             }
251             else
252             {
253                 sTemplateFile = sNewTemplateFile;
254             }
255         }
256 
257         //---------------------------------------------------------------------------------------------------------
258         void setInstalled( sal_Bool bNewInstalled )
259         {
260             bInstalled = bNewInstalled;
261         };
262 
263         //---------------------------------------------------------------------------------------------------------
264         void setFactory( const ::rtl::OUString& sNewFactory )
265         {
266             sFactory = sNewFactory;
267         };
268 
269         //---------------------------------------------------------------------------------------------------------
270         void setShortName( const ::rtl::OUString& sNewShortName )
271         {
272             sShortName = sNewShortName;
273         };
274 
275         //---------------------------------------------------------------------------------------------------------
276         void setTemplateFile( const ::rtl::OUString& sNewTemplateFile )
277         {
278             if( sTemplateFile != sNewTemplateFile )
279             {
280                 sTemplateFile        = sNewTemplateFile;
281                 bChangedTemplateFile = sal_True        ;
282             }
283         };
284 
285         //---------------------------------------------------------------------------------------------------------
286         void setWindowAttributes( const ::rtl::OUString& sNewWindowAttributes )
287         {
288             if( sWindowAttributes != sNewWindowAttributes )
289             {
290                 sWindowAttributes        = sNewWindowAttributes;
291                 bChangedWindowAttributes = sal_True            ;
292             }
293         };
294 
295         //---------------------------------------------------------------------------------------------------------
296         void setEmptyDocumentURL( const ::rtl::OUString& sNewEmptyDocumentURL )
297         {
298             if( sEmptyDocumentURL != sNewEmptyDocumentURL )
299             {
300                 sEmptyDocumentURL        = sNewEmptyDocumentURL;
301                 bChangedEmptyDocumentURL = sal_True            ;
302             }
303         };
304 
305         //---------------------------------------------------------------------------------------------------------
306         void setDefaultFilter( const ::rtl::OUString& sNewDefaultFilter )
307         {
308             if( sDefaultFilter != sNewDefaultFilter )
309             {
310                 sDefaultFilter       = sNewDefaultFilter;
311                 bChangedDefaultFilter = sal_True         ;
312             }
313         };
314 
315         //---------------------------------------------------------------------------------------------------------
316         void setIcon( sal_Int32 nNewIcon )
317         {
318             if( nNewIcon != nNewIcon )
319             {
320                 nNewIcon     = nNewIcon;
321                 bChangedIcon = sal_True;
322             }
323         };
324 
325     private:
326         css::uno::Reference< css::util::XStringSubstitution > getStringSubstitution()
327         {
328             if ( !xSubstVars.is() )
329             {
330                 xSubstVars
331                     = css::uno::Reference< css::util::XStringSubstitution >(
332                         xSMgr->createInstance(
333                             ::rtl::OUString(
334                                 RTL_CONSTASCII_USTRINGPARAM(
335                                     "com.sun.star.util.PathSubstitution" ) ) ),
336                             css::uno::UNO_QUERY );
337                 if ( !xSubstVars.is() )
338                     throw css::uno::RuntimeException(
339                         ::rtl::OUString(
340                             RTL_CONSTASCII_USTRINGPARAM(
341                                 "Cannot instanciate service "
342                                 "com.sun.star.util.PathSubstitution" ) ),
343                         css::uno::Reference< css::uno::XInterface >() );
344             }
345             return xSubstVars;
346         }
347 
348         sal_Bool            bInstalled                      ;
349         ::rtl::OUString     sFactory                        ;
350         ::rtl::OUString     sShortName                      ;
351         ::rtl::OUString     sTemplateFile                   ;
352         ::rtl::OUString     sWindowAttributes               ;
353         ::rtl::OUString     sEmptyDocumentURL               ;
354         ::rtl::OUString     sDefaultFilter                  ;
355         sal_Int32           nIcon                           ;
356 
357         sal_Bool            bChangedTemplateFile        :1  ;
358         sal_Bool            bChangedWindowAttributes    :1  ;
359         sal_Bool            bChangedEmptyDocumentURL    :1  ;
360         sal_Bool            bChangedDefaultFilter       :1  ;
361         sal_Bool            bChangedIcon                :1  ;
362         sal_Bool            bDefaultFilterReadonly      :1  ;
363 
364         css::uno::Reference< css::lang::XMultiServiceFactory > xSMgr;
365         css::uno::Reference< css::util::XStringSubstitution >  xSubstVars;
366 };
367 
368 typedef FactoryInfo   FactoryInfoList[FACTORYCOUNT];
369 
370 /*-************************************************************************************************************//**
371     @short          IMPL data container for wrapper class SvtModulOptions!
372     @descr          These class is used as a static data container of class SvtModuleOptions. The hold it by using
373                     a refcount and make it threadsafe by using an osl mutex. So we don't must do anything for that.
374                     We can implement pure functionality to read/write configuration data only.
375 
376 	@implements		-
377     @base           ConfigItem
378 
379 	@devstatus		ready to use
380     @threadsafe     no
381 *//*-*************************************************************************************************************/
382 class SvtModuleOptions_Impl : public ::utl::ConfigItem
383 {
384     //-------------------------------------------------------------------------------------------------------------
385 	//	public methods
386 	//-------------------------------------------------------------------------------------------------------------
387 	public:
388         //---------------------------------------------------------------------------------------------------------
389 		//	constructor / destructor
390 		//---------------------------------------------------------------------------------------------------------
391          SvtModuleOptions_Impl(SvtModuleOptions* pOutsideClass);
392         ~SvtModuleOptions_Impl();
393 
394 		//---------------------------------------------------------------------------------------------------------
395 		//	overloaded methods of baseclass
396 		//---------------------------------------------------------------------------------------------------------
397         virtual void Notify( const css::uno::Sequence< ::rtl::OUString >& lPropertyNames );
398         virtual void Commit(                                                             );
399 
400 		//---------------------------------------------------------------------------------------------------------
401 		//	public interface
402 		//---------------------------------------------------------------------------------------------------------
403         sal_Bool        IsModuleInstalled         (       SvtModuleOptions::EModule     eModule    ) const;
404 	    ::com::sun::star::uno::Sequence < ::rtl::OUString > GetAllServiceNames();
405         ::rtl::OUString GetFactoryName            (       SvtModuleOptions::EFactory    eFactory   ) const;
406         ::rtl::OUString GetFactoryShortName       (       SvtModuleOptions::EFactory    eFactory   ) const;
407         ::rtl::OUString GetFactoryStandardTemplate(       SvtModuleOptions::EFactory    eFactory   ) const;
408         ::rtl::OUString GetFactoryWindowAttributes(       SvtModuleOptions::EFactory    eFactory   ) const;
409         ::rtl::OUString GetFactoryEmptyDocumentURL(       SvtModuleOptions::EFactory    eFactory   ) const;
410         ::rtl::OUString GetFactoryDefaultFilter   (       SvtModuleOptions::EFactory    eFactory   ) const;
411         sal_Bool        IsDefaultFilterReadonly(          SvtModuleOptions::EFactory eFactory      ) const;
412         sal_Int32       GetFactoryIcon            (       SvtModuleOptions::EFactory    eFactory   ) const;
413         static sal_Bool ClassifyFactoryByName     ( const ::rtl::OUString&              sName      ,
414                                                           SvtModuleOptions::EFactory&   eFactory   );
415         void            SetFactoryStandardTemplate(       SvtModuleOptions::EFactory    eFactory   ,
416                                                     const ::rtl::OUString&              sTemplate  );
417         void            SetFactoryWindowAttributes(       SvtModuleOptions::EFactory    eFactory   ,
418                                                     const ::rtl::OUString&              sAttributes);
419         void            SetFactoryDefaultFilter   (       SvtModuleOptions::EFactory    eFactory   ,
420                                                     const ::rtl::OUString&              sFilter    );
421         void            MakeReadonlyStatesAvailable();
422 
423 	//-------------------------------------------------------------------------------------------------------------
424 	//	private methods
425 	//-------------------------------------------------------------------------------------------------------------
426 	private:
427         static css::uno::Sequence< ::rtl::OUString > impl_ExpandSetNames ( const css::uno::Sequence< ::rtl::OUString >& lSetNames   );
428                void                                  impl_Read           ( const css::uno::Sequence< ::rtl::OUString >& lSetNames   );
429 
430     //-------------------------------------------------------------------------------------------------------------
431     //  private types
432 	//-------------------------------------------------------------------------------------------------------------
433     private:
434 
435 	//-------------------------------------------------------------------------------------------------------------
436 	//	private member
437 	//-------------------------------------------------------------------------------------------------------------
438 	private:
439         FactoryInfoList     m_lFactories;
440         sal_Bool            m_bReadOnlyStatesWellKnown;
441         SvtModuleOptions*   m_pOutsideClass;
442 };
443 
444 //_________________________________________________________________________________________________________________
445 //	definitions
446 //_________________________________________________________________________________________________________________
447 
448 /*-************************************************************************************************************//**
449     @short      default ctor
450     @descr      We open our configuration here and read all neccessary values from it.
451                 These values are cached till everyone call Commit(). Then we write changed ones back to cfg.
452 
453     @seealso    baseclass ConfigItem
454     @seealso    method impl_Read()
455 
456     @param      -
457     @return     -
458 
459     @onerror    -
460     @threadsafe no
461 *//*-*************************************************************************************************************/
462 SvtModuleOptions_Impl::SvtModuleOptions_Impl(SvtModuleOptions* pOutsideClass)
463     :   ::utl::ConfigItem( ROOTNODE_FACTORIES )
464     ,   m_bReadOnlyStatesWellKnown( sal_False )
465     ,   m_pOutsideClass( pOutsideClass )
466 {
467     // First initialize list of factory infos! Otherwise we couldnt gurantee right working of these class.
468     for( sal_Int32 nFactory=0; nFactory<FACTORYCOUNT; ++nFactory )
469         m_lFactories[nFactory].free();
470 
471     // Get name list of all existing set node names in configuration to read her properties in impl_Read().
472     // These list is a list of long names of our factories.
473     const css::uno::Sequence< ::rtl::OUString > lFactories = GetNodeNames( ::rtl::OUString() );
474     impl_Read( lFactories );
475 
476     // Enable notification for changes by using configuration directly.
477     // So we can update our internal values immediatly.
478     EnableNotification( lFactories );
479 }
480 
481 /*-************************************************************************************************************//**
482     @short      default dtor
483     @descr      If any values of our cache was modified we should write it back to configuration.
484 
485     @attention  Don't forget to call "SetModified()" method of base class ConfigItem if any interface method
486                 of this class modify internal member list m_lFactories! Otherwise Commit() will never be called!!!
487 
488     @seealso    baseclass ConfigItem
489 
490     @param      -
491     @return     -
492 
493     @onerror    -
494     @threadsafe no
495 *//*-*************************************************************************************************************/
496 SvtModuleOptions_Impl::~SvtModuleOptions_Impl()
497 {
498     if( IsModified() == sal_True )
499 	{
500 		Commit();
501 	}
502 }
503 
504 /*-************************************************************************************************************//**
505     @short      called for notify of configmanager
506     @descr      These method is called from the ConfigManager before application ends or from the
507                 PropertyChangeListener if the sub tree broadcasts changes. You must update our
508                 internal values.
509 
510     @attention  We are registered for pure set node names only. So we can use our internal method "impl_Read()" to
511                 update our info list. Because - these method expand given name list to full qualified property list
512                 and use it to read the values. These values are filled into our internal member list m_lFactories
513                 at right position.
514 
515     @seealso    method impl_Read()
516 
517     @param      "lNames" is the list of set node entries which should be updated.
518     @return     -
519 
520     @onerror    -
521     @threadsafe no
522 *//*-*************************************************************************************************************/
523 void SvtModuleOptions_Impl::Notify( const css::uno::Sequence< ::rtl::OUString >& )
524 {
525     OSL_ENSURE( sal_False, "SvtModuleOptions_Impl::Notify()\nNot implemented yet!\n" );
526 }
527 
528 /*-****************************************************************************************************//**
529     @short      write changes to configuration
530     @descr      These method writes the changed values into the sub tree
531                 and should always called in our destructor to guarantee consistency of config data.
532 
533     @attention  We clear complete set in configuration first and write it completly new! So we don't must
534                 distinguish between existing, added or removed elements. Our internal cached values
535                 are the only and right ones.
536 
537     @seealso    baseclass ConfigItem
538 
539     @param      -
540     @return     -
541 
542     @onerror    -
543     @threadsafe no
544 *//*-*****************************************************************************************************/
545 void SvtModuleOptions_Impl::Commit()
546 {
547     // Reserve memory for ALL possible factory properties!
548     // Step over all factories and get her realy changed values only.
549     // Build list of these ones and use it for commit.
550     css::uno::Sequence< css::beans::PropertyValue > lCommitProperties( FACTORYCOUNT*PROPERTYCOUNT );
551     FactoryInfo*                                    pInfo            = NULL                        ;
552     sal_Int32                                       nRealCount       = 0                           ;
553     ::rtl::OUString                                 sBasePath                                      ;
554     for( sal_Int32 nFactory=0; nFactory<FACTORYCOUNT; ++nFactory )
555     {
556         pInfo = &(m_lFactories[nFactory]);
557 
558         // These path is used to build full qualified property names ....
559         // See pInfo->getChangedProperties() for further informations
560         sBasePath  = PATHSEPERATOR + pInfo->getFactory() + PATHSEPERATOR;
561 
562         const css::uno::Sequence< css::beans::PropertyValue > lChangedProperties = pInfo->getChangedProperties ( sBasePath );
563 		const css::beans::PropertyValue*					  pChangedProperties = lChangedProperties.getConstArray();
564         sal_Int32											  nPropertyCount     = lChangedProperties.getLength();
565         for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
566         {
567             lCommitProperties[nRealCount] = pChangedProperties[nProperty];
568             ++nRealCount;
569         }
570     }
571     // Resize commit list to real size.
572     // If nothing to do - suppress calling of configuration ...
573     // It could be to expensive :-)
574     if( nRealCount > 0 )
575     {
576         lCommitProperties.realloc( nRealCount );
577         SetSetProperties( ::rtl::OUString(), lCommitProperties );
578     }
579 }
580 
581 /*-****************************************************************************************************//**
582     @short      access method to get internal values
583     @descr      These methods implement easy access to our internal values.
584                 You give us right enum value to specify which module interest you ... we return right information.
585 
586     @attention  Some poeple use any value as enum ... but we support in header specified values only!
587                 We use it directly as index in our internal list. If enum value isn't right - we crash with an
588                 "index out of range"!!! Please use me right - otherwise there is no guarantee.
589 
590     @seealso    -
591 
592     @param      "eModule"  , index in list - specify module
593     @param      "eFactory" , index in list - specify factory
594     @param      "sTemplate", set new standard template for these factory
595     @return     Queried information.
596 
597     @onerror    We return default values. (mostly "not installed"!)
598     @threadsafe no
599 *//*-*****************************************************************************************************/
600 sal_Bool SvtModuleOptions_Impl::IsModuleInstalled( SvtModuleOptions::EModule eModule ) const
601 {
602     sal_Bool bInstalled = sal_False;
603     switch( eModule )
604     {
605         case SvtModuleOptions::E_SWRITER    :   bInstalled = m_lFactories[SvtModuleOptions::E_WRITER].getInstalled();
606                                                 break;
607         case SvtModuleOptions::E_SWEB       :   bInstalled = m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled();
608                                                 break;
609         case SvtModuleOptions::E_SGLOBAL    :   bInstalled = m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled();
610                                                 break;
611         case SvtModuleOptions::E_SCALC      :   bInstalled = m_lFactories[SvtModuleOptions::E_CALC].getInstalled();
612                                                 break;
613         case SvtModuleOptions::E_SDRAW      :   bInstalled = m_lFactories[SvtModuleOptions::E_DRAW].getInstalled();
614                                                 break;
615         case SvtModuleOptions::E_SIMPRESS   :   bInstalled = m_lFactories[SvtModuleOptions::E_IMPRESS].getInstalled();
616                                                 break;
617         case SvtModuleOptions::E_SMATH      :   bInstalled = m_lFactories[SvtModuleOptions::E_MATH].getInstalled();
618                                                 break;
619         case SvtModuleOptions::E_SCHART     :   bInstalled = m_lFactories[SvtModuleOptions::E_CHART].getInstalled();
620                                                 break;
621         case SvtModuleOptions::E_SSTARTMODULE :   bInstalled = m_lFactories[SvtModuleOptions::E_STARTMODULE].getInstalled();
622                                                 break;
623         case SvtModuleOptions::E_SBASIC     :   bInstalled = sal_True; // Couldn't be deselected by setup yet!
624                                                 break;
625 		case SvtModuleOptions::E_SDATABASE  :   bInstalled = m_lFactories[SvtModuleOptions::E_DATABASE].getInstalled();
626                                                 break;
627     }
628 
629     return bInstalled;
630 }
631 
632 ::com::sun::star::uno::Sequence < ::rtl::OUString > SvtModuleOptions_Impl::GetAllServiceNames()
633 {
634     sal_uInt32 nCount=0;
635     if( m_lFactories[SvtModuleOptions::E_WRITER].getInstalled() )
636 		nCount++;
637 	if ( m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled() )
638 		nCount++;
639 	if ( m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled() )
640 		nCount++;
641     if( m_lFactories[SvtModuleOptions::E_SCALC].getInstalled() )
642 		nCount++;
643     if( m_lFactories[SvtModuleOptions::E_SDRAW].getInstalled() )
644 		nCount++;
645     if( m_lFactories[SvtModuleOptions::E_SIMPRESS].getInstalled() )
646 		nCount++;
647     if( m_lFactories[SvtModuleOptions::E_SCHART].getInstalled() )
648 		nCount++;
649     if( m_lFactories[SvtModuleOptions::E_SMATH].getInstalled() )
650 		nCount++;
651     if( m_lFactories[SvtModuleOptions::E_SBASIC].getInstalled() )
652 		nCount++;
653 	if( m_lFactories[SvtModuleOptions::E_SDATABASE].getInstalled() )
654 		nCount++;
655 
656 	css::uno::Sequence < ::rtl::OUString > aRet( nCount );
657 	sal_Int32 n=0;
658     if( m_lFactories[SvtModuleOptions::E_WRITER].getInstalled() )
659 		aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITER].getFactory();
660 	if ( m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled() )
661 		aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITERWEB].getFactory();
662 	if ( m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled() )
663 		aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getFactory();
664     if( m_lFactories[SvtModuleOptions::E_SCALC].getInstalled() )
665 		aRet[n++] = m_lFactories[SvtModuleOptions::E_SCALC].getFactory();
666     if( m_lFactories[SvtModuleOptions::E_SDRAW].getInstalled() )
667 		aRet[n++] = m_lFactories[SvtModuleOptions::E_SDRAW].getFactory();
668     if( m_lFactories[SvtModuleOptions::E_SIMPRESS].getInstalled() )
669 		aRet[n++] = m_lFactories[SvtModuleOptions::E_SIMPRESS].getFactory();
670     if( m_lFactories[SvtModuleOptions::E_SCHART].getInstalled() )
671 		aRet[n++] = m_lFactories[SvtModuleOptions::E_SCHART].getFactory();
672     if( m_lFactories[SvtModuleOptions::E_SMATH].getInstalled() )
673 		aRet[n++] = m_lFactories[SvtModuleOptions::E_SMATH].getFactory();
674     if( m_lFactories[SvtModuleOptions::E_SBASIC].getInstalled() )
675 		aRet[n++] = m_lFactories[SvtModuleOptions::E_SBASIC].getFactory();
676 	if( m_lFactories[SvtModuleOptions::E_SDATABASE].getInstalled() )
677 		aRet[n++] = m_lFactories[SvtModuleOptions::E_SDATABASE].getFactory();
678 
679 	return aRet;
680 }
681 
682 //*****************************************************************************************************************
683 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryName( SvtModuleOptions::EFactory eFactory ) const
684 {
685     ::rtl::OUString sName;
686 
687     if( eFactory>=0 && eFactory<FACTORYCOUNT )
688     {
689         sName = m_lFactories[eFactory].getFactory();
690     }
691 
692     return sName;
693 }
694 
695 //*****************************************************************************************************************
696 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryShortName( SvtModuleOptions::EFactory eFactory ) const
697 {
698     // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet.
699     //            But it's good to plan further possibilities!
700 
701     //return m_lFactories[eFactory].sShortName;
702 
703     ::rtl::OUString sShortName;
704     switch( eFactory )
705     {
706         case SvtModuleOptions::E_WRITER        :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("swriter"));
707                                                   break;
708         case SvtModuleOptions::E_WRITERWEB     :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("swriter/web"));
709                                                   break;
710         case SvtModuleOptions::E_WRITERGLOBAL  :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("swriter/GlobalDocument"));
711                                                   break;
712         case SvtModuleOptions::E_CALC          :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("scalc"));
713                                                   break;
714         case SvtModuleOptions::E_DRAW          :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdraw"));
715                                                   break;
716         case SvtModuleOptions::E_IMPRESS       :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("simpress"));
717                                                   break;
718         case SvtModuleOptions::E_MATH          :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("smath"));
719                                                   break;
720         case SvtModuleOptions::E_CHART         :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("schart"));
721                                                   break;
722         case SvtModuleOptions::E_BASIC         :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sbasic"));
723                                                   break;
724 		case SvtModuleOptions::E_DATABASE     :  sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdatabase"));
725                                                   break;
726         default:
727             OSL_ASSERT( "unknown factory" );
728             break;
729     }
730 
731     return sShortName;
732 }
733 
734 //*****************************************************************************************************************
735 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ) const
736 {
737     ::rtl::OUString sFile;
738 
739     if( eFactory>=0 && eFactory<FACTORYCOUNT )
740     {
741         sFile = m_lFactories[eFactory].getTemplateFile();
742     }
743 
744     return sFile;
745 }
746 
747 //*****************************************************************************************************************
748 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryWindowAttributes( SvtModuleOptions::EFactory eFactory ) const
749 {
750     ::rtl::OUString sAttributes;
751 
752     if( eFactory>=0 && eFactory<FACTORYCOUNT )
753     {
754         sAttributes = m_lFactories[eFactory].getWindowAttributes();
755     }
756 
757     return sAttributes;
758 }
759 
760 //*****************************************************************************************************************
761 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryEmptyDocumentURL( SvtModuleOptions::EFactory eFactory ) const
762 {
763     // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet.
764     //            But it's good to plan further possibilities!
765 
766     //return m_lFactories[eFactory].getEmptyDocumentURL();
767 
768     ::rtl::OUString sURL;
769     switch( eFactory )
770     {
771         case SvtModuleOptions::E_WRITER        :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter"));
772                                                   break;
773         case SvtModuleOptions::E_WRITERWEB     :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter/web"));
774                                                   break;
775         case SvtModuleOptions::E_WRITERGLOBAL  :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter/GlobalDocument"));
776                                                   break;
777         case SvtModuleOptions::E_CALC          :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/scalc"));
778                                                   break;
779         case SvtModuleOptions::E_DRAW          :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/sdraw"));
780                                                   break;
781         case SvtModuleOptions::E_IMPRESS       :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/simpress?slot=6686"));
782                                                   break;
783         case SvtModuleOptions::E_MATH          :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/smath"));
784                                                   break;
785         case SvtModuleOptions::E_CHART         :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/schart"));
786                                                   break;
787         case SvtModuleOptions::E_BASIC         :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/sbasic"));
788                                                   break;
789 		case SvtModuleOptions::E_DATABASE     :  sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/sdatabase?Interactive"));
790                                                   break;
791         default:
792             OSL_ASSERT( "unknown factory" );
793             break;
794     }
795     return sURL;
796 }
797 
798 //*****************************************************************************************************************
799 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryDefaultFilter( SvtModuleOptions::EFactory eFactory ) const
800 {
801     ::rtl::OUString sDefaultFilter;
802 
803     if( eFactory>=0 && eFactory<FACTORYCOUNT )
804     {
805         sDefaultFilter = m_lFactories[eFactory].getDefaultFilter();
806     }
807     return sDefaultFilter;
808 }
809 //*****************************************************************************************************************
810 sal_Bool SvtModuleOptions_Impl::IsDefaultFilterReadonly( SvtModuleOptions::EFactory eFactory   ) const
811 {
812     sal_Bool bRet = sal_False;
813     if( eFactory>=0 && eFactory<FACTORYCOUNT )
814     {
815         bRet = m_lFactories[eFactory].isDefaultFilterReadonly();
816     }
817     return bRet;
818 }
819 
820 //*****************************************************************************************************************
821 sal_Int32 SvtModuleOptions_Impl::GetFactoryIcon( SvtModuleOptions::EFactory eFactory ) const
822 {
823     sal_Int32 nIcon = 0;
824 
825     if( eFactory>=0 && eFactory<FACTORYCOUNT )
826     {
827         nIcon = m_lFactories[eFactory].getIcon();
828     }
829 
830     return nIcon;
831 }
832 
833 //*****************************************************************************************************************
834 void SvtModuleOptions_Impl::SetFactoryStandardTemplate(       SvtModuleOptions::EFactory eFactory   ,
835                                                         const ::rtl::OUString&           sTemplate  )
836 {
837     if( eFactory>=0 && eFactory<FACTORYCOUNT )
838     {
839         m_lFactories[eFactory].setTemplateFile( sTemplate );
840         SetModified();
841     }
842 }
843 
844 //*****************************************************************************************************************
845 void SvtModuleOptions_Impl::SetFactoryWindowAttributes(       SvtModuleOptions::EFactory eFactory   ,
846                                                         const ::rtl::OUString&           sAttributes)
847 {
848     if( eFactory>=0 && eFactory<FACTORYCOUNT )
849     {
850         m_lFactories[eFactory].setWindowAttributes( sAttributes );
851         SetModified();
852     }
853 }
854 
855 //*****************************************************************************************************************
856 void SvtModuleOptions_Impl::SetFactoryDefaultFilter(       SvtModuleOptions::EFactory eFactory,
857                                                      const ::rtl::OUString&           sFilter )
858 {
859     if( eFactory>=0 && eFactory<FACTORYCOUNT )
860     {
861         m_lFactories[eFactory].setDefaultFilter( sFilter );
862         SetModified();
863     }
864 }
865 
866 /*-************************************************************************************************************//**
867     @short      return list of key names of ouer configuration management which represent our module tree
868     @descr      You give use a list of current existing set node names .. and we expand it for all
869                 well known properties which are neccessary for this implementation.
870                 These full expanded list should be used to get values of this properties.
871 
872     @seealso    ctor
873 
874     @param      -
875     @return     List of all relative addressed properties of given set entry names.
876 
877     @onerror    List will be empty.
878     @threadsafe no
879 *//*-*************************************************************************************************************/
880 css::uno::Sequence< ::rtl::OUString > SvtModuleOptions_Impl::impl_ExpandSetNames( const css::uno::Sequence< ::rtl::OUString >& lSetNames )
881 {
882     sal_Int32                             nCount     = lSetNames.getLength() ;
883     css::uno::Sequence< ::rtl::OUString > lPropNames ( nCount*PROPERTYCOUNT );
884 	::rtl::OUString*					  pPropNames = lPropNames.getArray() ;
885     sal_Int32                             nPropStart = 0                     ;
886 
887     for( sal_Int32 nName=0; nName<nCount; ++nName )
888     {
889         pPropNames[nPropStart+PROPERTYHANDLE_SHORTNAME       ] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_SHORTNAME       ;
890         pPropNames[nPropStart+PROPERTYHANDLE_TEMPLATEFILE    ] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_TEMPLATEFILE    ;
891         pPropNames[nPropStart+PROPERTYHANDLE_WINDOWATTRIBUTES] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_WINDOWATTRIBUTES;
892         pPropNames[nPropStart+PROPERTYHANDLE_EMPTYDOCUMENTURL] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_EMPTYDOCUMENTURL;
893         pPropNames[nPropStart+PROPERTYHANDLE_DEFAULTFILTER   ] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_DEFAULTFILTER   ;
894         pPropNames[nPropStart+PROPERTYHANDLE_ICON            ] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_ICON            ;
895         nPropStart += PROPERTYCOUNT;
896     }
897 
898     return lPropNames;
899 }
900 
901 /*-************************************************************************************************************//**
902     @short      helper to classify given factory by name
903     @descr      Every factory has his own long and short name. So we can match right enum value for internal using.
904 
905     @attention  We change in/out parameter "eFactory" in every case! But you should use it only, if return value is sal_True!
906                 Algorithm:  Set out-parameter to propably value ... and check the longname.
907                             If it match with these factory - break operation and return true AND right set parameter.
908                             Otherwise try next one and so on. If no factory was found return false. Out parameter eFactory
909                             is set to last tried value but shouldn't be used! Because our return value is false!
910 
911     @seealso    -
912 
913     @param      "sLongName" , long name of factory, which should be classified
914     @return     "eFactory"  , right enum value, which match given long name
915                 and true for successfully classification, false otherwise
916 
917     @onerror    We return false.
918     @threadsafe no
919 *//*-*************************************************************************************************************/
920 sal_Bool SvtModuleOptions_Impl::ClassifyFactoryByName( const ::rtl::OUString& sName, SvtModuleOptions::EFactory& eFactory )
921 {
922     sal_Bool bState;
923 
924     eFactory = SvtModuleOptions::E_WRITER     ;
925     bState   = ( sName == FACTORYNAME_WRITER );
926 
927     if( bState == sal_False )
928     {
929         eFactory = SvtModuleOptions::E_WRITERWEB     ;
930         bState   = ( sName == FACTORYNAME_WRITERWEB );
931     }
932     // no else!
933     if( bState == sal_False )
934     {
935         eFactory = SvtModuleOptions::E_WRITERGLOBAL     ;
936         bState   = ( sName == FACTORYNAME_WRITERGLOBAL );
937     }
938     // no else!
939     if( bState == sal_False )
940     {
941         eFactory = SvtModuleOptions::E_CALC     ;
942         bState   = ( sName == FACTORYNAME_CALC );
943     }
944     // no else!
945     if( bState == sal_False )
946     {
947         eFactory = SvtModuleOptions::E_DRAW     ;
948         bState   = ( sName == FACTORYNAME_DRAW );
949     }
950     // no else!
951     if( bState == sal_False )
952     {
953         eFactory = SvtModuleOptions::E_IMPRESS     ;
954         bState   = ( sName == FACTORYNAME_IMPRESS );
955     }
956     // no else!
957     if( bState == sal_False )
958     {
959         eFactory = SvtModuleOptions::E_MATH     ;
960         bState   = ( sName == FACTORYNAME_MATH );
961     }
962     // no else!
963     if( bState == sal_False )
964     {
965         eFactory = SvtModuleOptions::E_CHART     ;
966         bState   = ( sName == FACTORYNAME_CHART );
967     }
968 	// no else!
969     if( bState == sal_False )
970     {
971         eFactory = SvtModuleOptions::E_DATABASE     ;
972         bState   = ( sName == FACTORYNAME_DATABASE );
973     }
974     // no else!
975     if( bState == sal_False )
976     {
977         eFactory = SvtModuleOptions::E_STARTMODULE    ;
978         bState   = ( sName == FACTORYNAME_STARTMODULE);
979     }
980 
981     return bState;
982 }
983 
984 /*-************************************************************************************************************//**
985     @short      read factory configuration
986     @descr      Give us a list of pure factory names (long names!) which can be used as
987                 direct set node names ... and we read her property values and fill internal list.
988                 These method can be used by initial reading at ctor and later updating by "Notify()".
989 
990     @seealso    ctor
991     @seealso    method Notify()
992 
993     @param      "lFactories" is the list of set node entries which should be readed.
994     @return     -
995 
996     @onerror    We do nothing.
997     @threadsafe no
998 *//*-*************************************************************************************************************/
999 void SvtModuleOptions_Impl::impl_Read( const css::uno::Sequence< ::rtl::OUString >& lFactories )
1000 {
1001     // Expand every set node name in lFactories to full qualified pathes to his properties
1002     // and get right values from configuration.
1003     const css::uno::Sequence< ::rtl::OUString > lProperties = impl_ExpandSetNames( lFactories  );
1004     const css::uno::Sequence< css::uno::Any >   lValues     = GetProperties( lProperties );
1005 
1006 	// Safe impossible cases.
1007 	// We need values from ALL configuration keys.
1008 	// Follow assignment use order of values in relation to our list of key names!
1009     OSL_ENSURE( !(lProperties.getLength()!=lValues.getLength()), "SvtModuleOptions_Impl::impl_Read()\nI miss some values of configuration keys!\n" );
1010 
1011     // Algorithm:   We step over all given factory names and classify it. These enum value can be used as direct index
1012     //              in our member list m_lFactories! VAriable nPropertyStart marks start position of every factory
1013     //              and her properties in expanded property/value list. The defines PROPERTHANDLE_xxx are used as offset values
1014     //              added to nPropertyStart. So we can address every property relative in these lists.
1015     //              If we found any valid values ... we reset all existing informations for corresponding m_lFactories-entry and
1016     //              use a pointer to these struct in memory directly to set new values.
1017     //              But we set it only, if bInstalled is true. Otherwise all other values of a factory can be undeclared .. They
1018     //              shouldn't be used then.
1019     // Attention:   If a propertyset of a factory will be ignored we must step to next start position of next factory infos!
1020     //              see "nPropertyStart += PROPERTYCOUNT" ...
1021 
1022     sal_Int32                   nPropertyStart  = 0                     ;
1023     sal_Int32                   nNodeCount      = lFactories.getLength();
1024     FactoryInfo*                pInfo           = NULL                  ;
1025     SvtModuleOptions::EFactory  eFactory                                ;
1026 
1027     for( sal_Int32 nSetNode=0; nSetNode<nNodeCount; ++nSetNode )
1028     {
1029         const ::rtl::OUString& sFactoryName = lFactories[nSetNode];
1030         if( ClassifyFactoryByName( sFactoryName, eFactory ) == sal_True )
1031         {
1032 			::rtl::OUString sTemp;
1033 			sal_Int32       nTemp = 0;
1034 
1035             pInfo = &(m_lFactories[eFactory]);
1036             pInfo->free();
1037 
1038             pInfo->initInstalled( sal_True     );
1039             pInfo->initFactory  ( sFactoryName );
1040 
1041             if (lValues[nPropertyStart+PROPERTYHANDLE_SHORTNAME] >>= sTemp)
1042 				pInfo->initShortName( sTemp );
1043             if (lValues[nPropertyStart+PROPERTYHANDLE_TEMPLATEFILE] >>= sTemp)
1044 				pInfo->initTemplateFile( sTemp );
1045             if (lValues[nPropertyStart+PROPERTYHANDLE_WINDOWATTRIBUTES] >>= sTemp)
1046 				pInfo->initWindowAttributes( sTemp );
1047             if (lValues[nPropertyStart+PROPERTYHANDLE_EMPTYDOCUMENTURL] >>= sTemp)
1048 				pInfo->initEmptyDocumentURL( sTemp );
1049             if (lValues[nPropertyStart+PROPERTYHANDLE_DEFAULTFILTER   ] >>= sTemp)
1050 	            pInfo->initDefaultFilter( sTemp );
1051             if (lValues[nPropertyStart+PROPERTYHANDLE_ICON] >>= nTemp)
1052 				pInfo->initIcon( nTemp );
1053         }
1054         nPropertyStart += PROPERTYCOUNT;
1055     }
1056 }
1057 
1058 //*****************************************************************************************************************
1059 void SvtModuleOptions_Impl::MakeReadonlyStatesAvailable()
1060 {
1061     if (m_bReadOnlyStatesWellKnown)
1062         return;
1063 
1064     css::uno::Sequence< ::rtl::OUString > lFactories = GetNodeNames(::rtl::OUString());
1065     sal_Int32 c = lFactories.getLength();
1066     sal_Int32 i = 0;
1067     for (i=0; i<c; ++i)
1068     {
1069         ::rtl::OUStringBuffer sPath(256);
1070         sPath.append(lFactories[i]             );
1071         sPath.append(PATHSEPERATOR             );
1072         sPath.append(PROPERTYNAME_DEFAULTFILTER);
1073 
1074         lFactories[i] = sPath.makeStringAndClear();
1075     }
1076 
1077     css::uno::Sequence< sal_Bool > lReadonlyStates = GetReadOnlyStates(lFactories);
1078     for (i=0; i<c; ++i)
1079     {
1080         ::rtl::OUString&            rFactoryName = lFactories[i];
1081         SvtModuleOptions::EFactory  eFactory                    ;
1082 
1083         if (!ClassifyFactoryByName(rFactoryName, eFactory))
1084             continue;
1085 
1086         FactoryInfo& rInfo = m_lFactories[eFactory];
1087         rInfo.setDefaultFilterReadonly(lReadonlyStates[i]);
1088     }
1089 
1090     m_bReadOnlyStatesWellKnown = sal_True;
1091 }
1092 
1093 //*****************************************************************************************************************
1094 //	initialize static member
1095 //	DON'T DO IT IN YOUR HEADER!
1096 //	see definition for further informations
1097 //*****************************************************************************************************************
1098 SvtModuleOptions_Impl*  SvtModuleOptions::m_pDataContainer  = NULL  ;
1099 sal_Int32               SvtModuleOptions::m_nRefCount       = 0     ;
1100 
1101 /*-************************************************************************************************************//**
1102     @short      standard constructor and destructor
1103     @descr      This will initialize an instance with default values. We initialize/deinitialize our static data
1104                 container and create a static mutex, which is used for threadsafe code in further time of this object.
1105 
1106     @seealso    method impl_GetOwnStaticMutex()
1107 
1108     @param      -
1109     @return     -
1110 
1111     @onerror    -
1112     @threadsafe yes
1113 *//*-*************************************************************************************************************/
1114 SvtModuleOptions::SvtModuleOptions()
1115 {
1116     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1117 	++m_nRefCount;
1118     if( m_nRefCount == 1 )
1119 	{
1120         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtModuleOptions_Impl::ctor()");
1121         m_pDataContainer = new SvtModuleOptions_Impl(this);
1122 
1123         ItemHolder1::holdConfigItem(E_MODULEOPTIONS);
1124 	}
1125 }
1126 
1127 //*****************************************************************************************************************
1128 SvtModuleOptions::~SvtModuleOptions()
1129 {
1130     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1131 	--m_nRefCount;
1132     if( m_nRefCount == 0 )
1133 	{
1134 		delete m_pDataContainer;
1135 		m_pDataContainer = NULL;
1136 	}
1137 }
1138 
1139 /*-************************************************************************************************************//**
1140     @short      access to configuration data
1141     @descr      This methods allow read/write access to configuration values.
1142                 They are threadsafe. All calls are forwarded to impl-data-container. See there for further informations!
1143 
1144     @seealso    method impl_GetOwnStaticMutex()
1145 
1146     @param      -
1147     @return     -
1148 
1149     @onerror    -
1150     @threadsafe yes
1151 *//*-*************************************************************************************************************/
1152 sal_Bool SvtModuleOptions::IsModuleInstalled( EModule eModule ) const
1153 {
1154     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1155     return m_pDataContainer->IsModuleInstalled( eModule );
1156 }
1157 
1158 //*****************************************************************************************************************
1159 ::rtl::OUString SvtModuleOptions::GetFactoryName( EFactory eFactory ) const
1160 {
1161     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1162     return m_pDataContainer->GetFactoryName( eFactory );
1163 }
1164 
1165 //*****************************************************************************************************************
1166 ::rtl::OUString SvtModuleOptions::GetFactoryShortName( EFactory eFactory ) const
1167 {
1168     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1169     return m_pDataContainer->GetFactoryShortName( eFactory );
1170 }
1171 
1172 //*****************************************************************************************************************
1173 ::rtl::OUString SvtModuleOptions::GetFactoryStandardTemplate( EFactory eFactory ) const
1174 {
1175     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1176     return m_pDataContainer->GetFactoryStandardTemplate( eFactory );
1177 }
1178 
1179 //*****************************************************************************************************************
1180 ::rtl::OUString SvtModuleOptions::GetFactoryWindowAttributes( EFactory eFactory ) const
1181 {
1182     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1183     return m_pDataContainer->GetFactoryWindowAttributes( eFactory );
1184 }
1185 
1186 //*****************************************************************************************************************
1187 ::rtl::OUString SvtModuleOptions::GetFactoryEmptyDocumentURL( EFactory eFactory ) const
1188 {
1189     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1190     return m_pDataContainer->GetFactoryEmptyDocumentURL( eFactory );
1191 }
1192 
1193 //*****************************************************************************************************************
1194 ::rtl::OUString SvtModuleOptions::GetFactoryDefaultFilter( EFactory eFactory ) const
1195 {
1196     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1197     return m_pDataContainer->GetFactoryDefaultFilter( eFactory );
1198 }
1199 //*****************************************************************************************************************
1200 sal_Bool SvtModuleOptions::IsDefaultFilterReadonly( EFactory eFactory   ) const
1201 {
1202     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1203     m_pDataContainer->MakeReadonlyStatesAvailable();
1204     return m_pDataContainer->IsDefaultFilterReadonly( eFactory );
1205 }
1206 //*****************************************************************************************************************
1207 sal_Int32 SvtModuleOptions::GetFactoryIcon( EFactory eFactory ) const
1208 {
1209     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1210     return m_pDataContainer->GetFactoryIcon( eFactory );
1211 }
1212 
1213 //*****************************************************************************************************************
1214 sal_Bool SvtModuleOptions::ClassifyFactoryByName( const ::rtl::OUString& sName    ,
1215                                                         EFactory&        eFactory )
1216 {
1217     // We don't need any mutex here ... because we don't use any member here!
1218     return SvtModuleOptions_Impl::ClassifyFactoryByName( sName, eFactory );
1219 }
1220 
1221 //*****************************************************************************************************************
1222 void SvtModuleOptions::SetFactoryStandardTemplate(       EFactory         eFactory   ,
1223                                                    const ::rtl::OUString& sTemplate  )
1224 {
1225     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1226     m_pDataContainer->SetFactoryStandardTemplate( eFactory, sTemplate );
1227 }
1228 
1229 //*****************************************************************************************************************
1230 void SvtModuleOptions::SetFactoryWindowAttributes(       EFactory         eFactory   ,
1231                                                    const ::rtl::OUString& sAttributes)
1232 {
1233     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1234     m_pDataContainer->SetFactoryWindowAttributes( eFactory, sAttributes );
1235 }
1236 
1237 //*****************************************************************************************************************
1238 void SvtModuleOptions::SetFactoryDefaultFilter(       EFactory         eFactory,
1239                                                 const ::rtl::OUString& sFilter )
1240 {
1241     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1242     m_pDataContainer->SetFactoryDefaultFilter( eFactory, sFilter );
1243 }
1244 
1245 //*****************************************************************************************************************
1246 sal_Bool SvtModuleOptions::IsMath() const
1247 {
1248     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1249     return m_pDataContainer->IsModuleInstalled( E_SMATH );
1250 }
1251 
1252 //*****************************************************************************************************************
1253 sal_Bool SvtModuleOptions::IsChart() const
1254 {
1255     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1256     return m_pDataContainer->IsModuleInstalled( E_SCHART );
1257 }
1258 
1259 //*****************************************************************************************************************
1260 sal_Bool SvtModuleOptions::IsCalc() const
1261 {
1262     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1263     return m_pDataContainer->IsModuleInstalled( E_SCALC );
1264 }
1265 
1266 //*****************************************************************************************************************
1267 sal_Bool SvtModuleOptions::IsDraw() const
1268 {
1269     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1270     return m_pDataContainer->IsModuleInstalled( E_SDRAW );
1271 }
1272 
1273 //*****************************************************************************************************************
1274 sal_Bool SvtModuleOptions::IsWriter() const
1275 {
1276     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1277     return m_pDataContainer->IsModuleInstalled( E_SWRITER );
1278 }
1279 
1280 //*****************************************************************************************************************
1281 sal_Bool SvtModuleOptions::IsImpress() const
1282 {
1283     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1284     return m_pDataContainer->IsModuleInstalled( E_SIMPRESS );
1285 }
1286 
1287 //*****************************************************************************************************************
1288 sal_Bool SvtModuleOptions::IsBasicIDE() const
1289 {
1290     return sal_True;
1291 }
1292 //*****************************************************************************************************************
1293 sal_Bool SvtModuleOptions::IsDataBase() const
1294 {
1295     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1296     return m_pDataContainer->IsModuleInstalled( E_SDATABASE );
1297 }
1298 //*****************************************************************************************************************
1299 sal_uInt32 SvtModuleOptions::GetFeatures() const
1300 {
1301     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1302 
1303     sal_uInt32 nFeature = 0;
1304 
1305     if( m_pDataContainer->IsModuleInstalled( E_SWRITER ) == sal_True )
1306         nFeature |= FEATUREFLAG_WRITER;
1307     if( m_pDataContainer->IsModuleInstalled( E_SCALC ) == sal_True )
1308         nFeature |= FEATUREFLAG_CALC;
1309     if( m_pDataContainer->IsModuleInstalled( E_SDRAW ) == sal_True )
1310         nFeature |= FEATUREFLAG_DRAW;
1311     if( m_pDataContainer->IsModuleInstalled( E_SIMPRESS ) == sal_True )
1312         nFeature |= FEATUREFLAG_IMPRESS;
1313     if( m_pDataContainer->IsModuleInstalled( E_SCHART ) == sal_True )
1314         nFeature |= FEATUREFLAG_CHART;
1315     if( m_pDataContainer->IsModuleInstalled( E_SMATH ) == sal_True )
1316         nFeature |= FEATUREFLAG_MATH;
1317     if( m_pDataContainer->IsModuleInstalled( E_SBASIC ) == sal_True )
1318         nFeature |= FEATUREFLAG_BASICIDE;
1319 	if( m_pDataContainer->IsModuleInstalled( E_SDATABASE ) == sal_True )
1320         nFeature |= FEATUREFLAG_INSIGHT;
1321 
1322     return nFeature;
1323 }
1324 
1325 /*-****************************************************************************************************//**
1326     @short      return a reference to a static mutex
1327     @descr      These class is threadsafe.
1328                 We create a static mutex only for one time and use it to protect our refcount and container
1329                 member!
1330 
1331     @seealso    -
1332 
1333     @param      -
1334     @return     A reference to a static mutex member.
1335 
1336     @onerror    -
1337     @threadsafe yes
1338 *//*-*****************************************************************************************************/
1339 ::osl::Mutex& SvtModuleOptions::impl_GetOwnStaticMutex()
1340 {
1341 	// Initialize static mutex only for one time!
1342     static ::osl::Mutex* pMutex = NULL;
1343 	// If these method first called (Mutex not already exist!) ...
1344     if( pMutex == NULL )
1345     {
1346 		// ... we must create a new one. Protect follow code with the global mutex -
1347 		// It must be - we create a static variable!
1348         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1349 		// We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
1350         if( pMutex == NULL )
1351         {
1352 			// Create the new mutex and set it for return on static variable.
1353             static ::osl::Mutex aMutex;
1354             pMutex = &aMutex;
1355         }
1356     }
1357 	// Return new created or already existing mutex object.
1358     return *pMutex;
1359 }
1360 
1361 ::rtl::OUString SvtModuleOptions::GetModuleName( EModule eModule ) const
1362 {
1363     switch( eModule )
1364     {
1365         case SvtModuleOptions::E_SWRITER    :   { return ::rtl::OUString::createFromAscii("Writer"); }
1366         case SvtModuleOptions::E_SWEB       :   { return ::rtl::OUString::createFromAscii("Web"); }
1367         case SvtModuleOptions::E_SGLOBAL    :   { return ::rtl::OUString::createFromAscii("Global"); }
1368         case SvtModuleOptions::E_SCALC      :   { return ::rtl::OUString::createFromAscii("Calc"); }
1369         case SvtModuleOptions::E_SDRAW      :   { return ::rtl::OUString::createFromAscii("Draw"); }
1370         case SvtModuleOptions::E_SIMPRESS   :   { return ::rtl::OUString::createFromAscii("Impress"); }
1371         case SvtModuleOptions::E_SMATH      :   { return ::rtl::OUString::createFromAscii("Math"); }
1372         case SvtModuleOptions::E_SCHART     :   { return ::rtl::OUString::createFromAscii("Chart"); }
1373         case SvtModuleOptions::E_SBASIC     :   { return ::rtl::OUString::createFromAscii("Basic"); }
1374 		case SvtModuleOptions::E_SDATABASE  :   { return ::rtl::OUString::createFromAscii("Database"); }
1375         default:
1376             OSL_ASSERT( "unknown module" );
1377             break;
1378     }
1379 
1380     return ::rtl::OUString();
1381 }
1382 
1383 ::rtl::OUString SvtModuleOptions::GetModuleName( EFactory eFactory ) const
1384 {
1385     switch( eFactory )
1386     {
1387         case SvtModuleOptions::E_WRITER         :   { return ::rtl::OUString::createFromAscii("Writer"); }
1388         case SvtModuleOptions::E_WRITERWEB      :   { return ::rtl::OUString::createFromAscii("Writer"); }
1389         case SvtModuleOptions::E_WRITERGLOBAL   :   { return ::rtl::OUString::createFromAscii("Writer"); }
1390         case SvtModuleOptions::E_CALC           :   { return ::rtl::OUString::createFromAscii("Calc"); }
1391         case SvtModuleOptions::E_DRAW           :   { return ::rtl::OUString::createFromAscii("Draw"); }
1392         case SvtModuleOptions::E_IMPRESS        :   { return ::rtl::OUString::createFromAscii("Impress"); }
1393         case SvtModuleOptions::E_MATH           :   { return ::rtl::OUString::createFromAscii("Math"); }
1394         case SvtModuleOptions::E_CHART          :   { return ::rtl::OUString::createFromAscii("Chart"); }
1395         case SvtModuleOptions::E_BASIC          :   { return ::rtl::OUString::createFromAscii("Basic"); }
1396 		case SvtModuleOptions::E_DATABASE		:   { return ::rtl::OUString::createFromAscii("Database"); }
1397         default:
1398             OSL_ASSERT( "unknown factory" );
1399             break;
1400     }
1401 
1402     return ::rtl::OUString();
1403 }
1404 
1405 /*-----------------------------------------------
1406     07.03.2004 15:03
1407 -----------------------------------------------*/
1408 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByShortName(const ::rtl::OUString& sName)
1409 {
1410     if (sName.equalsAscii("swriter"))
1411         return E_WRITER;
1412     if (sName.equalsIgnoreAsciiCaseAscii("swriter/Web")) // sometimes they are registerd for swriter/web :-(
1413         return E_WRITERWEB;
1414     if (sName.equalsIgnoreAsciiCaseAscii("swriter/GlobalDocument")) // sometimes they are registerd for swriter/globaldocument :-(
1415         return E_WRITERGLOBAL;
1416     if (sName.equalsAscii("scalc"))
1417         return E_CALC;
1418     if (sName.equalsAscii("sdraw"))
1419         return E_DRAW;
1420     if (sName.equalsAscii("simpress"))
1421         return E_IMPRESS;
1422     if (sName.equalsAscii("schart"))
1423         return E_CHART;
1424     if (sName.equalsAscii("smath"))
1425         return E_MATH;
1426     if (sName.equalsAscii("sbasic"))
1427         return E_BASIC;
1428     if (sName.equalsAscii("sdatabase"))
1429         return E_DATABASE;
1430 
1431     return E_UNKNOWN_FACTORY;
1432 }
1433 
1434 /*-----------------------------------------------
1435     31.07.2003 10:41
1436 -----------------------------------------------*/
1437 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByServiceName(const ::rtl::OUString& sName)
1438 {
1439     if (sName.equals(FACTORYNAME_WRITERGLOBAL))
1440         return E_WRITERGLOBAL;
1441     if (sName.equals(FACTORYNAME_WRITERWEB))
1442         return E_WRITERWEB;
1443     if (sName.equals(FACTORYNAME_WRITER))
1444         return E_WRITER;
1445     if (sName.equals(FACTORYNAME_CALC))
1446         return E_CALC;
1447     if (sName.equals(FACTORYNAME_DRAW))
1448         return E_DRAW;
1449     if (sName.equals(FACTORYNAME_IMPRESS))
1450         return E_IMPRESS;
1451     if (sName.equals(FACTORYNAME_MATH))
1452         return E_MATH;
1453     if (sName.equals(FACTORYNAME_CHART))
1454         return E_CHART;
1455 	if (sName.equals(FACTORYNAME_DATABASE))
1456         return E_DATABASE;
1457 
1458     return E_UNKNOWN_FACTORY;
1459 }
1460 
1461 /*-----------------------------------------------
1462     31.07.2003 14:39
1463 -----------------------------------------------*/
1464 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByURL(const ::rtl::OUString&                                 sURL            ,
1465                                                                   const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor)
1466 {
1467     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::utl::getProcessServiceFactory();
1468     if (!xSMGR.is())
1469         return E_UNKNOWN_FACTORY;
1470 
1471     css::uno::Reference< css::container::XNameAccess > xFilterCfg;
1472     css::uno::Reference< css::container::XNameAccess > xTypeCfg ;
1473     try
1474     {
1475         xFilterCfg = css::uno::Reference< css::container::XNameAccess >(
1476             xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.FilterFactory")), css::uno::UNO_QUERY);
1477         xTypeCfg = css::uno::Reference< css::container::XNameAccess >(
1478             xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection")), css::uno::UNO_QUERY);
1479     }
1480     catch(const css::uno::RuntimeException&)
1481         { throw; }
1482     catch(const css::uno::Exception&)
1483         { return E_UNKNOWN_FACTORY; }
1484 
1485     ::comphelper::SequenceAsHashMap stlDesc(lMediaDescriptor);
1486 
1487     // is there already a filter inside the descriptor?
1488     ::rtl::OUString sFilterName = stlDesc.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("FilterName"), ::rtl::OUString());
1489     if (sFilterName.getLength())
1490     {
1491         try
1492         {
1493             ::comphelper::SequenceAsHashMap stlFilterProps   (xFilterCfg->getByName(sFilterName));
1494             ::rtl::OUString                 sDocumentService = stlFilterProps.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("DocumentService"), ::rtl::OUString());
1495             SvtModuleOptions::EFactory      eApp             = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
1496 
1497             if (eApp != E_UNKNOWN_FACTORY)
1498                 return eApp;
1499         }
1500         catch(const css::uno::RuntimeException&)
1501             { throw; }
1502         catch(const css::uno::Exception&)
1503             { /* do nothing here ... may the following code can help!*/ }
1504     }
1505 
1506     // is there already a type inside the descriptor?
1507     ::rtl::OUString sTypeName = stlDesc.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("TypeName"), ::rtl::OUString());
1508     if (!sTypeName.getLength())
1509     {
1510         // no :-(
1511         // start flat detection of URL
1512         css::uno::Reference< css::document::XTypeDetection > xDetect(xTypeCfg, css::uno::UNO_QUERY);
1513         sTypeName = xDetect->queryTypeByURL(sURL);
1514     }
1515 
1516     if (!sTypeName.getLength())
1517         return E_UNKNOWN_FACTORY;
1518 
1519     // yes - there is a type info
1520     // Try to find the preferred filter.
1521     try
1522     {
1523         ::comphelper::SequenceAsHashMap stlTypeProps     (xTypeCfg->getByName(sTypeName));
1524         ::rtl::OUString                 sPreferredFilter = stlTypeProps.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("PreferredFilter"), ::rtl::OUString());
1525         ::comphelper::SequenceAsHashMap stlFilterProps   (xFilterCfg->getByName(sPreferredFilter));
1526         ::rtl::OUString                 sDocumentService = stlFilterProps.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("DocumentService"), ::rtl::OUString());
1527         SvtModuleOptions::EFactory      eApp             = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
1528 
1529         if (eApp != E_UNKNOWN_FACTORY)
1530             return eApp;
1531     }
1532     catch(const css::uno::RuntimeException&)
1533         { throw; }
1534     catch(const css::uno::Exception&)
1535         { /* do nothing here ... may the following code can help!*/ }
1536 
1537     // no filter/no type/no detection result => no fun :-)
1538     return E_UNKNOWN_FACTORY;
1539 }
1540 
1541 /*-----------------------------------------------
1542     31.07.2003 10:41
1543 -----------------------------------------------*/
1544 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel >& xModel)
1545 {
1546     css::uno::Reference< css::lang::XServiceInfo > xInfo(xModel, css::uno::UNO_QUERY);
1547     if (!xInfo.is())
1548         return E_UNKNOWN_FACTORY;
1549 
1550     const css::uno::Sequence< ::rtl::OUString > lServices = xInfo->getSupportedServiceNames();
1551     const ::rtl::OUString*                      pServices = lServices.getConstArray();
1552 
1553     for (sal_Int32 i=0; i<lServices.getLength() ; ++i)
1554     {
1555         SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(pServices[i]);
1556         if (eApp != E_UNKNOWN_FACTORY)
1557             return eApp;
1558     }
1559 
1560     return E_UNKNOWN_FACTORY;
1561 }
1562 
1563 ::com::sun::star::uno::Sequence < ::rtl::OUString > SvtModuleOptions::GetAllServiceNames()
1564 {
1565     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1566     return m_pDataContainer->GetAllServiceNames();
1567 }
1568 
1569 ::rtl::OUString SvtModuleOptions::GetDefaultModuleName()
1570 {
1571 	::rtl::OUString aModule;
1572     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SWRITER))
1573         aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITER);
1574     else
1575     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SCALC))
1576         aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_CALC);
1577     else
1578     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SIMPRESS))
1579         aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_IMPRESS);
1580     else
1581     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
1582         aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_DATABASE);
1583     else
1584     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SDRAW))
1585         aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_DRAW);
1586     else
1587     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SWEB))
1588         aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITERWEB);
1589     else
1590     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SGLOBAL))
1591         aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITERGLOBAL);
1592     else
1593     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SMATH))
1594         aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_MATH);
1595 	return aModule;
1596 }
1597 
1598