Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef __FRAMEWORK_PATTERN_CONFIGURATION_HXX_
30 : : #define __FRAMEWORK_PATTERN_CONFIGURATION_HXX_
31 : :
32 : : #include <services.h>
33 : : #include <general.h>
34 : :
35 : : #include <com/sun/star/uno/Sequence.hxx>
36 : : #include <com/sun/star/uno/Any.hxx>
37 : :
38 : : #include <com/sun/star/beans/PropertyValue.hpp>
39 : : #include <com/sun/star/uno/XInterface.hpp>
40 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 : :
42 : : #include <rtl/ustrbuf.hxx>
43 : :
44 : : #ifndef css
45 : : namespace css = ::com::sun::star;
46 : : #endif
47 : :
48 : : namespace framework{
49 : : namespace pattern{
50 : : namespace configuration{
51 : :
52 : : //-----------------------------------------------
53 : : class ConfigurationHelper
54 : : {
55 : :
56 : : public:
57 : :
58 : : //---------------------------------------
59 : : /** @short allow opening of a configuration access
60 : : in different working modes.
61 : :
62 : : @descr All enum values must be useable as flags
63 : : mapped into a int32 value!
64 : : */
65 : : enum EOpenMode
66 : : {
67 : : /// open it readonly (default=readwrite!)
68 : : E_READONLY = 1,
69 : : /// disable fallback handling for localized cfg nodes
70 : : E_ALL_LOCALES = 2
71 : : };
72 : :
73 : : //-------------------------------------------
74 : : // interface
75 : : public:
76 : :
77 : : //---------------------------------------
78 : : /**
79 : : @short opens a configuration access.
80 : :
81 : : @descr TODO
82 : :
83 : : @param xSMGR
84 : : this method need an uno service manager for internal work.
85 : :
86 : : @param sPackage
87 : : name the configuration file.
88 : : e.g. "/.org.openoffice.Setup"
89 : : Note: It must start with "/" but end without(!) "/"!
90 : :
91 : : @param sRelPath
92 : : describe the relativ path of the requested key inside
93 : : the specified package.
94 : : e.g. "Office/Factories"
95 : : Note: Its not allowed to start or end with a "/"!
96 : : Further you must use encoded path elements if
97 : : e.g. set nodes are involved.
98 : :
99 : : @param nOpenFlags
100 : : force opening of the configuration access in special mode.
101 : : see enum EOpenMode for further informations.
102 : : */
103 : 6443 : static css::uno::Reference< css::uno::XInterface > openConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
104 : : const ::rtl::OUString& sPackage ,
105 : : const ::rtl::OUString& sRelPath ,
106 : : sal_Int32 nOpenFlags)
107 : : {
108 : 6443 : css::uno::Reference< css::uno::XInterface > xCFG;
109 : :
110 : : try
111 : : {
112 : : css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider(
113 [ + - ][ + - ]: 6443 : xSMGR->createInstance(SERVICENAME_CFGPROVIDER), css::uno::UNO_QUERY_THROW);
[ + - ][ + - ]
114 : :
115 : 6443 : ::rtl::OUStringBuffer sPath(1024);
116 [ + - ]: 6443 : sPath.append(sPackage );
117 [ + - ]: 6443 : sPath.append(static_cast<sal_Unicode>('/'));
118 [ + - ]: 6443 : sPath.append(sRelPath );
119 : :
120 : 6443 : sal_Bool bReadOnly = ((nOpenFlags & ConfigurationHelper::E_READONLY ) == ConfigurationHelper::E_READONLY );
121 : 6443 : sal_Bool bAllLocales = ((nOpenFlags & ConfigurationHelper::E_ALL_LOCALES) == ConfigurationHelper::E_ALL_LOCALES);
122 : :
123 : 6443 : sal_Int32 c = 1;
124 [ - + ]: 6443 : if (bAllLocales)
125 : 0 : c = 2;
126 : :
127 [ + - ]: 6443 : css::uno::Sequence< css::uno::Any > lParams(c);
128 : 6443 : css::beans::PropertyValue aParam;
129 : :
130 : 6443 : aParam.Name = ::rtl::OUString("nodepath");
131 [ + - ][ + - ]: 6443 : aParam.Value <<= sPath.makeStringAndClear();
132 [ + - ][ + - ]: 6443 : lParams[0] <<= aParam;
133 : :
134 [ - + ]: 6443 : if (bAllLocales)
135 : : {
136 : 0 : aParam.Name = ::rtl::OUString("*");
137 [ # # ]: 0 : aParam.Value <<= sal_True;
138 [ # # ][ # # ]: 0 : lParams[1] <<= aParam;
139 : : }
140 : :
141 [ + - ]: 6443 : if (bReadOnly)
142 [ + - ][ + - ]: 6443 : xCFG = xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS, lParams);
[ + - ][ + - ]
143 : : else
144 [ # # ][ # # ]: 6443 : xCFG = xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGUPDATEACCESS, lParams);
[ # # ][ # # ]
[ + - ]
145 : : }
146 [ # # # ]: 0 : catch(const css::uno::RuntimeException& exRun)
147 [ # # ]: 0 : { throw exRun; }
148 [ # # ]: 0 : catch(const css::uno::Exception&)
149 : 0 : { xCFG.clear(); }
150 : :
151 : 6443 : return xCFG;
152 : : }
153 : : };
154 : :
155 : : } // namespace configuration
156 : : } // namespace pattern
157 : : } // namespace framework
158 : :
159 : : #endif // __FRAMEWORK_PATTERN_CONFIGURATION_HXX_
160 : :
161 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|