LCOV - code coverage report
Current view: top level - stoc/source/simpleregistry - simpleregistry.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 461 0.0 %
Date: 2014-04-14 Functions: 0 47 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10