merge the formfield patch from ooo-build
[ooovba.git] / configmgr / workben / apitest / cfgregistry.cxx
bloba1f26c25cc17e67157884ef027a2d10e162acfc0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cfgregistry.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
33 #include <memory.h>
34 #include <stdio.h>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36 #include <com/sun/star/container/XNameReplace.hpp>
37 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
38 #include <com/sun/star/container/XChild.hpp>
39 #include <com/sun/star/util/XChangesBatch.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/registry/XSimpleRegistry.hpp>
42 #include <com/sun/star/util/XFlushable.hpp>
43 #include <cppuhelper/servicefactory.hxx>
44 #include <cppuhelper/implbase1.hxx>
45 #ifndef _CPPUHELPER_EXTRACT_HXX_
46 #include <cppuhelper/extract.hxx>
47 #endif
48 #include <vos/conditn.hxx>
49 #include <osl/diagnose.h>
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::util;
54 using namespace ::com::sun::star::xml;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::container;
57 using namespace ::com::sun::star::registry;
58 using namespace ::vos;
59 using namespace ::cppu;
60 //using namespace ::configmgr;
62 //=============================================================================
63 //= a dirty littly class for printing ascii characters
64 //=============================================================================
65 class OAsciiOutput
67 protected:
68 sal_Char* m_pCharacters;
70 public:
71 OAsciiOutput(const ::rtl::OUString& _rUnicodeChars);
72 ~OAsciiOutput() { delete m_pCharacters; }
74 const sal_Char* getCharacters() const { return m_pCharacters; }
77 //-----------------------------------------------------------------------------
78 OAsciiOutput::OAsciiOutput(const ::rtl::OUString& _rUnicodeChars)
80 sal_Int32 nLen = _rUnicodeChars.getLength();
81 m_pCharacters = new sal_Char[nLen + 1];
82 sal_Char* pFillPtr = m_pCharacters;
83 const sal_Unicode* pSourcePtr = _rUnicodeChars.getStr();
84 #if OSL_DEBUG_LEVEL > 1
85 sal_Bool bAsserted = sal_False;
86 #endif
87 for (sal_Int32 i=0; i<nLen; ++i, ++pFillPtr, ++pSourcePtr)
89 OSL_ENSURE(bAsserted || !(bAsserted = (*pSourcePtr >= 0x80)),
90 "OAsciiOutput::OAsciiOutput : non-ascii character found !");
91 *pFillPtr = *reinterpret_cast<const sal_Char*>(pSourcePtr);
93 *pFillPtr = 0;
96 #define ASCII_STRING(rtlOUString) OAsciiOutput(rtlOUString).getCharacters()
97 #define UNI_STRING(asciiString) ::rtl::OUString::createFromAscii(asciiString)
99 //=============================================================================
100 //=============================================================================
102 #if (defined UNX) || (defined OS2)
103 void main( int argc, char * argv[] )
104 #else
105 void _cdecl main( int argc, char * argv[] )
106 #endif
108 TimeValue aTimeout;
109 aTimeout.Seconds = 5;
110 aTimeout.Nanosec = 0;
112 Reference< XMultiServiceFactory > xORB = createRegistryServiceFactory(
113 ::rtl::OUString::createFromAscii("l:\\bin.a\\applicat.rdb"),
114 ::rtl::OUString()
116 if (!xORB.is())
118 fprintf(stdout, "could not create the service factory !\n\n");
119 return;
124 Reference< XSimpleRegistry > xConfigurationRegistry;
125 printf("instantiating the configuration registry access\n\r");
126 xConfigurationRegistry = xConfigurationRegistry.query(
127 xORB->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationRegistry"))
130 const sal_Char* pLayoutNode = "com.sun.star.Inet";
131 printf("opening the registry access to %s\n\r", pLayoutNode);
132 xConfigurationRegistry->open(UNI_STRING(pLayoutNode), sal_False, sal_False);
134 printf("retrieving the root key, enumerating elements\n\r");
135 Reference< XRegistryKey > xRoot = xConfigurationRegistry->getRootKey();
136 Sequence< ::rtl::OUString > aKeyNames = xRoot->getKeyNames();
137 const ::rtl::OUString* pKeyNames = aKeyNames.getConstArray();
138 for (sal_Int32 i=0; i<aKeyNames.getLength(); ++i, ++pKeyNames)
139 printf("\t%i\t%s\n\r", i, ASCII_STRING(*pKeyNames));
141 const sal_Char* pUpdateKey = "Proxy/NoProxy";
142 printf("retrieving the key for %s\n\r", pUpdateKey);
143 Reference< XRegistryKey > xTabStopsKey = xRoot->openKey(UNI_STRING(pUpdateKey));
145 /* xTabStopsKey->createKey(UNI_STRING("blupp"));
147 Sequence< ::rtl::OUString > sLanguages = xTabStopsKey->getStringListValue();
148 sLanguages.realloc(sLanguages.getLength() + 1);
149 sLanguages[sLanguages.getLength() - 1] = UNI_STRING("ru");
150 xTabStopsKey->setStringListValue(sLanguages);
153 ::rtl::OUString sTest = xTabStopsKey->getStringValue();
154 xTabStopsKey->setStringValue(UNI_STRING("blimp"));
156 printf("flushing the changes\n\r");
157 Reference< XFlushable > xCommit(xConfigurationRegistry, UNO_QUERY);
158 xCommit->flush();
160 catch(RuntimeException& e)
162 printf("\n\r\n\rcaught an RuntimeException :\n\r");
163 printf(" exception message : %s\n\r", ASCII_STRING(e.Message));
164 return;
166 catch(Exception& e)
168 printf("\n\r\n\rcaught an Exception :\n\r");
169 printf(" exception message : %s\n\r", ASCII_STRING(e.Message));
170 return;