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