update dev300-m58
[ooovba.git] / framework / source / inc / pattern / configuration.hxx
blob94728bcb24094a34f414bf222e3312eb5bccfa96
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: configuration.hxx,v $
10 * $Revision: 1.4 $
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 //_______________________________________________
35 // own includes
37 #include <services.h>
38 #include <general.h>
40 //_______________________________________________
41 // interface includes
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>
47 #endif
48 #include <com/sun/star/uno/XInterface.hpp>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 //_______________________________________________
52 // other includes
53 #include <rtl/ustrbuf.hxx>
55 //_______________________________________________
56 // namespaces
58 #ifndef css
59 namespace css = ::com::sun::star;
60 #endif
62 namespace framework{
63 namespace pattern{
64 namespace configuration{
66 //_______________________________________________
67 // definitions
69 //-----------------------------------------------
70 class ConfigurationHelper
72 //-------------------------------------------
73 // const
74 public:
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!
83 enum EOpenMode
85 /// open it readonly (default=readwrite!)
86 E_READONLY = 1,
87 /// disable fallback handling for localized cfg nodes
88 E_ALL_LOCALES = 2
91 //-------------------------------------------
92 // interface
93 public:
95 //---------------------------------------
96 /**
97 @short opens a configuration access.
99 @descr TODO
101 @param xSMGR
102 this method need an uno service manager for internal work.
104 @param sPackage
105 name the configuration file.
106 e.g. "/.org.openoffice.Setup"
107 Note: It must start with "/" but end without(!) "/"!
109 @param sRelPath
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.
117 @param nOpenFlags
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);
143 sal_Int32 c = 1;
144 if (bAllLocales)
145 c = 2;
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;
154 if (bAllLocales)
156 aParam.Name = ::rtl::OUString::createFromAscii("*");
157 aParam.Value <<= sal_True;
158 lParams[1] <<= aParam;
161 if (bReadOnly)
162 xCFG = xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS, lParams);
163 else
164 xCFG = xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGUPDATEACCESS, lParams);
166 catch(const css::uno::RuntimeException& exRun)
167 { throw exRun; }
168 catch(const css::uno::Exception&)
169 { xCFG.clear(); }
171 return xCFG;
175 } // namespace configuration
176 } // namespace pattern
177 } // namespace framework
179 #endif // __FRAMEWORK_PATTERN_CONFIGURATION_HXX_