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 : : #include "PresenterConfigurationAccess.hxx"
30 : :
31 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 : : #include <com/sun/star/beans/PropertyValue.hpp>
33 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
34 : : #include <com/sun/star/util/XChangesBatch.hpp>
35 : :
36 : : using namespace ::com::sun::star;
37 : : using namespace ::com::sun::star::uno;
38 : : using ::rtl::OUString;
39 : :
40 : : #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
41 : :
42 : : namespace sdext { namespace presenter {
43 : :
44 : 8 : const ::rtl::OUString PresenterConfigurationAccess::msPresenterScreenRootName =
45 : : A2S("/org.openoffice.Office.extension.PresenterScreen/");
46 : :
47 : 0 : PresenterConfigurationAccess::PresenterConfigurationAccess (
48 : : const Reference<XComponentContext>& rxContext,
49 : : const OUString& rsRootName,
50 : : WriteMode eMode)
51 : : : mxRoot(),
52 : 0 : maNode()
53 : : {
54 : : try
55 : : {
56 [ # # ][ # # ]: 0 : Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
57 [ # # ]: 0 : if (xFactory.is())
58 : : {
59 [ # # ]: 0 : Sequence<Any> aCreationArguments(3);
60 [ # # ]: 0 : aCreationArguments[0] = makeAny(beans::PropertyValue(
61 : : A2S("nodepath"),
62 : : 0,
63 : : makeAny(rsRootName),
64 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
65 [ # # ]: 0 : aCreationArguments[1] = makeAny(beans::PropertyValue(
66 : : A2S("depth"),
67 : : 0,
68 : : makeAny((sal_Int32)-1),
69 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
70 [ # # ]: 0 : aCreationArguments[2] = makeAny(beans::PropertyValue(
71 : : A2S("lazywrite"),
72 : : 0,
73 : : makeAny(true),
74 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
75 : :
76 : 0 : OUString sAccessService;
77 [ # # ]: 0 : if (eMode == READ_ONLY)
78 [ # # ]: 0 : sAccessService = A2S("com.sun.star.configuration.ConfigurationAccess");
79 : : else
80 [ # # ]: 0 : sAccessService = A2S("com.sun.star.configuration.ConfigurationUpdateAccess");
81 : :
82 : : Reference<lang::XMultiServiceFactory> xProvider (
83 [ # # ]: 0 : xFactory->createInstanceWithContext(
84 : : A2S("com.sun.star.configuration.ConfigurationProvider"),
85 : 0 : rxContext),
86 [ # # ][ # # ]: 0 : UNO_QUERY_THROW);
[ # # ]
87 [ # # ]: 0 : mxRoot = xProvider->createInstanceWithArguments(
88 [ # # ][ # # ]: 0 : sAccessService, aCreationArguments);
89 [ # # ][ # # ]: 0 : maNode <<= mxRoot;
90 [ # # ]: 0 : }
91 : : }
92 [ # # ]: 0 : catch (const Exception& rException)
93 : : {
94 : : OSL_TRACE ("caught exception while opening configuration: %s",
95 : : ::rtl::OUStringToOString(rException.Message,
96 : : RTL_TEXTENCODING_UTF8).getStr());
97 : : }
98 : 0 : }
99 : :
100 : 0 : PresenterConfigurationAccess::~PresenterConfigurationAccess (void)
101 : : {
102 : 0 : }
103 : :
104 : 0 : bool PresenterConfigurationAccess::IsValid (void) const
105 : : {
106 : 0 : return mxRoot.is();
107 : : }
108 : :
109 : 0 : Any PresenterConfigurationAccess::GetConfigurationNode (const OUString& sPathToNode)
110 : : {
111 : : return GetConfigurationNode(
112 : : Reference<container::XHierarchicalNameAccess>(mxRoot, UNO_QUERY),
113 [ # # ]: 0 : sPathToNode);
114 : : }
115 : :
116 : 0 : bool PresenterConfigurationAccess::GoToChild (const ::rtl::OUString& rsPathToNode)
117 : : {
118 [ # # ]: 0 : if ( ! IsValid())
119 : 0 : return false;
120 : :
121 [ # # ]: 0 : Reference<container::XHierarchicalNameAccess> xNode (maNode, UNO_QUERY);
122 [ # # ]: 0 : if (xNode.is())
123 : : {
124 : : maNode = GetConfigurationNode(
125 : : Reference<container::XHierarchicalNameAccess>(maNode, UNO_QUERY),
126 [ # # ][ # # ]: 0 : rsPathToNode);
127 [ # # ][ # # ]: 0 : if (Reference<XInterface>(maNode, UNO_QUERY).is())
128 : 0 : return true;
129 : : }
130 : :
131 [ # # ]: 0 : mxRoot = NULL;
132 : 0 : return false;
133 : : }
134 : :
135 : 0 : bool PresenterConfigurationAccess::GoToChild (const Predicate& rPredicate)
136 : : {
137 [ # # ]: 0 : if ( ! IsValid())
138 : 0 : return false;
139 : :
140 [ # # ]: 0 : maNode = Find(Reference<container::XNameAccess>(maNode,UNO_QUERY), rPredicate);
141 [ # # ]: 0 : if (Reference<XInterface>(maNode, UNO_QUERY).is())
142 : 0 : return true;
143 : :
144 : 0 : mxRoot = NULL;
145 : 0 : return false;
146 : : }
147 : :
148 : 0 : bool PresenterConfigurationAccess::SetProperty (
149 : : const ::rtl::OUString& rsPropertyName,
150 : : const Any& rValue)
151 : : {
152 [ # # ]: 0 : Reference<beans::XPropertySet> xProperties (maNode, UNO_QUERY);
153 [ # # ]: 0 : if (xProperties.is())
154 : : {
155 [ # # ][ # # ]: 0 : xProperties->setPropertyValue(rsPropertyName, rValue);
156 : 0 : return true;
157 : : }
158 : : else
159 : 0 : return false;
160 : : }
161 : :
162 : 0 : Any PresenterConfigurationAccess::GetConfigurationNode (
163 : : const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
164 : : const OUString& sPathToNode)
165 : : {
166 [ # # ]: 0 : if (sPathToNode.isEmpty())
167 : 0 : return Any(rxNode);
168 : :
169 : : try
170 : : {
171 [ # # ]: 0 : if (rxNode.is())
172 : : {
173 [ # # ][ # # ]: 0 : return rxNode->getByHierarchicalName(sPathToNode);
174 : : }
175 : : }
176 : 0 : catch (const Exception& rException)
177 : : {
178 : : OSL_TRACE ("caught exception while getting configuration node %s: %s",
179 : : ::rtl::OUStringToOString(sPathToNode, RTL_TEXTENCODING_UTF8).getStr(),
180 : : ::rtl::OUStringToOString(rException.Message, RTL_TEXTENCODING_UTF8).getStr());
181 : : }
182 : :
183 [ # # ]: 0 : return Any();
184 : : }
185 : :
186 : 0 : Reference<beans::XPropertySet> PresenterConfigurationAccess::GetNodeProperties (
187 : : const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
188 : : const ::rtl::OUString& rsPathToNode)
189 : : {
190 [ # # ]: 0 : return Reference<beans::XPropertySet>(GetConfigurationNode(rxNode, rsPathToNode), UNO_QUERY);
191 : : }
192 : :
193 : 0 : void PresenterConfigurationAccess::CommitChanges (void)
194 : : {
195 [ # # ]: 0 : Reference<util::XChangesBatch> xConfiguration (mxRoot, UNO_QUERY);
196 [ # # ]: 0 : if (xConfiguration.is())
197 [ # # ][ # # ]: 0 : xConfiguration->commitChanges();
198 : 0 : }
199 : :
200 : 0 : void PresenterConfigurationAccess::ForAll (
201 : : const Reference<container::XNameAccess>& rxContainer,
202 : : const ::std::vector<OUString>& rArguments,
203 : : const ItemProcessor& rProcessor)
204 : : {
205 [ # # ]: 0 : if (rxContainer.is())
206 : : {
207 [ # # ]: 0 : ::std::vector<Any> aValues(rArguments.size());
208 [ # # ][ # # ]: 0 : Sequence<OUString> aKeys (rxContainer->getElementNames());
209 [ # # ]: 0 : for (sal_Int32 nItemIndex=0; nItemIndex<aKeys.getLength(); ++nItemIndex)
210 : : {
211 : 0 : bool bHasAllValues (true);
212 [ # # ]: 0 : const OUString& rsKey (aKeys[nItemIndex]);
213 [ # # ][ # # ]: 0 : Reference<container::XNameAccess> xSetItem (rxContainer->getByName(rsKey), UNO_QUERY);
[ # # ]
214 [ # # ]: 0 : Reference<beans::XPropertySet> xSet (xSetItem, UNO_QUERY);
215 : : OSL_ASSERT(xSet.is());
216 [ # # ]: 0 : if (xSetItem.is())
217 : : {
218 : : // Get from the current item of the container the children
219 : : // that match the names in the rArguments list.
220 [ # # ]: 0 : for (sal_uInt32 nValueIndex=0; nValueIndex<aValues.size(); ++nValueIndex)
221 : : {
222 [ # # ][ # # ]: 0 : if ( ! xSetItem->hasByName(rArguments[nValueIndex]))
[ # # ]
223 : 0 : bHasAllValues = false;
224 : : else
225 [ # # ][ # # ]: 0 : aValues[nValueIndex] = xSetItem->getByName(rArguments[nValueIndex]);
226 : : }
227 : : }
228 : : else
229 : 0 : bHasAllValues = false;
230 [ # # ]: 0 : if (bHasAllValues)
231 [ # # ]: 0 : rProcessor(rsKey,aValues);
232 [ # # ]: 0 : }
233 : : }
234 : 0 : }
235 : :
236 : 0 : void PresenterConfigurationAccess::ForAll (
237 : : const Reference<container::XNameAccess>& rxContainer,
238 : : const PropertySetProcessor& rProcessor)
239 : : {
240 [ # # ]: 0 : if (rxContainer.is())
241 : : {
242 [ # # ][ # # ]: 0 : Sequence<OUString> aKeys (rxContainer->getElementNames());
243 [ # # ]: 0 : for (sal_Int32 nItemIndex=0; nItemIndex<aKeys.getLength(); ++nItemIndex)
244 : : {
245 [ # # ]: 0 : const OUString& rsKey (aKeys[nItemIndex]);
246 [ # # ][ # # ]: 0 : Reference<beans::XPropertySet> xSet (rxContainer->getByName(rsKey), UNO_QUERY);
[ # # ]
247 [ # # ]: 0 : if (xSet.is())
248 [ # # ]: 0 : rProcessor(rsKey, xSet);
249 [ # # ]: 0 : }
250 : : }
251 : 0 : }
252 : :
253 : 0 : Any PresenterConfigurationAccess::Find (
254 : : const Reference<container::XNameAccess>& rxContainer,
255 : : const Predicate& rPredicate)
256 : : {
257 [ # # ]: 0 : if (rxContainer.is())
258 : : {
259 [ # # ][ # # ]: 0 : Sequence<OUString> aKeys (rxContainer->getElementNames());
260 [ # # ]: 0 : for (sal_Int32 nItemIndex=0; nItemIndex<aKeys.getLength(); ++nItemIndex)
261 : : {
262 : : Reference<beans::XPropertySet> xProperties (
263 [ # # ][ # # ]: 0 : rxContainer->getByName(aKeys[nItemIndex]),
264 [ # # ][ # # ]: 0 : UNO_QUERY);
265 [ # # ]: 0 : if (xProperties.is())
266 [ # # ][ # # ]: 0 : if (rPredicate(aKeys[nItemIndex], xProperties))
[ # # ]
267 [ # # ]: 0 : return Any(xProperties);
268 [ # # ][ # # ]: 0 : }
[ # # ]
269 : : }
270 : 0 : return Any();
271 : : }
272 : :
273 : 0 : bool PresenterConfigurationAccess::IsStringPropertyEqual (
274 : : const ::rtl::OUString& rsValue,
275 : : const ::rtl::OUString& rsPropertyName,
276 : : const css::uno::Reference<css::beans::XPropertySet>& rxNode)
277 : : {
278 : 0 : OUString sValue;
279 [ # # ][ # # ]: 0 : if (GetProperty(rxNode, rsPropertyName) >>= sValue)
280 : 0 : return sValue == rsValue;
281 : : else
282 : 0 : return false;
283 : : }
284 : :
285 : 0 : Any PresenterConfigurationAccess::GetProperty (
286 : : const Reference<beans::XPropertySet>& rxProperties,
287 : : const OUString& rsKey)
288 : : {
289 : : OSL_ASSERT(rxProperties.is());
290 [ # # ]: 0 : if ( ! rxProperties.is())
291 : 0 : return Any();
292 : : try
293 : : {
294 [ # # ][ # # ]: 0 : Reference<beans::XPropertySetInfo> xInfo (rxProperties->getPropertySetInfo());
295 [ # # ]: 0 : if (xInfo.is())
296 [ # # ][ # # ]: 0 : if ( ! xInfo->hasPropertyByName(rsKey))
[ # # ]
297 : 0 : return Any();
298 [ # # ][ # # ]: 0 : return rxProperties->getPropertyValue(rsKey);
[ # # ]
299 : : }
300 : 0 : catch (beans::UnknownPropertyException&)
301 : : {
302 : : }
303 : 0 : return Any();
304 : : }
305 : :
306 [ + - ][ + - ]: 24 : } } // end of namespace sdext::tools
307 : :
308 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|