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/XInterface.hpp>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include <comphelper/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>
52 namespace com::sun::star::uno
{ class XComponentContext
; }
57 public cppu::WeakImplHelper
<
58 css::registry::XSimpleRegistry
, css::lang::XServiceInfo
>
66 virtual OUString SAL_CALL
getURL() override
;
68 virtual void SAL_CALL
open(
69 OUString
const & rURL
, sal_Bool bReadOnly
, sal_Bool bCreate
) override
;
71 virtual sal_Bool SAL_CALL
isValid() override
;
73 virtual void SAL_CALL
close() override
;
75 virtual void SAL_CALL
destroy() override
;
77 virtual css::uno::Reference
< css::registry::XRegistryKey
> SAL_CALL
78 getRootKey() override
;
80 virtual sal_Bool SAL_CALL
isReadOnly() override
;
82 virtual void SAL_CALL
mergeKey(
83 OUString
const & aKeyName
, OUString
const & aUrl
) override
;
85 virtual OUString SAL_CALL
getImplementationName() override
86 { return "com.sun.star.comp.stoc.SimpleRegistry"; }
88 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
89 { return cppu::supportsService(this, ServiceName
); }
91 virtual css::uno::Sequence
< OUString
> SAL_CALL
92 getSupportedServiceNames() override
94 css::uno::Sequence
< OUString
> names
{ "com.sun.star.registry.SimpleRegistry" };
101 class Key
: public cppu::WeakImplHelper
< css::registry::XRegistryKey
> {
104 rtl::Reference
< SimpleRegistry
> const & registry
,
105 RegistryKey
const & key
):
106 registry_(registry
), key_(key
) {}
109 virtual OUString SAL_CALL
getKeyName() override
;
111 virtual sal_Bool SAL_CALL
isReadOnly() override
;
113 virtual sal_Bool SAL_CALL
isValid() override
;
115 virtual css::registry::RegistryKeyType SAL_CALL
getKeyType(
116 OUString
const & rKeyName
) override
;
118 virtual css::registry::RegistryValueType SAL_CALL
getValueType() override
;
120 virtual sal_Int32 SAL_CALL
getLongValue() override
;
122 virtual void SAL_CALL
setLongValue(sal_Int32 value
) override
;
124 virtual css::uno::Sequence
< sal_Int32
> SAL_CALL
getLongListValue() override
;
126 virtual void SAL_CALL
setLongListValue(
127 css::uno::Sequence
< sal_Int32
> const & seqValue
) override
;
129 virtual OUString SAL_CALL
getAsciiValue() override
;
131 virtual void SAL_CALL
setAsciiValue(OUString
const & value
) override
;
133 virtual css::uno::Sequence
< OUString
> SAL_CALL
getAsciiListValue() override
;
135 virtual void SAL_CALL
setAsciiListValue(
136 css::uno::Sequence
< OUString
> const & seqValue
) override
;
138 virtual OUString SAL_CALL
getStringValue() override
;
140 virtual void SAL_CALL
setStringValue(OUString
const & value
) override
;
142 virtual css::uno::Sequence
< OUString
> SAL_CALL
getStringListValue() override
;
144 virtual void SAL_CALL
setStringListValue(
145 css::uno::Sequence
< OUString
> const & seqValue
) override
;
147 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getBinaryValue() override
;
149 virtual void SAL_CALL
setBinaryValue(
150 css::uno::Sequence
< sal_Int8
> const & value
) override
;
152 virtual css::uno::Reference
< css::registry::XRegistryKey
> SAL_CALL
openKey(
153 OUString
const & aKeyName
) override
;
155 virtual css::uno::Reference
< css::registry::XRegistryKey
> SAL_CALL
156 createKey(OUString
const & aKeyName
) override
;
158 virtual void SAL_CALL
closeKey() override
;
160 virtual void SAL_CALL
deleteKey(OUString
const & rKeyName
) override
;
163 css::uno::Sequence
< css::uno::Reference
< css::registry::XRegistryKey
> >
164 SAL_CALL
openKeys() override
;
166 virtual css::uno::Sequence
< OUString
> SAL_CALL
getKeyNames() override
;
168 virtual sal_Bool SAL_CALL
createLink(
169 OUString
const & aLinkName
, OUString
const & aLinkTarget
) override
;
171 virtual void SAL_CALL
deleteLink(OUString
const & rLinkName
) override
;
173 virtual OUString SAL_CALL
getLinkTarget(OUString
const & rLinkName
) override
;
175 virtual OUString SAL_CALL
getResolvedName(OUString
const & aKeyName
) override
;
177 rtl::Reference
< SimpleRegistry
> registry_
;
181 OUString
Key::getKeyName() {
182 osl::MutexGuard
guard(registry_
->mutex_
);
183 return key_
.getName();
186 sal_Bool
Key::isReadOnly()
188 osl::MutexGuard
guard(registry_
->mutex_
);
189 return key_
.isReadOnly();
192 sal_Bool
Key::isValid() {
193 osl::MutexGuard
guard(registry_
->mutex_
);
194 return key_
.isValid();
197 css::registry::RegistryKeyType
Key::getKeyType(OUString
const & )
199 return css::registry::RegistryKeyType_KEY
;
202 css::registry::RegistryValueType
Key::getValueType()
204 osl::MutexGuard
guard(registry_
->mutex_
);
207 RegError err
= key_
.getValueInfo(OUString(), &type
, &size
);
209 case RegError::NO_ERROR
:
211 case RegError::INVALID_VALUE
:
212 type
= RegValueType::NOT_DEFINED
;
215 throw css::registry::InvalidRegistryException(
216 "com.sun.star.registry.SimpleRegistry key getValueType:"
217 " underlying RegistryKey::getValueInfo() = " + OUString::number(static_cast<int>(err
)),
218 static_cast< OWeakObject
* >(this));
222 std::abort(); // this cannot happen
223 // pseudo-fall-through to avoid warnings on MSC
224 case RegValueType::NOT_DEFINED
:
225 return css::registry::RegistryValueType_NOT_DEFINED
;
226 case RegValueType::LONG
:
227 return css::registry::RegistryValueType_LONG
;
228 case RegValueType::STRING
:
229 return css::registry::RegistryValueType_ASCII
;
230 case RegValueType::UNICODE
:
231 return css::registry::RegistryValueType_STRING
;
232 case RegValueType::BINARY
:
233 return css::registry::RegistryValueType_BINARY
;
234 case RegValueType::LONGLIST
:
235 return css::registry::RegistryValueType_LONGLIST
;
236 case RegValueType::STRINGLIST
:
237 return css::registry::RegistryValueType_ASCIILIST
;
238 case RegValueType::UNICODELIST
:
239 return css::registry::RegistryValueType_STRINGLIST
;
243 sal_Int32
Key::getLongValue()
245 osl::MutexGuard
guard(registry_
->mutex_
);
247 RegError err
= key_
.getValue(OUString(), &value
);
249 case RegError::NO_ERROR
:
251 case RegError::INVALID_VALUE
:
252 throw css::registry::InvalidValueException(
253 "com.sun.star.registry.SimpleRegistry key getLongValue:"
254 " underlying RegistryKey::getValue() = RegError::INVALID_VALUE",
255 static_cast< OWeakObject
* >(this));
257 throw css::registry::InvalidRegistryException(
258 "com.sun.star.registry.SimpleRegistry key getLongValue:"
259 " underlying RegistryKey::getValue() = " + OUString::number(static_cast<int>(err
)),
260 static_cast< OWeakObject
* >(this));
265 void Key::setLongValue(sal_Int32 value
)
267 osl::MutexGuard
guard(registry_
->mutex_
);
268 RegError err
= key_
.setValue(
269 OUString(), RegValueType::LONG
, &value
, sizeof (sal_Int32
));
270 if (err
!= RegError::NO_ERROR
) {
271 throw css::registry::InvalidRegistryException(
272 "com.sun.star.registry.SimpleRegistry key setLongValue:"
273 " underlying RegistryKey::setValue() = " + OUString::number(static_cast<int>(err
)),
274 static_cast< OWeakObject
* >(this));
278 css::uno::Sequence
< sal_Int32
> Key::getLongListValue()
280 osl::MutexGuard
guard(registry_
->mutex_
);
281 RegistryValueList
< sal_Int32
> list
;
282 RegError err
= key_
.getLongListValue(OUString(), list
);
284 case RegError::NO_ERROR
:
286 case RegError::VALUE_NOT_EXISTS
:
287 return css::uno::Sequence
< sal_Int32
>();
288 case RegError::INVALID_VALUE
:
289 throw css::registry::InvalidValueException(
290 "com.sun.star.registry.SimpleRegistry key getLongListValue:"
291 " underlying RegistryKey::getLongListValue() ="
292 " RegError::INVALID_VALUE",
293 static_cast< OWeakObject
* >(this));
295 throw css::registry::InvalidRegistryException(
296 "com.sun.star.registry.SimpleRegistry key getLongListValue:"
297 " underlying RegistryKey::getLongListValue() = " + OUString::number(static_cast<int>(err
)),
298 static_cast< OWeakObject
* >(this));
300 sal_uInt32 n
= list
.getLength();
301 if (n
> SAL_MAX_INT32
) {
302 throw css::registry::InvalidValueException(
303 "com.sun.star.registry.SimpleRegistry key getLongListValue:"
304 " underlying RegistryKey::getLongListValue() too large",
305 static_cast< OWeakObject
* >(this));
307 css::uno::Sequence
< sal_Int32
> value(static_cast< sal_Int32
>(n
));
308 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
309 value
[static_cast< sal_Int32
>(i
)] = list
.getElement(i
);
314 void Key::setLongListValue(css::uno::Sequence
< sal_Int32
> const & seqValue
)
316 osl::MutexGuard
guard(registry_
->mutex_
);
317 auto list
= comphelper::sequenceToContainer
<std::vector
<sal_Int32
>>(seqValue
);
318 RegError err
= key_
.setLongListValue(
319 OUString(), list
.data(), static_cast< sal_uInt32
>(list
.size()));
320 if (err
!= RegError::NO_ERROR
) {
321 throw css::registry::InvalidRegistryException(
322 "com.sun.star.registry.SimpleRegistry key setLongListValue:"
323 " underlying RegistryKey::setLongListValue() = " + OUString::number(static_cast<int>(err
)),
324 static_cast< OWeakObject
* >(this));
328 OUString
Key::getAsciiValue()
330 osl::MutexGuard
guard(registry_
->mutex_
);
333 RegError err
= key_
.getValueInfo(OUString(), &type
, &size
);
334 if (err
!= RegError::NO_ERROR
) {
335 throw css::registry::InvalidRegistryException(
336 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
337 " underlying RegistryKey::getValueInfo() = " + OUString::number(static_cast<int>(err
)),
338 static_cast< OWeakObject
* >(this));
340 if (type
!= RegValueType::STRING
) {
341 throw css::registry::InvalidValueException(
342 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
343 " underlying RegistryKey type = " + OUString::number(static_cast<int>(type
)),
344 static_cast< OWeakObject
* >(this));
346 // size contains terminating null (error in underlying registry.cxx):
348 throw css::registry::InvalidValueException(
349 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
350 " underlying RegistryKey size 0 cannot happen due to"
352 static_cast< OWeakObject
* >(this));
354 if (size
> SAL_MAX_INT32
) {
355 throw css::registry::InvalidValueException(
356 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
357 " underlying RegistryKey size too large",
358 static_cast< OWeakObject
* >(this));
360 std::vector
< char > list(size
);
361 err
= key_
.getValue(OUString(), list
.data());
362 if (err
!= RegError::NO_ERROR
) {
363 throw css::registry::InvalidRegistryException(
364 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
365 " underlying RegistryKey::getValue() = " + OUString::number(static_cast<int>(err
)),
366 static_cast< OWeakObject
* >(this));
368 if (list
[size
- 1] != '\0') {
369 throw css::registry::InvalidValueException(
370 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
371 " underlying RegistryKey value must be null-terminated due"
373 static_cast< OWeakObject
* >(this));
376 if (!rtl_convertStringToUString(
377 &value
.pData
, list
.data(),
378 static_cast< sal_Int32
>(size
- 1), RTL_TEXTENCODING_UTF8
,
379 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|
380 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|
381 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)))
383 throw css::registry::InvalidValueException(
384 "com.sun.star.registry.SimpleRegistry key getAsciiValue:"
385 " underlying RegistryKey not UTF-8",
386 static_cast< OWeakObject
* >(this));
391 void Key::setAsciiValue(OUString
const & value
)
393 osl::MutexGuard
guard(registry_
->mutex_
);
395 if (!value
.convertToString(
396 &utf8
, RTL_TEXTENCODING_UTF8
,
397 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
398 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)))
400 throw css::uno::RuntimeException(
401 "com.sun.star.registry.SimpleRegistry key setAsciiValue:"
403 static_cast< OWeakObject
* >(this));
405 RegError err
= key_
.setValue(
406 OUString(), RegValueType::STRING
,
407 const_cast< char * >(utf8
.getStr()), utf8
.getLength() + 1);
408 // +1 for terminating null (error in underlying registry.cxx)
409 if (err
!= RegError::NO_ERROR
) {
410 throw css::registry::InvalidRegistryException(
411 "com.sun.star.registry.SimpleRegistry key setAsciiValue:"
412 " underlying RegistryKey::setValue() = " + OUString::number(static_cast<int>(err
)),
413 static_cast< OWeakObject
* >(this));
417 css::uno::Sequence
< OUString
> Key::getAsciiListValue()
419 osl::MutexGuard
guard(registry_
->mutex_
);
420 RegistryValueList
< char * > list
;
421 RegError err
= key_
.getStringListValue(OUString(), list
);
423 case RegError::NO_ERROR
:
425 case RegError::VALUE_NOT_EXISTS
:
426 return css::uno::Sequence
< OUString
>();
427 case RegError::INVALID_VALUE
:
428 throw css::registry::InvalidValueException(
429 "com.sun.star.registry.SimpleRegistry key"
430 " getAsciiListValue: underlying"
431 " RegistryKey::getStringListValue() = RegError::INVALID_VALUE",
432 static_cast< OWeakObject
* >(this));
434 throw css::registry::InvalidRegistryException(
435 "com.sun.star.registry.SimpleRegistry key"
436 " getAsciiListValue: underlying"
437 " RegistryKey::getStringListValue() = " + OUString::number(static_cast<int>(err
)),
438 static_cast< OWeakObject
* >(this));
440 sal_uInt32 n
= list
.getLength();
441 if (n
> SAL_MAX_INT32
) {
442 throw css::registry::InvalidValueException(
443 "com.sun.star.registry.SimpleRegistry key"
444 " getAsciiListValue: underlying"
445 " RegistryKey::getStringListValue() too large",
446 static_cast< OWeakObject
* >(this));
448 css::uno::Sequence
< OUString
> value(static_cast< sal_Int32
>(n
));
449 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
450 char * el
= list
.getElement(i
);
451 sal_Int32 size
= rtl_str_getLength(el
);
452 if (!rtl_convertStringToUString(
453 &value
[static_cast< sal_Int32
>(i
)].pData
, el
, size
,
454 RTL_TEXTENCODING_UTF8
,
455 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
|
456 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
|
457 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
)))
459 throw css::registry::InvalidValueException(
460 "com.sun.star.registry.SimpleRegistry key"
461 " getAsciiListValue: underlying RegistryKey not"
463 static_cast< OWeakObject
* >(this));
469 void Key::setAsciiListValue(
470 css::uno::Sequence
< OUString
> const & seqValue
)
472 osl::MutexGuard
guard(registry_
->mutex_
);
473 std::vector
< OString
> list
;
474 for (const auto& rValue
: seqValue
) {
476 if (!rValue
.convertToString(
477 &utf8
, RTL_TEXTENCODING_UTF8
,
478 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
479 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
)))
481 throw css::uno::RuntimeException(
482 "com.sun.star.registry.SimpleRegistry key"
483 " setAsciiListValue: value not UTF-16",
484 static_cast< OWeakObject
* >(this));
486 list
.push_back(utf8
);
488 std::vector
< char * > list2
;
489 for (const auto& rItem
: list
)
491 list2
.push_back(const_cast< char * >(rItem
.getStr()));
493 RegError err
= key_
.setStringListValue(
494 OUString(), list2
.data(), static_cast< sal_uInt32
>(list2
.size()));
495 if (err
!= RegError::NO_ERROR
) {
496 throw css::registry::InvalidRegistryException(
497 "com.sun.star.registry.SimpleRegistry key"
498 " setAsciiListValue: underlying"
499 " RegistryKey::setStringListValue() = " + OUString::number(static_cast<int>(err
)),
500 static_cast< OWeakObject
* >(this));
504 OUString
Key::getStringValue()
506 osl::MutexGuard
guard(registry_
->mutex_
);
509 RegError err
= key_
.getValueInfo(OUString(), &type
, &size
);
510 if (err
!= RegError::NO_ERROR
) {
511 throw css::registry::InvalidRegistryException(
512 "com.sun.star.registry.SimpleRegistry key getStringValue:"
513 " underlying RegistryKey::getValueInfo() = " + OUString::number(static_cast<int>(err
)),
514 static_cast< OWeakObject
* >(this));
516 if (type
!= RegValueType::UNICODE
) {
517 throw css::registry::InvalidValueException(
518 "com.sun.star.registry.SimpleRegistry key getStringValue:"
519 " underlying RegistryKey type = " + OUString::number(static_cast<int>(type
)),
520 static_cast< OWeakObject
* >(this));
522 // size contains terminating null and is *2 (error in underlying
524 if (size
== 0 || (size
& 1) == 1) {
525 throw css::registry::InvalidValueException(
526 "com.sun.star.registry.SimpleRegistry key getStringValue:"
527 " underlying RegistryKey size 0 or odd cannot happen due to"
529 static_cast< OWeakObject
* >(this));
531 if (size
> SAL_MAX_INT32
) {
532 throw css::registry::InvalidValueException(
533 "com.sun.star.registry.SimpleRegistry key getStringValue:"
534 " underlying RegistryKey size too large",
535 static_cast< OWeakObject
* >(this));
537 std::vector
< sal_Unicode
> list(size
);
538 err
= key_
.getValue(OUString(), list
.data());
539 if (err
!= RegError::NO_ERROR
) {
540 throw css::registry::InvalidRegistryException(
541 "com.sun.star.registry.SimpleRegistry key getStringValue:"
542 " underlying RegistryKey::getValue() = " + OUString::number(static_cast<int>(err
)),
543 static_cast< OWeakObject
* >(this));
545 if (list
[size
/2 - 1] != 0) {
546 throw css::registry::InvalidValueException(
547 "com.sun.star.registry.SimpleRegistry key getStringValue:"
548 " underlying RegistryKey value must be null-terminated due"
550 static_cast< OWeakObject
* >(this));
552 return OUString(list
.data(), static_cast< sal_Int32
>(size
/2 - 1));
555 void Key::setStringValue(OUString
const & value
)
557 osl::MutexGuard
guard(registry_
->mutex_
);
558 RegError err
= key_
.setValue(
559 OUString(), RegValueType::UNICODE
,
560 const_cast< sal_Unicode
* >(value
.getStr()),
561 (value
.getLength() + 1) * sizeof (sal_Unicode
));
562 // +1 for terminating null (error in underlying registry.cxx)
563 if (err
!= RegError::NO_ERROR
) {
564 throw css::registry::InvalidRegistryException(
565 "com.sun.star.registry.SimpleRegistry key setStringValue:"
566 " underlying RegistryKey::setValue() = " + OUString::number(static_cast<int>(err
)),
567 static_cast< OWeakObject
* >(this));
571 css::uno::Sequence
< OUString
> Key::getStringListValue()
573 osl::MutexGuard
guard(registry_
->mutex_
);
574 RegistryValueList
< sal_Unicode
* > list
;
575 RegError err
= key_
.getUnicodeListValue(OUString(), list
);
577 case RegError::NO_ERROR
:
579 case RegError::VALUE_NOT_EXISTS
:
580 return css::uno::Sequence
< OUString
>();
581 case RegError::INVALID_VALUE
:
582 throw css::registry::InvalidValueException(
583 "com.sun.star.registry.SimpleRegistry key"
584 " getStringListValue: underlying"
585 " RegistryKey::getUnicodeListValue() = RegError::INVALID_VALUE",
586 static_cast< OWeakObject
* >(this));
588 throw css::registry::InvalidRegistryException(
589 "com.sun.star.registry.SimpleRegistry key"
590 " getStringListValue: underlying"
591 " RegistryKey::getUnicodeListValue() = " + OUString::number(static_cast<int>(err
)),
592 static_cast< OWeakObject
* >(this));
594 sal_uInt32 n
= list
.getLength();
595 if (n
> SAL_MAX_INT32
) {
596 throw css::registry::InvalidValueException(
597 "com.sun.star.registry.SimpleRegistry key"
598 " getStringListValue: underlying"
599 " RegistryKey::getUnicodeListValue() too large",
600 static_cast< OWeakObject
* >(this));
602 css::uno::Sequence
< OUString
> value(static_cast< sal_Int32
>(n
));
603 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
604 value
[static_cast< sal_Int32
>(i
)] = list
.getElement(i
);
609 void Key::setStringListValue(
610 css::uno::Sequence
< OUString
> const & seqValue
)
612 osl::MutexGuard
guard(registry_
->mutex_
);
613 std::vector
< sal_Unicode
* > list
;
614 list
.reserve(seqValue
.getLength());
615 std::transform(seqValue
.begin(), seqValue
.end(), std::back_inserter(list
),
616 [](const OUString
& rValue
) -> sal_Unicode
* { return const_cast<sal_Unicode
*>(rValue
.getStr()); });
617 RegError err
= key_
.setUnicodeListValue(
618 OUString(), list
.data(), static_cast< sal_uInt32
>(list
.size()));
619 if (err
!= RegError::NO_ERROR
) {
620 throw css::registry::InvalidRegistryException(
621 "com.sun.star.registry.SimpleRegistry key"
622 " setStringListValue: underlying"
623 " RegistryKey::setUnicodeListValue() = " + OUString::number(static_cast<int>(err
)),
624 static_cast< OWeakObject
* >(this));
628 css::uno::Sequence
< sal_Int8
> Key::getBinaryValue()
630 osl::MutexGuard
guard(registry_
->mutex_
);
633 RegError err
= key_
.getValueInfo(OUString(), &type
, &size
);
634 if (err
!= RegError::NO_ERROR
) {
635 throw css::registry::InvalidRegistryException(
636 "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
637 " underlying RegistryKey::getValueInfo() = " + OUString::number(static_cast<int>(err
)),
638 static_cast< OWeakObject
* >(this));
640 if (type
!= RegValueType::BINARY
) {
641 throw css::registry::InvalidValueException(
642 "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
643 " underlying RegistryKey type = " + OUString::number(static_cast<int>(type
)),
644 static_cast< OWeakObject
* >(this));
646 if (size
> SAL_MAX_INT32
) {
647 throw css::registry::InvalidValueException(
648 "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
649 " underlying RegistryKey size too large",
650 static_cast< OWeakObject
* >(this));
652 css::uno::Sequence
< sal_Int8
> value(static_cast< sal_Int32
>(size
));
653 err
= key_
.getValue(OUString(), value
.getArray());
654 if (err
!= RegError::NO_ERROR
) {
655 throw css::registry::InvalidRegistryException(
656 "com.sun.star.registry.SimpleRegistry key getBinaryValue:"
657 " underlying RegistryKey::getValue() = " + OUString::number(static_cast<int>(err
)),
658 static_cast< OWeakObject
* >(this));
663 void Key::setBinaryValue(css::uno::Sequence
< sal_Int8
> const & value
)
665 osl::MutexGuard
guard(registry_
->mutex_
);
666 RegError err
= key_
.setValue(
667 OUString(), RegValueType::BINARY
,
668 const_cast< sal_Int8
* >(value
.getConstArray()),
669 static_cast< sal_uInt32
>(value
.getLength()));
670 if (err
!= RegError::NO_ERROR
) {
671 throw css::registry::InvalidRegistryException(
672 "com.sun.star.registry.SimpleRegistry key setBinaryValue:"
673 " underlying RegistryKey::setValue() = " + OUString::number(static_cast<int>(err
)),
674 static_cast< OWeakObject
* >(this));
678 css::uno::Reference
< css::registry::XRegistryKey
> Key::openKey(
679 OUString
const & aKeyName
)
681 osl::MutexGuard
guard(registry_
->mutex_
);
683 RegError err
= key_
.openKey(aKeyName
, key
);
685 case RegError::NO_ERROR
:
686 return new Key(registry_
, key
);
687 case RegError::KEY_NOT_EXISTS
:
688 return css::uno::Reference
< css::registry::XRegistryKey
>();
690 throw css::registry::InvalidRegistryException(
691 "com.sun.star.registry.SimpleRegistry key openKey:"
692 " underlying RegistryKey::openKey() = " + OUString::number(static_cast<int>(err
)),
693 static_cast< OWeakObject
* >(this));
697 css::uno::Reference
< css::registry::XRegistryKey
> Key::createKey(
698 OUString
const & aKeyName
)
700 osl::MutexGuard
guard(registry_
->mutex_
);
702 RegError err
= key_
.createKey(aKeyName
, key
);
704 case RegError::NO_ERROR
:
705 return new Key(registry_
, key
);
706 case RegError::INVALID_KEYNAME
:
707 return css::uno::Reference
< css::registry::XRegistryKey
>();
709 throw css::registry::InvalidRegistryException(
710 "com.sun.star.registry.SimpleRegistry key createKey:"
711 " underlying RegistryKey::createKey() = " + OUString::number(static_cast<int>(err
)),
712 static_cast< OWeakObject
* >(this));
718 osl::MutexGuard
guard(registry_
->mutex_
);
719 RegError err
= key_
.closeKey();
720 if (err
!= RegError::NO_ERROR
) {
721 throw css::registry::InvalidRegistryException(
722 "com.sun.star.registry.SimpleRegistry key closeKey:"
723 " underlying RegistryKey::closeKey() = " + OUString::number(static_cast<int>(err
)),
724 static_cast< OWeakObject
* >(this));
728 void Key::deleteKey(OUString
const & rKeyName
)
730 osl::MutexGuard
guard(registry_
->mutex_
);
731 RegError err
= key_
.deleteKey(rKeyName
);
732 if (err
!= RegError::NO_ERROR
) {
733 throw css::registry::InvalidRegistryException(
734 "com.sun.star.registry.SimpleRegistry key deleteKey:"
735 " underlying RegistryKey::deleteKey() = " + OUString::number(static_cast<int>(err
)),
736 static_cast< OWeakObject
* >(this));
740 css::uno::Sequence
< css::uno::Reference
< css::registry::XRegistryKey
> >
743 osl::MutexGuard
guard(registry_
->mutex_
);
744 RegistryKeyArray list
;
745 RegError err
= key_
.openSubKeys(OUString(), list
);
746 if (err
!= RegError::NO_ERROR
) {
747 throw css::registry::InvalidRegistryException(
748 "com.sun.star.registry.SimpleRegistry key openKeys:"
749 " underlying RegistryKey::openSubKeys() = " + OUString::number(static_cast<int>(err
)),
750 static_cast< OWeakObject
* >(this));
752 sal_uInt32 n
= list
.getLength();
753 if (n
> SAL_MAX_INT32
) {
754 throw css::registry::InvalidRegistryException(
755 "com.sun.star.registry.SimpleRegistry key getKeyNames:"
756 " underlying RegistryKey::getKeyNames() too large",
757 static_cast< OWeakObject
* >(this));
759 css::uno::Sequence
< css::uno::Reference
< css::registry::XRegistryKey
> >
760 keys(static_cast< sal_Int32
>(n
));
761 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
762 keys
[static_cast< sal_Int32
>(i
)] = new Key(
763 registry_
, list
.getElement(i
));
768 css::uno::Sequence
< OUString
> Key::getKeyNames()
770 osl::MutexGuard
guard(registry_
->mutex_
);
771 RegistryKeyNames list
;
772 RegError err
= key_
.getKeyNames(OUString(), list
);
773 if (err
!= RegError::NO_ERROR
) {
774 throw css::registry::InvalidRegistryException(
775 "com.sun.star.registry.SimpleRegistry key getKeyNames:"
776 " underlying RegistryKey::getKeyNames() = " + OUString::number(static_cast<int>(err
)),
777 static_cast< OWeakObject
* >(this));
779 sal_uInt32 n
= list
.getLength();
780 if (n
> SAL_MAX_INT32
) {
781 throw css::registry::InvalidRegistryException(
782 "com.sun.star.registry.SimpleRegistry key getKeyNames:"
783 " underlying RegistryKey::getKeyNames() too large",
784 static_cast< OWeakObject
* >(this));
786 css::uno::Sequence
< OUString
> names(static_cast< sal_Int32
>(n
));
787 for (sal_uInt32 i
= 0; i
< n
; ++i
) {
788 names
[static_cast< sal_Int32
>(i
)] = list
.getElement(i
);
793 sal_Bool
Key::createLink(
794 OUString
const & /*aLinkName*/, OUString
const & /*aLinkTarget*/)
796 throw css::registry::InvalidRegistryException(
797 "com.sun.star.registry.SimpleRegistry key createLink: links are no longer supported",
798 static_cast< OWeakObject
* >(this));
801 void Key::deleteLink(OUString
const & /*rLinkName*/)
803 throw css::registry::InvalidRegistryException(
804 "com.sun.star.registry.SimpleRegistry key deleteLink: links are no longer supported",
805 static_cast< OWeakObject
* >(this));
808 OUString
Key::getLinkTarget(OUString
const & /*rLinkName*/)
810 throw css::registry::InvalidRegistryException(
811 "com.sun.star.registry.SimpleRegistry key getLinkTarget: links are no longer supported",
812 static_cast< OWeakObject
* >(this));
815 OUString
Key::getResolvedName(OUString
const & aKeyName
)
817 osl::MutexGuard
guard(registry_
->mutex_
);
819 RegError err
= key_
.getResolvedKeyName(aKeyName
, resolved
);
820 if (err
!= RegError::NO_ERROR
) {
821 throw css::registry::InvalidRegistryException(
822 "com.sun.star.registry.SimpleRegistry key getResolvedName:"
823 " underlying RegistryKey::getResolvedName() = " + OUString::number(static_cast<int>(err
)),
824 static_cast< OWeakObject
* >(this));
829 OUString
SimpleRegistry::getURL() {
830 osl::MutexGuard
guard(mutex_
);
831 return registry_
.getName();
834 void SimpleRegistry::open(
835 OUString
const & rURL
, sal_Bool bReadOnly
, sal_Bool bCreate
)
837 osl::MutexGuard
guard(mutex_
);
838 RegError err
= (rURL
.isEmpty() && bCreate
)
839 ? RegError::REGISTRY_NOT_EXISTS
840 : registry_
.open(rURL
, bReadOnly
? RegAccessMode::READONLY
: RegAccessMode::READWRITE
);
841 if (err
== RegError::REGISTRY_NOT_EXISTS
&& bCreate
) {
842 err
= registry_
.create(rURL
);
844 if (err
!= RegError::NO_ERROR
) {
845 throw css::registry::InvalidRegistryException(
846 "com.sun.star.registry.SimpleRegistry.open(" + rURL
+
847 "): underlying Registry::open/create() = " + OUString::number(static_cast<int>(err
)),
848 static_cast< OWeakObject
* >(this));
852 sal_Bool
SimpleRegistry::isValid() {
853 osl::MutexGuard
guard(mutex_
);
854 return registry_
.isValid();
857 void SimpleRegistry::close()
859 osl::MutexGuard
guard(mutex_
);
860 RegError err
= registry_
.close();
861 if (err
!= RegError::NO_ERROR
) {
862 throw css::registry::InvalidRegistryException(
863 "com.sun.star.registry.SimpleRegistry.close:"
864 " underlying Registry::close() = " + OUString::number(static_cast<int>(err
)),
865 static_cast< OWeakObject
* >(this));
869 void SimpleRegistry::destroy()
871 osl::MutexGuard
guard(mutex_
);
872 RegError err
= registry_
.destroy(OUString());
873 if (err
!= RegError::NO_ERROR
) {
874 throw css::registry::InvalidRegistryException(
875 "com.sun.star.registry.SimpleRegistry.destroy:"
876 " underlying Registry::destroy() = " + OUString::number(static_cast<int>(err
)),
877 static_cast< OWeakObject
* >(this));
881 css::uno::Reference
< css::registry::XRegistryKey
> SimpleRegistry::getRootKey()
883 osl::MutexGuard
guard(mutex_
);
885 RegError err
= registry_
.openRootKey(root
);
886 if (err
!= RegError::NO_ERROR
) {
887 throw css::registry::InvalidRegistryException(
888 "com.sun.star.registry.SimpleRegistry.getRootKey:"
889 " underlying Registry::getRootKey() = " + OUString::number(static_cast<int>(err
)),
890 static_cast< OWeakObject
* >(this));
892 return new Key(this, root
);
895 sal_Bool
SimpleRegistry::isReadOnly()
897 osl::MutexGuard
guard(mutex_
);
898 return registry_
.isReadOnly();
901 void SimpleRegistry::mergeKey(
902 OUString
const & aKeyName
, OUString
const & aUrl
)
904 osl::MutexGuard
guard(mutex_
);
906 RegError err
= registry_
.openRootKey(root
);
907 if (err
== RegError::NO_ERROR
) {
908 err
= registry_
.mergeKey(root
, aKeyName
, aUrl
, false);
911 case RegError::NO_ERROR
:
912 case RegError::MERGE_CONFLICT
:
914 case RegError::MERGE_ERROR
:
915 throw css::registry::MergeConflictException(
916 "com.sun.star.registry.SimpleRegistry.mergeKey:"
917 " underlying Registry::mergeKey() = RegError::MERGE_ERROR",
918 static_cast< cppu::OWeakObject
* >(this));
920 throw css::registry::InvalidRegistryException(
921 "com.sun.star.registry.SimpleRegistry.mergeKey:"
922 " underlying Registry::getRootKey/mergeKey() = " + OUString::number(static_cast<int>(err
)),
923 static_cast< OWeakObject
* >(this));
929 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
930 com_sun_star_comp_stoc_SimpleRegistry_get_implementation(
931 SAL_UNUSED_PARAMETER
css::uno::XComponentContext
*,
932 css::uno::Sequence
<css::uno::Any
> const &)
934 return cppu::acquire(new SimpleRegistry
);
937 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */