Update ooo320-m1
[ooovba.git] / configmgr / workben / apitest / cfgapi.cxx
blobf774027c9ce53c1643f0712bee7b852933232013
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: cfgapi.cxx,v $
10 * $Revision: 1.24 $
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 #define _PRIVATE_TEST_
35 #include <iostream>
36 using namespace std;
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/uno/Type.hxx>
40 #include <com/sun/star/uno/TypeClass.hpp>
42 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/container/XHierarchicalName.hpp>
45 #include <com/sun/star/container/XNamed.hpp>
46 #include <com/sun/star/container/XNameReplace.hpp>
47 #include <com/sun/star/container/XChild.hpp>
48 #include <com/sun/star/beans/XExactName.hpp>
49 #include <com/sun/star/util/XChangesBatch.hpp>
52 #include <rtl/ustring.hxx>
53 #include <rtl/string.hxx>
54 #include <cppuhelper/servicefactory.hxx>
55 #include <com/sun/star/uno/Sequence.h>
56 #include <com/sun/star/uno/Any.h>
57 #include <osl/profile.hxx>
58 #include <osl/process.h>
59 #include <osl/file.h>
61 #include "createpropertyvalue.hxx"
63 #include "typeconverter.hxx"
65 // #include <com/sun/star/configuration/XConfigurationSync.hpp>
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::lang;
69 using namespace ::com::sun::star::container;
70 using namespace ::com::sun::star::beans;
71 //using namespace ::com::sun::star::util;
72 using namespace ::com::sun::star::util;
74 using ::rtl::OUString;
75 using ::rtl::OString;
76 //using namespace ::configmgr;
78 using namespace ::cppu;
80 #define ASCII(x) ::rtl::OUString::createFromAscii(x)
82 ostream& operator << (ostream& out, rtl::OUString const& aStr)
84 sal_Unicode const* const pStr = aStr.getStr();
85 sal_Unicode const* const pEnd = pStr + aStr.getLength();
86 for (sal_Unicode const* p = pStr; p < pEnd; ++p)
87 if (0 < *p && *p < 127) // ASCII
88 out << char(*p);
89 else
90 out << "[\\u" << hex << *p << "]";
91 return out;
94 void showSequence(const Sequence<OUString> &aSeq)
96 OUString aArray;
97 const OUString *pStr = aSeq.getConstArray();
98 for (int i=0;i<aSeq.getLength();i++)
100 OUString aStr = pStr[i];
101 // aArray += aStr + ASCII(", ");
102 cout << aStr << endl;
104 volatile int dummy = 0;
107 //=============================================================================
109 inline void operator <<= (::rtl::OUString& _rUnicodeString, const sal_Char* _pAsciiString)
111 _rUnicodeString = ::rtl::OUString::createFromAscii(_pAsciiString);
114 inline void operator <<= (::rtl::OUString& _rUnicodeString, const ::rtl::OString& _rAsciiString)
116 _rUnicodeString <<= _rAsciiString.getStr();
119 inline void operator <<= (Any& _rUnoValue, const sal_Char* _pAsciiString)
121 _rUnoValue <<= ::rtl::OUString::createFromAscii(_pAsciiString);
124 inline void operator <<= (Any& _rUnoValue, const ::rtl::OString& _rAsciiString)
126 _rUnoValue <<= _rAsciiString.getStr();
129 //=============================================================================
130 void test_read_access(Reference< XInterface >& xIface, Reference< XMultiServiceFactory > &xMSF);
131 //=============================================================================
132 struct prompt_and_wait
134 char const* myText;
135 prompt_and_wait(char const* text = "") : myText(text) {}
136 ~prompt_and_wait()
138 cout << myText << ">" << endl;
139 int const mx = int( (+0u - +1u) >> 1);
141 char c=0;
142 if (cin.get(c) && c != '\n')
143 cin.ignore(mx,'\n');
146 static prompt_and_wait exit_prompt("Quitting\nQ");
149 Reference< XChangesBatch > xChangesBatch = NULL;
150 void commit()
152 if (xChangesBatch.is())
154 xChangesBatch->commitChanges();
158 // -----------------------------------------------------------------------------
159 static sal_Bool s_bInitialized = sal_False;
160 #ifdef LLA_PRIVAT_DEBUG
161 static const sal_Char* s_pSourcePath = "l:/src625/configmgr/workben/local_io/share";
162 static const sal_Char* s_pUpdatePath = "l:/src625/configmgr/workben/local_io/user";
163 static const sal_Char* s_pRootNode = "org.openoffice.ucb.Hierarchy"; // "org.openoffice.test";
164 static const sal_Char* s_pServerType = "local";
165 static const sal_Char* s_pLocale = "de-DE";
166 static const sal_Char* s_pServer = "";
167 static const sal_Char* s_pUser = "";
168 static const sal_Char* s_pPassword = "";
169 #else
170 static const sal_Char* s_pSourcePath = "g:/src/configmgr/workben/local_io/share";
171 static const sal_Char* s_pUpdatePath = "g:/src/configmgr/workben/local_io/user";
172 static const sal_Char* s_pRootNode = "org.openoffice.Office.TypeDetection";
173 static const sal_Char* s_pServerType = "setup";
174 static const sal_Char* s_pLocale = "de-DE";
175 static const sal_Char* s_pServer = "lautrec-3108:19205";
176 static const sal_Char* s_pUser = "lars";
177 static const sal_Char* s_pPassword = "";
178 #endif
181 // -----------------------------------------------------------------------------
182 static void loadDefaults()
184 if (s_bInitialized)
185 return;
187 s_bInitialized = sal_True;
191 // the executable file name
192 ::rtl::OUString sExecutable;
193 osl_getExecutableFile(&sExecutable.pData);
194 // cut the name, add a cfgapi.ini to the path
195 sal_Int32 nLastSep = sExecutable.lastIndexOf('/');
196 if (-1 != nLastSep)
197 sExecutable = sExecutable.copy(0, nLastSep + 1);
198 #ifdef UNX
199 sExecutable += ::rtl::OUString::createFromAscii("cfgapirc");
200 #else
201 sExecutable += ::rtl::OUString::createFromAscii("cfgapi.ini");
202 #endif
203 ::rtl::OUString sNormalized;
204 sNormalized = sExecutable;
205 if (1)
207 ::osl::Profile aProfile(sNormalized);
209 static ::rtl::OString sSection("defaults");
210 static ::rtl::OString sSourcePath("sourcepath");
211 static ::rtl::OString sUpdatePath("updatepath");
212 static ::rtl::OString sRootNode("rootnode");
213 static ::rtl::OString sServerType("servertype");
214 static ::rtl::OString sLocale("Locale");
215 static ::rtl::OString sServer("Server");
216 static ::rtl::OString sUser("User");
217 static ::rtl::OString sPassword("Password");
219 // read some strings.
220 // Do this static because we want to redirect the global static character pointers to the buffers.
221 static ::rtl::OString s_sSourcePath = aProfile.readString(sSection, sSourcePath, s_pSourcePath);
222 static ::rtl::OString s_sUpdatePath = aProfile.readString(sSection, sUpdatePath, s_pUpdatePath);
223 static ::rtl::OString s_sRootNode = aProfile.readString(sSection, sRootNode, s_pRootNode);
224 static ::rtl::OString s_sServerType = aProfile.readString(sSection, sServerType, s_pServerType);
225 static ::rtl::OString s_sLocale = aProfile.readString(sSection, sLocale, s_pLocale);
226 static ::rtl::OString s_sServer = aProfile.readString(sSection, sServer, s_pServer);
227 static ::rtl::OString s_sUser = aProfile.readString(sSection, sUser, s_pUser);
228 static ::rtl::OString s_sPassword = aProfile.readString(sSection, sPassword, s_pPassword);
230 // do this redirection
231 s_pSourcePath = s_sSourcePath.getStr();
232 s_pUpdatePath = s_sUpdatePath.getStr();
233 s_pRootNode = s_sRootNode.getStr();
234 s_pServerType = s_sServerType.getStr();
235 s_pLocale = s_sLocale.getStr();
236 s_pServer = s_sServer.getStr();
237 s_pUser = s_sUser.getStr();
238 s_pPassword = s_sPassword.getStr();
241 catch(std::exception& e)
243 e.what(); // silence warnings
247 // -----------------------------------------------------------------------------
248 Sequence<Any> createSequence(const OUString &sUser, const OUString &sPasswd)
250 Sequence< Any > aCPArgs;
252 if (sUser.getLength() > 0)
254 aCPArgs.realloc(1);
255 aCPArgs[0] <<= configmgr::createPropertyValue(ASCII("user"), sUser);
257 if (sPasswd.getLength() > 0)
259 aCPArgs.realloc(2);
260 aCPArgs[1] <<= configmgr::createPropertyValue(ASCII("password"), sPasswd);
262 return aCPArgs;
265 //=============================================================================
266 #include <string.h>
267 #if (defined UNX) || (defined OS2)
268 #else
269 #include <conio.h>
270 #endif
272 OString input(const char* pDefaultText, char cEcho)
274 // PRE: a Default Text would be shown, cEcho is a Value which will show if a key is pressed.
275 const int MAX_INPUT_LEN = 500;
276 char aBuffer[MAX_INPUT_LEN];
278 strcpy(aBuffer, pDefaultText);
279 int nLen = strlen(aBuffer);
281 #ifdef WNT
282 char ch = '\0';
284 cout << aBuffer;
285 cout.flush();
287 while(ch != 13)
289 ch = getch();
290 if (ch == 8)
292 if (nLen > 0)
294 cout << "\b \b";
295 cout.flush();
296 --nLen;
297 aBuffer[nLen] = '\0';
299 else
301 cout << "\a";
302 cout.flush();
305 else if (ch != 13)
307 if (nLen < MAX_INPUT_LEN)
309 if (cEcho == 0)
311 cout << ch;
313 else
315 cout << cEcho;
317 cout.flush();
318 aBuffer[nLen++] = ch;
319 aBuffer[nLen] = '\0';
321 else
323 cout << "\a";
324 cout.flush();
328 #else
329 if (!cin.getline(aBuffer,sizeof aBuffer))
330 return OString();
331 #endif
332 return OString(aBuffer);
335 // -----------------------------------------------------------------------------
336 rtl::OUString enterValue(const char* _aStr, const char* _aDefault, bool _bIsAPassword)
338 cout << _aStr;
339 cout.flush();
341 OUString sValue;
342 sValue <<= input(_aDefault, _bIsAPassword ? '*' : 0);
343 return sValue;
348 // -----------------------------------------------------------------------------
349 // ---------------------------------- M A I N ----------------------------------
350 // -----------------------------------------------------------------------------
352 #if (defined UNX) || (defined OS2)
353 int main( int argc, char * argv[] )
354 #else
355 int _cdecl main( int argc, char * argv[] )
356 #endif
358 TimeValue aTimeout;
359 aTimeout.Seconds = 5;
360 aTimeout.Nanosec = 0;
362 // cout << " Please insert Text: ";
363 // cout.flush();
364 // OString aTxt = input("Der Text", 0);
365 // cout << endl << "You inserted: " << aTxt.getStr() << endl;
367 // cout << "Please insert Password: ";
368 // cout.flush();
369 // OString aPasswd = input("", '*');
370 // cout << endl << "You inserted: " << aPasswd.getStr() << endl;
372 loadDefaults();
376 OUString const sServiceRegistry = OUString::createFromAscii( argc > 1 ? argv[1] : "applicat.rdb" );
377 Reference< XMultiServiceFactory > xORB = createRegistryServiceFactory(
378 sServiceRegistry,
379 ::rtl::OUString()
381 if (!xORB.is())
383 ::flush(cout);
384 cerr << "Could not create the service factory !\n\n";
385 return 1;
387 cout << "Service factory created !\n---------------------------------------------------------------" << endl;
389 Sequence< Any > aCPArgs;
391 OUString sServerType = enterValue("servertype: ", s_pServerType, false);
392 cout << endl;
395 rtl::OUString sUser;
397 bool bLocal = sServerType.equalsIgnoreAsciiCase(ASCII("local")) || sServerType.equalsIgnoreAsciiCase(ASCII("setup"));
398 if (!bLocal)
400 rtl::OUString sServer;
401 sServer = enterValue("server : ", s_pServer,false);
402 cout << endl;
404 sUser = enterValue("user : ", s_pUser, false);
405 cout << endl;
407 OUString sPasswd = enterValue("password: ", s_pPassword, true);
408 cout << endl;
410 aCPArgs = createSequence(sUser, sPasswd);
412 aCPArgs.realloc(aCPArgs.getLength() + 1);
413 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("server"), sServer);
415 OUString sTimeout = ASCII("10000");
416 aCPArgs.realloc(aCPArgs.getLength() + 1);
417 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("timeout"), sTimeout);
420 else
422 rtl::OUString sSharePath, sUserPath;
423 sSharePath = enterValue("share path: ", s_pSourcePath, false);
424 cout << endl;
425 sUserPath = enterValue("user path : ", s_pUpdatePath, false);
426 cout << endl;
428 aCPArgs.realloc(aCPArgs.getLength() + 1);
429 sal_Int32 nCount = aCPArgs.getLength() - 1;
430 Any *pAny = &aCPArgs[nCount];
431 *pAny <<= configmgr::createPropertyValue(ASCII("sourcepath"), sSharePath);
432 aCPArgs.realloc(aCPArgs.getLength() + 1);
433 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("updatepath"), sUserPath);
436 aCPArgs.realloc(aCPArgs.getLength() + 1);
437 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("servertype"), sServerType);
439 Reference< XMultiServiceFactory > xCfgProvider(
440 xORB->createInstanceWithArguments(
441 ::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"),
442 aCPArgs),
443 UNO_QUERY);
444 if (!xCfgProvider.is())
446 ::flush(cout);
447 cerr << "Could not create the configuration provider !\n\n";
448 return 3;
454 char aPath[300] = "/";
455 int nStart = sizeof( "/" ) - 1;
457 cout << "---------------------------------------------------------------\n Configuration Provider created !\n---------------------------------------------------------------" << endl;
459 Sequence< Any > aArgs;
460 aArgs = createSequence(sUser, ASCII(""));
462 OUString sPath = enterValue("nodepath: ", s_pRootNode, false);
463 cout << endl;
465 aArgs.realloc(aArgs.getLength() + 1);
466 aArgs[aArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("nodepath"), sPath);
468 if (!bLocal)
470 OUString sLocale = enterValue("locale : ", s_pLocale, false);
471 cout << endl;
472 aArgs.realloc(aArgs.getLength() + 1);
473 aArgs[aArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("locale"), sLocale);
476 #else
477 OUString aStr = ASCII("String");
478 sal_Int32 nDepth = 10;
479 Sequence< Any > aArgs(2);
481 aArgs[0] <<= aStr;
482 aArgs[1] <<= nDepth;
483 #endif
485 Reference< XInterface > xIFace = xCfgProvider->createInstanceWithArguments(
486 OUString::createFromAscii("com.sun.star.configuration.ConfigurationUpdateAccess"),
487 aArgs);
488 cout << "---------------------------------------------------------------\n Configuration Read/Write Access created !\n---------------------------------------------------------------" << endl;
490 xChangesBatch = Reference< XChangesBatch >(xIFace, UNO_QUERY);
492 Sequence<OUString> aSeq = xCfgProvider->getAvailableServiceNames();
493 showSequence(aSeq);
495 test_read_access(xIFace, xCfgProvider);
497 catch (Exception& e)
499 ::flush(cout);
500 cerr << "Caught exception: " << e.Message << endl;
503 catch (...)
505 flush(cout);
506 cerr << "BUG: Caught UNKNOWN exception (?) " << endl;
509 return 0;
512 ///////////////////////////////////////////////////////////////////////////////////////////
513 void test(Reference< XHierarchicalName >& xAccessName)
515 if (xAccessName.is())
516 cout << "Accessing Node: " << xAccessName->getHierarchicalName();
517 else
518 cout << "BUG: XHierarchicalName not available";
519 cout << endl;
521 void test(Reference< XNamed >& xAccess)
523 if (xAccess.is())
524 cout << "Node is named: " << xAccess->getName();
525 else
526 cout << "BUG: XNamed not available";
527 cout << endl;
530 ///////////////////////////////////////////////////////////////////////////////////////////
531 void write(Reference<XNameAccess >& xAccess)
533 if (xAccess.is())
535 Sequence<OUString> aNames( xAccess->getElementNames() );
537 cout << "Element Names: (" << aNames.getLength() << ")";
538 for (int i = 0; i < aNames.getLength(); ++i)
539 cout << "\n[" << i << "] -\t" << aNames[i];
540 cout << endl;
542 else
543 cout << "BUG: XNameAccess not available";
544 cout << endl;
546 void write(Reference< XChild >& xChild)
548 if (xChild.is())
549 cout << "\n[ P ] -\tParent";
550 else
551 cout << "BUG: Parent not available (no XChild)";
552 cout << endl;
554 ///////////////////////////////////////////////////////////////////////////////////////////
556 bool ask(Reference< XInterface >& xIface, Reference<XMultiServiceFactory> &);
558 void test_read_access(Reference< XInterface >& xIface, Reference< XMultiServiceFactory > &xMSF)
560 using com::sun::star::uno::UNO_QUERY;
563 cout << "\n\n---------------------------------------------------------------" << endl;
564 Reference< XNameAccess > xAccess(xIface, UNO_QUERY);
565 Reference< XChild > xChild(xIface, UNO_QUERY);
566 Reference< XHierarchicalName > xAccessPath(xIface,UNO_QUERY);
567 Reference< XNamed > xAccessName(xIface,UNO_QUERY);
568 // Reference< XHierarchicalNameAccess >& xAccess(xIface, UNO_QUERY);
570 test(xAccessPath);
571 test(xAccessName);
572 write(xAccess);
573 write(xChild);
575 while (ask(xIface, xMSF));
578 bool ask(Reference< XInterface >& xIface, Reference< XMultiServiceFactory > &xMSF)
580 cout << "\n[ Q ] -> <Quit>";
581 cout << "\n[ S ] -> <SetValue> ";
582 cout << endl;
584 cout << "\n:> " << flush;
585 char buf[200] = {0};
588 bool bHandled = false;
589 bool bInserted = false;
591 if (cin.getline(buf,sizeof buf))
593 Reference< XInterface > xNext;
594 if ((buf[0] == 'q' || buf[0] == 'Q') && (0 == buf[1]))
596 return false;
598 else if (buf[0] == 0)
600 return true;
602 else if((buf[0] == 0 || buf[0] == 'o' || buf[0] == 'O') && (0 == buf[1]))
605 cout << "work Offline" << endl;
606 Reference<com::sun::star::configuration::XConfigurationSync> xSync(xMSF, UNO_QUERY);
608 Sequence< Any > aArgs2(5);
609 sal_Int32 n=0;
610 aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Setup"));
611 // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Common"));
612 // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Java"));
613 // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Writer"));
614 // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.ucb.Hierarchy"));
615 xSync->offline(aArgs2);
616 bHandled = true;
619 else if((buf[0] == 0 || buf[0] == 's' || buf[0] == 'S') && (0 == buf[1]))
621 // Replace a Value
622 Reference< XNameAccess > xAccess(xIface, UNO_QUERY);
624 cout << "SetMode, insert a Number" << endl;
625 cin.getline(buf,sizeof buf);
626 bInserted = true;
629 else if ((buf[0] == 'p' || buf[0] == 'P') && (0 == buf[1]))
631 Reference< XChild > xChild(xIface, UNO_QUERY);
632 if (xChild.is())
633 xNext = xChild->getParent();
634 bHandled = true;
637 if (bHandled == false)
639 Reference< XNameAccess > xAccess(xIface, UNO_QUERY);
640 Reference< XHierarchicalNameAccess > xDeepAccess(xIface, UNO_QUERY);
641 Reference< XExactName > xExactName(xIface, UNO_QUERY);
643 if (xAccess.is() || xDeepAccess.is())
645 OUString aName;
646 OUString aInput = OUString::createFromAscii(buf);
648 if (xExactName.is())
650 ::rtl::OUString sTemp = xExactName->getExactName(aInput);
651 if (sTemp.getLength())
652 aInput = sTemp;
655 if (xAccess.is() && xAccess->hasByName(aInput))
657 aName = aInput;
659 else if (xDeepAccess.is() && xDeepAccess->hasByHierarchicalName(aInput))
661 aName = aInput;
663 else if ('0' <= buf[0] && buf[0] <= '9' && xAccess.is())
665 unsigned int n = unsigned(atoi(buf));
666 Sequence<OUString> aNames = xAccess->getElementNames();
667 if (n < aNames.getLength())
668 aName = aNames[n];
671 if (aName.getLength())
673 bool bNest = aInput.indexOf(sal_Unicode('/')) >= 0;
675 Any aElement = bNest ? ( xDeepAccess.is() ? xDeepAccess->getByHierarchicalName(aName) : Any())
676 : ( xAccess. is() ? xAccess-> getByName(aName) : Any() );
678 while (aElement.getValueTypeClass() == TypeClass_ANY)
680 Any aWrap(aElement);
681 aWrap >>= aElement;
683 sal_Bool bValue = true;
684 sal_Bool bValueOk = false;
686 switch (aElement.getValueTypeClass() )
688 case TypeClass_INTERFACE: bValue = false; break;
689 case TypeClass_BOOLEAN:
691 sal_Bool* pVal = (sal_Bool*)aElement.getValue();
692 bValueOk = (pVal != 0);
694 cout << "VALUE '" << aName << "' is a BOOLEAN = ";
695 if (!bValueOk)
696 cout << "NULL (error!!)";
697 else if (*pVal)
698 cout << "'TRUE'";
699 else
700 cout << "'FALSE'";
702 cout << endl;
704 break;
705 case TypeClass_SHORT:
707 sal_Int16 aValue;
708 cout << "VALUE '" << aName << "' is a SHORT (16 bit) = ";
709 if (bValueOk = (aElement >>= aValue))
710 cout << aValue;
711 else
712 cout << "ERROR RETRIEVING VALUE";
713 cout << endl;
715 break;
716 case TypeClass_LONG:
719 sal_Int32 aValue;
720 cout << "VALUE '" << aName << "' is a INT (32 bit) = ";
721 if (bValueOk = (aElement >>= aValue))
722 cout << aValue;
723 else
724 cout << "ERROR RETRIEVING VALUE";
725 cout << endl;
727 break;
728 case TypeClass_HYPER:
730 sal_Int64 aValue;
731 cout << "VALUE '" << aName << "' is a LONG (64 bit) = ";
732 if (bValueOk = (aElement >>= aValue))
733 cout << double(aValue);
734 else
735 cout << "ERROR RETRIEVING VALUE";
736 cout << endl;
738 break;
739 case TypeClass_DOUBLE:
741 double aValue;
742 cout << "VALUE '" << aName << "' is a DOUBLE = ";
743 if (bValueOk = (aElement >>= aValue))
744 cout << aValue;
745 else
746 cout << "ERROR RETRIEVING VALUE";
747 cout << endl;
749 break;
750 case TypeClass_STRING:
752 OUString aValue;
753 cout << "VALUE '" << aName << "' is a STRING = ";
754 if (bValueOk = (aElement >>= aValue))
755 cout << "\"" << aValue << "\"";
756 else
757 cout << "ERROR RETRIEVING VALUE";
758 cout << endl;
760 break;
761 case TypeClass_SEQUENCE:
763 cout << "VALUE '" << aName << "' is a SEQUENCE or BINARY" << endl;
765 Type aTypeS = configmgr::getSequenceElementType(aElement.getValueType());
766 OUString sType = configmgr::toTypeName(aTypeS.getTypeClass());
767 cout << "Real type is Sequence<" << sType << ">" << endl;
768 bValueOk = true;
770 break;
771 case TypeClass_VOID:
772 cout << "ELEMENT '" << aName << "' is NULL and VOID " << endl;
773 bValueOk = true;
774 break;
775 default:
776 cout << "Error: ELEMENT '" << aName << "' is of unknown or unrecognized type" << endl;
777 break;
779 if (bValue)
781 if (bInserted)
783 if (aElement.getValueTypeClass() == TypeClass_BOOLEAN ||
784 aElement.getValueTypeClass() == TypeClass_VOID)
786 cout << "Set Value (Type=BOOL) to :";
787 cout.flush();
788 cin.getline(buf,sizeof buf);
789 OUString aInput = OUString::createFromAscii(buf);
790 sal_Bool bValue = false;
791 if (aInput.equalsIgnoreAsciiCase(ASCII("true")))
792 bValue = true;
794 OUString aStr = ASCII("false");
795 Any aValueAny;
796 aValueAny <<= bValue;
798 Reference< XNameReplace > xNameReplace(xAccess, UNO_QUERY);
799 if (xNameReplace.is())
801 xNameReplace->replaceByName(aName, aValueAny);
802 commit();
804 bInserted = false;
806 else if (aElement.getValueTypeClass() == TypeClass_STRING)
808 cout << "set value (type = string) to : ";
809 cout.flush();
810 cin.getline(buf,sizeof buf);
811 Any aValue;
812 aValue <<= buf;
814 Reference< XNameReplace > xNameReplace(xAccess, UNO_QUERY);
815 if (xNameReplace.is())
817 xNameReplace->replaceByName(aName, aValue);
818 commit();
820 bInserted = false;
822 else
824 cout << "Sorry, only BOOLEAN Values can changed today." << endl;
827 prompt_and_wait();
828 return bValueOk ? true : false;
831 if (aElement >>= xNext)
832 cout << "Got an Interface for '" << aName << "'" << endl;
833 else
834 cout << "Error: Cannot get an Interface for '" << aName << "'" << endl;
836 else
838 cout << "Error: No element \"" << aInput << "\" found." <<endl;
843 if (xNext.is())
845 xIface = xNext;
846 return true;
848 cout << "Error: could not obtain the requested Object " << endl;
850 else
852 cout << "Input Error " << endl;
853 return true;
856 catch (Exception& e)
858 cout << "An Exception occurred: " << e.Message << endl;
861 catch (...)
863 cout << "An UNKNOWN Exception occurred !" << endl;
866 prompt_and_wait();
867 return true;