1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: configuration.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_PATTERN_CONFIGURATION_HXX_
32 #define __FRAMEWORK_PATTERN_CONFIGURATION_HXX_
34 //_______________________________________________
40 //_______________________________________________
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <com/sun/star/uno/Any.hxx>
45 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HXX_
46 #include <com/sun/star/beans/PropertyValue.hpp>
48 #include <com/sun/star/uno/XInterface.hpp>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 //_______________________________________________
53 #include <rtl/ustrbuf.hxx>
55 //_______________________________________________
59 namespace css
= ::com::sun::star
;
64 namespace configuration
{
66 //_______________________________________________
69 //-----------------------------------------------
70 class ConfigurationHelper
72 //-------------------------------------------
76 //---------------------------------------
77 /** @short allow opening of a configuration access
78 in different working modes.
80 @descr All enum values must be useable as flags
81 mapped into a int32 value!
85 /// open it readonly (default=readwrite!)
87 /// disable fallback handling for localized cfg nodes
91 //-------------------------------------------
95 //---------------------------------------
97 @short opens a configuration access.
102 this method need an uno service manager for internal work.
105 name the configuration file.
106 e.g. "/.org.openoffice.Setup"
107 Note: It must start with "/" but end without(!) "/"!
110 describe the relativ path of the requested key inside
111 the specified package.
112 e.g. "Office/Factories"
113 Note: Its not allowed to start or end with a "/"!
114 Further you must use encoded path elements if
115 e.g. set nodes are involved.
118 force opening of the configuration access in special mode.
119 see enum EOpenMode for further informations.
121 static css::uno::Reference
< css::uno::XInterface
> openConfig(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
122 const ::rtl::OUString
& sPackage
,
123 const ::rtl::OUString
& sRelPath
,
124 sal_Int32 nOpenFlags
)
126 static ::rtl::OUString PATH_SEPERATOR
= ::rtl::OUString::createFromAscii("/");
128 css::uno::Reference
< css::uno::XInterface
> xCFG
;
132 css::uno::Reference
< css::lang::XMultiServiceFactory
> xConfigProvider(
133 xSMGR
->createInstance(SERVICENAME_CFGPROVIDER
), css::uno::UNO_QUERY_THROW
);
135 ::rtl::OUStringBuffer
sPath(1024);
136 sPath
.append(sPackage
);
137 sPath
.append(PATH_SEPERATOR
);
138 sPath
.append(sRelPath
);
140 sal_Bool bReadOnly
= ((nOpenFlags
& ConfigurationHelper::E_READONLY
) == ConfigurationHelper::E_READONLY
);
141 sal_Bool bAllLocales
= ((nOpenFlags
& ConfigurationHelper::E_ALL_LOCALES
) == ConfigurationHelper::E_ALL_LOCALES
);
147 css::uno::Sequence
< css::uno::Any
> lParams(c
);
148 css::beans::PropertyValue aParam
;
150 aParam
.Name
= ::rtl::OUString::createFromAscii("nodepath");
151 aParam
.Value
<<= sPath
.makeStringAndClear();
152 lParams
[0] <<= aParam
;
156 aParam
.Name
= ::rtl::OUString::createFromAscii("*");
157 aParam
.Value
<<= sal_True
;
158 lParams
[1] <<= aParam
;
162 xCFG
= xConfigProvider
->createInstanceWithArguments(SERVICENAME_CFGREADACCESS
, lParams
);
164 xCFG
= xConfigProvider
->createInstanceWithArguments(SERVICENAME_CFGUPDATEACCESS
, lParams
);
166 catch(const css::uno::RuntimeException
& exRun
)
168 catch(const css::uno::Exception
&)
175 } // namespace configuration
176 } // namespace pattern
177 } // namespace framework
179 #endif // __FRAMEWORK_PATTERN_CONFIGURATION_HXX_