xref: /trunk/main/framework/source/services/pathsettings.cxx (revision e901e6e41c1fd2ceb1d01c5bbfa2b102c167f93f)
16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
36d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
56d739b60SAndrew Rist  * distributed with this work for additional information
66d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
76d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
136d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist  * software distributed under the License is distributed on an
156d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
176d739b60SAndrew Rist  * specific language governing permissions and limitations
186d739b60SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_framework.hxx"
24cdf0e10cSrcweir // ______________________________________________
25cdf0e10cSrcweir // my own includes
26cdf0e10cSrcweir 
2715289133Smseidel /** Attention: stl headers must(!) be included at first. Otherwise it can make trouble
28cdf0e10cSrcweir                with solaris headers ...
29cdf0e10cSrcweir */
30cdf0e10cSrcweir #include <vector>
31cdf0e10cSrcweir #include <services/pathsettings.hxx>
32cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
33cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
34cdf0e10cSrcweir #include <services.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // ______________________________________________
37cdf0e10cSrcweir // interface includes
38cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/XProperty.hpp>
40cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
41cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
42cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
43cdf0e10cSrcweir #include <com/sun/star/util/XChangesNotifier.hpp>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir // ______________________________________________
46cdf0e10cSrcweir // includes of other projects
47cdf0e10cSrcweir #include <tools/urlobj.hxx>
48cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
49cdf0e10cSrcweir #include <rtl/logfile.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
52cdf0e10cSrcweir #include <unotools/configpathes.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include <fwkdllapi.h>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // ______________________________________________
57cdf0e10cSrcweir //  non exported const
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #define CFG_READONLY_DEFAULT    sal_False
60cdf0e10cSrcweir 
61cdf0e10cSrcweir const ::rtl::OUString CFGPROP_INTERNALPATHES = ::rtl::OUString::createFromAscii("InternalPaths");
62cdf0e10cSrcweir const ::rtl::OUString CFGPROP_USERPATHES     = ::rtl::OUString::createFromAscii("UserPaths"    );
63cdf0e10cSrcweir const ::rtl::OUString CFGPROP_WRITEPATH      = ::rtl::OUString::createFromAscii("WritePath"    );
64cdf0e10cSrcweir const ::rtl::OUString CFGPROP_ISSINGLEPATH   = ::rtl::OUString::createFromAscii("IsSinglePath" );
65cdf0e10cSrcweir 
66cdf0e10cSrcweir /*
67cdf0e10cSrcweir     0 : old style              "Template"              string using ";" as seperator
68cdf0e10cSrcweir     1 : internal paths         "Template_internal"     string list
69cdf0e10cSrcweir     2 : user paths             "Template_user"         string list
70cdf0e10cSrcweir     3 : write path             "Template_write"        string
71cdf0e10cSrcweir  */
72cdf0e10cSrcweir 
73cdf0e10cSrcweir const ::rtl::OUString POSTFIX_INTERNAL_PATHES = ::rtl::OUString::createFromAscii("_internal");
74cdf0e10cSrcweir const ::rtl::OUString POSTFIX_USER_PATHES     = ::rtl::OUString::createFromAscii("_user"    );
75cdf0e10cSrcweir const ::rtl::OUString POSTFIX_WRITE_PATH      = ::rtl::OUString::createFromAscii("_writable");
76cdf0e10cSrcweir 
77cdf0e10cSrcweir const sal_Int32 IDGROUP_OLDSTYLE        = 0;
78cdf0e10cSrcweir const sal_Int32 IDGROUP_INTERNAL_PATHES = 1;
79cdf0e10cSrcweir const sal_Int32 IDGROUP_USER_PATHES     = 2;
80cdf0e10cSrcweir const sal_Int32 IDGROUP_WRITE_PATH      = 3;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir const sal_Int32 IDGROUP_COUNT           = 4;
83cdf0e10cSrcweir 
impl_getPropGroup(sal_Int32 nID)84cdf0e10cSrcweir sal_Int32 impl_getPropGroup(sal_Int32 nID)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     return (nID % IDGROUP_COUNT);
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // ______________________________________________
90cdf0e10cSrcweir //  namespace
91cdf0e10cSrcweir 
92cdf0e10cSrcweir namespace framework
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //-----------------------------------------------------------------------------
96cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo
97cdf0e10cSrcweir 
DEFINE_XINTERFACE_7(PathSettings,OWeakObject,DIRECT_INTERFACE (css::lang::XTypeProvider),DIRECT_INTERFACE (css::lang::XServiceInfo),DERIVED_INTERFACE (css::lang::XEventListener,css::util::XChangesListener),DIRECT_INTERFACE (css::util::XChangesListener),DIRECT_INTERFACE (css::beans::XPropertySet),DIRECT_INTERFACE (css::beans::XFastPropertySet),DIRECT_INTERFACE (css::beans::XMultiPropertySet))98cdf0e10cSrcweir DEFINE_XINTERFACE_7                     (   PathSettings                                             ,
99cdf0e10cSrcweir                                             OWeakObject                                              ,
100cdf0e10cSrcweir                                             DIRECT_INTERFACE ( css::lang::XTypeProvider              ),
101cdf0e10cSrcweir                                             DIRECT_INTERFACE ( css::lang::XServiceInfo               ),
102cdf0e10cSrcweir                                             DERIVED_INTERFACE( css::lang::XEventListener, css::util::XChangesListener),
103cdf0e10cSrcweir                                             DIRECT_INTERFACE ( css::util::XChangesListener           ),
104cdf0e10cSrcweir                                             DIRECT_INTERFACE ( css::beans::XPropertySet              ),
105cdf0e10cSrcweir                                             DIRECT_INTERFACE ( css::beans::XFastPropertySet          ),
106cdf0e10cSrcweir                                             DIRECT_INTERFACE ( css::beans::XMultiPropertySet        )
107cdf0e10cSrcweir                                         )
108cdf0e10cSrcweir 
109cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_7                  (   PathSettings                                            ,
110cdf0e10cSrcweir                                             css::lang::XTypeProvider                                ,
111cdf0e10cSrcweir                                             css::lang::XServiceInfo                                 ,
112cdf0e10cSrcweir                                             css::lang::XEventListener                               ,
113cdf0e10cSrcweir                                             css::util::XChangesListener                             ,
114cdf0e10cSrcweir                                             css::beans::XPropertySet                                ,
115cdf0e10cSrcweir                                             css::beans::XFastPropertySet                            ,
116cdf0e10cSrcweir                                             css::beans::XMultiPropertySet
117cdf0e10cSrcweir                                         )
118cdf0e10cSrcweir 
119cdf0e10cSrcweir DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   PathSettings                                            ,
120cdf0e10cSrcweir                                             ::cppu::OWeakObject                                     ,
121cdf0e10cSrcweir                                             SERVICENAME_PATHSETTINGS                                ,
122cdf0e10cSrcweir                                             IMPLEMENTATIONNAME_PATHSETTINGS
123cdf0e10cSrcweir                                         )
124cdf0e10cSrcweir 
125cdf0e10cSrcweir DEFINE_INIT_SERVICE                     (   PathSettings,
126cdf0e10cSrcweir                                             {
127cdf0e10cSrcweir                                                 /*Attention
128cdf0e10cSrcweir                                                     I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
129cdf0e10cSrcweir                                                     to create a new instance of this class by our own supported service factory.
130*e901e6e4Smseidel                                                     see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further information!
131cdf0e10cSrcweir                                                 */
132cdf0e10cSrcweir 
133cdf0e10cSrcweir                                                 // fill cache
134cdf0e10cSrcweir                                                 impl_readAll();
135cdf0e10cSrcweir                                             }
136cdf0e10cSrcweir                                         )
137cdf0e10cSrcweir 
138cdf0e10cSrcweir //-----------------------------------------------------------------------------
139cdf0e10cSrcweir PathSettings::PathSettings( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
140cdf0e10cSrcweir     //  Init baseclasses first
141cdf0e10cSrcweir     //  Attention: Don't change order of initialization!
142cdf0e10cSrcweir     //      ThreadHelpBase is a struct with a lock as member. We can't use a lock as direct member!
143cdf0e10cSrcweir     //      We must garant right initialization and a valid value of this to initialize other baseclasses!
144cdf0e10cSrcweir     :   ThreadHelpBase()
145cdf0e10cSrcweir     ,   ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >(m_aLock.getShareableOslMutex())
146cdf0e10cSrcweir     ,   ::cppu::OPropertySetHelper(*(static_cast< ::cppu::OBroadcastHelper* >(this)))
147cdf0e10cSrcweir     ,   ::cppu::OWeakObject()
148cdf0e10cSrcweir     // Init member
149cdf0e10cSrcweir     ,   m_xSMGR    (xSMGR)
150cdf0e10cSrcweir     ,   m_pPropHelp(0    )
151cdf0e10cSrcweir     ,  m_bIgnoreEvents(sal_False)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "PathSettings::PathSettings" );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir //-----------------------------------------------------------------------------
~PathSettings()157cdf0e10cSrcweir PathSettings::~PathSettings()
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     if (m_pPropHelp)
160cdf0e10cSrcweir        delete m_pPropHelp;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //-----------------------------------------------------------------------------
changesOccurred(const css::util::ChangesEvent & aEvent)164cdf0e10cSrcweir void SAL_CALL PathSettings::changesOccurred(const css::util::ChangesEvent& aEvent)
165cdf0e10cSrcweir     throw (css::uno::RuntimeException)
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "PathSettings::changesOccurred" );
168cdf0e10cSrcweir     /*
169cdf0e10cSrcweir     if (m_bIgnoreEvents)
170cdf0e10cSrcweir         return;
171cdf0e10cSrcweir     */
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     sal_Int32 c                 = aEvent.Changes.getLength();
174cdf0e10cSrcweir     sal_Int32 i                 = 0;
175cdf0e10cSrcweir     sal_Bool  bUpdateDescriptor = sal_False;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     for (i=0; i<c; ++i)
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         const css::util::ElementChange& aChange = aEvent.Changes[i];
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         ::rtl::OUString sChanged;
182cdf0e10cSrcweir         aChange.Accessor >>= sChanged;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         ::rtl::OUString sPath = ::utl::extractFirstFromConfigurationPath(sChanged);
185cdf0e10cSrcweir         if (sPath.getLength())
186cdf0e10cSrcweir         {
187cdf0e10cSrcweir             PathSettings::EChangeOp eOp = impl_updatePath(sPath, sal_True);
188cdf0e10cSrcweir             if (
189cdf0e10cSrcweir                 (eOp == PathSettings::E_ADDED  ) ||
190cdf0e10cSrcweir                 (eOp == PathSettings::E_REMOVED)
191cdf0e10cSrcweir                )
192cdf0e10cSrcweir                 bUpdateDescriptor = sal_True;
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     if (bUpdateDescriptor)
197cdf0e10cSrcweir         impl_rebuildPropertyDescriptor();
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //-----------------------------------------------------------------------------
disposing(const css::lang::EventObject & aSource)201cdf0e10cSrcweir void SAL_CALL PathSettings::disposing(const css::lang::EventObject& aSource)
202cdf0e10cSrcweir     throw(css::uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "PathSettings::disposing" );
205cdf0e10cSrcweir     // SAFE ->
206cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     if (aSource.Source == m_xCfgNew)
209cdf0e10cSrcweir         m_xCfgNew.clear();
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     aWriteLock.unlock();
212cdf0e10cSrcweir     // <- SAFE
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_readAll()216cdf0e10cSrcweir void PathSettings::impl_readAll()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "PathSettings::impl_readAll" );
219cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT(aLog, "framework (as96863) ::PathSettings::load config (all)");
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     // TODO think about me
222cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCfg    = fa_getCfgNew();
223cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString >              lPaths = xCfg->getElementNames();
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     sal_Int32 c = lPaths.getLength();
226cdf0e10cSrcweir     sal_Int32 i = 0;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     for (i=0; i<c; ++i)
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         const ::rtl::OUString& sPath = lPaths[i];
231cdf0e10cSrcweir         impl_updatePath(sPath, sal_False);
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     impl_rebuildPropertyDescriptor();
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir //-----------------------------------------------------------------------------
238cdf0e10cSrcweir // NO substitution here ! It's done outside ...
impl_readOldFormat(const::rtl::OUString & sPath)239cdf0e10cSrcweir OUStringList PathSettings::impl_readOldFormat(const ::rtl::OUString& sPath)
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "PathSettings::impl_readOldFormat" );
242cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCfg( fa_getCfgOld() );
243cdf0e10cSrcweir     OUStringList aPathVal;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     if( xCfg->hasByName(sPath) )
246cdf0e10cSrcweir     {
247cdf0e10cSrcweir         css::uno::Any aVal( xCfg->getByName(sPath) );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir         ::rtl::OUString                       sStringVal;
250cdf0e10cSrcweir         css::uno::Sequence< ::rtl::OUString > lStringListVal;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir         if (aVal >>= sStringVal)
253cdf0e10cSrcweir         {
254cdf0e10cSrcweir             aPathVal.push_back(sStringVal);
255cdf0e10cSrcweir         }
256cdf0e10cSrcweir         else if (aVal >>= lStringListVal)
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             aPathVal << lStringListVal;
259cdf0e10cSrcweir         }
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     return aPathVal;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir //-----------------------------------------------------------------------------
266cdf0e10cSrcweir // NO substitution here ! It's done outside ...
impl_readNewFormat(const::rtl::OUString & sPath)267cdf0e10cSrcweir PathSettings::PathInfo PathSettings::impl_readNewFormat(const ::rtl::OUString& sPath)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCfg = fa_getCfgNew();
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     // get access to the "queried" path
272cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xPath;
273cdf0e10cSrcweir     xCfg->getByName(sPath) >>= xPath;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     PathSettings::PathInfo aPathVal;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir     // read internal path list
278cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xIPath;
279cdf0e10cSrcweir     xPath->getByName(CFGPROP_INTERNALPATHES) >>= xIPath;
280cdf0e10cSrcweir     aPathVal.lInternalPaths << xIPath->getElementNames();
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     // read user defined path list
283cdf0e10cSrcweir     aPathVal.lUserPaths << xPath->getByName(CFGPROP_USERPATHES);
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     // read the writeable path
286cdf0e10cSrcweir     xPath->getByName(CFGPROP_WRITEPATH) >>= aPathVal.sWritePath;
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     // read state props
289cdf0e10cSrcweir     xPath->getByName(CFGPROP_ISSINGLEPATH) >>= aPathVal.bIsSinglePath;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     // analyze finalized/mandatory states
292cdf0e10cSrcweir     aPathVal.bIsReadonly = sal_False;
293cdf0e10cSrcweir     css::uno::Reference< css::beans::XProperty > xInfo(xPath, css::uno::UNO_QUERY);
294cdf0e10cSrcweir     if (xInfo.is())
295cdf0e10cSrcweir     {
296cdf0e10cSrcweir         css::beans::Property aInfo = xInfo->getAsProperty();
297cdf0e10cSrcweir         sal_Bool bFinalized = ((aInfo.Attributes & css::beans::PropertyAttribute::READONLY ) == css::beans::PropertyAttribute::READONLY );
298cdf0e10cSrcweir         //sal_Bool bMandatory = ((aInfo.Attributes & css::beans::PropertyAttribute::REMOVEABLE) != css::beans::PropertyAttribute::REMOVEABLE);
299cdf0e10cSrcweir 
300cdf0e10cSrcweir         // Note: Till we support finalized / mandatory on our API more in detail we handle
30107a3d7f1SPedro Giffuni         // all states simple as READONLY ! But because all really needed paths are "mandatory" by default
302cdf0e10cSrcweir         // we have to handle "finalized" as the real "readonly" indicator .
303cdf0e10cSrcweir         aPathVal.bIsReadonly = bFinalized;
304cdf0e10cSrcweir     }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir     return aPathVal;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_storePath(const PathSettings::PathInfo & aPath)310cdf0e10cSrcweir void PathSettings::impl_storePath(const PathSettings::PathInfo& aPath)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "PathSettings::impl_storePath" );
313cdf0e10cSrcweir     m_bIgnoreEvents = sal_True;
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCfgNew = fa_getCfgNew();
316cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xCfgOld = fa_getCfgOld();
317cdf0e10cSrcweir 
318*e901e6e4Smseidel     // try to replace path-parts with well known and supported variables.
319*e901e6e4Smseidel     // So an office can be moved easily to another location without losing
320*e901e6e4Smseidel     // its related paths.
321cdf0e10cSrcweir     PathInfo aResubstPath(aPath);
322cdf0e10cSrcweir     impl_subst(aResubstPath, sal_True);
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     // update new configuration
325cdf0e10cSrcweir     if (! aResubstPath.bIsSinglePath)
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::writeRelativeKey(xCfgNew,
328cdf0e10cSrcweir                                                             aResubstPath.sPathName,
329cdf0e10cSrcweir                                                             CFGPROP_USERPATHES,
330cdf0e10cSrcweir                                                             css::uno::makeAny(aResubstPath.lUserPaths.getAsConstList()));
331cdf0e10cSrcweir     }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     ::comphelper::ConfigurationHelper::writeRelativeKey(xCfgNew,
334cdf0e10cSrcweir                                                         aResubstPath.sPathName,
335cdf0e10cSrcweir                                                         CFGPROP_WRITEPATH,
336cdf0e10cSrcweir                                                         css::uno::makeAny(aResubstPath.sWritePath));
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     ::comphelper::ConfigurationHelper::flush(xCfgNew);
339cdf0e10cSrcweir 
340cdf0e10cSrcweir     // remove the whole path from the old configuration !
34107a3d7f1SPedro Giffuni     // Otherwise we can't make sure that the diff between new and old configuration
34207a3d7f1SPedro Giffuni     // on loading time really represent an user setting !!!
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     // Check if the given path exists inside the old configuration.
34507a3d7f1SPedro Giffuni     // Because our new configuration knows more then the list of old paths ... !
346cdf0e10cSrcweir     if (xCfgOld->hasByName(aResubstPath.sPathName))
347cdf0e10cSrcweir     {
348cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertySet > xProps(xCfgOld, css::uno::UNO_QUERY_THROW);
349cdf0e10cSrcweir         xProps->setPropertyValue(aResubstPath.sPathName, css::uno::Any());
350cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::flush(xCfgOld);
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir     m_bIgnoreEvents = sal_False;
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir //-----------------------------------------------------------------------------
357cdf0e10cSrcweir #ifdef MIGRATE_OLD_USER_PATHES
impl_mergeOldUserPaths(PathSettings::PathInfo & rPath,const OUStringList & lOld)358cdf0e10cSrcweir void PathSettings::impl_mergeOldUserPaths(      PathSettings::PathInfo& rPath,
359cdf0e10cSrcweir                                           const OUStringList&           lOld )
360cdf0e10cSrcweir {
361cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "PathSettings::impl_mergeOldUserPaths" );
362cdf0e10cSrcweir     OUStringList::const_iterator pIt;
363cdf0e10cSrcweir     for (  pIt  = lOld.begin();
364cdf0e10cSrcweir            pIt != lOld.end()  ;
365cdf0e10cSrcweir          ++pIt                )
366cdf0e10cSrcweir     {
367cdf0e10cSrcweir         const ::rtl::OUString& sOld = *pIt;
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         if (rPath.bIsSinglePath)
370cdf0e10cSrcweir         {
371cdf0e10cSrcweir             LOG_ASSERT2(lOld.size()>1, "PathSettings::impl_mergeOldUserPaths()", "Single path has more then one path value inside old configuration (Common.xcu)!")
372cdf0e10cSrcweir             if (! rPath.sWritePath.equals(sOld))
373cdf0e10cSrcweir                rPath.sWritePath = sOld;
374cdf0e10cSrcweir         }
375cdf0e10cSrcweir         else
376cdf0e10cSrcweir         {
377cdf0e10cSrcweir             if (
378cdf0e10cSrcweir                 (  rPath.lInternalPaths.findConst(sOld) == rPath.lInternalPaths.end()) &&
379cdf0e10cSrcweir                 (  rPath.lUserPaths.findConst(sOld)     == rPath.lUserPaths.end()    ) &&
380cdf0e10cSrcweir                 (! rPath.sWritePath.equals(sOld)                                     )
381cdf0e10cSrcweir                )
382cdf0e10cSrcweir                rPath.lUserPaths.push_back(sOld);
383cdf0e10cSrcweir         }
384cdf0e10cSrcweir     }
385cdf0e10cSrcweir }
386cdf0e10cSrcweir #endif // MIGRATE_OLD_USER_PATHES
387cdf0e10cSrcweir 
388cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_updatePath(const::rtl::OUString & sPath,sal_Bool bNotifyListener)389cdf0e10cSrcweir PathSettings::EChangeOp PathSettings::impl_updatePath(const ::rtl::OUString& sPath          ,
390cdf0e10cSrcweir                                                             sal_Bool         bNotifyListener)
391cdf0e10cSrcweir {
392cdf0e10cSrcweir     // SAFE ->
393cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
394cdf0e10cSrcweir 
395cdf0e10cSrcweir     PathSettings::PathInfo* pPathOld = 0;
396cdf0e10cSrcweir     PathSettings::PathInfo* pPathNew = 0;
397cdf0e10cSrcweir     PathSettings::EChangeOp eOp      = PathSettings::E_UNDEFINED;
398cdf0e10cSrcweir     PathSettings::PathInfo  aPath;
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     try
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         aPath = impl_readNewFormat(sPath);
403cdf0e10cSrcweir         aPath.sPathName = sPath;
404cdf0e10cSrcweir         // replace all might existing variables with real values
40507a3d7f1SPedro Giffuni         // Do it before these old paths will be compared against the
406*e901e6e4Smseidel         // new path configuration. Otherwise some strings uses different variables ... but substitution
407cdf0e10cSrcweir         // will produce strings with same content (because some variables are redundant!)
408cdf0e10cSrcweir         impl_subst(aPath, sal_False);
409cdf0e10cSrcweir     }
410cdf0e10cSrcweir     catch(const css::uno::RuntimeException& exRun)
411cdf0e10cSrcweir         { throw exRun; }
412cdf0e10cSrcweir     catch(const css::container::NoSuchElementException&)
413cdf0e10cSrcweir         { eOp = PathSettings::E_REMOVED; }
414cdf0e10cSrcweir     catch(const css::uno::Exception& exAny)
415cdf0e10cSrcweir         { throw exAny; }
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     #ifdef MIGRATE_OLD_USER_PATHES
418cdf0e10cSrcweir     try
419cdf0e10cSrcweir     {
420cdf0e10cSrcweir         // migration of old user defined values on demand
421cdf0e10cSrcweir         // can be disabled for a new major
422cdf0e10cSrcweir         OUStringList lOldVals = impl_readOldFormat(sPath);
423cdf0e10cSrcweir         // replace all might existing variables with real values
42407a3d7f1SPedro Giffuni         // Do it before these old paths will be compared against the
425*e901e6e4Smseidel         // new path configuration. Otherwise some strings uses different variables ... but substitution
426cdf0e10cSrcweir         // will produce strings with same content (because some variables are redundant!)
427cdf0e10cSrcweir         impl_subst(lOldVals, fa_getSubstitution(), sal_False);
428cdf0e10cSrcweir         impl_mergeOldUserPaths(aPath, lOldVals);
429cdf0e10cSrcweir     }
430cdf0e10cSrcweir     catch(const css::uno::RuntimeException& exRun)
431cdf0e10cSrcweir         { throw exRun; }
432cdf0e10cSrcweir     // Normal(!) exceptions can be ignored!
433cdf0e10cSrcweir     // E.g. in case an addon installs a new path, which was not well known for an OOo 1.x installation
43407a3d7f1SPedro Giffuni     // we can't find a value for it inside the "old" configuration. So a NoSuchElementException
435cdf0e10cSrcweir     // will be normal .-)
436cdf0e10cSrcweir     catch(const css::uno::Exception&)
437cdf0e10cSrcweir         {}
438cdf0e10cSrcweir     #endif // MIGRATE_OLD_USER_PATHES
439cdf0e10cSrcweir 
440cdf0e10cSrcweir     PathSettings::PathHash::iterator pPath = m_lPaths.find(sPath);
441cdf0e10cSrcweir     if (eOp == PathSettings::E_UNDEFINED)
442cdf0e10cSrcweir     {
443cdf0e10cSrcweir         if (pPath != m_lPaths.end())
444cdf0e10cSrcweir             eOp = PathSettings::E_CHANGED;
445cdf0e10cSrcweir         else
446cdf0e10cSrcweir             eOp = PathSettings::E_ADDED;
447cdf0e10cSrcweir     }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     switch(eOp)
450cdf0e10cSrcweir     {
451cdf0e10cSrcweir         case PathSettings::E_ADDED :
452cdf0e10cSrcweir              {
453cdf0e10cSrcweir                 if (bNotifyListener)
454cdf0e10cSrcweir                 {
455cdf0e10cSrcweir                     pPathOld = 0;
456cdf0e10cSrcweir                     pPathNew = &aPath;
457cdf0e10cSrcweir                     impl_notifyPropListener(eOp, sPath, pPathOld, pPathNew);
458cdf0e10cSrcweir                 }
459cdf0e10cSrcweir                 m_lPaths[sPath] = aPath;
460cdf0e10cSrcweir              }
461cdf0e10cSrcweir              break;
462cdf0e10cSrcweir 
463cdf0e10cSrcweir         case PathSettings::E_CHANGED :
464cdf0e10cSrcweir              {
465cdf0e10cSrcweir                 if (bNotifyListener)
466cdf0e10cSrcweir                 {
467cdf0e10cSrcweir                     pPathOld = &(pPath->second);
468cdf0e10cSrcweir                     pPathNew = &aPath;
469cdf0e10cSrcweir                     impl_notifyPropListener(eOp, sPath, pPathOld, pPathNew);
470cdf0e10cSrcweir                 }
471cdf0e10cSrcweir                 m_lPaths[sPath] = aPath;
472cdf0e10cSrcweir              }
473cdf0e10cSrcweir              break;
474cdf0e10cSrcweir 
475cdf0e10cSrcweir         case PathSettings::E_REMOVED :
476cdf0e10cSrcweir              {
477cdf0e10cSrcweir                 if (pPath != m_lPaths.end())
478cdf0e10cSrcweir                 {
479cdf0e10cSrcweir                     if (bNotifyListener)
480cdf0e10cSrcweir                     {
481cdf0e10cSrcweir                         pPathOld = &(pPath->second);
482cdf0e10cSrcweir                         pPathNew = 0;
483cdf0e10cSrcweir                         impl_notifyPropListener(eOp, sPath, pPathOld, pPathNew);
484cdf0e10cSrcweir                     }
485cdf0e10cSrcweir                     m_lPaths.erase(pPath);
486cdf0e10cSrcweir                 }
487cdf0e10cSrcweir              }
488cdf0e10cSrcweir              break;
489cdf0e10cSrcweir 
490cdf0e10cSrcweir         default: // to let compiler be happy
491cdf0e10cSrcweir              break;
492cdf0e10cSrcweir     }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     return eOp;
495cdf0e10cSrcweir }
496cdf0e10cSrcweir 
497cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_mapPathName2IDList(const::rtl::OUString & sPath)498cdf0e10cSrcweir css::uno::Sequence< sal_Int32 > PathSettings::impl_mapPathName2IDList(const ::rtl::OUString& sPath)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     ::rtl::OUString sOldStyleProp = sPath;
501cdf0e10cSrcweir     ::rtl::OUString sInternalProp = sPath+POSTFIX_INTERNAL_PATHES;
502cdf0e10cSrcweir     ::rtl::OUString sUserProp     = sPath+POSTFIX_USER_PATHES;
503cdf0e10cSrcweir     ::rtl::OUString sWriteProp    = sPath+POSTFIX_WRITE_PATH;
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     // Attention: The default set of IDs is fix and must follow these schema.
50615289133Smseidel     // Otherwise the outside code ant work for new added properties.
507cdf0e10cSrcweir     // Why ?
508cdf0e10cSrcweir     // The outside code must fire N events for every changed property.
509cdf0e10cSrcweir     // And the knowing about packaging of variables of the structure PathInfo
51007a3d7f1SPedro Giffuni     // follow these group IDs ! But if such ID isn't in the range of [0..IDGROUP_COUNT]
51107a3d7f1SPedro Giffuni     // the outside can't determine the right group ... and can't fire the right events .-)
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     css::uno::Sequence< sal_Int32 > lIDs(IDGROUP_COUNT);
514cdf0e10cSrcweir     lIDs[0] = IDGROUP_OLDSTYLE       ;
515cdf0e10cSrcweir     lIDs[1] = IDGROUP_INTERNAL_PATHES;
516cdf0e10cSrcweir     lIDs[2] = IDGROUP_USER_PATHES    ;
517cdf0e10cSrcweir     lIDs[3] = IDGROUP_WRITE_PATH     ;
518cdf0e10cSrcweir 
519cdf0e10cSrcweir     sal_Int32 c = m_lPropDesc.getLength();
520cdf0e10cSrcweir     sal_Int32 i = 0;
521cdf0e10cSrcweir     for (i=0; i<c; ++i)
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         const css::beans::Property& rProp = m_lPropDesc[i];
524cdf0e10cSrcweir 
525cdf0e10cSrcweir         if (rProp.Name.equals(sOldStyleProp))
526cdf0e10cSrcweir             lIDs[IDGROUP_OLDSTYLE] = rProp.Handle;
527cdf0e10cSrcweir         else
528cdf0e10cSrcweir         if (rProp.Name.equals(sInternalProp))
529cdf0e10cSrcweir             lIDs[IDGROUP_INTERNAL_PATHES] = rProp.Handle;
530cdf0e10cSrcweir         else
531cdf0e10cSrcweir         if (rProp.Name.equals(sUserProp))
532cdf0e10cSrcweir             lIDs[IDGROUP_USER_PATHES] = rProp.Handle;
533cdf0e10cSrcweir         else
534cdf0e10cSrcweir         if (rProp.Name.equals(sWriteProp))
535cdf0e10cSrcweir             lIDs[IDGROUP_WRITE_PATH] = rProp.Handle;
536cdf0e10cSrcweir     }
537cdf0e10cSrcweir 
538cdf0e10cSrcweir     return lIDs;
539cdf0e10cSrcweir }
540cdf0e10cSrcweir 
541cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_notifyPropListener(PathSettings::EChangeOp,const::rtl::OUString & sPath,const PathSettings::PathInfo * pPathOld,const PathSettings::PathInfo * pPathNew)542cdf0e10cSrcweir void PathSettings::impl_notifyPropListener(      PathSettings::EChangeOp /*eOp*/     ,
543cdf0e10cSrcweir                                            const ::rtl::OUString&        sPath   ,
544cdf0e10cSrcweir                                            const PathSettings::PathInfo* pPathOld,
545cdf0e10cSrcweir                                            const PathSettings::PathInfo* pPathNew)
546cdf0e10cSrcweir {
547cdf0e10cSrcweir     css::uno::Sequence< sal_Int32 >     lHandles(1);
548cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > lOldVals(1);
549cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > lNewVals(1);
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     css::uno::Sequence< sal_Int32 > lIDs   = impl_mapPathName2IDList(sPath);
552cdf0e10cSrcweir     sal_Int32                       c      = lIDs.getLength();
553cdf0e10cSrcweir     sal_Int32                       i      = 0;
554cdf0e10cSrcweir     sal_Int32                       nMaxID = m_lPropDesc.getLength()-1;
555cdf0e10cSrcweir     for (i=0; i<c; ++i)
556cdf0e10cSrcweir     {
557cdf0e10cSrcweir         sal_Int32 nID = lIDs[i];
558cdf0e10cSrcweir 
559cdf0e10cSrcweir         if (
560cdf0e10cSrcweir             (nID < 0     ) ||
561cdf0e10cSrcweir             (nID > nMaxID)
562cdf0e10cSrcweir            )
563cdf0e10cSrcweir            continue;
564cdf0e10cSrcweir 
565cdf0e10cSrcweir         lHandles[0] = nID;
566cdf0e10cSrcweir         switch(impl_getPropGroup(nID))
567cdf0e10cSrcweir         {
568cdf0e10cSrcweir             case IDGROUP_OLDSTYLE :
569cdf0e10cSrcweir                  {
570cdf0e10cSrcweir                     if (pPathOld)
571cdf0e10cSrcweir                     {
572cdf0e10cSrcweir                         ::rtl::OUString sVal = impl_convertPath2OldStyle(*pPathOld);
573cdf0e10cSrcweir                         lOldVals[0] <<= sVal;
574cdf0e10cSrcweir                     }
575cdf0e10cSrcweir                     if (pPathNew)
576cdf0e10cSrcweir                     {
577cdf0e10cSrcweir                         ::rtl::OUString sVal = impl_convertPath2OldStyle(*pPathNew);
578cdf0e10cSrcweir                         lNewVals[0] <<= sVal;
579cdf0e10cSrcweir                     }
580cdf0e10cSrcweir                  }
581cdf0e10cSrcweir                  break;
582cdf0e10cSrcweir 
583cdf0e10cSrcweir             case IDGROUP_INTERNAL_PATHES :
584cdf0e10cSrcweir                  {
585cdf0e10cSrcweir                     if (pPathOld)
586cdf0e10cSrcweir                         lOldVals[0] <<= pPathOld->lInternalPaths.getAsConstList();
587cdf0e10cSrcweir                     if (pPathNew)
588cdf0e10cSrcweir                         lNewVals[0] <<= pPathNew->lInternalPaths.getAsConstList();
589cdf0e10cSrcweir                  }
590cdf0e10cSrcweir                  break;
591cdf0e10cSrcweir 
592cdf0e10cSrcweir             case IDGROUP_USER_PATHES :
593cdf0e10cSrcweir                  {
594cdf0e10cSrcweir                     if (pPathOld)
595cdf0e10cSrcweir                         lOldVals[0] <<= pPathOld->lUserPaths.getAsConstList();
596cdf0e10cSrcweir                     if (pPathNew)
597cdf0e10cSrcweir                         lNewVals[0] <<= pPathNew->lUserPaths.getAsConstList();
598cdf0e10cSrcweir                  }
599cdf0e10cSrcweir                  break;
600cdf0e10cSrcweir 
601cdf0e10cSrcweir             case IDGROUP_WRITE_PATH :
602cdf0e10cSrcweir                  {
603cdf0e10cSrcweir                     if (pPathOld)
604cdf0e10cSrcweir                         lOldVals[0] <<= pPathOld->sWritePath;
605cdf0e10cSrcweir                     if (pPathNew)
606cdf0e10cSrcweir                         lNewVals[0] <<= pPathNew->sWritePath;
607cdf0e10cSrcweir                  }
608cdf0e10cSrcweir                  break;
609cdf0e10cSrcweir         }
610cdf0e10cSrcweir 
611cdf0e10cSrcweir         fire(lHandles.getArray(),
612cdf0e10cSrcweir              lNewVals.getArray(),
613cdf0e10cSrcweir              lOldVals.getArray(),
614cdf0e10cSrcweir              1,
615cdf0e10cSrcweir              sal_False);
616cdf0e10cSrcweir     }
617cdf0e10cSrcweir }
618cdf0e10cSrcweir 
619cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_subst(OUStringList & lVals,const css::uno::Reference<css::util::XStringSubstitution> & xSubst,sal_Bool bReSubst)620cdf0e10cSrcweir void PathSettings::impl_subst(      OUStringList&                                          lVals   ,
621cdf0e10cSrcweir                               const css::uno::Reference< css::util::XStringSubstitution >& xSubst  ,
622cdf0e10cSrcweir                                     sal_Bool                                               bReSubst)
623cdf0e10cSrcweir {
624cdf0e10cSrcweir     OUStringList::iterator pIt;
625cdf0e10cSrcweir 
626cdf0e10cSrcweir     for (  pIt  = lVals.begin();
627cdf0e10cSrcweir            pIt != lVals.end()  ;
628cdf0e10cSrcweir          ++pIt                 )
629cdf0e10cSrcweir     {
630cdf0e10cSrcweir         const ::rtl::OUString& sOld = *pIt;
631cdf0e10cSrcweir               ::rtl::OUString  sNew ;
632cdf0e10cSrcweir         if (bReSubst)
633cdf0e10cSrcweir             sNew = xSubst->reSubstituteVariables(sOld);
634cdf0e10cSrcweir         else
635cdf0e10cSrcweir             sNew = xSubst->substituteVariables(sOld, sal_False);
636cdf0e10cSrcweir 
637cdf0e10cSrcweir         *pIt = sNew;
638cdf0e10cSrcweir     }
639cdf0e10cSrcweir }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_subst(PathSettings::PathInfo & aPath,sal_Bool bReSubst)642cdf0e10cSrcweir void PathSettings::impl_subst(PathSettings::PathInfo& aPath   ,
643cdf0e10cSrcweir                               sal_Bool                bReSubst)
644cdf0e10cSrcweir {
645cdf0e10cSrcweir     css::uno::Reference< css::util::XStringSubstitution > xSubst = fa_getSubstitution();
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     impl_subst(aPath.lInternalPaths, xSubst, bReSubst);
648cdf0e10cSrcweir     impl_subst(aPath.lUserPaths    , xSubst, bReSubst);
649cdf0e10cSrcweir     if (bReSubst)
650cdf0e10cSrcweir         aPath.sWritePath = xSubst->reSubstituteVariables(aPath.sWritePath);
651cdf0e10cSrcweir     else
652cdf0e10cSrcweir         aPath.sWritePath = xSubst->substituteVariables(aPath.sWritePath, sal_False);
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_convertPath2OldStyle(const PathSettings::PathInfo & rPath) const656cdf0e10cSrcweir ::rtl::OUString PathSettings::impl_convertPath2OldStyle(const PathSettings::PathInfo& rPath) const
657cdf0e10cSrcweir {
658cdf0e10cSrcweir     OUStringList::const_iterator pIt;
659cdf0e10cSrcweir     OUStringList                 lTemp;
660cdf0e10cSrcweir     lTemp.reserve(rPath.lInternalPaths.size() + rPath.lUserPaths.size() + 1);
661cdf0e10cSrcweir 
662cdf0e10cSrcweir     for (  pIt  = rPath.lInternalPaths.begin();
663cdf0e10cSrcweir            pIt != rPath.lInternalPaths.end()  ;
664cdf0e10cSrcweir          ++pIt                                 )
665cdf0e10cSrcweir     {
666cdf0e10cSrcweir         lTemp.push_back(*pIt);
667cdf0e10cSrcweir     }
668cdf0e10cSrcweir     for (  pIt  = rPath.lUserPaths.begin();
669cdf0e10cSrcweir            pIt != rPath.lUserPaths.end()  ;
670cdf0e10cSrcweir          ++pIt                             )
671cdf0e10cSrcweir     {
672cdf0e10cSrcweir         lTemp.push_back(*pIt);
673cdf0e10cSrcweir     }
674cdf0e10cSrcweir 
675cdf0e10cSrcweir     if (rPath.sWritePath.getLength() > 0)
676cdf0e10cSrcweir         lTemp.push_back(rPath.sWritePath);
677cdf0e10cSrcweir 
678cdf0e10cSrcweir     ::rtl::OUStringBuffer sPathVal(256);
679cdf0e10cSrcweir     for (  pIt  = lTemp.begin();
680cdf0e10cSrcweir            pIt != lTemp.end()  ;
681cdf0e10cSrcweir                                )
682cdf0e10cSrcweir     {
683cdf0e10cSrcweir         sPathVal.append(*pIt);
684cdf0e10cSrcweir         ++pIt;
685cdf0e10cSrcweir         if (pIt != lTemp.end())
686cdf0e10cSrcweir             sPathVal.appendAscii(";");
687cdf0e10cSrcweir     }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir     return sPathVal.makeStringAndClear();
690cdf0e10cSrcweir }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_convertOldStyle2Path(const::rtl::OUString & sOldStylePath) const693cdf0e10cSrcweir OUStringList PathSettings::impl_convertOldStyle2Path(const ::rtl::OUString& sOldStylePath) const
694cdf0e10cSrcweir {
695cdf0e10cSrcweir     OUStringList lList;
696cdf0e10cSrcweir     sal_Int32    nToken = 0;
697cdf0e10cSrcweir     do
698cdf0e10cSrcweir     {
699cdf0e10cSrcweir         ::rtl::OUString sToken = sOldStylePath.getToken(0, ';', nToken);
700cdf0e10cSrcweir         if (sToken.getLength())
701cdf0e10cSrcweir             lList.push_back(sToken);
702cdf0e10cSrcweir     }
703cdf0e10cSrcweir     while(nToken >= 0);
704cdf0e10cSrcweir 
705cdf0e10cSrcweir     return lList;
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_purgeKnownPaths(const PathSettings::PathInfo & rPath,OUStringList & lList)709cdf0e10cSrcweir void PathSettings::impl_purgeKnownPaths(const PathSettings::PathInfo& rPath,
710cdf0e10cSrcweir                                                OUStringList&           lList)
711cdf0e10cSrcweir {
712cdf0e10cSrcweir     OUStringList::const_iterator pIt;
713cdf0e10cSrcweir     for (  pIt  = rPath.lInternalPaths.begin();
714cdf0e10cSrcweir            pIt != rPath.lInternalPaths.end()  ;
715cdf0e10cSrcweir          ++pIt                                 )
716cdf0e10cSrcweir     {
717cdf0e10cSrcweir         const ::rtl::OUString& rItem = *pIt;
718cdf0e10cSrcweir         OUStringList::iterator pItem = lList.find(rItem);
719cdf0e10cSrcweir         if (pItem != lList.end())
720cdf0e10cSrcweir             lList.erase(pItem);
721cdf0e10cSrcweir     }
722cdf0e10cSrcweir     for (  pIt  = rPath.lUserPaths.begin();
723cdf0e10cSrcweir            pIt != rPath.lUserPaths.end()  ;
724cdf0e10cSrcweir          ++pIt                             )
725cdf0e10cSrcweir     {
726cdf0e10cSrcweir         const ::rtl::OUString& rItem = *pIt;
727cdf0e10cSrcweir         OUStringList::iterator pItem = lList.find(rItem);
728cdf0e10cSrcweir         if (pItem != lList.end())
729cdf0e10cSrcweir             lList.erase(pItem);
730cdf0e10cSrcweir     }
731cdf0e10cSrcweir 
732cdf0e10cSrcweir     OUStringList::iterator pItem = lList.find(rPath.sWritePath);
733cdf0e10cSrcweir     if (pItem != lList.end())
734cdf0e10cSrcweir         lList.erase(pItem);
735cdf0e10cSrcweir }
736cdf0e10cSrcweir 
737cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_rebuildPropertyDescriptor()738cdf0e10cSrcweir void PathSettings::impl_rebuildPropertyDescriptor()
739cdf0e10cSrcweir {
740cdf0e10cSrcweir     // SAFE ->
741cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
742cdf0e10cSrcweir 
743cdf0e10cSrcweir     sal_Int32 c = (sal_Int32)m_lPaths.size();
744cdf0e10cSrcweir     sal_Int32 i = 0;
745cdf0e10cSrcweir     m_lPropDesc.realloc(c*IDGROUP_COUNT);
746cdf0e10cSrcweir 
747cdf0e10cSrcweir     PathHash::const_iterator pIt;
748cdf0e10cSrcweir     for (  pIt  = m_lPaths.begin();
749cdf0e10cSrcweir            pIt != m_lPaths.end()  ;
750cdf0e10cSrcweir          ++pIt                     )
751cdf0e10cSrcweir     {
752cdf0e10cSrcweir         const PathSettings::PathInfo& rPath = pIt->second;
753cdf0e10cSrcweir               css::beans::Property*   pProp = 0;
754cdf0e10cSrcweir 
755cdf0e10cSrcweir         pProp             = &(m_lPropDesc[i]);
756cdf0e10cSrcweir         pProp->Name       = rPath.sPathName;
757cdf0e10cSrcweir         pProp->Handle     = i;
758cdf0e10cSrcweir         pProp->Type       = ::getCppuType((::rtl::OUString*)0);
759cdf0e10cSrcweir         pProp->Attributes = css::beans::PropertyAttribute::BOUND;
760cdf0e10cSrcweir         if (rPath.bIsReadonly)
761cdf0e10cSrcweir             pProp->Attributes |= css::beans::PropertyAttribute::READONLY;
762cdf0e10cSrcweir         ++i;
763cdf0e10cSrcweir 
764cdf0e10cSrcweir         pProp             = &(m_lPropDesc[i]);
765cdf0e10cSrcweir         pProp->Name       = rPath.sPathName+POSTFIX_INTERNAL_PATHES;
766cdf0e10cSrcweir         pProp->Handle     = i;
767cdf0e10cSrcweir         pProp->Type       = ::getCppuType((css::uno::Sequence< ::rtl::OUString >*)0);
768cdf0e10cSrcweir         pProp->Attributes = css::beans::PropertyAttribute::BOUND   |
769cdf0e10cSrcweir                             css::beans::PropertyAttribute::READONLY;
770cdf0e10cSrcweir         ++i;
771cdf0e10cSrcweir 
772cdf0e10cSrcweir         pProp             = &(m_lPropDesc[i]);
773cdf0e10cSrcweir         pProp->Name       = rPath.sPathName+POSTFIX_USER_PATHES;
774cdf0e10cSrcweir         pProp->Handle     = i;
775cdf0e10cSrcweir         pProp->Type       = ::getCppuType((css::uno::Sequence< ::rtl::OUString >*)0);
776cdf0e10cSrcweir         pProp->Attributes = css::beans::PropertyAttribute::BOUND;
777cdf0e10cSrcweir         if (rPath.bIsReadonly)
778cdf0e10cSrcweir             pProp->Attributes |= css::beans::PropertyAttribute::READONLY;
779cdf0e10cSrcweir         ++i;
780cdf0e10cSrcweir 
781cdf0e10cSrcweir         pProp             = &(m_lPropDesc[i]);
782cdf0e10cSrcweir         pProp->Name       = rPath.sPathName+POSTFIX_WRITE_PATH;
783cdf0e10cSrcweir         pProp->Handle     = i;
784cdf0e10cSrcweir         pProp->Type       = ::getCppuType((::rtl::OUString*)0);
785cdf0e10cSrcweir         pProp->Attributes = css::beans::PropertyAttribute::BOUND;
786cdf0e10cSrcweir         if (rPath.bIsReadonly)
787cdf0e10cSrcweir             pProp->Attributes |= css::beans::PropertyAttribute::READONLY;
788cdf0e10cSrcweir         ++i;
789cdf0e10cSrcweir     }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir     if (m_pPropHelp)
792cdf0e10cSrcweir        delete m_pPropHelp;
793cdf0e10cSrcweir     m_pPropHelp = new ::cppu::OPropertyArrayHelper(m_lPropDesc, sal_False); // false => not sorted ... must be done inside helper
794cdf0e10cSrcweir 
795cdf0e10cSrcweir     aWriteLock.unlock();
796cdf0e10cSrcweir     // <- SAFE
797cdf0e10cSrcweir }
798cdf0e10cSrcweir 
799cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_getPathValue(sal_Int32 nID) const800cdf0e10cSrcweir css::uno::Any PathSettings::impl_getPathValue(sal_Int32 nID) const
801cdf0e10cSrcweir {
802cdf0e10cSrcweir     const PathSettings::PathInfo* pPath = impl_getPathAccessConst(nID);
803cdf0e10cSrcweir     if (! pPath)
804cdf0e10cSrcweir         throw css::container::NoSuchElementException();
805cdf0e10cSrcweir 
806cdf0e10cSrcweir     css::uno::Any aVal;
807cdf0e10cSrcweir     switch(impl_getPropGroup(nID))
808cdf0e10cSrcweir     {
809cdf0e10cSrcweir         case IDGROUP_OLDSTYLE :
810cdf0e10cSrcweir              {
811cdf0e10cSrcweir                 ::rtl::OUString sVal = impl_convertPath2OldStyle(*pPath);
812cdf0e10cSrcweir                 aVal <<= sVal;
813cdf0e10cSrcweir              }
814cdf0e10cSrcweir              break;
815cdf0e10cSrcweir 
816cdf0e10cSrcweir         case IDGROUP_INTERNAL_PATHES :
817cdf0e10cSrcweir              {
818cdf0e10cSrcweir                 aVal <<= pPath->lInternalPaths.getAsConstList();
819cdf0e10cSrcweir              }
820cdf0e10cSrcweir              break;
821cdf0e10cSrcweir 
822cdf0e10cSrcweir         case IDGROUP_USER_PATHES :
823cdf0e10cSrcweir              {
824cdf0e10cSrcweir                 aVal <<= pPath->lUserPaths.getAsConstList();
825cdf0e10cSrcweir              }
826cdf0e10cSrcweir              break;
827cdf0e10cSrcweir 
828cdf0e10cSrcweir         case IDGROUP_WRITE_PATH :
829cdf0e10cSrcweir              {
830cdf0e10cSrcweir                 aVal <<= pPath->sWritePath;
831cdf0e10cSrcweir              }
832cdf0e10cSrcweir              break;
833cdf0e10cSrcweir     }
834cdf0e10cSrcweir 
835cdf0e10cSrcweir     return aVal;
836cdf0e10cSrcweir }
837cdf0e10cSrcweir 
838cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_setPathValue(sal_Int32 nID,const css::uno::Any & aVal)839cdf0e10cSrcweir void PathSettings::impl_setPathValue(      sal_Int32      nID ,
840cdf0e10cSrcweir                                      const css::uno::Any& aVal)
841cdf0e10cSrcweir {
842cdf0e10cSrcweir     PathSettings::PathInfo* pOrgPath = impl_getPathAccess(nID);
843cdf0e10cSrcweir     if (! pOrgPath)
844cdf0e10cSrcweir         throw css::container::NoSuchElementException();
845cdf0e10cSrcweir 
846cdf0e10cSrcweir     // We work on a copied path ... so we can be sure that errors during this operation
847cdf0e10cSrcweir     // does not make our internal cache invalid .-)
848cdf0e10cSrcweir     PathSettings::PathInfo aChangePath(*pOrgPath);
849cdf0e10cSrcweir 
850cdf0e10cSrcweir     switch(impl_getPropGroup(nID))
851cdf0e10cSrcweir     {
852cdf0e10cSrcweir         case IDGROUP_OLDSTYLE :
853cdf0e10cSrcweir              {
854cdf0e10cSrcweir                 ::rtl::OUString sVal;
855cdf0e10cSrcweir                 aVal >>= sVal;
856cdf0e10cSrcweir                 OUStringList lList = impl_convertOldStyle2Path(sVal);
857cdf0e10cSrcweir                 impl_subst(lList, fa_getSubstitution(), sal_False);
858cdf0e10cSrcweir                 impl_purgeKnownPaths(aChangePath, lList);
859cdf0e10cSrcweir                 if (! impl_isValidPath(lList))
860cdf0e10cSrcweir                     throw css::lang::IllegalArgumentException();
861cdf0e10cSrcweir 
862cdf0e10cSrcweir                 if (aChangePath.bIsSinglePath)
863cdf0e10cSrcweir                 {
864cdf0e10cSrcweir                     LOG_ASSERT2(lList.size()>1, "PathSettings::impl_setPathValue()", "You try to set more then path value for a defined SINGLE_PATH!")
865cdf0e10cSrcweir                     if ( !lList.empty() )
866cdf0e10cSrcweir                         aChangePath.sWritePath = *(lList.begin());
867cdf0e10cSrcweir                     else
868cdf0e10cSrcweir                         aChangePath.sWritePath = ::rtl::OUString();
869cdf0e10cSrcweir                 }
870cdf0e10cSrcweir                 else
871cdf0e10cSrcweir                 {
872cdf0e10cSrcweir                     OUStringList::const_iterator pIt;
873cdf0e10cSrcweir                     for (  pIt  = lList.begin();
874cdf0e10cSrcweir                            pIt != lList.end()  ;
875cdf0e10cSrcweir                          ++pIt                 )
876cdf0e10cSrcweir                     {
877cdf0e10cSrcweir                         aChangePath.lUserPaths.push_back(*pIt);
878cdf0e10cSrcweir                     }
879cdf0e10cSrcweir                 }
880cdf0e10cSrcweir              }
881cdf0e10cSrcweir              break;
882cdf0e10cSrcweir 
883cdf0e10cSrcweir         case IDGROUP_INTERNAL_PATHES :
884cdf0e10cSrcweir              {
885cdf0e10cSrcweir                 if (aChangePath.bIsSinglePath)
886cdf0e10cSrcweir                 {
887cdf0e10cSrcweir                     ::rtl::OUStringBuffer sMsg(256);
888cdf0e10cSrcweir                     sMsg.appendAscii("The path '"    );
889cdf0e10cSrcweir                     sMsg.append     (aChangePath.sPathName);
89007a3d7f1SPedro Giffuni                     sMsg.appendAscii("' is defined as SINGLE_PATH. It's sub set of internal paths can't be set.");
891cdf0e10cSrcweir                     throw css::uno::Exception(sMsg.makeStringAndClear(),
892cdf0e10cSrcweir                                               static_cast< ::cppu::OWeakObject* >(this));
893cdf0e10cSrcweir                 }
894cdf0e10cSrcweir 
895cdf0e10cSrcweir                 OUStringList lList;
896cdf0e10cSrcweir                 lList << aVal;
897cdf0e10cSrcweir                 if (! impl_isValidPath(lList))
898cdf0e10cSrcweir                     throw css::lang::IllegalArgumentException();
899cdf0e10cSrcweir                 aChangePath.lInternalPaths = lList;
900cdf0e10cSrcweir              }
901cdf0e10cSrcweir              break;
902cdf0e10cSrcweir 
903cdf0e10cSrcweir         case IDGROUP_USER_PATHES :
904cdf0e10cSrcweir              {
905cdf0e10cSrcweir                 if (aChangePath.bIsSinglePath)
906cdf0e10cSrcweir                 {
907cdf0e10cSrcweir                     ::rtl::OUStringBuffer sMsg(256);
908cdf0e10cSrcweir                     sMsg.appendAscii("The path '"    );
909cdf0e10cSrcweir                     sMsg.append     (aChangePath.sPathName);
91007a3d7f1SPedro Giffuni                     sMsg.appendAscii("' is defined as SINGLE_PATH. It's sub set of internal paths can't be set.");
911cdf0e10cSrcweir                     throw css::uno::Exception(sMsg.makeStringAndClear(),
912cdf0e10cSrcweir                                               static_cast< ::cppu::OWeakObject* >(this));
913cdf0e10cSrcweir                 }
914cdf0e10cSrcweir 
915cdf0e10cSrcweir                 OUStringList lList;
916cdf0e10cSrcweir                 lList << aVal;
917cdf0e10cSrcweir                 if (! impl_isValidPath(lList))
918cdf0e10cSrcweir                     throw css::lang::IllegalArgumentException();
919cdf0e10cSrcweir                 aChangePath.lUserPaths = lList;
920cdf0e10cSrcweir              }
921cdf0e10cSrcweir              break;
922cdf0e10cSrcweir 
923cdf0e10cSrcweir         case IDGROUP_WRITE_PATH :
924cdf0e10cSrcweir              {
925cdf0e10cSrcweir                 ::rtl::OUString sVal;
926cdf0e10cSrcweir                 aVal >>= sVal;
927cdf0e10cSrcweir                 if (! impl_isValidPath(sVal))
928cdf0e10cSrcweir                     throw css::lang::IllegalArgumentException();
929cdf0e10cSrcweir                 aChangePath.sWritePath = sVal;
930cdf0e10cSrcweir              }
931cdf0e10cSrcweir              break;
932cdf0e10cSrcweir     }
933cdf0e10cSrcweir 
934cdf0e10cSrcweir     // TODO check if path has at least one path value set
935cdf0e10cSrcweir     // At least it depends from the feature using this path, if an empty path list is allowed.
936cdf0e10cSrcweir     /*
937cdf0e10cSrcweir     if (impl_isPathEmpty(aChangePath))
938cdf0e10cSrcweir     {
939cdf0e10cSrcweir         ::rtl::OUStringBuffer sMsg(256);
940cdf0e10cSrcweir         sMsg.appendAscii("The path '"    );
941cdf0e10cSrcweir         sMsg.append     (aChangePath.sPathName);
942cdf0e10cSrcweir         sMsg.appendAscii("' is empty now ... Not a real good idea.");
943cdf0e10cSrcweir         throw css::uno::Exception(sMsg.makeStringAndClear(),
944cdf0e10cSrcweir                                   static_cast< ::cppu::OWeakObject* >(this));
945cdf0e10cSrcweir     }
946cdf0e10cSrcweir     */
947cdf0e10cSrcweir 
948cdf0e10cSrcweir     // first we should try to store the changed (copied!) path ...
949*e901e6e4Smseidel     // In case an error occurs on saving time an exception is thrown ...
95030acf5e8Spfg     // If no exception occurs we can update our internal cache (means
951cdf0e10cSrcweir     // we can overwrite pOrgPath !
952cdf0e10cSrcweir     impl_storePath(aChangePath);
953cdf0e10cSrcweir     pOrgPath->takeOver(aChangePath);
954cdf0e10cSrcweir }
955cdf0e10cSrcweir 
956cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_isValidPath(const OUStringList & lPath) const957cdf0e10cSrcweir sal_Bool PathSettings::impl_isValidPath(const OUStringList& lPath) const
958cdf0e10cSrcweir {
959cdf0e10cSrcweir     OUStringList::const_iterator pIt;
960cdf0e10cSrcweir     for (  pIt  = lPath.begin();
961cdf0e10cSrcweir            pIt != lPath.end()  ;
962cdf0e10cSrcweir          ++pIt                 )
963cdf0e10cSrcweir     {
964cdf0e10cSrcweir         const ::rtl::OUString& rVal = *pIt;
965cdf0e10cSrcweir         if (! impl_isValidPath(rVal))
966cdf0e10cSrcweir             return sal_False;
967cdf0e10cSrcweir     }
968cdf0e10cSrcweir 
969cdf0e10cSrcweir     return sal_True;
970cdf0e10cSrcweir }
971cdf0e10cSrcweir 
972cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_isValidPath(const::rtl::OUString & sPath) const973cdf0e10cSrcweir sal_Bool PathSettings::impl_isValidPath(const ::rtl::OUString& sPath) const
974cdf0e10cSrcweir {
975cdf0e10cSrcweir     // allow empty path to reset a path.
97607a3d7f1SPedro Giffuni // idea by LLA to support empty paths
977cdf0e10cSrcweir //  if (sPath.getLength() == 0)
978cdf0e10cSrcweir //  {
979cdf0e10cSrcweir //      return sal_True;
980cdf0e10cSrcweir //  }
981cdf0e10cSrcweir 
982cdf0e10cSrcweir     return (! INetURLObject(sPath).HasError());
983cdf0e10cSrcweir }
984cdf0e10cSrcweir 
985cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_extractBaseFromPropName(const::rtl::OUString & sPropName)986cdf0e10cSrcweir ::rtl::OUString impl_extractBaseFromPropName(const ::rtl::OUString& sPropName)
987cdf0e10cSrcweir {
988cdf0e10cSrcweir     sal_Int32 i = -1;
989cdf0e10cSrcweir 
990cdf0e10cSrcweir     i = sPropName.indexOf(POSTFIX_INTERNAL_PATHES);
991cdf0e10cSrcweir     if (i > -1)
992cdf0e10cSrcweir         return sPropName.copy(0, i);
993cdf0e10cSrcweir     i = sPropName.indexOf(POSTFIX_USER_PATHES);
994cdf0e10cSrcweir     if (i > -1)
995cdf0e10cSrcweir         return sPropName.copy(0, i);
996cdf0e10cSrcweir     i = sPropName.indexOf(POSTFIX_WRITE_PATH);
997cdf0e10cSrcweir     if (i > -1)
998cdf0e10cSrcweir         return sPropName.copy(0, i);
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir     return sPropName;
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_getPathAccess(sal_Int32 nHandle)1004cdf0e10cSrcweir PathSettings::PathInfo* PathSettings::impl_getPathAccess(sal_Int32 nHandle)
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir     // SAFE ->
1007cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir     if (nHandle > (m_lPropDesc.getLength()-1))
1010cdf0e10cSrcweir         return 0;
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir     const css::beans::Property&            rProp = m_lPropDesc[nHandle];
1013cdf0e10cSrcweir           ::rtl::OUString                  sProp = impl_extractBaseFromPropName(rProp.Name);
1014cdf0e10cSrcweir           PathSettings::PathHash::iterator rPath = m_lPaths.find(sProp);
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir     if (rPath != m_lPaths.end())
1017cdf0e10cSrcweir        return &(rPath->second);
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir     return 0;
1020cdf0e10cSrcweir     // <- SAFE
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir //-----------------------------------------------------------------------------
impl_getPathAccessConst(sal_Int32 nHandle) const1024cdf0e10cSrcweir const PathSettings::PathInfo* PathSettings::impl_getPathAccessConst(sal_Int32 nHandle) const
1025cdf0e10cSrcweir {
1026cdf0e10cSrcweir     // SAFE ->
1027cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir     if (nHandle > (m_lPropDesc.getLength()-1))
1030cdf0e10cSrcweir         return 0;
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir     const css::beans::Property&                  rProp = m_lPropDesc[nHandle];
1033cdf0e10cSrcweir           ::rtl::OUString                        sProp = impl_extractBaseFromPropName(rProp.Name);
1034cdf0e10cSrcweir           PathSettings::PathHash::const_iterator rPath = m_lPaths.find(sProp);
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir     if (rPath != m_lPaths.end())
1037cdf0e10cSrcweir        return &(rPath->second);
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir     return 0;
1040cdf0e10cSrcweir     // <- SAFE
1041cdf0e10cSrcweir }
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir //-----------------------------------------------------------------------------
convertFastPropertyValue(css::uno::Any & aConvertedValue,css::uno::Any & aOldValue,sal_Int32 nHandle,const css::uno::Any & aValue)1044cdf0e10cSrcweir sal_Bool SAL_CALL PathSettings::convertFastPropertyValue(      css::uno::Any& aConvertedValue,
1045cdf0e10cSrcweir                                                                css::uno::Any& aOldValue      ,
1046cdf0e10cSrcweir                                                                sal_Int32      nHandle        ,
1047cdf0e10cSrcweir                                                          const css::uno::Any& aValue         )
1048cdf0e10cSrcweir     throw(css::lang::IllegalArgumentException)
1049cdf0e10cSrcweir {
1050cdf0e10cSrcweir     // throws NoSuchElementException !
1051cdf0e10cSrcweir     css::uno::Any aCurrentVal = impl_getPathValue(nHandle);
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir     return PropHelper::willPropertyBeChanged(
1054cdf0e10cSrcweir                 aCurrentVal,
1055cdf0e10cSrcweir                 aValue,
1056cdf0e10cSrcweir                 aOldValue,
1057cdf0e10cSrcweir                 aConvertedValue);
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir //-----------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const css::uno::Any & aValue)1061cdf0e10cSrcweir void SAL_CALL PathSettings::setFastPropertyValue_NoBroadcast(      sal_Int32      nHandle,
1062cdf0e10cSrcweir                                                              const css::uno::Any& aValue )
1063cdf0e10cSrcweir     throw(css::uno::Exception)
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir     // throws NoSuchElement- and IllegalArgumentException !
1066cdf0e10cSrcweir     impl_setPathValue(nHandle, aValue);
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir //-----------------------------------------------------------------------------
getFastPropertyValue(css::uno::Any & aValue,sal_Int32 nHandle) const1070cdf0e10cSrcweir void SAL_CALL PathSettings::getFastPropertyValue(css::uno::Any& aValue ,
1071cdf0e10cSrcweir                                                  sal_Int32      nHandle) const
1072cdf0e10cSrcweir {
1073cdf0e10cSrcweir     aValue = impl_getPathValue(nHandle);
1074cdf0e10cSrcweir }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir //-----------------------------------------------------------------------------
getInfoHelper()1077cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& SAL_CALL PathSettings::getInfoHelper()
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir     return *m_pPropHelp;
1080cdf0e10cSrcweir }
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir //-----------------------------------------------------------------------------
getPropertySetInfo()1083cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL PathSettings::getPropertySetInfo()
1084cdf0e10cSrcweir     throw(css::uno::RuntimeException)
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir     return css::uno::Reference< css::beans::XPropertySetInfo >(createPropertySetInfo(getInfoHelper()));
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir //-----------------------------------------------------------------------------
fa_getSubstitution()1090cdf0e10cSrcweir css::uno::Reference< css::util::XStringSubstitution > PathSettings::fa_getSubstitution()
1091cdf0e10cSrcweir {
1092cdf0e10cSrcweir     // SAFE ->
1093cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1094cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
1095cdf0e10cSrcweir     css::uno::Reference< css::util::XStringSubstitution >  xSubst = m_xSubstitution;
1096cdf0e10cSrcweir     aReadLock.unlock();
1097cdf0e10cSrcweir     // <- SAFE
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir     if (! xSubst.is())
1100cdf0e10cSrcweir     {
1101cdf0e10cSrcweir         // create the needed substitution service.
1102*e901e6e4Smseidel         // We must replace all used variables inside read path values.
110307a3d7f1SPedro Giffuni         // In case we can't do so ... the whole office can't work really.
1104cfd52e18Smseidel         // That's why it seems to be OK to throw a RuntimeException then.
1105cdf0e10cSrcweir         xSubst = css::uno::Reference< css::util::XStringSubstitution >(
1106cdf0e10cSrcweir                                 xSMGR->createInstance(SERVICENAME_SUBSTITUTEPATHVARIABLES),
1107cdf0e10cSrcweir                                 css::uno::UNO_QUERY_THROW);
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir         // SAFE ->
1110cdf0e10cSrcweir         WriteGuard aWriteLock(m_aLock);
1111cdf0e10cSrcweir         m_xSubstitution = xSubst;
1112cdf0e10cSrcweir         aWriteLock.unlock();
1113cdf0e10cSrcweir     }
1114cdf0e10cSrcweir 
1115cdf0e10cSrcweir     return xSubst;
1116cdf0e10cSrcweir }
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir //-----------------------------------------------------------------------------
fa_getCfgOld()1119cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > PathSettings::fa_getCfgOld()
1120cdf0e10cSrcweir {
1121cdf0e10cSrcweir     const static ::rtl::OUString CFG_NODE_OLD = ::rtl::OUString::createFromAscii("org.openoffice.Office.Common/Path/Current");
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir     // SAFE ->
1124cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1125cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
1126cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess >     xCfg  = m_xCfgOld;
1127cdf0e10cSrcweir     aReadLock.unlock();
1128cdf0e10cSrcweir     // <- SAFE
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir     if (! xCfg.is())
1131cdf0e10cSrcweir     {
1132cdf0e10cSrcweir         xCfg = css::uno::Reference< css::container::XNameAccess >(
1133cdf0e10cSrcweir                    ::comphelper::ConfigurationHelper::openConfig(
1134cdf0e10cSrcweir                         xSMGR,
1135cdf0e10cSrcweir                         CFG_NODE_OLD,
113607a3d7f1SPedro Giffuni                         ::comphelper::ConfigurationHelper::E_STANDARD), // not readonly! Sometimes we need write access there !!!
1137cdf0e10cSrcweir                    css::uno::UNO_QUERY_THROW);
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir         // SAFE ->
1140cdf0e10cSrcweir         WriteGuard aWriteLock(m_aLock);
1141cdf0e10cSrcweir         m_xCfgOld = xCfg;
1142cdf0e10cSrcweir         aWriteLock.unlock();
1143cdf0e10cSrcweir     }
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir     return xCfg;
1146cdf0e10cSrcweir }
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir //-----------------------------------------------------------------------------
fa_getCfgNew()1149cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > PathSettings::fa_getCfgNew()
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir     const static ::rtl::OUString CFG_NODE_NEW = ::rtl::OUString::createFromAscii("org.openoffice.Office.Paths/Paths");
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir     // SAFE ->
1154cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
1155cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
1156cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess >     xCfg  = m_xCfgNew;
1157cdf0e10cSrcweir     aReadLock.unlock();
1158cdf0e10cSrcweir     // <- SAFE
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir     if (! xCfg.is())
1161cdf0e10cSrcweir     {
1162cdf0e10cSrcweir         xCfg = css::uno::Reference< css::container::XNameAccess >(
1163cdf0e10cSrcweir                    ::comphelper::ConfigurationHelper::openConfig(
1164cdf0e10cSrcweir                         xSMGR,
1165cdf0e10cSrcweir                         CFG_NODE_NEW,
1166cdf0e10cSrcweir                         ::comphelper::ConfigurationHelper::E_STANDARD),
1167cdf0e10cSrcweir                    css::uno::UNO_QUERY_THROW);
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir         // SAFE ->
1170cdf0e10cSrcweir         WriteGuard aWriteLock(m_aLock);
1171cdf0e10cSrcweir         m_xCfgNew = xCfg;
1172cdf0e10cSrcweir         aWriteLock.unlock();
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir         css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(xCfg, css::uno::UNO_QUERY_THROW);
1175cdf0e10cSrcweir         xBroadcaster->addChangesListener(static_cast< css::util::XChangesListener* >(this));
1176cdf0e10cSrcweir     }
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir     return xCfg;
1179cdf0e10cSrcweir }
1180cdf0e10cSrcweir 
1181cdf0e10cSrcweir } // namespace framework
1182*e901e6e4Smseidel 
1183*e901e6e4Smseidel /* vim: set noet sw=4 ts=4: */
1184