1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
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/implbase.hxx>
38 #include <cppuhelper/supportsservice.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>
55 public cppu::WeakImplHelper
<
56 css::registry::XSimpleRegistry
, css::lang::XServiceInfo
>
64 virtual OUString SAL_CALL
getURL() override
;
66 virtual void SAL_CALL
open(
67 OUString
const & rURL
, sal_Bool bReadOnly
, sal_Bool bCreate
) override
;
69 virtual sal_Bool SAL_CALL
isValid() override
;
71 virtual void SAL_CALL
close() override
;
73 virtual void SAL_CALL
destroy() override
;
75 virtual css::uno::Reference
< css::registry::XRegistryKey
> SAL_CALL
76 getRootKey() override
;
78 virtual sal_Bool SAL_CALL
isReadOnly() override
;
80 virtual void SAL_CALL
mergeKey(
81 OUString
const & aKeyName
, OUString
const & aUrl
) override
;
83 virtual OUString SAL_CALL
getImplementationName() override
84 { return OUString("com.sun.star.comp.stoc.SimpleRegistry"); }
86 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
87 { return cppu::supportsService(this, ServiceName
); }
89 virtual css::uno::Sequence
< OUString
> SAL_CALL
90 getSupportedServiceNames() override
92 css::uno::Sequence
< OUString
> names
{ "com.sun.star.registry.SimpleRegistry" };
99 class Key
: public cppu::WeakImplHelper
< css::registry::XRegistryKey
> {
102 rtl::Reference
< SimpleRegistry
> const & registry
,
103 RegistryKey
const & key
):
104 registry_(registry
), key_(key
) {}
107 virtual OUString SAL_CALL
getKeyName() override
;
109 virtual sal_Bool SAL_CALL
isReadOnly() override
;
111 virtual sal_Bool SAL_CALL
isValid() override
;
113 virtual css::registry::RegistryKeyType SAL_CALL
getKeyType(
114 OUString
const & rKeyName
) override
;
116 virtual css::registry::RegistryValueType SAL_CALL
getValueType() override
;
118 virtual sal_Int32 SAL_CALL
getLongValue() override
;
120 virtual void SAL_CALL
setLongValue(sal_Int32 value
) override
;
122 virtual css::uno::Sequence
< sal_Int32
> SAL_CALL
getLongListValue() override
;
124 virtual void SAL_CALL
setLongListValue(
125 css::uno::Sequence
< sal_Int32
> const & seqValue
) override
;
127 virtual OUString SAL_CALL
getAsciiValue() override
;
129 virtual void SAL_CALL
setAsciiValue(OUString
const & value
) override
;
131 virtual css::uno::Sequence
< OUString
> SAL_CALL
getAsciiListValue() override
;
133 virtual void SAL_CALL
setAsciiListValue(
134 css::uno::Sequence
< OUString
> const & seqValue
) override
;
136 virtual OUString SAL_CALL
getStringValue() override
;
138 virtual void SAL_CALL
setStringValue(OUString
const & value
) override
;
140 virtual css::uno::Sequence
< OUString
> SAL_CALL
getStringListValue() override
;
142 virtual void SAL_CALL
setStringListValue(
143 css::uno::Sequence
< OUString
> const & seqValue
) override
;
145 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getBinaryValue() override
;
147 virtual void SAL_CALL
setBinaryValue(
148 css::uno::Sequence
< sal_Int8
> const & value
) override
;
150 virtual css::uno::Reference
< css::registry::XRegistryKey
> SAL_CALL
openKey(
151 OUString
const & aKeyName
) override
;
153 virtual css::uno::Reference
< css::registry::XRegistryKey
> SAL_CALL
154 createKey(OUString
const & aKeyName
) override
;
156 virtual void SAL_CALL
closeKey() override
;
158 virtual void SAL_CALL
deleteKey(OUString
const & rKeyName
) override
;
161 css::uno::Sequence
< css::uno::Reference
< css::registry::XRegistryKey
> >
162 SAL_CALL
openKeys() override
;
164 virtual css::uno::Sequence
< OUString
> SAL_CALL
getKeyNames() override
;
166 virtual sal_Bool SAL_CALL
createLink(
167 OUString
const & aLinkName
, OUString
const & aLinkTarget
) override
;
169 virtual void SAL_CALL
deleteLink(OUString
const & rLinkName
) override
;
171 virtual OUString SAL_CALL
getLinkTarget(OUString
const & rLinkName
) override
;
173 virtual OUString SAL_CALL
getResolvedName(OUString
const & aKeyName
) override
;
175 rtl::Reference
< SimpleRegistry
> registry_
;
179 OUString
Key::getKeyName() {
180 osl::MutexGuard
guard(registry_
->mutex_
);
181 return key_
.getName();
184 sal_Bool
Key::isReadOnly()
186 osl::MutexGuard
guard(registry_
->mutex_
);
187 return key_
.isReadOnly();
190 sal_Bool
Key::isValid() {
191 osl::MutexGuard
guard(registry_
->mutex_
);
192 return key_
.isValid();
195 css::registry::RegistryKeyType
Key::getKeyType(OUString
const & )
197 return css::registry::RegistryKeyType_KEY
;
200 css::registry::RegistryValueType
Key::getValueType()
202 osl::MutexGuard
guard(registry_
->mutex_
);
205 RegError err
= key_
.getValueInfo(OUString(), &type
, &size
);
207 case RegError::NO_ERROR
:
209 case RegError::INVALID_VALUE
:
210 type
= RegValueType::NOT_DEFINED
;
213 throw css::registry::InvalidRegistryException(
214 "com.sun.star.registry.SimpleRegistry key getValueType:"
215 " underlying RegistryKey::getValueInfo() = " + OUString::number(static_cast<int>(err
)),
216 static_cast< OWeakObject
* >(this));
220 std::abort(); // this cannot happen
221 // pseudo-fall-through to avoid warnings on MSC
222 case RegValueType::NOT_DEFINED
:
223 return css::registry::RegistryValueType_NOT_DEFINED
;
224 case RegValueType::LONG
:
225 return css::registry::RegistryValueType_LONG
;
226 case RegValueType::STRING
:
227 return css::registry::RegistryValueType_ASCII
;
228 case RegValueType::UNICODE
:
229 return css::registry::RegistryValueType_STRING
;
230 case RegValueType::BINARY
:
231 return css::registry::RegistryValueType_BINARY
;
232 case RegValueType::LONGLIST
:
233 return css::registry::RegistryValueType_LONGLIST
;
234 case RegValueType::STRINGLIST
:
235 return css::registry::RegistryValueType_ASCIILIST
;
236 case RegValueType::UNICODELIST
:
237 return css::registry::RegistryValueType_STRINGLIST
;
241 sal_Int32
Key::getLongValue()
243 osl::MutexGuard
guard(registry_
->mutex_
);
245 RegError err
= key_
.getValue(OUString(), &value
);
247 case RegError::NO_ERROR
:
249 case RegError::INVALID_VALUE
:
250 throw css::registry::InvalidValueException(
251 "com.sun.star.registry.SimpleRegistry key getLongValue:"
252 " underlying RegistryKey::getValue() = RegError::INVALID_VALUE",
253 static_cast< OWeakObject
* >(this));
255 throw css::registry::InvalidRegistryException(
256 "com.sun.star.registry.SimpleRegistry key getLongValue:"
257 " underlying RegistryKey::getValue() = " + OUString::number(static_cast<int>(err
)),
258 static_cast< OWeakObject
* >(this));
263 void Key::setLongValue(sal_Int32 value
)
265 osl::MutexGuard
guard(registry_
->mutex_
);
266 RegError err
= key_
.setValue(
267 OUString(), RegValueType::LONG
, &value
, sizeof (sal_Int32
));
268 if (err
!= RegError::NO_ERROR
) {
269 throw css::registry::InvalidRegistryException(
270 "com.sun.star.registry.SimpleRegistry key setLongValue:"
271 " underlying RegistryKey::setValue() = " + OUString::number(static_cast<int>(err
)),
272 static_cast< OWeakObject
* >(this));
276 css::uno::Sequence
< sal_Int32
> Key::getLongListValue()
278 osl::MutexGuard
guard(registry_
->mutex_
);
279 RegistryValueList
< sal_Int32
> list
;
280 RegError err
= key_
.getLongListValue(OUString(), list
);
282 case RegError::NO_ERROR
:
284 case RegError::VALUE_NOT_EXISTS
:
285 return css::uno::Sequence
< sal_Int32
>();
286 case RegError::INVALID_VALUE
:
287 throw css::registry::InvalidValueException(
288 "com.sun.star.registry.SimpleRegistry key getLongListValue:"
289 " underlying RegistryKey::getLongListValue() ="
290 " RegError::INVALID_VALUE",
291 static_cast< OWeakObject
* >(this));
293 throw css::registry::InvalidRegistryException(
294 "com.sun.star.registry.SimpleRegistry key getLongListValue:"
295 " underlying RegistryKey::getLongListValue() = " + OUString::number(static_cast<int>(err
)),
296 static_cast< OWeakObject
* >(this));
298 sal_uInt32 n
= list
.getLength();
299 if (n
> SAL_MAX_INT32
) {
300 throw css::registry::InvalidValueException(
301 "com.sun.star.registry.SimpleRegistry key getLongListValue:"
302 " underlying RegistryKey::getLongListValue() too large",
303 static_cast< OWeakObject
* >(this));
305 css::uno::Sequence
< sal_Int32
> value(static_cast< sal_Int32
>(n
));
306 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
307 value
[static_cast< sal_Int32
>(i
)] = list
.getElement(i
);
312 void Key::setLongListValue(css::uno::Sequence
< sal_Int32
> const & seqValue
)
314 osl::MutexGuard
guard(registry_
->mutex_
);
315 std::vector
< sal_Int32
> list
;
316 for (sal_Int32 i
= 0; i
< seqValue
.getLength(); ++i
) {
317 list
.push_back(seqValue
[i
]);
319 RegError err
= key_
.setLongListValue(
320 OUString(), list
.data(), static_cast< sal_uInt32
>(list
.size()));
321 if (err
!= RegError::NO_ERROR
) {
322 throw css::registry::InvalidRegistryException(
323 "com.sun.star.registry.SimpleRegistry key setLongListValue:"
324 " underlying RegistryKey::setLongListValue() = " + OUString::number(static_cast<int>(err
)),
325 static_cast< OWeakObject
* >(this));
329 OUString
Key::getAsciiValue()
331 osl::MutexGuard
guard(registry_
->mutex_
);
334 RegError err
= key_
.getValueInfo(OUString(), &type
, &size
);
335 if (err
!= RegError::NO_ERROR
) {
336 throw css::registry::InvalidRegistryException(
337 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
338 " underlying RegistryKey::getValueInfo() = " + OUString::number(static_cast<int>(err
)),
339 static_cast< OWeakObject
* >(this));
341 if (type
!= RegValueType::STRING
) {
342 throw css::registry::InvalidValueException(
343 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
344 " underlying RegistryKey type = " + OUString::number(static_cast<int>(type
)),
345 static_cast< OWeakObject
* >(this));
347 // size contains terminating null (error in underlying registry.cxx):
349 throw css::registry::InvalidValueException(
350 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
351 " underlying RegistryKey size 0 cannot happen due to"
353 static_cast< OWeakObject
* >(this));
355 if (size
> SAL_MAX_INT32
) {
356 throw css::registry::InvalidValueException(
357 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
358 " underlying RegistryKey size too large",
359 static_cast< OWeakObject
* >(this));
361 std::vector
< char > list(size
);
362 err
= key_
.getValue(OUString(), &list
[0]);
363 if (err
!= RegError::NO_ERROR
) {
364 throw css::registry::InvalidRegistryException(
365 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
366 " underlying RegistryKey::getValue() = " + OUString::number(static_cast<int>(err
)),
367 static_cast< OWeakObject
* >(this));
369 if (list
[size
- 1] != '\0') {
370 throw css::registry::InvalidValueException(
371 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
372 " underlying RegistryKey value must be null-terminated due"
374 static_cast< OWeakObject
* >(this));
377 if (!rtl_convertStringToUString(
378 &value
.pData
, &list
[0],
379 static_cast< sal_Int32
>(size
- 1), RTL_TEXTENCODING_UTF8
,
380 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|
381 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|
382 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)))
384 throw css::registry::InvalidValueException(
385 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
386 " underlying RegistryKey not UTF-8",
387 static_cast< OWeakObject
* >(this));
392 void Key::setAsciiValue(OUString
const & value
)
394 osl::MutexGuard
guard(registry_
->mutex_
);
396 if (!value
.convertToString(
397 &utf8
, RTL_TEXTENCODING_UTF8
,
398 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
399 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)))
401 throw css::uno::RuntimeException(
402 "com.sun.star.registry.SimpleRegistry key setAsciiValue:"
404 static_cast< OWeakObject
* >(this));
406 RegError err
= key_
.setValue(
407 OUString(), RegValueType::STRING
,
408 const_cast< char * >(utf8
.getStr()), utf8
.getLength() + 1);
409 // +1 for terminating null (error in underlying registry.cxx)
410 if (err
!= RegError::NO_ERROR
) {
411 throw css::registry::InvalidRegistryException(
412 "com.sun.star.registry.SimpleRegistry key setAsciiValue:"
413 " underlying RegistryKey::setValue() = " + OUString::number(static_cast<int>(err
)),
414 static_cast< OWeakObject
* >(this));
418 css::uno::Sequence
< OUString
> Key::getAsciiListValue()
420 osl::MutexGuard
guard(registry_
->mutex_
);
421 RegistryValueList
< char * > list
;
422 RegError err
= key_
.getStringListValue(OUString(), list
);
424 case RegError::NO_ERROR
:
426 case RegError::VALUE_NOT_EXISTS
:
427 return css::uno::Sequence
< OUString
>();
428 case RegError::INVALID_VALUE
:
429 throw css::registry::InvalidValueException(
430 "com.sun.star.registry.SimpleRegistry key"
431 " getAsciiListValue: underlying"
432 " RegistryKey::getStringListValue() = RegError::INVALID_VALUE",
433 static_cast< OWeakObject
* >(this));
435 throw css::registry::InvalidRegistryException(
436 "com.sun.star.registry.SimpleRegistry key"
437 " getAsciiListValue: underlying"
438 " RegistryKey::getStringListValue() = " + OUString::number(static_cast<int>(err
)),
439 static_cast< OWeakObject
* >(this));
441 sal_uInt32 n
= list
.getLength();
442 if (n
> SAL_MAX_INT32
) {
443 throw css::registry::InvalidValueException(
444 "com.sun.star.registry.SimpleRegistry key"
445 " getAsciiListValue: underlying"
446 " RegistryKey::getStringListValue() too large",
447 static_cast< OWeakObject
* >(this));
449 css::uno::Sequence
< OUString
> value(static_cast< sal_Int32
>(n
));
450 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
451 char * el
= list
.getElement(i
);
452 sal_Int32 size
= rtl_str_getLength(el
);
453 if (!rtl_convertStringToUString(
454 &value
[static_cast< sal_Int32
>(i
)].pData
, el
, size
,
455 RTL_TEXTENCODING_UTF8
,
456 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|
457 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|
458 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)))
460 throw css::registry::InvalidValueException(
461 "com.sun.star.registry.SimpleRegistry key"
462 " getAsciiListValue: underlying RegistryKey not"
464 static_cast< OWeakObject
* >(this));
470 void Key::setAsciiListValue(
471 css::uno::Sequence
< OUString
> const & seqValue
)
473 osl::MutexGuard
guard(registry_
->mutex_
);
474 std::vector
< OString
> list
;
475 for (sal_Int32 i
= 0; i
< seqValue
.getLength(); ++i
) {
477 if (!seqValue
[i
].convertToString(
478 &utf8
, RTL_TEXTENCODING_UTF8
,
479 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
480 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)))
482 throw css::uno::RuntimeException(
483 "com.sun.star.registry.SimpleRegistry key"
484 " setAsciiListValue: value not UTF-16",
485 static_cast< OWeakObject
* >(this));
487 list
.push_back(utf8
);
489 std::vector
< char * > list2
;
490 for (std::vector
< OString
>::iterator
i(list
.begin()); i
!= list
.end();
493 list2
.push_back(const_cast< char * >(i
->getStr()));
495 RegError err
= key_
.setStringListValue(
496 OUString(), list2
.data(), static_cast< sal_uInt32
>(list2
.size()));
497 if (err
!= RegError::NO_ERROR
) {
498 throw css::registry::InvalidRegistryException(
499 "com.sun.star.registry.SimpleRegistry key"
500 " setAsciiListValue: underlying"
501 " RegistryKey::setStringListValue() = " + OUString::number(static_cast<int>(err
)),
502 static_cast< OWeakObject
* >(this));
506 OUString
Key::getStringValue()
508 osl::MutexGuard
guard(registry_
->mutex_
);
511 RegError err
= key_
.getValueInfo(OUString(), &type
, &size
);
512 if (err
!= RegError::NO_ERROR
) {
513 throw css::registry::InvalidRegistryException(
514 "com.sun.star.registry.SimpleRegistry key getStringValue:"
515 " underlying RegistryKey::getValueInfo() = " + OUString::number(static_cast<int>(err
)),
516 static_cast< OWeakObject
* >(this));
518 if (type
!= RegValueType::UNICODE
) {
519 throw css::registry::InvalidValueException(
520 "com.sun.star.registry.SimpleRegistry key getStringValue:"
521 " underlying RegistryKey type = " + OUString::number(static_cast<int>(type
)),
522 static_cast< OWeakObject
* >(this));
524 // size contains terminating null and is *2 (error in underlying
526 if (size
== 0 || (size
& 1) == 1) {
527 throw css::registry::InvalidValueException(
528 "com.sun.star.registry.SimpleRegistry key getStringValue:"
529 " underlying RegistryKey size 0 or odd cannot happen due to"
531 static_cast< OWeakObject
* >(this));
533 if (size
> SAL_MAX_INT32
) {
534 throw css::registry::InvalidValueException(
535 "com.sun.star.registry.SimpleRegistry key getStringValue:"
536 " underlying RegistryKey size too large",
537 static_cast< OWeakObject
* >(this));
539 std::vector
< sal_Unicode
> list(size
);
540 err
= key_
.getValue(OUString(), &list
[0]);
541 if (err
!= RegError::NO_ERROR
) {
542 throw css::registry::InvalidRegistryException(
543 "com.sun.star.registry.SimpleRegistry key getStringValue:"
544 " underlying RegistryKey::getValue() = " + OUString::number(static_cast<int>(err
)),
545 static_cast< OWeakObject
* >(this));
547 if (list
[size
/2 - 1] != 0) {
548 throw css::registry::InvalidValueException(
549 "com.sun.star.registry.SimpleRegistry key getStringValue:"
550 " underlying RegistryKey value must be null-terminated due"
552 static_cast< OWeakObject
* >(this));
554 return OUString(&list
[0], static_cast< sal_Int32
>(size
/2 - 1));
557 void Key::setStringValue(OUString
const & value
)
559 osl::MutexGuard
guard(registry_
->mutex_
);
560 RegError err
= key_
.setValue(
561 OUString(), RegValueType::UNICODE
,
562 const_cast< sal_Unicode
* >(value
.getStr()),
563 (value
.getLength() + 1) * sizeof (sal_Unicode
));
564 // +1 for terminating null (error in underlying registry.cxx)
565 if (err
!= RegError::NO_ERROR
) {
566 throw css::registry::InvalidRegistryException(
567 "com.sun.star.registry.SimpleRegistry key setStringValue:"
568 " underlying RegistryKey::setValue() = " + OUString::number(static_cast<int>(err
)),
569 static_cast< OWeakObject
* >(this));
573 css::uno::Sequence
< OUString
> Key::getStringListValue()
575 osl::MutexGuard
guard(registry_
->mutex_
);
576 RegistryValueList
< sal_Unicode
* > list
;
577 RegError err
= key_
.getUnicodeListValue(OUString(), list
);
579 case RegError::NO_ERROR
:
581 case RegError::VALUE_NOT_EXISTS
:
582 return css::uno::Sequence
< OUString
>();
583 case RegError::INVALID_VALUE
:
584 throw css::registry::InvalidValueException(
585 "com.sun.star.registry.SimpleRegistry key"
586 " getStringListValue: underlying"
587 " RegistryKey::getUnicodeListValue() = RegError::INVALID_VALUE",
588 static_cast< OWeakObject
* >(this));
590 throw css::registry::InvalidRegistryException(
591 "com.sun.star.registry.SimpleRegistry key"
592 " getStringListValue: underlying"
593 " RegistryKey::getUnicodeListValue() = " + OUString::number(static_cast<int>(err
)),
594 static_cast< OWeakObject
* >(this));
596 sal_uInt32 n
= list
.getLength();
597 if (n
> SAL_MAX_INT32
) {
598 throw css::registry::InvalidValueException(
599 "com.sun.star.registry.SimpleRegistry key"
600 " getStringListValue: underlying"
601 " RegistryKey::getUnicodeListValue() too large",
602 static_cast< OWeakObject
* >(this));
604 css::uno::Sequence
< OUString
> value(static_cast< sal_Int32
>(n
));
605 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
606 value
[static_cast< sal_Int32
>(i
)] = list
.getElement(i
);
611 void Key::setStringListValue(
612 css::uno::Sequence
< OUString
> const & seqValue
)
614 osl::MutexGuard
guard(registry_
->mutex_
);
615 std::vector
< sal_Unicode
* > list
;
616 for (sal_Int32 i
= 0; i
< seqValue
.getLength(); ++i
) {
617 list
.push_back(const_cast< sal_Unicode
* >(seqValue
[i
].getStr()));
619 RegError err
= key_
.setUnicodeListValue(
620 OUString(), list
.data(), static_cast< sal_uInt32
>(list
.size()));
621 if (err
!= RegError::NO_ERROR
) {
622 throw css::registry::InvalidRegistryException(
623 "com.sun.star.registry.SimpleRegistry key"
624 " setStringListValue: underlying"
625 " RegistryKey::setUnicodeListValue() = " + OUString::number(static_cast<int>(err
)),
626 static_cast< OWeakObject
* >(this));
630 css::uno::Sequence
< sal_Int8
> Key::getBinaryValue()
632 osl::MutexGuard
guard(registry_
->mutex_
);
635 RegError err
= key_
.getValueInfo(OUString(), &type
, &size
);
636 if (err
!= RegError::NO_ERROR
) {
637 throw css::registry::InvalidRegistryException(
638 "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
639 " underlying RegistryKey::getValueInfo() = " + OUString::number(static_cast<int>(err
)),
640 static_cast< OWeakObject
* >(this));
642 if (type
!= RegValueType::BINARY
) {
643 throw css::registry::InvalidValueException(
644 "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
645 " underlying RegistryKey type = " + OUString::number(static_cast<int>(type
)),
646 static_cast< OWeakObject
* >(this));
648 if (size
> SAL_MAX_INT32
) {
649 throw css::registry::InvalidValueException(
650 "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
651 " underlying RegistryKey size too large",
652 static_cast< OWeakObject
* >(this));
654 css::uno::Sequence
< sal_Int8
> value(static_cast< sal_Int32
>(size
));
655 err
= key_
.getValue(OUString(), value
.getArray());
656 if (err
!= RegError::NO_ERROR
) {
657 throw css::registry::InvalidRegistryException(
658 "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
659 " underlying RegistryKey::getValue() = " + OUString::number(static_cast<int>(err
)),
660 static_cast< OWeakObject
* >(this));
665 void Key::setBinaryValue(css::uno::Sequence
< sal_Int8
> const & value
)
667 osl::MutexGuard
guard(registry_
->mutex_
);
668 RegError err
= key_
.setValue(
669 OUString(), RegValueType::BINARY
,
670 const_cast< sal_Int8
* >(value
.getConstArray()),
671 static_cast< sal_uInt32
>(value
.getLength()));
672 if (err
!= RegError::NO_ERROR
) {
673 throw css::registry::InvalidRegistryException(
674 "com.sun.star.registry.SimpleRegistry key setBinaryValue:"
675 " underlying RegistryKey::setValue() = " + OUString::number(static_cast<int>(err
)),
676 static_cast< OWeakObject
* >(this));
680 css::uno::Reference
< css::registry::XRegistryKey
> Key::openKey(
681 OUString
const & aKeyName
)
683 osl::MutexGuard
guard(registry_
->mutex_
);
685 RegError err
= key_
.openKey(aKeyName
, key
);
687 case RegError::NO_ERROR
:
688 return new Key(registry_
, key
);
689 case RegError::KEY_NOT_EXISTS
:
690 return css::uno::Reference
< css::registry::XRegistryKey
>();
692 throw css::registry::InvalidRegistryException(
693 "com.sun.star.registry.SimpleRegistry key openKey:"
694 " underlying RegistryKey::openKey() = " + OUString::number(static_cast<int>(err
)),
695 static_cast< OWeakObject
* >(this));
699 css::uno::Reference
< css::registry::XRegistryKey
> Key::createKey(
700 OUString
const & aKeyName
)
702 osl::MutexGuard
guard(registry_
->mutex_
);
704 RegError err
= key_
.createKey(aKeyName
, key
);
706 case RegError::NO_ERROR
:
707 return new Key(registry_
, key
);
708 case RegError::INVALID_KEYNAME
:
709 return css::uno::Reference
< css::registry::XRegistryKey
>();
711 throw css::registry::InvalidRegistryException(
712 "com.sun.star.registry.SimpleRegistry key createKey:"
713 " underlying RegistryKey::createKey() = " + OUString::number(static_cast<int>(err
)),
714 static_cast< OWeakObject
* >(this));
720 osl::MutexGuard
guard(registry_
->mutex_
);
721 RegError err
= key_
.closeKey();
722 if (err
!= RegError::NO_ERROR
) {
723 throw css::registry::InvalidRegistryException(
724 "com.sun.star.registry.SimpleRegistry key closeKey:"
725 " underlying RegistryKey::closeKey() = " + OUString::number(static_cast<int>(err
)),
726 static_cast< OWeakObject
* >(this));
730 void Key::deleteKey(OUString
const & rKeyName
)
732 osl::MutexGuard
guard(registry_
->mutex_
);
733 RegError err
= key_
.deleteKey(rKeyName
);
734 if (err
!= RegError::NO_ERROR
) {
735 throw css::registry::InvalidRegistryException(
736 "com.sun.star.registry.SimpleRegistry key deleteKey:"
737 " underlying RegistryKey::deleteKey() = " + OUString::number(static_cast<int>(err
)),
738 static_cast< OWeakObject
* >(this));
742 css::uno::Sequence
< css::uno::Reference
< css::registry::XRegistryKey
> >
745 osl::MutexGuard
guard(registry_
->mutex_
);
746 RegistryKeyArray list
;
747 RegError err
= key_
.openSubKeys(OUString(), list
);
748 if (err
!= RegError::NO_ERROR
) {
749 throw css::registry::InvalidRegistryException(
750 "com.sun.star.registry.SimpleRegistry key openKeys:"
751 " underlying RegistryKey::openSubKeys() = " + OUString::number(static_cast<int>(err
)),
752 static_cast< OWeakObject
* >(this));
754 sal_uInt32 n
= list
.getLength();
755 if (n
> SAL_MAX_INT32
) {
756 throw css::registry::InvalidRegistryException(
757 "com.sun.star.registry.SimpleRegistry key getKeyNames:"
758 " underlying RegistryKey::getKeyNames() too large",
759 static_cast< OWeakObject
* >(this));
761 css::uno::Sequence
< css::uno::Reference
< css::registry::XRegistryKey
> >
762 keys(static_cast< sal_Int32
>(n
));
763 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
764 keys
[static_cast< sal_Int32
>(i
)] = new Key(
765 registry_
, list
.getElement(i
));
770 css::uno::Sequence
< OUString
> Key::getKeyNames()
772 osl::MutexGuard
guard(registry_
->mutex_
);
773 RegistryKeyNames list
;
774 RegError err
= key_
.getKeyNames(OUString(), list
);
775 if (err
!= RegError::NO_ERROR
) {
776 throw css::registry::InvalidRegistryException(
777 "com.sun.star.registry.SimpleRegistry key getKeyNames:"
778 " underlying RegistryKey::getKeyNames() = " + OUString::number(static_cast<int>(err
)),
779 static_cast< OWeakObject
* >(this));
781 sal_uInt32 n
= list
.getLength();
782 if (n
> SAL_MAX_INT32
) {
783 throw css::registry::InvalidRegistryException(
784 "com.sun.star.registry.SimpleRegistry key getKeyNames:"
785 " underlying RegistryKey::getKeyNames() too large",
786 static_cast< OWeakObject
* >(this));
788 css::uno::Sequence
< OUString
> names(static_cast< sal_Int32
>(n
));
789 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
790 names
[static_cast< sal_Int32
>(i
)] = list
.getElement(i
);
795 sal_Bool
Key::createLink(
796 OUString
const & /*aLinkName*/, OUString
const & /*aLinkTarget*/)
798 throw css::registry::InvalidRegistryException(
799 "com.sun.star.registry.SimpleRegistry key createLink: links are no longer supported",
800 static_cast< OWeakObject
* >(this));
803 void Key::deleteLink(OUString
const & /*rLinkName*/)
805 throw css::registry::InvalidRegistryException(
806 "com.sun.star.registry.SimpleRegistry key deleteLink: links are no longer supported",
807 static_cast< OWeakObject
* >(this));
810 OUString
Key::getLinkTarget(OUString
const & /*rLinkName*/)
812 throw css::registry::InvalidRegistryException(
813 "com.sun.star.registry.SimpleRegistry key getLinkTarget: links are no longer supported",
814 static_cast< OWeakObject
* >(this));
817 OUString
Key::getResolvedName(OUString
const & aKeyName
)
819 osl::MutexGuard
guard(registry_
->mutex_
);
821 RegError err
= key_
.getResolvedKeyName(aKeyName
, resolved
);
822 if (err
!= RegError::NO_ERROR
) {
823 throw css::registry::InvalidRegistryException(
824 "com.sun.star.registry.SimpleRegistry key getResolvedName:"
825 " underlying RegistryKey::getResolvedName() = " + OUString::number(static_cast<int>(err
)),
826 static_cast< OWeakObject
* >(this));
831 OUString
SimpleRegistry::getURL() {
832 osl::MutexGuard
guard(mutex_
);
833 return registry_
.getName();
836 void SimpleRegistry::open(
837 OUString
const & rURL
, sal_Bool bReadOnly
, sal_Bool bCreate
)
839 osl::MutexGuard
guard(mutex_
);
840 RegError err
= (rURL
.isEmpty() && bCreate
)
841 ? RegError::REGISTRY_NOT_EXISTS
842 : registry_
.open(rURL
, bReadOnly
? RegAccessMode::READONLY
: RegAccessMode::READWRITE
);
843 if (err
== RegError::REGISTRY_NOT_EXISTS
&& bCreate
) {
844 err
= registry_
.create(rURL
);
846 if (err
!= RegError::NO_ERROR
) {
847 throw css::registry::InvalidRegistryException(
848 "com.sun.star.registry.SimpleRegistry.open(" + rURL
+
849 "): underlying Registry::open/create() = " + OUString::number(static_cast<int>(err
)),
850 static_cast< OWeakObject
* >(this));
854 sal_Bool
SimpleRegistry::isValid() {
855 osl::MutexGuard
guard(mutex_
);
856 return registry_
.isValid();
859 void SimpleRegistry::close()
861 osl::MutexGuard
guard(mutex_
);
862 RegError err
= registry_
.close();
863 if (err
!= RegError::NO_ERROR
) {
864 throw css::registry::InvalidRegistryException(
865 "com.sun.star.registry.SimpleRegistry.close:"
866 " underlying Registry::close() = " + OUString::number(static_cast<int>(err
)),
867 static_cast< OWeakObject
* >(this));
871 void SimpleRegistry::destroy()
873 osl::MutexGuard
guard(mutex_
);
874 RegError err
= registry_
.destroy(OUString());
875 if (err
!= RegError::NO_ERROR
) {
876 throw css::registry::InvalidRegistryException(
877 "com.sun.star.registry.SimpleRegistry.destroy:"
878 " underlying Registry::destroy() = " + OUString::number(static_cast<int>(err
)),
879 static_cast< OWeakObject
* >(this));
883 css::uno::Reference
< css::registry::XRegistryKey
> SimpleRegistry::getRootKey()
885 osl::MutexGuard
guard(mutex_
);
887 RegError err
= registry_
.openRootKey(root
);
888 if (err
!= RegError::NO_ERROR
) {
889 throw css::registry::InvalidRegistryException(
890 "com.sun.star.registry.SimpleRegistry.getRootKey:"
891 " underlying Registry::getRootKey() = " + OUString::number(static_cast<int>(err
)),
892 static_cast< OWeakObject
* >(this));
894 return new Key(this, root
);
897 sal_Bool
SimpleRegistry::isReadOnly()
899 osl::MutexGuard
guard(mutex_
);
900 return registry_
.isReadOnly();
903 void SimpleRegistry::mergeKey(
904 OUString
const & aKeyName
, OUString
const & aUrl
)
906 osl::MutexGuard
guard(mutex_
);
908 RegError err
= registry_
.openRootKey(root
);
909 if (err
== RegError::NO_ERROR
) {
910 err
= registry_
.mergeKey(root
, aKeyName
, aUrl
, false);
913 case RegError::NO_ERROR
:
914 case RegError::MERGE_CONFLICT
:
916 case RegError::MERGE_ERROR
:
917 throw css::registry::MergeConflictException(
918 "com.sun.star.registry.SimpleRegistry.mergeKey:"
919 " underlying Registry::mergeKey() = RegError::MERGE_ERROR",
920 static_cast< cppu::OWeakObject
* >(this));
922 throw css::registry::InvalidRegistryException(
923 "com.sun.star.registry.SimpleRegistry.mergeKey:"
924 " underlying Registry::getRootKey/mergeKey() = " + OUString::number(static_cast<int>(err
)),
925 static_cast< OWeakObject
* >(this));
931 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
932 com_sun_star_comp_stoc_SimpleRegistry_get_implementation(
933 SAL_UNUSED_PARAMETER
css::uno::XComponentContext
*,
934 css::uno::Sequence
<css::uno::Any
> const &)
936 return cppu::acquire(new SimpleRegistry
);
939 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */