Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <cstdlib>
23 : #include <vector>
24 :
25 : #include "com/sun/star/lang/XServiceInfo.hpp"
26 : #include "com/sun/star/registry/InvalidRegistryException.hpp"
27 : #include "com/sun/star/registry/InvalidValueException.hpp"
28 : #include "com/sun/star/registry/MergeConflictException.hpp"
29 : #include "com/sun/star/registry/RegistryKeyType.hpp"
30 : #include "com/sun/star/registry/XRegistryKey.hpp"
31 : #include "com/sun/star/registry/XSimpleRegistry.hpp"
32 : #include "com/sun/star/uno/Reference.hxx"
33 : #include "com/sun/star/uno/RuntimeException.hpp"
34 : #include "com/sun/star/uno/XComponentContext.hpp"
35 : #include "com/sun/star/uno/XInterface.hpp"
36 : #include "com/sun/star/uno/Sequence.hxx"
37 : #include "cppuhelper/implbase1.hxx"
38 : #include "cppuhelper/implbase2.hxx"
39 : #include "cppuhelper/weak.hxx"
40 : #include "osl/mutex.hxx"
41 : #include "registry/registry.hxx"
42 : #include "registry/regtype.h"
43 : #include "rtl/ref.hxx"
44 : #include "rtl/string.h"
45 : #include "rtl/string.hxx"
46 : #include "rtl/textcvt.h"
47 : #include "rtl/textenc.h"
48 : #include "rtl/ustring.h"
49 : #include "rtl/ustring.hxx"
50 : #include "sal/types.h"
51 :
52 : #include "bootstrapservices.hxx"
53 :
54 : namespace {
55 :
56 : class SimpleRegistry:
57 : public cppu::WeakImplHelper2<
58 : css::registry::XSimpleRegistry, css::lang::XServiceInfo >
59 : {
60 : public:
61 4 : SimpleRegistry() {}
62 :
63 8 : ~SimpleRegistry() {}
64 :
65 : osl::Mutex mutex_;
66 :
67 : private:
68 : virtual OUString SAL_CALL getURL() throw (css::uno::RuntimeException);
69 :
70 : virtual void SAL_CALL open(
71 : OUString const & rURL, sal_Bool bReadOnly, sal_Bool bCreate)
72 : throw (
73 : css::registry::InvalidRegistryException,
74 : css::uno::RuntimeException);
75 :
76 : virtual sal_Bool SAL_CALL isValid() throw (css::uno::RuntimeException);
77 :
78 : virtual void SAL_CALL close() throw (
79 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
80 :
81 : virtual void SAL_CALL destroy() throw(
82 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
83 :
84 : virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
85 : getRootKey() throw(
86 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
87 :
88 : virtual sal_Bool SAL_CALL isReadOnly() throw(
89 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
90 :
91 : virtual void SAL_CALL mergeKey(
92 : OUString const & aKeyName, OUString const & aUrl)
93 : throw (
94 : css::registry::InvalidRegistryException,
95 : css::registry::MergeConflictException, css::uno::RuntimeException);
96 :
97 0 : virtual OUString SAL_CALL getImplementationName()
98 : throw (css::uno::RuntimeException)
99 0 : { return stoc_bootstrap::simreg_getImplementationName(); }
100 :
101 0 : virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
102 : throw (css::uno::RuntimeException)
103 0 : { return ServiceName == getSupportedServiceNames()[0]; }
104 :
105 : virtual css::uno::Sequence< OUString > SAL_CALL
106 0 : getSupportedServiceNames() throw (css::uno::RuntimeException)
107 0 : { return stoc_bootstrap::simreg_getSupportedServiceNames(); }
108 :
109 : Registry registry_;
110 : };
111 :
112 92 : class Key: public cppu::WeakImplHelper1< css::registry::XRegistryKey > {
113 : public:
114 46 : Key(
115 : rtl::Reference< SimpleRegistry > const & registry,
116 : RegistryKey const & key):
117 46 : registry_(registry), key_(key) {}
118 :
119 : private:
120 : virtual OUString SAL_CALL getKeyName()
121 : throw (css::uno::RuntimeException);
122 :
123 : virtual sal_Bool SAL_CALL isReadOnly() throw (
124 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
125 :
126 : virtual sal_Bool SAL_CALL isValid() throw(css::uno::RuntimeException);
127 :
128 : virtual css::registry::RegistryKeyType SAL_CALL getKeyType(
129 : OUString const & rKeyName)
130 : throw (
131 : css::registry::InvalidRegistryException,
132 : css::uno::RuntimeException);
133 :
134 : virtual css::registry::RegistryValueType SAL_CALL getValueType() throw(
135 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
136 :
137 : virtual sal_Int32 SAL_CALL getLongValue() throw (
138 : css::registry::InvalidRegistryException,
139 : css::registry::InvalidValueException, css::uno::RuntimeException);
140 :
141 : virtual void SAL_CALL setLongValue(sal_Int32 value) throw (
142 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
143 :
144 : virtual css::uno::Sequence< sal_Int32 > SAL_CALL getLongListValue() throw(
145 : css::registry::InvalidRegistryException,
146 : css::registry::InvalidValueException, css::uno::RuntimeException);
147 :
148 : virtual void SAL_CALL setLongListValue(
149 : com::sun::star::uno::Sequence< sal_Int32 > const & seqValue)
150 : throw (
151 : css::registry::InvalidRegistryException,
152 : css::uno::RuntimeException);
153 :
154 : virtual OUString SAL_CALL getAsciiValue() throw (
155 : css::registry::InvalidRegistryException,
156 : css::registry::InvalidValueException, css::uno::RuntimeException);
157 :
158 : virtual void SAL_CALL setAsciiValue(OUString const & value) throw (
159 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
160 :
161 : virtual css::uno::Sequence< OUString > SAL_CALL getAsciiListValue()
162 : throw (
163 : css::registry::InvalidRegistryException,
164 : css::registry::InvalidValueException, css::uno::RuntimeException);
165 :
166 : virtual void SAL_CALL setAsciiListValue(
167 : css::uno::Sequence< OUString > const & seqValue)
168 : throw (
169 : css::registry::InvalidRegistryException,
170 : css::uno::RuntimeException);
171 :
172 : virtual OUString SAL_CALL getStringValue() throw(
173 : css::registry::InvalidRegistryException,
174 : css::registry::InvalidValueException, css::uno::RuntimeException);
175 :
176 : virtual void SAL_CALL setStringValue(OUString const & value) throw (
177 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
178 :
179 : virtual css::uno::Sequence< OUString > SAL_CALL getStringListValue()
180 : throw (
181 : css::registry::InvalidRegistryException,
182 : css::registry::InvalidValueException, css::uno::RuntimeException);
183 :
184 : virtual void SAL_CALL setStringListValue(
185 : css::uno::Sequence< OUString > const & seqValue)
186 : throw (
187 : css::registry::InvalidRegistryException,
188 : css::uno::RuntimeException);
189 :
190 : virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue() throw (
191 : css::registry::InvalidRegistryException,
192 : css::registry::InvalidValueException, css::uno::RuntimeException);
193 :
194 : virtual void SAL_CALL setBinaryValue(
195 : css::uno::Sequence< sal_Int8 > const & value)
196 : throw (
197 : css::registry::InvalidRegistryException,
198 : css::uno::RuntimeException);
199 :
200 : virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL openKey(
201 : OUString const & aKeyName)
202 : throw (
203 : css::registry::InvalidRegistryException,
204 : css::uno::RuntimeException);
205 :
206 : virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
207 : createKey(OUString const & aKeyName) throw (
208 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
209 :
210 : virtual void SAL_CALL closeKey() throw (
211 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
212 :
213 : virtual void SAL_CALL deleteKey(OUString const & rKeyName) throw (
214 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
215 :
216 : virtual
217 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
218 : SAL_CALL openKeys() throw (
219 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
220 :
221 : virtual css::uno::Sequence< OUString > SAL_CALL getKeyNames() throw (
222 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
223 :
224 : virtual sal_Bool SAL_CALL createLink(
225 : OUString const & aLinkName, OUString const & aLinkTarget)
226 : throw (
227 : css::registry::InvalidRegistryException,
228 : css::uno::RuntimeException);
229 :
230 : virtual void SAL_CALL deleteLink(OUString const & rLinkName) throw (
231 : css::registry::InvalidRegistryException, css::uno::RuntimeException);
232 :
233 : virtual OUString SAL_CALL getLinkTarget(OUString const & rLinkName)
234 : throw (
235 : css::registry::InvalidRegistryException,
236 : css::uno::RuntimeException);
237 :
238 : virtual OUString SAL_CALL getResolvedName(OUString const & aKeyName)
239 : throw (
240 : css::registry::InvalidRegistryException,
241 : css::uno::RuntimeException);
242 :
243 : rtl::Reference< SimpleRegistry > registry_;
244 : RegistryKey key_;
245 : };
246 :
247 28 : OUString Key::getKeyName() throw (css::uno::RuntimeException) {
248 28 : osl::MutexGuard guard(registry_->mutex_);
249 28 : return key_.getName();
250 : }
251 :
252 1 : sal_Bool Key::isReadOnly()
253 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
254 : {
255 1 : osl::MutexGuard guard(registry_->mutex_);
256 1 : return key_.isReadOnly();
257 : }
258 :
259 19 : sal_Bool Key::isValid() throw (css::uno::RuntimeException) {
260 19 : osl::MutexGuard guard(registry_->mutex_);
261 19 : return key_.isValid();
262 : }
263 :
264 7 : css::registry::RegistryKeyType Key::getKeyType(OUString const & rKeyName)
265 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
266 : {
267 7 : osl::MutexGuard guard(registry_->mutex_);
268 : RegKeyType type;
269 7 : RegError err = key_.getKeyType(rKeyName, &type);
270 7 : if (err != REG_NO_ERROR) {
271 : throw css::registry::InvalidRegistryException(
272 : (OUString("com.sun.star.registry.SimpleRegistry key getKeyType:"
273 0 : " underlying RegistryKey::getKeyType() = ") +
274 0 : OUString::number(err)),
275 0 : static_cast< OWeakObject * >(this));
276 : }
277 7 : switch (type) {
278 : default:
279 0 : std::abort(); // this cannot happen
280 : // pseudo-fall-through to avoid warnings on MSC
281 : case RG_KEYTYPE:
282 7 : return css::registry::RegistryKeyType_KEY;
283 : case RG_LINKTYPE:
284 0 : return css::registry::RegistryKeyType_LINK;
285 7 : }
286 : }
287 :
288 11 : css::registry::RegistryValueType Key::getValueType()
289 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
290 : {
291 11 : osl::MutexGuard guard(registry_->mutex_);
292 : RegValueType type;
293 : sal_uInt32 size;
294 11 : RegError err = key_.getValueInfo(OUString(), &type, &size);
295 11 : switch (err) {
296 : case REG_NO_ERROR:
297 3 : break;
298 : case REG_INVALID_VALUE:
299 8 : type = RG_VALUETYPE_NOT_DEFINED;
300 8 : break;
301 : default:
302 : throw css::registry::InvalidRegistryException(
303 : (OUString("com.sun.star.registry.SimpleRegistry key getValueType:"
304 0 : " underlying RegistryKey::getValueInfo() = ") +
305 0 : OUString::number(err)),
306 0 : static_cast< OWeakObject * >(this));
307 : }
308 11 : switch (type) {
309 : default:
310 0 : std::abort(); // this cannot happen
311 : // pseudo-fall-through to avoid warnings on MSC
312 : case RG_VALUETYPE_NOT_DEFINED:
313 8 : return css::registry::RegistryValueType_NOT_DEFINED;
314 : case RG_VALUETYPE_LONG:
315 0 : return css::registry::RegistryValueType_LONG;
316 : case RG_VALUETYPE_STRING:
317 3 : return css::registry::RegistryValueType_ASCII;
318 : case RG_VALUETYPE_UNICODE:
319 0 : return css::registry::RegistryValueType_STRING;
320 : case RG_VALUETYPE_BINARY:
321 0 : return css::registry::RegistryValueType_BINARY;
322 : case RG_VALUETYPE_LONGLIST:
323 0 : return css::registry::RegistryValueType_LONGLIST;
324 : case RG_VALUETYPE_STRINGLIST:
325 0 : return css::registry::RegistryValueType_ASCIILIST;
326 : case RG_VALUETYPE_UNICODELIST:
327 0 : return css::registry::RegistryValueType_STRINGLIST;
328 11 : }
329 : }
330 :
331 0 : sal_Int32 Key::getLongValue() throw (
332 : css::registry::InvalidRegistryException,
333 : css::registry::InvalidValueException, css::uno::RuntimeException)
334 : {
335 0 : osl::MutexGuard guard(registry_->mutex_);
336 : sal_Int32 value;
337 0 : RegError err = key_.getValue(OUString(), &value);
338 0 : switch (err) {
339 : case REG_NO_ERROR:
340 0 : break;
341 : case REG_INVALID_VALUE:
342 : throw css::registry::InvalidValueException(
343 : OUString("com.sun.star.registry.SimpleRegistry key getLongValue:"
344 : " underlying RegistryKey::getValue() = REG_INVALID_VALUE"),
345 0 : static_cast< OWeakObject * >(this));
346 : default:
347 : throw css::registry::InvalidRegistryException(
348 : (OUString("com.sun.star.registry.SimpleRegistry key getLongValue:"
349 0 : " underlying RegistryKey::getValue() = ") +
350 0 : OUString::number(err)),
351 0 : static_cast< OWeakObject * >(this));
352 : }
353 0 : return value;
354 : }
355 :
356 0 : void Key::setLongValue(sal_Int32 value)
357 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
358 : {
359 0 : osl::MutexGuard guard(registry_->mutex_);
360 : RegError err = key_.setValue(
361 0 : OUString(), RG_VALUETYPE_LONG, &value, sizeof (sal_Int32));
362 0 : if (err != REG_NO_ERROR) {
363 : throw css::registry::InvalidRegistryException(
364 : (OUString("com.sun.star.registry.SimpleRegistry key setLongValue:"
365 0 : " underlying RegistryKey::setValue() = ") +
366 0 : OUString::number(err)),
367 0 : static_cast< OWeakObject * >(this));
368 0 : }
369 0 : }
370 :
371 0 : css::uno::Sequence< sal_Int32 > Key::getLongListValue() throw (
372 : css::registry::InvalidRegistryException,
373 : css::registry::InvalidValueException, css::uno::RuntimeException)
374 : {
375 0 : osl::MutexGuard guard(registry_->mutex_);
376 0 : RegistryValueList< sal_Int32 > list;
377 0 : RegError err = key_.getLongListValue(OUString(), list);
378 0 : switch (err) {
379 : case REG_NO_ERROR:
380 0 : break;
381 : case REG_VALUE_NOT_EXISTS:
382 0 : return css::uno::Sequence< sal_Int32 >();
383 : case REG_INVALID_VALUE:
384 : throw css::registry::InvalidValueException(
385 : OUString("com.sun.star.registry.SimpleRegistry key getLongListValue:"
386 : " underlying RegistryKey::getLongListValue() ="
387 : " REG_INVALID_VALUE"),
388 0 : static_cast< OWeakObject * >(this));
389 : default:
390 : throw css::registry::InvalidRegistryException(
391 : (OUString("com.sun.star.registry.SimpleRegistry key getLongListValue:"
392 0 : " underlying RegistryKey::getLongListValue() = ") +
393 0 : OUString::number(err)),
394 0 : static_cast< OWeakObject * >(this));
395 : }
396 0 : sal_uInt32 n = list.getLength();
397 0 : if (n > SAL_MAX_INT32) {
398 : throw css::registry::InvalidValueException(
399 : OUString("com.sun.star.registry.SimpleRegistry key getLongListValue:"
400 : " underlying RegistryKey::getLongListValue() too large"),
401 0 : static_cast< OWeakObject * >(this));
402 : }
403 0 : css::uno::Sequence< sal_Int32 > value(static_cast< sal_Int32 >(n));
404 0 : for (sal_uInt32 i = 0; i < n; ++i) {
405 0 : value[static_cast< sal_Int32 >(i)] = list.getElement(i);
406 : }
407 0 : return value;
408 : }
409 :
410 0 : void Key::setLongListValue(css::uno::Sequence< sal_Int32 > const & seqValue)
411 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
412 : {
413 0 : osl::MutexGuard guard(registry_->mutex_);
414 0 : std::vector< sal_Int32 > list;
415 0 : for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
416 0 : list.push_back(seqValue[i]);
417 : }
418 : RegError err = key_.setLongListValue(
419 0 : OUString(), list.empty() ? 0 : &list[0],
420 0 : static_cast< sal_uInt32 >(list.size()));
421 0 : if (err != REG_NO_ERROR) {
422 : throw css::registry::InvalidRegistryException(
423 : (OUString("com.sun.star.registry.SimpleRegistry key setLongListValue:"
424 0 : " underlying RegistryKey::setLongListValue() = ") +
425 0 : OUString::number(err)),
426 0 : static_cast< OWeakObject * >(this));
427 0 : }
428 0 : }
429 :
430 3 : OUString Key::getAsciiValue() throw (
431 : css::registry::InvalidRegistryException,
432 : css::registry::InvalidValueException, css::uno::RuntimeException)
433 : {
434 3 : osl::MutexGuard guard(registry_->mutex_);
435 : RegValueType type;
436 : sal_uInt32 size;
437 3 : RegError err = key_.getValueInfo(OUString(), &type, &size);
438 3 : if (err != REG_NO_ERROR) {
439 : throw css::registry::InvalidRegistryException(
440 : (OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
441 0 : " underlying RegistryKey::getValueInfo() = ") +
442 0 : OUString::number(err)),
443 0 : static_cast< OWeakObject * >(this));
444 : }
445 3 : if (type != RG_VALUETYPE_STRING) {
446 : throw css::registry::InvalidValueException(
447 : (OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
448 0 : " underlying RegistryKey type = ") +
449 0 : OUString::number(type)),
450 0 : static_cast< OWeakObject * >(this));
451 : }
452 : // size contains terminating null (error in underlying registry.cxx):
453 3 : if (size == 0) {
454 : throw css::registry::InvalidValueException(
455 : OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
456 : " underlying RegistryKey size 0 cannot happen due to"
457 : " design error"),
458 0 : static_cast< OWeakObject * >(this));
459 : }
460 3 : if (size > SAL_MAX_INT32) {
461 : throw css::registry::InvalidValueException(
462 : OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
463 : " underlying RegistryKey size too large"),
464 0 : static_cast< OWeakObject * >(this));
465 : }
466 6 : std::vector< char > list(size);
467 3 : err = key_.getValue(OUString(), &list[0]);
468 3 : if (err != REG_NO_ERROR) {
469 : throw css::registry::InvalidRegistryException(
470 : (OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
471 0 : " underlying RegistryKey::getValue() = ") +
472 0 : OUString::number(err)),
473 0 : static_cast< OWeakObject * >(this));
474 : }
475 3 : if (list[size - 1] != '\0') {
476 : throw css::registry::InvalidValueException(
477 : OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
478 : " underlying RegistryKey value must be null-terminated due"
479 : " to design error"),
480 0 : static_cast< OWeakObject * >(this));
481 : }
482 3 : OUString value;
483 3 : if (!rtl_convertStringToUString(
484 3 : &value.pData, &list[0],
485 3 : static_cast< sal_Int32 >(size - 1), RTL_TEXTENCODING_UTF8,
486 : (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
487 : RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
488 6 : RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
489 : {
490 : throw css::registry::InvalidValueException(
491 : OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
492 : " underlying RegistryKey not UTF-8"),
493 0 : static_cast< OWeakObject * >(this));
494 : }
495 6 : return value;
496 : }
497 :
498 4 : void Key::setAsciiValue(OUString const & value)
499 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
500 : {
501 4 : osl::MutexGuard guard(registry_->mutex_);
502 8 : OString utf8;
503 4 : if (!value.convertToString(
504 : &utf8, RTL_TEXTENCODING_UTF8,
505 : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
506 4 : RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
507 : {
508 : throw css::uno::RuntimeException(
509 : OUString("com.sun.star.registry.SimpleRegistry key setAsciiValue:"
510 : " value not UTF-16"),
511 0 : static_cast< OWeakObject * >(this));
512 : }
513 : RegError err = key_.setValue(
514 : OUString(), RG_VALUETYPE_STRING,
515 4 : const_cast< char * >(utf8.getStr()), utf8.getLength() + 1);
516 : // +1 for terminating null (error in underlying registry.cxx)
517 4 : if (err != REG_NO_ERROR) {
518 : throw css::registry::InvalidRegistryException(
519 : (OUString("com.sun.star.registry.SimpleRegistry key setAsciiValue:"
520 0 : " underlying RegistryKey::setValue() = ") +
521 0 : OUString::number(err)),
522 0 : static_cast< OWeakObject * >(this));
523 4 : }
524 4 : }
525 :
526 0 : css::uno::Sequence< OUString > Key::getAsciiListValue() throw (
527 : css::registry::InvalidRegistryException,
528 : css::registry::InvalidValueException, css::uno::RuntimeException)
529 : {
530 0 : osl::MutexGuard guard(registry_->mutex_);
531 0 : RegistryValueList< char * > list;
532 0 : RegError err = key_.getStringListValue(OUString(), list);
533 0 : switch (err) {
534 : case REG_NO_ERROR:
535 0 : break;
536 : case REG_VALUE_NOT_EXISTS:
537 0 : return css::uno::Sequence< OUString >();
538 : case REG_INVALID_VALUE:
539 : throw css::registry::InvalidValueException(
540 : OUString("com.sun.star.registry.SimpleRegistry key"
541 : " getAsciiListValue: underlying"
542 : " RegistryKey::getStringListValue() = REG_INVALID_VALUE"),
543 0 : static_cast< OWeakObject * >(this));
544 : default:
545 : throw css::registry::InvalidRegistryException(
546 : (OUString("com.sun.star.registry.SimpleRegistry key"
547 : " getAsciiListValue: underlying"
548 0 : " RegistryKey::getStringListValue() = ") +
549 0 : OUString::number(err)),
550 0 : static_cast< OWeakObject * >(this));
551 : }
552 0 : sal_uInt32 n = list.getLength();
553 0 : if (n > SAL_MAX_INT32) {
554 : throw css::registry::InvalidValueException(
555 : OUString("com.sun.star.registry.SimpleRegistry key"
556 : " getAsciiListValue: underlying"
557 : " RegistryKey::getStringListValue() too large"),
558 0 : static_cast< OWeakObject * >(this));
559 : }
560 0 : css::uno::Sequence< OUString > value(static_cast< sal_Int32 >(n));
561 0 : for (sal_uInt32 i = 0; i < n; ++i) {
562 0 : char * el = list.getElement(i);
563 0 : sal_Int32 size = rtl_str_getLength(el);
564 0 : if (!rtl_convertStringToUString(
565 0 : &value[static_cast< sal_Int32 >(i)].pData, el, size,
566 : RTL_TEXTENCODING_UTF8,
567 : (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
568 : RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
569 0 : RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
570 : {
571 : throw css::registry::InvalidValueException(
572 : OUString("com.sun.star.registry.SimpleRegistry key"
573 : " getAsciiListValue: underlying RegistryKey not"
574 : " UTF-8"),
575 0 : static_cast< OWeakObject * >(this));
576 : }
577 : }
578 0 : return value;
579 : }
580 :
581 1 : void Key::setAsciiListValue(
582 : css::uno::Sequence< OUString > const & seqValue)
583 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
584 : {
585 1 : osl::MutexGuard guard(registry_->mutex_);
586 2 : std::vector< OString > list;
587 2 : for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
588 1 : OString utf8;
589 2 : if (!seqValue[i].convertToString(
590 : &utf8, RTL_TEXTENCODING_UTF8,
591 : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
592 1 : RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
593 : {
594 : throw css::uno::RuntimeException(
595 : OUString("com.sun.star.registry.SimpleRegistry key"
596 : " setAsciiListValue: value not UTF-16"),
597 0 : static_cast< OWeakObject * >(this));
598 : }
599 1 : list.push_back(utf8);
600 1 : }
601 2 : std::vector< char * > list2;
602 2 : for (std::vector< OString >::iterator i(list.begin()); i != list.end();
603 : ++i)
604 : {
605 1 : list2.push_back(const_cast< char * >(i->getStr()));
606 : }
607 : RegError err = key_.setStringListValue(
608 1 : OUString(), list2.empty() ? 0 : &list2[0],
609 2 : static_cast< sal_uInt32 >(list2.size()));
610 1 : if (err != REG_NO_ERROR) {
611 : throw css::registry::InvalidRegistryException(
612 : (OUString("com.sun.star.registry.SimpleRegistry key"
613 : " setAsciiListValue: underlying"
614 0 : " RegistryKey::setStringListValue() = ") +
615 0 : OUString::number(err)),
616 0 : static_cast< OWeakObject * >(this));
617 1 : }
618 1 : }
619 :
620 0 : OUString Key::getStringValue() throw (
621 : css::registry::InvalidRegistryException,
622 : css::registry::InvalidValueException, css::uno::RuntimeException)
623 : {
624 0 : osl::MutexGuard guard(registry_->mutex_);
625 : RegValueType type;
626 : sal_uInt32 size;
627 0 : RegError err = key_.getValueInfo(OUString(), &type, &size);
628 0 : if (err != REG_NO_ERROR) {
629 : throw css::registry::InvalidRegistryException(
630 : (OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
631 0 : " underlying RegistryKey::getValueInfo() = ") +
632 0 : OUString::number(err)),
633 0 : static_cast< OWeakObject * >(this));
634 : }
635 0 : if (type != RG_VALUETYPE_UNICODE) {
636 : throw css::registry::InvalidValueException(
637 : (OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
638 0 : " underlying RegistryKey type = ") +
639 0 : OUString::number(type)),
640 0 : static_cast< OWeakObject * >(this));
641 : }
642 : // size contains terminating null and is *2 (error in underlying
643 : // registry.cxx):
644 0 : if (size == 0 || (size & 1) == 1) {
645 : throw css::registry::InvalidValueException(
646 : OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
647 : " underlying RegistryKey size 0 or odd cannot happen due to"
648 : " design error"),
649 0 : static_cast< OWeakObject * >(this));
650 : }
651 0 : if (size > SAL_MAX_INT32) {
652 : throw css::registry::InvalidValueException(
653 : OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
654 : " underlying RegistryKey size too large"),
655 0 : static_cast< OWeakObject * >(this));
656 : }
657 0 : std::vector< sal_Unicode > list(size);
658 0 : err = key_.getValue(OUString(), &list[0]);
659 0 : if (err != REG_NO_ERROR) {
660 : throw css::registry::InvalidRegistryException(
661 : (OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
662 0 : " underlying RegistryKey::getValue() = ") +
663 0 : OUString::number(err)),
664 0 : static_cast< OWeakObject * >(this));
665 : }
666 0 : if (list[size/2 - 1] != 0) {
667 : throw css::registry::InvalidValueException(
668 : OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
669 : " underlying RegistryKey value must be null-terminated due"
670 : " to design error"),
671 0 : static_cast< OWeakObject * >(this));
672 : }
673 0 : return OUString(&list[0], static_cast< sal_Int32 >(size/2 - 1));
674 : }
675 :
676 0 : void Key::setStringValue(OUString const & value)
677 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
678 : {
679 0 : osl::MutexGuard guard(registry_->mutex_);
680 : RegError err = key_.setValue(
681 : OUString(), RG_VALUETYPE_UNICODE,
682 0 : const_cast< sal_Unicode * >(value.getStr()),
683 0 : (value.getLength() + 1) * sizeof (sal_Unicode));
684 : // +1 for terminating null (error in underlying registry.cxx)
685 0 : if (err != REG_NO_ERROR) {
686 : throw css::registry::InvalidRegistryException(
687 : (OUString("com.sun.star.registry.SimpleRegistry key setStringValue:"
688 0 : " underlying RegistryKey::setValue() = ") +
689 0 : OUString::number(err)),
690 0 : static_cast< OWeakObject * >(this));
691 0 : }
692 0 : }
693 :
694 0 : css::uno::Sequence< OUString > Key::getStringListValue() throw (
695 : css::registry::InvalidRegistryException,
696 : css::registry::InvalidValueException, css::uno::RuntimeException)
697 : {
698 0 : osl::MutexGuard guard(registry_->mutex_);
699 0 : RegistryValueList< sal_Unicode * > list;
700 0 : RegError err = key_.getUnicodeListValue(OUString(), list);
701 0 : switch (err) {
702 : case REG_NO_ERROR:
703 0 : break;
704 : case REG_VALUE_NOT_EXISTS:
705 0 : return css::uno::Sequence< OUString >();
706 : case REG_INVALID_VALUE:
707 : throw css::registry::InvalidValueException(
708 : OUString("com.sun.star.registry.SimpleRegistry key"
709 : " getStringListValue: underlying"
710 : " RegistryKey::getUnicodeListValue() = REG_INVALID_VALUE"),
711 0 : static_cast< OWeakObject * >(this));
712 : default:
713 : throw css::registry::InvalidRegistryException(
714 : (OUString("com.sun.star.registry.SimpleRegistry key"
715 : " getStringListValue: underlying"
716 0 : " RegistryKey::getUnicodeListValue() = ") +
717 0 : OUString::number(err)),
718 0 : static_cast< OWeakObject * >(this));
719 : }
720 0 : sal_uInt32 n = list.getLength();
721 0 : if (n > SAL_MAX_INT32) {
722 : throw css::registry::InvalidValueException(
723 : OUString("com.sun.star.registry.SimpleRegistry key"
724 : " getStringListValue: underlying"
725 : " RegistryKey::getUnicodeListValue() too large"),
726 0 : static_cast< OWeakObject * >(this));
727 : }
728 0 : css::uno::Sequence< OUString > value(static_cast< sal_Int32 >(n));
729 0 : for (sal_uInt32 i = 0; i < n; ++i) {
730 0 : value[static_cast< sal_Int32 >(i)] = list.getElement(i);
731 : }
732 0 : return value;
733 : }
734 :
735 0 : void Key::setStringListValue(
736 : css::uno::Sequence< OUString > const & seqValue)
737 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
738 : {
739 0 : osl::MutexGuard guard(registry_->mutex_);
740 0 : std::vector< sal_Unicode * > list;
741 0 : for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
742 0 : list.push_back(const_cast< sal_Unicode * >(seqValue[i].getStr()));
743 : }
744 : RegError err = key_.setUnicodeListValue(
745 0 : OUString(), list.empty() ? 0 : &list[0],
746 0 : static_cast< sal_uInt32 >(list.size()));
747 0 : if (err != REG_NO_ERROR) {
748 : throw css::registry::InvalidRegistryException(
749 : (OUString("com.sun.star.registry.SimpleRegistry key"
750 : " setStringListValue: underlying"
751 0 : " RegistryKey::setUnicodeListValue() = ") +
752 0 : OUString::number(err)),
753 0 : static_cast< OWeakObject * >(this));
754 0 : }
755 0 : }
756 :
757 0 : css::uno::Sequence< sal_Int8 > Key::getBinaryValue()
758 : throw (
759 : css::registry::InvalidRegistryException,
760 : css::registry::InvalidValueException, css::uno::RuntimeException)
761 : {
762 0 : osl::MutexGuard guard(registry_->mutex_);
763 : RegValueType type;
764 : sal_uInt32 size;
765 0 : RegError err = key_.getValueInfo(OUString(), &type, &size);
766 0 : if (err != REG_NO_ERROR) {
767 : throw css::registry::InvalidRegistryException(
768 : (OUString("com.sun.star.registry.SimpleRegistry key getBinaryValue:"
769 0 : " underlying RegistryKey::getValueInfo() = ") +
770 0 : OUString::number(err)),
771 0 : static_cast< OWeakObject * >(this));
772 : }
773 0 : if (type != RG_VALUETYPE_BINARY) {
774 : throw css::registry::InvalidValueException(
775 : (OUString("com.sun.star.registry.SimpleRegistry key getBinaryValue:"
776 0 : " underlying RegistryKey type = ") +
777 0 : OUString::number(type)),
778 0 : static_cast< OWeakObject * >(this));
779 : }
780 0 : if (size > SAL_MAX_INT32) {
781 : throw css::registry::InvalidValueException(
782 : OUString("com.sun.star.registry.SimpleRegistry key getBinaryValue:"
783 : " underlying RegistryKey size too large"),
784 0 : static_cast< OWeakObject * >(this));
785 : }
786 0 : css::uno::Sequence< sal_Int8 > value(static_cast< sal_Int32 >(size));
787 0 : err = key_.getValue(OUString(), value.getArray());
788 0 : if (err != REG_NO_ERROR) {
789 : throw css::registry::InvalidRegistryException(
790 : (OUString("com.sun.star.registry.SimpleRegistry key getBinaryValue:"
791 0 : " underlying RegistryKey::getValue() = ") +
792 0 : OUString::number(err)),
793 0 : static_cast< OWeakObject * >(this));
794 : }
795 0 : return value;
796 : }
797 :
798 0 : void Key::setBinaryValue(css::uno::Sequence< sal_Int8 > const & value)
799 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
800 : {
801 0 : osl::MutexGuard guard(registry_->mutex_);
802 : RegError err = key_.setValue(
803 : OUString(), RG_VALUETYPE_BINARY,
804 0 : const_cast< sal_Int8 * >(value.getConstArray()),
805 0 : static_cast< sal_uInt32 >(value.getLength()));
806 0 : if (err != REG_NO_ERROR) {
807 : throw css::registry::InvalidRegistryException(
808 : (OUString("com.sun.star.registry.SimpleRegistry key setBinaryValue:"
809 0 : " underlying RegistryKey::setValue() = ") +
810 0 : OUString::number(err)),
811 0 : static_cast< OWeakObject * >(this));
812 0 : }
813 0 : }
814 :
815 19 : css::uno::Reference< css::registry::XRegistryKey > Key::openKey(
816 : OUString const & aKeyName)
817 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
818 : {
819 19 : osl::MutexGuard guard(registry_->mutex_);
820 38 : RegistryKey key;
821 19 : RegError err = key_.openKey(aKeyName, key);
822 19 : switch (err) {
823 : case REG_NO_ERROR:
824 13 : return new Key(registry_, key);
825 : case REG_KEY_NOT_EXISTS:
826 6 : return css::uno::Reference< css::registry::XRegistryKey >();
827 : default:
828 : throw css::registry::InvalidRegistryException(
829 : (OUString("com.sun.star.registry.SimpleRegistry key openKey:"
830 0 : " underlying RegistryKey::openKey() = ") +
831 0 : OUString::number(err)),
832 0 : static_cast< OWeakObject * >(this));
833 19 : }
834 : }
835 :
836 15 : css::uno::Reference< css::registry::XRegistryKey > Key::createKey(
837 : OUString const & aKeyName)
838 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
839 : {
840 15 : osl::MutexGuard guard(registry_->mutex_);
841 30 : RegistryKey key;
842 15 : RegError err = key_.createKey(aKeyName, key);
843 15 : switch (err) {
844 : case REG_NO_ERROR:
845 15 : return new Key(registry_, key);
846 : case REG_INVALID_KEYNAME:
847 0 : return css::uno::Reference< css::registry::XRegistryKey >();
848 : default:
849 : throw css::registry::InvalidRegistryException(
850 : (OUString("com.sun.star.registry.SimpleRegistry key createKey:"
851 0 : " underlying RegistryKey::createKey() = ") +
852 0 : OUString::number(err)),
853 0 : static_cast< OWeakObject * >(this));
854 15 : }
855 : }
856 :
857 20 : void Key::closeKey()
858 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
859 : {
860 20 : osl::MutexGuard guard(registry_->mutex_);
861 20 : RegError err = key_.closeKey();
862 20 : if (err != REG_NO_ERROR) {
863 : throw css::registry::InvalidRegistryException(
864 : (OUString("com.sun.star.registry.SimpleRegistry key closeKey:"
865 0 : " underlying RegistryKey::closeKey() = ") +
866 0 : OUString::number(err)),
867 0 : static_cast< OWeakObject * >(this));
868 20 : }
869 20 : }
870 :
871 2 : void Key::deleteKey(OUString const & rKeyName)
872 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
873 : {
874 2 : osl::MutexGuard guard(registry_->mutex_);
875 2 : RegError err = key_.deleteKey(rKeyName);
876 2 : if (err != REG_NO_ERROR) {
877 : throw css::registry::InvalidRegistryException(
878 : (OUString("com.sun.star.registry.SimpleRegistry key deleteKey:"
879 0 : " underlying RegistryKey::deleteKey() = ") +
880 0 : OUString::number(err)),
881 0 : static_cast< OWeakObject * >(this));
882 2 : }
883 2 : }
884 :
885 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
886 7 : Key::openKeys()
887 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
888 : {
889 7 : osl::MutexGuard guard(registry_->mutex_);
890 14 : RegistryKeyArray list;
891 7 : RegError err = key_.openSubKeys(OUString(), list);
892 7 : if (err != REG_NO_ERROR) {
893 : throw css::registry::InvalidRegistryException(
894 : (OUString("com.sun.star.registry.SimpleRegistry key openKeys:"
895 0 : " underlying RegistryKey::openSubKeys() = ") +
896 0 : OUString::number(err)),
897 0 : static_cast< OWeakObject * >(this));
898 : }
899 7 : sal_uInt32 n = list.getLength();
900 7 : if (n > SAL_MAX_INT32) {
901 : throw css::registry::InvalidRegistryException(
902 : OUString("com.sun.star.registry.SimpleRegistry key getKeyNames:"
903 : " underlying RegistryKey::getKeyNames() too large"),
904 0 : static_cast< OWeakObject * >(this));
905 : }
906 : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
907 7 : keys(static_cast< sal_Int32 >(n));
908 15 : for (sal_uInt32 i = 0; i < n; ++i) {
909 24 : keys[static_cast< sal_Int32 >(i)] = new Key(
910 16 : registry_, list.getElement(i));
911 : }
912 14 : return keys;
913 : }
914 :
915 8 : css::uno::Sequence< OUString > Key::getKeyNames()
916 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
917 : {
918 8 : osl::MutexGuard guard(registry_->mutex_);
919 16 : RegistryKeyNames list;
920 8 : RegError err = key_.getKeyNames(OUString(), list);
921 8 : if (err != REG_NO_ERROR) {
922 : throw css::registry::InvalidRegistryException(
923 : (OUString("com.sun.star.registry.SimpleRegistry key getKeyNames:"
924 0 : " underlying RegistryKey::getKeyNames() = ") +
925 0 : OUString::number(err)),
926 0 : static_cast< OWeakObject * >(this));
927 : }
928 8 : sal_uInt32 n = list.getLength();
929 8 : if (n > SAL_MAX_INT32) {
930 : throw css::registry::InvalidRegistryException(
931 : OUString("com.sun.star.registry.SimpleRegistry key getKeyNames:"
932 : " underlying RegistryKey::getKeyNames() too large"),
933 0 : static_cast< OWeakObject * >(this));
934 : }
935 8 : css::uno::Sequence< OUString > names(static_cast< sal_Int32 >(n));
936 15 : for (sal_uInt32 i = 0; i < n; ++i) {
937 7 : names[static_cast< sal_Int32 >(i)] = list.getElement(i);
938 : }
939 16 : return names;
940 : }
941 :
942 0 : sal_Bool Key::createLink(
943 : OUString const & aLinkName, OUString const & aLinkTarget)
944 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
945 : {
946 0 : osl::MutexGuard guard(registry_->mutex_);
947 0 : RegError err = key_.createLink(aLinkName, aLinkTarget);
948 0 : switch (err) {
949 : case REG_NO_ERROR:
950 0 : return true;
951 : case REG_INVALID_KEY:
952 : case REG_DETECT_RECURSION:
953 : throw css::registry::InvalidRegistryException(
954 : (OUString("com.sun.star.registry.SimpleRegistry key createLink:"
955 0 : " underlying RegistryKey::createLink() = ") +
956 0 : OUString::number(err)),
957 0 : static_cast< OWeakObject * >(this));
958 : default:
959 0 : return false;
960 0 : }
961 : }
962 :
963 0 : void Key::deleteLink(OUString const & rLinkName)
964 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
965 : {
966 0 : osl::MutexGuard guard(registry_->mutex_);
967 0 : RegError err = key_.deleteLink(rLinkName);
968 0 : if (err != REG_NO_ERROR) {
969 : throw css::registry::InvalidRegistryException(
970 : (OUString("com.sun.star.registry.SimpleRegistry key deleteLink:"
971 0 : " underlying RegistryKey::deleteLink() = ") +
972 0 : OUString::number(err)),
973 0 : static_cast< OWeakObject * >(this));
974 0 : }
975 0 : }
976 :
977 0 : OUString Key::getLinkTarget(OUString const & rLinkName)
978 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
979 : {
980 0 : osl::MutexGuard guard(registry_->mutex_);
981 0 : OUString target;
982 0 : RegError err = key_.getLinkTarget(rLinkName, target);
983 0 : if (err != REG_NO_ERROR) {
984 : throw css::registry::InvalidRegistryException(
985 : (OUString("com.sun.star.registry.SimpleRegistry key getLinkTarget:"
986 0 : " underlying RegistryKey::getLinkTarget() = ") +
987 0 : OUString::number(err)),
988 0 : static_cast< OWeakObject * >(this));
989 : }
990 0 : return target;
991 : }
992 :
993 0 : OUString Key::getResolvedName(OUString const & aKeyName)
994 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
995 : {
996 0 : osl::MutexGuard guard(registry_->mutex_);
997 0 : OUString resolved;
998 0 : RegError err = key_.getResolvedKeyName(aKeyName, true, resolved);
999 0 : if (err != REG_NO_ERROR) {
1000 : throw css::registry::InvalidRegistryException(
1001 : (OUString("com.sun.star.registry.SimpleRegistry key getResolvedName:"
1002 0 : " underlying RegistryKey::getResolvedName() = ") +
1003 0 : OUString::number(err)),
1004 0 : static_cast< OWeakObject * >(this));
1005 : }
1006 0 : return resolved;
1007 : }
1008 :
1009 0 : OUString SimpleRegistry::getURL() throw (css::uno::RuntimeException) {
1010 0 : osl::MutexGuard guard(mutex_);
1011 0 : return registry_.getName();
1012 : }
1013 :
1014 4 : void SimpleRegistry::open(
1015 : OUString const & rURL, sal_Bool bReadOnly, sal_Bool bCreate)
1016 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1017 : {
1018 4 : osl::MutexGuard guard(mutex_);
1019 6 : RegError err = (rURL.isEmpty() && bCreate)
1020 : ? REG_REGISTRY_NOT_EXISTS
1021 6 : : registry_.open(rURL, bReadOnly ? REG_READONLY : REG_READWRITE);
1022 4 : if (err == REG_REGISTRY_NOT_EXISTS && bCreate) {
1023 4 : err = registry_.create(rURL);
1024 : }
1025 4 : if (err != REG_NO_ERROR) {
1026 : throw css::registry::InvalidRegistryException(
1027 0 : (OUString("com.sun.star.registry.SimpleRegistry.open(") +
1028 0 : rURL +
1029 0 : OUString("): underlying Registry::open/create() = ") +
1030 0 : OUString::number(err)),
1031 0 : static_cast< OWeakObject * >(this));
1032 4 : }
1033 4 : }
1034 :
1035 0 : sal_Bool SimpleRegistry::isValid() throw (css::uno::RuntimeException) {
1036 0 : osl::MutexGuard guard(mutex_);
1037 0 : return registry_.isValid();
1038 : }
1039 :
1040 2 : void SimpleRegistry::close()
1041 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1042 : {
1043 2 : osl::MutexGuard guard(mutex_);
1044 2 : RegError err = registry_.close();
1045 2 : if (err != REG_NO_ERROR) {
1046 : throw css::registry::InvalidRegistryException(
1047 : (OUString("com.sun.star.registry.SimpleRegistry.close:"
1048 0 : " underlying Registry::close() = ") +
1049 0 : OUString::number(err)),
1050 0 : static_cast< OWeakObject * >(this));
1051 2 : }
1052 2 : }
1053 :
1054 0 : void SimpleRegistry::destroy()
1055 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1056 : {
1057 0 : osl::MutexGuard guard(mutex_);
1058 0 : RegError err = registry_.destroy(OUString());
1059 0 : if (err != REG_NO_ERROR) {
1060 : throw css::registry::InvalidRegistryException(
1061 : (OUString("com.sun.star.registry.SimpleRegistry.destroy:"
1062 0 : " underlying Registry::destroy() = ") +
1063 0 : OUString::number(err)),
1064 0 : static_cast< OWeakObject * >(this));
1065 0 : }
1066 0 : }
1067 :
1068 10 : css::uno::Reference< css::registry::XRegistryKey > SimpleRegistry::getRootKey()
1069 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1070 : {
1071 10 : osl::MutexGuard guard(mutex_);
1072 20 : RegistryKey root;
1073 10 : RegError err = registry_.openRootKey(root);
1074 10 : if (err != REG_NO_ERROR) {
1075 : throw css::registry::InvalidRegistryException(
1076 : (OUString("com.sun.star.registry.SimpleRegistry.getRootKey:"
1077 0 : " underlying Registry::getRootKey() = ") +
1078 0 : OUString::number(err)),
1079 0 : static_cast< OWeakObject * >(this));
1080 : }
1081 20 : return new Key(this, root);
1082 : }
1083 :
1084 0 : sal_Bool SimpleRegistry::isReadOnly()
1085 : throw (css::registry::InvalidRegistryException, css::uno::RuntimeException)
1086 : {
1087 0 : osl::MutexGuard guard(mutex_);
1088 0 : return registry_.isReadOnly();
1089 : }
1090 :
1091 0 : void SimpleRegistry::mergeKey(
1092 : OUString const & aKeyName, OUString const & aUrl)
1093 : throw (
1094 : css::registry::InvalidRegistryException,
1095 : css::registry::MergeConflictException, css::uno::RuntimeException)
1096 : {
1097 0 : osl::MutexGuard guard(mutex_);
1098 0 : RegistryKey root;
1099 0 : RegError err = registry_.openRootKey(root);
1100 0 : if (err == REG_NO_ERROR) {
1101 0 : err = registry_.mergeKey(root, aKeyName, aUrl, false, false);
1102 : }
1103 0 : switch (err) {
1104 : case REG_NO_ERROR:
1105 : case REG_MERGE_CONFLICT:
1106 0 : break;
1107 : case REG_MERGE_ERROR:
1108 : throw css::registry::MergeConflictException(
1109 : OUString("com.sun.star.registry.SimpleRegistry.mergeKey:"
1110 : " underlying Registry::mergeKey() = REG_MERGE_ERROR"),
1111 0 : static_cast< cppu::OWeakObject * >(this));
1112 : default:
1113 : throw css::registry::InvalidRegistryException(
1114 : (OUString("com.sun.star.registry.SimpleRegistry.mergeKey:"
1115 0 : " underlying Registry::getRootKey/mergeKey() = ") +
1116 0 : OUString::number(err)),
1117 0 : static_cast< OWeakObject * >(this));
1118 0 : }
1119 0 : }
1120 :
1121 : }
1122 :
1123 : namespace stoc_bootstrap {
1124 :
1125 4 : css::uno::Reference< css::uno::XInterface > SimpleRegistry_CreateInstance(
1126 : SAL_UNUSED_PARAMETER css::uno::Reference< css::uno::XComponentContext >
1127 : const &)
1128 : {
1129 4 : return static_cast< cppu::OWeakObject * >(new SimpleRegistry);
1130 : }
1131 :
1132 2 : css::uno::Sequence< OUString > simreg_getSupportedServiceNames() {
1133 2 : css::uno::Sequence< OUString > names(1);
1134 2 : names[0] = OUString("com.sun.star.registry.SimpleRegistry");
1135 2 : return names;
1136 : }
1137 :
1138 7 : OUString simreg_getImplementationName() {
1139 7 : return OUString("com.sun.star.comp.stoc.SimpleRegistry");
1140 : }
1141 :
1142 : }
1143 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|