summaryrefslogtreecommitdiff
path: root/framework/source/services/pathsettings.cxx
blob: 0a7bece7a26a1b2bb4d3b226983ce637ffe15d62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
/*************************************************************************
 *
 *  $RCSfile: pathsettings.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: hr $ $Date: 2003-03-25 18:21:53 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

// ______________________________________________
// my own includes

/** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
               with solaris headers ...
*/
#include <vector>

#ifndef __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
#include <services/pathsettings.hxx>
#endif

#ifndef __FRAMEWORK_THREADHELP_READGUARD_HXX_
#include <threadhelp/readguard.hxx>
#endif

#ifndef __FRAMEWORK_THREADHELP_WRITEGUARD_HXX_
#include <threadhelp/writeguard.hxx>
#endif

#ifndef __FRAMEWORK_SERVICES_H_
#include <services.h>
#endif

// ______________________________________________
// interface includes

#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif

// ______________________________________________
// includes of other projects

#ifndef _URLOBJ_HXX
#include <tools/urlobj.hxx>
#endif

#ifndef _RTL_USTRBUF_HXX_
#include <rtl/ustrbuf.hxx>
#endif

// ______________________________________________
//  non exported const

#define CFG_READONLY_DEFAULT    sal_False

// ______________________________________________
//  namespace

namespace framework
{

const ::rtl::OUString PathSettingsCfg::PropNames[] =
{
    PATHSETTINGS_PROPNAME_ADDIN         ,
    PATHSETTINGS_PROPNAME_AUTOCORRECT   ,
    PATHSETTINGS_PROPNAME_AUTOTEXT      ,
    PATHSETTINGS_PROPNAME_BACKUP        ,
    PATHSETTINGS_PROPNAME_BASIC         ,
    PATHSETTINGS_PROPNAME_BITMAP        ,
    PATHSETTINGS_PROPNAME_CONFIG        ,
    PATHSETTINGS_PROPNAME_DICTIONARY    ,
    PATHSETTINGS_PROPNAME_FAVORITE      ,
    PATHSETTINGS_PROPNAME_FILTER        ,
    PATHSETTINGS_PROPNAME_GALLERY       ,
    PATHSETTINGS_PROPNAME_GRAPHIC       ,
    PATHSETTINGS_PROPNAME_HELP          ,
    PATHSETTINGS_PROPNAME_LINGUISTIC    ,
    PATHSETTINGS_PROPNAME_MODULE        ,
    PATHSETTINGS_PROPNAME_PALETTE       ,
    PATHSETTINGS_PROPNAME_PLUGIN        ,
    PATHSETTINGS_PROPNAME_STORAGE       ,
    PATHSETTINGS_PROPNAME_TEMP          ,
    PATHSETTINGS_PROPNAME_TEMPLATE      ,
    PATHSETTINGS_PROPNAME_UICONFIG      ,
    PATHSETTINGS_PROPNAME_USERCONFIG    ,
    PATHSETTINGS_PROPNAME_USERDICTIONARY,
    PATHSETTINGS_PROPNAME_WORK
};

const css::beans::Property PathSettingsCfg::Properties[] =
{
    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_ADDIN],
        PathSettingsCfg::E_ADDIN,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_AUTOCORRECT],
        PathSettingsCfg::E_AUTOCORRECT,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_AUTOTEXT],
        PathSettingsCfg::E_AUTOTEXT,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_BACKUP],
        PathSettingsCfg::E_BACKUP,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_BASIC],
        PathSettingsCfg::E_BASIC,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_BITMAP],
        PathSettingsCfg::E_BITMAP,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_CONFIG],
        PathSettingsCfg::E_CONFIG,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_DICTIONARY],
        PathSettingsCfg::E_DICTIONARY,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_FAVORITE],
        PathSettingsCfg::E_FAVORITE,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_FILTER],
        PathSettingsCfg::E_FILTER,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_GALLERY],
        PathSettingsCfg::E_GALLERY,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_GRAPHIC],
        PathSettingsCfg::E_GRAPHIC,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_HELP],
        PathSettingsCfg::E_HELP,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_LINGUISTIC],
        PathSettingsCfg::E_LINGUISTIC,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_MODULE],
        PathSettingsCfg::E_MODULE,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_PALETTE],
        PathSettingsCfg::E_PALETTE,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_PLUGIN],
        PathSettingsCfg::E_PLUGIN,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_STORAGE],
        PathSettingsCfg::E_STORAGE,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_TEMP],
        PathSettingsCfg::E_TEMP,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_TEMPLATE],
        PathSettingsCfg::E_TEMPLATE,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_UICONFIG],
        PathSettingsCfg::E_UICONFIG,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_USERCONFIG],
        PathSettingsCfg::E_USERCONFIG,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_USERDICTIONARY],
        PathSettingsCfg::E_USERDICTIONARY,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND),

    css::beans::Property(
        PathSettingsCfg::PropNames[PathSettingsCfg::E_WORK],
        PathSettingsCfg::E_WORK,
        ::getCppuType((rtl::OUString*)NULL),
        css::beans::PropertyAttribute::BOUND)
};

// ______________________________________________

/** it fill this new cache instance and prepare all neccessary structures.
    Note: It's very important for our work, that another helper service PathSubstitution could be created here.
    It's needed later .. and without its work the pathes which are provided here will not valid.
    That's why we throw a RuntimeException in case this service couldn't be created!
 */

PathSettingsCfg::PathSettingsCfg( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
    :   ::utl::ConfigItem( DECLARE_ASCII("Office.Common/Path/Current") )
{
    // create the needed substitution service.
    // We must replace all used variables inside readed path values.
    // In case we can't do so ... the whole office can't work realy.
    // That's why it seams to be OK to throw a RuntimeException then.
    if (xSMGR.is())
    {
        m_xSubstitution = css::uno::Reference< css::util::XStringSubstitution >(
                            xSMGR->createInstance(SERVICENAME_SUBSTITUTEPATHVARIABLES),
                            css::uno::UNO_QUERY);
    }
    if (!m_xSubstitution.is())
        throw css::uno::RuntimeException(DECLARE_ASCII("Could not create substitution service. Path settings will not work."),css::uno::Reference< css::uno::XInterface >());

    // create mapping for path names to her ID's
    // This hash content is fix and already defined by some fix arrays of the class PathSettingsCfg.
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_ADDIN         ]] = PathSettingsCfg::E_ADDIN         ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_AUTOCORRECT   ]] = PathSettingsCfg::E_AUTOCORRECT   ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_AUTOTEXT      ]] = PathSettingsCfg::E_AUTOTEXT      ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_BACKUP        ]] = PathSettingsCfg::E_BACKUP        ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_BASIC         ]] = PathSettingsCfg::E_BASIC         ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_BITMAP        ]] = PathSettingsCfg::E_BITMAP        ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_CONFIG        ]] = PathSettingsCfg::E_CONFIG        ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_DICTIONARY    ]] = PathSettingsCfg::E_DICTIONARY    ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_FAVORITE      ]] = PathSettingsCfg::E_FAVORITE      ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_FILTER        ]] = PathSettingsCfg::E_FILTER        ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_GALLERY       ]] = PathSettingsCfg::E_GALLERY       ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_GRAPHIC       ]] = PathSettingsCfg::E_GRAPHIC       ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_HELP          ]] = PathSettingsCfg::E_HELP          ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_LINGUISTIC    ]] = PathSettingsCfg::E_LINGUISTIC    ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_MODULE        ]] = PathSettingsCfg::E_MODULE        ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_PALETTE       ]] = PathSettingsCfg::E_PALETTE       ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_PLUGIN        ]] = PathSettingsCfg::E_PLUGIN        ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_STORAGE       ]] = PathSettingsCfg::E_STORAGE       ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_TEMP          ]] = PathSettingsCfg::E_TEMP          ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_TEMPLATE      ]] = PathSettingsCfg::E_TEMPLATE      ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_UICONFIG      ]] = PathSettingsCfg::E_UICONFIG      ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_USERCONFIG    ]] = PathSettingsCfg::E_USERCONFIG    ;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_USERDICTIONARY]] = PathSettingsCfg::E_USERDICTIONARY;
    m_lIDMap[PathSettingsCfg::PropNames[PathSettingsCfg::E_WORK          ]] = PathSettingsCfg::E_WORK          ;

    // use fix list of all needed path names to read her values from the configuration.
    // Call impl_read() method mit optimization parameter "bSearchID=sal_False"!
    // So hash map isn't used to map from given property name to the corresponding ID.
    // It's not neccessary here. Because we have a fix list of names, which correspond
    // directly to an ID by it's position inside the array ...
    const css::uno::Sequence< ::rtl::OUString > lNames(PathSettingsCfg::PropNames,PATHSETTINGS_PROPCOUNT);
    impl_read(lNames,sal_False);
}

// ______________________________________________

/** nothing to do here ...
    Because we are a write-through cache ... all items should be already saved.
    But may it's better to check it for debug purposes.
 */

PathSettingsCfg::~PathSettingsCfg()
{
    LOG_ASSERT(!IsModified(), "PathSettingsCfg::~PathSettingsCfg()\nModified state of a write-through cache shouldn't be possible at the end of lifetime.\n")
}

// ______________________________________________

/** There are some outside changed items, which should be updated inside this cache too.
 */

void PathSettingsCfg::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& lPropertyNames )
{
    // Attention: These list of pathes isn't well known nor fix. We can't use our optimization here,
    // that the prop ID/Handle is the same as the current array position.
    // That's why we must use our special hash for mapping path names to her corresponding ID.
    // => second parameter bSearchID=sal_True must be used here
    impl_read(lPropertyNames,sal_True);
}

// ______________________________________________

/** return the current path value for this entry.
 */

::rtl::OUString PathSettingsCfg::getPath( EPropHandle nID ) const
{
    // SAFE {
    ReadGuard aReadLock(m_aLock);
    return m_lPathes[nID].sValue;
}

// ______________________________________________

/** set he new path value for this entry.
    But it's done only, if it will change realy.
    And because this class is implemented as a write through cache,
    this new value is written immediatly to the configuration.
 */

void PathSettingsCfg::setPath(       EPropHandle      nID    ,
                               const ::rtl::OUString& sValue )
{
    // SAFE {
    WriteGuard aWriteLock(m_aLock);

    // has somthing changed?
    if (m_lPathes[nID].sValue.equals(sValue))
        return;

    // is it readonly?
    // It's an implementation error if this method is called for readonly properties!
    // Our helper class OPropertySetHelper throws normaly a PropertyVetoExceptio, if somehwere
    // tries to call setPropertyValue() for readonly properties.
    if (m_lPathes[nID].bReadOnly)
    {
        LOG_WARNING("PathSettingsCfg::setPath()", "Unexpected set call for readonly path detected!")
        return;
    }

    // take over the new value into our cache structures
    m_lPathes[nID].sValue = sValue;

    aWriteLock.unlock();
    // } SAFE

    // update the configuration immediatly
    sal_Bool bMultiPath = isMultiPath(nID);

    css::uno::Sequence< ::rtl::OUString > lNames  (1);
    css::uno::Sequence< css::uno::Any >   lValues (1);
    ::rtl::OUString*                      pNames  = lNames.getArray();
    css::uno::Any*                        pValues = lValues.getArray();
    ::rtl::OUString                       sReSubst;

    // SAFE {
    ReadGuard aReadLock(m_aLock);
    if (bMultiPath)
    {
        css::uno::Sequence< ::rtl::OUString > lMulti;
        sal_Int32 nToken = 0;
        do
        {
            ::rtl::OUString sToken = m_lPathes[nID].sValue.getToken(0, ';', nToken);
            if (sToken.getLength())
            {
                sReSubst = m_xSubstitution->reSubstituteVariables(sToken);
                lMulti.realloc(lMulti.getLength()+1);
                lMulti[lMulti.getLength()-1] = sReSubst;
            }
        }
        while(nToken>=0);
        pNames[0]    = m_lPathes[nID].sPath;
        pValues[0] <<= lMulti;
    }
    else
    {
        pNames[0]    = m_lPathes[nID].sPath;
        sReSubst     = m_xSubstitution->reSubstituteVariables(m_lPathes[nID].sValue);
        pValues[0] <<= sReSubst;
    }
    aReadLock.unlock();
    // } SAFE

    PutProperties(lNames, lValues);
}

// ______________________________________________

/** return the readonly state of a path entry.
 */

sal_Bool PathSettingsCfg::isReadOnly( EPropHandle nID ) const
{
    // SAFE {
    ReadGuard aReadLock(m_aLock);
    return m_lPathes[nID].bReadOnly;
}

// ______________________________________________

/** return information about the path type of a path entry.
    We know single and multi paths.
 */

sal_Bool PathSettingsCfg::isMultiPath( EPropHandle nID ) const
{
    // multi paths are fix be definition!
    sal_Bool bKnownMulti = (nID == PathSettingsCfg::E_AUTOCORRECT||
                            nID == PathSettingsCfg::E_AUTOTEXT   ||
                            nID == PathSettingsCfg::E_BASIC      ||
                            nID == PathSettingsCfg::E_GALLERY    ||
                            nID == PathSettingsCfg::E_PLUGIN     ||
                            nID == PathSettingsCfg::E_TEMPLATE   ||
                            nID == PathSettingsCfg::E_UICONFIG   );
    #ifdef ENABLE_ASSERTIONS
        // But we detected it during reading from the configuration too.
        // We should use this information to check if something was changed for this definition.
        // May our method returns the wrong state then!
        // SAFE {
        ReadGuard aReadLock(m_aLock);
        LOG_ASSERT(bKnownMulti==m_lPathes[nID].bMultiPath, "PathSettingsCfg::isMultiPath()\nThere seams to be a difference between known and detected multi pathes!\n")
        aReadLock.unlock();
        // } SAFE
    #endif
    return bKnownMulti;
}

// ______________________________________________

/** return a descriptor for all supported properties.
    Normaly this descriptor is fix. So you can use the static const value "Properties".
    But the readonly state of a property must be detected during runtime.
    So we must path this structure on demand.
 */

const css::uno::Sequence< css::beans::Property > PathSettingsCfg::getPropertyDescriptor() const
{
    sal_Int32                                  nCount = PATHSETTINGS_PROPCOUNT;
    css::uno::Sequence< css::beans::Property > lDesc  (Properties,nCount);
    css::beans::Property*                      pDesc  = lDesc.getArray();

    // SAFE {
    ReadGuard aReadLock(m_aLock);
    for (sal_Int32 p=0; p<nCount; ++p)
    {
        if (m_lPathes[p].bReadOnly)
            pDesc[p].Attributes |= css::beans::PropertyAttribute::READONLY;
        else
            pDesc[p].Attributes &= ~css::beans::PropertyAttribute::READONLY;
    }
    aReadLock.unlock();
    // } SAFE
    return lDesc;
}

// ______________________________________________

/** return the corresponding property handle for the given property name.
    We use an internal fix hash map to do so.
    Attention: If you call this method e.g. with an unknown property name
    the returned ID will be undefined! Please check the returned boolean
    state of this method everytimes. Otherwhise we try to let it crash then :-)
 */

sal_Bool PathSettingsCfg::mapName2Handle( const ::rtl::OUString& sName ,
                                                EPropHandle&     rID   ) const
{
    // SAFE {
    ReadGuard aReadLock(m_aLock);
    NameToHandleHash::const_iterator pIt      = m_lIDMap.find(sName);
    sal_Bool                         bSuccess = (pIt!=m_lIDMap.end());
    aReadLock.unlock();
    // } SAFE

    if (bSuccess)
        rID = (EPropHandle)(pIt->second);
    else
        // let it crash :-) Better to find wrong using of this method!
        rID = (EPropHandle)-1;
    return bSuccess;
}

// ______________________________________________

/** read the path values from the configuration.
    The special parameter bSearchID enable/disable optional mapping of
    property names to her property handle. As optimization it can be disabled
    if the caller is hure, that the array index inside the parameter lNames
    can be used as such handle without any check. That can be true for
    sorted, fix and full filled lists of properties only! See struct PropNames/EPropHandle too!
 */

void PathSettingsCfg::impl_read( const css::uno::Sequence< ::rtl::OUString >& lNames    ,
                                       sal_Bool                               bSearchID )
{
    sal_Int32                                   nCount    = lNames.getLength();
    const css::uno::Sequence< css::uno::Any >   lValues   = ConfigItem::GetProperties(lNames);
    const css::uno::Sequence< sal_Bool >        lROStates = ConfigItem::GetReadOnlyStates(lNames);
    const ::rtl::OUString*                      pNames    = lNames.getConstArray();
    const css::uno::Any*                        pValues   = lValues.getConstArray();
    const sal_Bool*                             pROStates = lROStates.getConstArray();

    // All getted list (names, values, readonly states) must work together.
    // They must have the same size. Otherwhise combination of it can produce wrong results!
    if ( lValues.getLength()!=lNames.getLength() || lROStates.getLength()!=lNames.getLength() )
    {
        LOG_WARNING("PathSettingsCfg::impl_read()", "GetProperties() or GetReadOnlyStates does not return valid count of items.")
        return;
    }

    for (sal_Int32 n=0; n<nCount; ++n)
    {
        // Dont define these variables outside of this loop scope!
        // Otherwhise you have to be shure that they will be reseted for every new loop ...
        ::rtl::OUString sTempVal;
        ::rtl::OUString sPathVal;
        sal_Bool        bMulti  = sal_False;

        if (!pValues[n].hasValue())
        {
            LOG_WARNING("PathSettingsCfg::impl_read()", "Missing a path value. Item will be ignored.")
            continue;
        }

        // get the path value
        switch (pValues[n].getValueTypeClass())
        {
            // single pathes
            case ::com::sun::star::uno::TypeClass_STRING :
            {
                if (!(pValues[n]>>=sTempVal))
                {
                    LOG_WARNING("PathSettingsCfg::impl_read()", "Could not unpack path value.")
                    continue;
                }

                sPathVal = m_xSubstitution->substituteVariables(sTempVal,sal_False);
                bMulti   = sal_False;
                break;
            }

            // multi pathes
            case ::com::sun::star::uno::TypeClass_SEQUENCE :
            {
                css::uno::Sequence< ::rtl::OUString > lMulti;
                if (!(pValues[n]>>=lMulti))
                {
                    LOG_WARNING("PathSettingsCfg::impl_read()", "Could not unpack multi path value.")
                    continue;
                }

                ::rtl::OUStringBuffer  sBuffer     (256);
                const ::rtl::OUString* pMulti      = lMulti.getConstArray();
                sal_Int32              nMultiCount = lMulti.getLength();
                for (sal_Int32 m=0; m<nMultiCount; ++m)
                {
                    sTempVal = m_xSubstitution->substituteVariables(pMulti[m],sal_False);
                    sBuffer.append(sTempVal);
                    if (m<nMultiCount-1)
                        sBuffer.appendAscii(";");
                }
                sPathVal = sBuffer.makeStringAndClear();
                bMulti   = sal_True;
                break;
            }

            // unknown!
            default:
            {
                LOG_WARNING("PathSettingsCfg::impl_read()", "Unknown path type detected!")
                continue;
            }
        }

        // insert new value inside internal structures
        EPropHandle nID = (EPropHandle)n;
        if (bSearchID)
        {
            if (!mapName2Handle(pNames[n],nID))
            {
                LOG_WARNING("PathSettingsCfg::impl_read()", "Mapping from name to ID failed!")
                continue;
            }
        }

        m_lPathes[nID].sPath      = pNames[n];
        m_lPathes[nID].sValue     = sPathVal;
        m_lPathes[nID].bReadOnly  = pROStates[n];
        m_lPathes[nID].bMultiPath = bMulti;
    }
}

// ______________________________________________

/** check if the given path value seams to be a valid URL or system path.
 */

sal_Bool PathSettingsCfg::isValidValue( const ::rtl::OUString& sValue     ,
                                              sal_Bool         bMultiPath ) const
{
    sal_Bool bOk = sal_True;

    if (bMultiPath)
    {
        sal_Int32 nToken = 0;
        do
        {
            ::rtl::OUString sToken = sValue.getToken(0, ';', nToken);
            if (sToken.getLength())
                bOk = !INetURLObject(sToken).HasError();
        }
        while(nToken>=0 && bOk);
    }
    else
    {
        bOk = !INetURLObject(sValue).HasError();
    }

    return bOk;
}

// ______________________________________________

/** it checks the given path value and tries to correct it.
    Correction can be done by substitution of variables.
    May the user tried to set a value which includes such variables.
 */

sal_Bool PathSettingsCfg::checkAndSubstituteValue( ::rtl::OUString& sValue     ,
                                                   sal_Bool         bMultiPath ) const
{
    sal_Bool bOk = isValidValue(sValue,bMultiPath);

    if (!bOk)
    {
        try
        {
            // SAFE {
            ReadGuard aReadLock(m_aLock);
            ::rtl::OUString sSubst = m_xSubstitution->substituteVariables(sValue,sal_True);
            aReadLock.unlock();
            // } SAFE
            bOk = PathSettingsCfg::isValidValue(sSubst,bMultiPath);
            if (bOk)
                sValue = sSubst;
        }
        catch(const css::container::NoSuchElementException&)
        {
            bOk = sal_False;
        }
    }

    return bOk;
}

// ______________________________________________
// XInterface, XTypeProvider, XServiceInfo

DEFINE_XINTERFACE_5                     (   PathSettings                                             ,
                                            OWeakObject                                              ,
                                            DIRECT_INTERFACE( css::lang::XTypeProvider              ),
                                            DIRECT_INTERFACE( css::lang::XServiceInfo               ),
                                            DIRECT_INTERFACE( css::beans::XPropertySet              ),
                                            DIRECT_INTERFACE( css::beans::XFastPropertySet          ),
                                            DIRECT_INTERFACE( css::beans::XMultiPropertySet         )
                                        )

DEFINE_XTYPEPROVIDER_5                  (   PathSettings                                            ,
                                            css::lang::XTypeProvider                                ,
                                            css::lang::XServiceInfo                                 ,
                                            css::beans::XPropertySet                                ,
                                            css::beans::XFastPropertySet                            ,
                                            css::beans::XMultiPropertySet
                                        )

DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   PathSettings                                            ,
                                            ::cppu::OWeakObject                                     ,
                                            SERVICENAME_PATHSETTINGS                                ,
                                            IMPLEMENTATIONNAME_PATHSETTINGS
                                        )

DEFINE_INIT_SERVICE                     (   PathSettings,
                                            {
                                                /*Attention
                                                    I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
                                                    to create a new instance of this class by our own supported service factory.
                                                    see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
                                                */
                                            }
                                        )

/*-************************************************************************************************************//**
    @short      standard constructor to create instance by factory
    @descr      This constructor initialize a new instance of this class by valid factory,
                and will be set valid values on his member and baseclasses.

    @attention  a)  Don't use your own reference during an UNO-Service-ctor! There is no guarantee, that you
                    will get over this. (e.g. using of your reference as parameter to initialize some member)
                    Do such things in DEFINE_INIT_SERVICE() method, which is called automaticly after your ctor!!!
                b)  Baseclass OBroadcastHelper is a typedef in namespace cppu!
                    The microsoft compiler has some problems to handle it right BY using namespace explicitly ::cppu::OBroadcastHelper.
                    If we write it without a namespace or expand the typedef to OBrodcastHelperVar<...> -> it will be OK!?
                    I don't know why! (other compiler not tested .. but it works!)

    @seealso    method DEFINE_INIT_SERVICE()

    @param      "xFactory" is the multi service manager, which create this instance.
                The value must be different from NULL!
    @return     -

    @onerror    We throw an ASSERT in debug version or do nothing in relaese version.
*//*-*************************************************************************************************************/
PathSettings::PathSettings( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
        //  Init baseclasses first
        //  Attention: Don't change order of initialization!
        //      ThreadHelpBase is a struct with a lock as member. We can't use a lock as direct member!
        //      We must garant right initialization and a valid value of this to initialize other baseclasses!
        :   PathSettingsCfg             ( xSMGR                                             )
        ,   ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >           ( m_aLock.getShareableOslMutex()         )
        ,   ::cppu::OPropertySetHelper  ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
        ,   ::cppu::OWeakObject         (                                                   )
        // Init member
        ,   m_xSMGR                     ( xSMGR                                             )
{
}

/*-************************************************************************************************************//**
    @short      standard destructor
    @descr      This one do NOTHING! Use dispose() instaed of this.

    @seealso    method dispose()

    @param      -
    @return     -

    @onerror    -
*//*-*************************************************************************************************************/
PathSettings::~PathSettings()
{
}

/*-************************************************************************************************************//**
    @short      try to convert a property value
    @descr      This method is called from helperclass "OPropertySetHelper".
                Don't use this directly!
                You must try to convert the value of given propertyhandle and
                return results of this operation. This will be used to ask vetoable
                listener. If no listener has a veto, we will change value realy!
                ( in method setFastPropertyValue_NoBroadcast(...) )

    @attention  Methods of OPropertySethelper are safed by using our shared osl mutex! (see ctor!)
                So we must use different locks to make our implementation threadsafe.

    @seealso    class OPropertySetHelper
    @seealso    method setFastPropertyValue_NoBroadcast()
    @seealso    method impl_tryToChangeProperty()

    @param      "aConvertedValue"   new converted value of property
    @param      "aOldValue"         old value of property
    @param      "nHandle"           handle of property
    @param      "aValue"            new value of property
    @return     sal_True if value will be changed, sal_FALSE otherway

    @onerror    IllegalArgumentException, if you call this with an invalid argument
    @threadsafe yes
*//*-*************************************************************************************************************/
sal_Bool SAL_CALL PathSettings::convertFastPropertyValue(   css::uno::Any&          aConvertedValue ,
                                                            css::uno::Any&          aOldValue       ,
                                                            sal_Int32               nHandle         ,
                                                            const css::uno::Any&    aValue          ) throw( css::lang::IllegalArgumentException )
{
    EPropHandle nID = (EPropHandle)nHandle;
    return PropHelper::willPropertyBeChanged(
        css::uno::makeAny(getPath(nID)),
        aValue,
        aOldValue,
        aConvertedValue);
}

/*-************************************************************************************************************//**
    @short      set value of a bound property
    @descr      This method is calling from helperclass "OPropertySetHelper".
                Don't use this directly!
                Handle and value are valid everyway! You must set the new value only.
                After this, baseclass send messages to all listener automaticly.

    @seealso    class OPropertySetHelper

    @param      "nHandle"   handle of property to change
    @param      "aValue"    new value of property
    @return     -

    @onerror    An exception is thrown.
    @threadsafe yes
*//*-*************************************************************************************************************/
void SAL_CALL PathSettings::setFastPropertyValue_NoBroadcast(   sal_Int32               nHandle ,
                                                                const css::uno::Any&    aValue  )
    throw( css::uno::Exception )
{
    EPropHandle     nID        = (EPropHandle)nHandle;
    sal_Bool        bReadOnly  = isReadOnly(nID);
    sal_Bool        bMultiPath = isMultiPath(nID);
    ::rtl::OUString sValue     ;

    // Is this value a valid one?
    if (
        (!(aValue >>= sValue                       )) ||
        !(checkAndSubstituteValue(sValue,bMultiPath))
       )
    {
        ::rtl::OUStringBuffer sBuffer(256);
        sBuffer.appendAscii("\""                    );
        sBuffer.append     (sValue                  );
        sBuffer.appendAscii("\" is not a valid URL!");
        throw css::lang::IllegalArgumentException(
                sBuffer.makeStringAndClear(),
                static_cast< cppu::OWeakObject *>(this),
                0);
    }

    // update cache and config
    setPath(nID, sValue);
}

/*-************************************************************************************************************//**
    @short      get value of a bound property
    @descr      This method is calling from helperclass "OPropertySetHelper".
                Don't use this directly!

    @attention  We don't need any mutex or lock here ... We use threadsafe container or methods here only!

    @seealso    class OPropertySetHelper

    @param      "nHandle"   handle of property to change
    @param      "aValue"    current value of property
    @return     -

    @onerror    -
    @threadsafe yes
*//*-*************************************************************************************************************/
void SAL_CALL PathSettings::getFastPropertyValue(   css::uno::Any& aValue  ,
                                                    sal_Int32      nHandle ) const
{
    PathSettingsCfg::EPropHandle nID = (PathSettingsCfg::EPropHandle)nHandle;
    aValue <<= getPath(nID);
}

/*-************************************************************************************************************//**
    @short      return structure and information about bound properties
    @descr      This method is calling from helperclass "OPropertySetHelper".
                Don't use this directly!

    @attention  You must use global lock (method use static variable) ... and it must be the shareable osl mutex of it.
                Because; our baseclass use this mutex to make his code threadsafe. We use our lock!
                So we could have two different mutex/lock mechanism at the same object.

    @seealso    class OPropertySetHelper

    @param      -
    @return     structure with property-informations

    @onerror    -
    @threadsafe yes
*//*-*************************************************************************************************************/
::cppu::IPropertyArrayHelper& SAL_CALL PathSettings::getInfoHelper()
{
    // Optimize this method !
    // We initialize a static variable only one time. And we don't must use a mutex at every call!
    // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
    static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;

    if( pInfoHelper == NULL )
    {
        // Ready for multithreading
        ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
        // Control this pointer again, another instance can be faster then these!
        if( pInfoHelper == NULL )
        {
            // Define static member to give structure of properties to baseclass "OPropertySetHelper".
            // "getPropertyDescriptor" is a non exported function of our base class PathSettingsCfg
            // which creates the right descriptor on demand and patch against some fix informations
            // e.g. the readonly attribute!
            // Last parameter set to "sal_True" indicates => table is sorted by name.
            static ::cppu::OPropertyArrayHelper aInfoHelper(getPropertyDescriptor(), sal_True);
            pInfoHelper = &aInfoHelper;
        }
    }

    return(*pInfoHelper);
}

/*-************************************************************************************************************//**
    @short      return propertysetinfo
    @descr      You can call this method to get information about transient properties
                of this object.

    @attention  You must use global lock (method use static variable) ... and it must be the shareable osl mutex of it.
                Because; our baseclass use this mutex to make his code threadsafe. We use our lock!
                So we could have two different mutex/lock mechanism at the same object.

    @seealso    class OPropertySetHelper
    @seealso    interface XPropertySet
    @seealso    interface XMultiPropertySet

    @param      -
    @return     reference to object with information [XPropertySetInfo]

    @onerror    -
    @threadsafe yes
*//*-*************************************************************************************************************/
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL PathSettings::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException)
{
    // Optimize this method !
    // We initialize a static variable only one time. And we don't must use a mutex at every call!
    // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
    static css::uno::Reference< css::beans::XPropertySetInfo >* pInfo = NULL;

    if( pInfo == NULL )
    {
        // Ready for multithreading
        ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
        // Control this pointer again, another instance can be faster then these!
        if( pInfo == NULL )
        {
            // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
            // (Use method "getInfoHelper()".)
            static css::uno::Reference< css::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
            pInfo = &xInfo;
        }
    }

    return (*pInfo);
}

} // namespace framework