merge the formfield patch from ooo-build
[ooovba.git] / configmgr / workben / apitest / cfgapi_timetest.cxx
blobc7d32eb7832e3d3de6216963e81fed305adcb369
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_timetest.cxx,v $
10 * $Revision: 1.7 $
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 <vector>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/uno/Type.hxx>
42 #include <com/sun/star/uno/TypeClass.hpp>
44 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
45 #include <com/sun/star/container/XNameAccess.hpp>
46 #include <com/sun/star/container/XHierarchicalName.hpp>
47 #include <com/sun/star/container/XNamed.hpp>
48 #include <com/sun/star/container/XNameReplace.hpp>
49 #include <com/sun/star/container/XChild.hpp>
50 #include <com/sun/star/beans/XExactName.hpp>
51 #include <com/sun/star/util/XChangesBatch.hpp>
54 #include <rtl/ustring.hxx>
55 #include <rtl/string.hxx>
56 #include <cppuhelper/servicefactory.hxx>
57 #include <com/sun/star/uno/Sequence.h>
58 #include <com/sun/star/uno/Any.h>
59 #include <osl/profile.hxx>
60 #include <osl/process.h>
61 #include <osl/file.h>
63 #include "createpropertyvalue.hxx"
65 #include "typeconverter.hxx"
67 // #include <com/sun/star/configuration/XConfigurationSync.hpp>
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::container;
72 using namespace ::com::sun::star::beans;
73 //using namespace ::com::sun::star::util;
74 using namespace ::com::sun::star::util;
76 using ::rtl::OUString;
77 using ::rtl::OString;
78 //using namespace ::configmgr;
80 using namespace ::cppu;
82 #define ASCII(x) ::rtl::OUString::createFromAscii(x)
84 bool m_bInteractive = false;
86 #define COUT if(m_bInteractive) cout
88 ostream& operator << (ostream& out, rtl::OUString const& aStr)
90 sal_Unicode const* const pStr = aStr.getStr();
91 sal_Unicode const* const pEnd = pStr + aStr.getLength();
92 for (sal_Unicode const* p = pStr; p < pEnd; ++p)
93 if (0 < *p && *p < 127) // ASCII
94 out << char(*p);
95 else
96 out << "[\\u" << hex << *p << "]";
97 return out;
100 void showSequence(const Sequence<OUString> &aSeq)
102 OUString aArray;
103 const OUString *pStr = aSeq.getConstArray();
104 for (int i=0;i<aSeq.getLength();i++)
106 OUString aStr = pStr[i];
107 // aArray += aStr + ASCII(", ");
108 COUT << aStr << endl;
110 volatile int dummy = 0;
113 //=============================================================================
115 inline void operator <<= (::rtl::OUString& _rUnicodeString, const sal_Char* _pAsciiString)
117 _rUnicodeString = ::rtl::OUString::createFromAscii(_pAsciiString);
120 inline void operator <<= (::rtl::OUString& _rUnicodeString, const ::rtl::OString& _rAsciiString)
122 _rUnicodeString <<= _rAsciiString.getStr();
125 inline void operator <<= (Any& _rUnoValue, const sal_Char* _pAsciiString)
127 _rUnoValue <<= ::rtl::OUString::createFromAscii(_pAsciiString);
130 inline void operator <<= (Any& _rUnoValue, const ::rtl::OString& _rAsciiString)
132 _rUnoValue <<= _rAsciiString.getStr();
135 //=============================================================================
136 void test_read_access(Reference< XInterface >& xIface, const Reference< XMultiServiceFactory > &xMSF);
137 //=============================================================================
139 // -----------------------------------------------------------------------------
140 struct prompt_and_wait
142 char const* myText;
143 prompt_and_wait(char const* text = "") : myText(text) {}
144 ~prompt_and_wait()
146 if (m_bInteractive)
148 COUT << myText << ">" << endl;
149 int const mx = int( (+0u - +1u) >> 1);
151 char c=0;
152 if (cin.get(c) && c != '\n')
153 cin.ignore(mx,'\n');
157 static prompt_and_wait exit_prompt("Quitting\nQ");
160 Reference< XChangesBatch > xChangesBatch = NULL;
161 void commit()
163 if (xChangesBatch.is())
165 xChangesBatch->commitChanges();
169 // -----------------------------------------------------------------------------
170 static sal_Bool s_bInitialized = sal_False;
171 static const sal_Char* s_pSourcePath = "f:/office60_623/share/config/registry";
172 static const sal_Char* s_pUpdatePath = "f:/office60_623/user/config/registry";
173 static const sal_Char* s_pRootNode = "org.openoffice.Office.Common";
174 static const sal_Char* s_pServerType = "local";
175 static const sal_Char* s_pLocale = "de-DE";
176 static const sal_Char* s_pServer = "lautrec-3108:19205";
177 static const sal_Char* s_pUser = "lars";
178 static const sal_Char* s_pPassword = "";
180 std::vector<rtl::OString> m_sNodes;
182 // -----------------------------------------------------------------------------
183 static void loadDefaults()
185 if (s_bInitialized)
186 return;
188 s_bInitialized = sal_True;
192 // the executable file name
193 ::rtl::OUString sExecutable;
194 osl_getExecutableFile(&sExecutable.pData);
195 // cut the name, add a cfgapi.ini to the path
196 sal_Int32 nLastSep = sExecutable.lastIndexOf('/');
197 if (-1 != nLastSep)
198 sExecutable = sExecutable.copy(0, nLastSep + 1);
199 #ifdef UNX
200 sExecutable += ::rtl::OUString::createFromAscii("cfgapirc");
201 #else
202 sExecutable += ::rtl::OUString::createFromAscii("cfgapi.ini");
203 #endif
204 ::rtl::OUString sSystem;
205 if (osl_File_E_None == osl_getSystemPathFromFileURL(sExecutable.pData, &sSystem.pData))
207 ::osl::Profile aProfile(sExecutable);
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();
240 static ::rtl::OString sNodeSection("nodes");
241 static ::rtl::OString sCount("count");
242 rtl::OUString sCountValue;
243 sCountValue <<= aProfile.readString(sNodeSection, sCount, "0");
244 sal_Int32 nCount = sCountValue.toInt32();
245 for (sal_Int32 i=0;i<nCount;i++)
247 ::rtl::OString sNodeName("node");
248 sNodeName += OString::valueOf(i);
249 ::rtl::OString sNode = aProfile.readString(sNodeSection, sNodeName, "");
250 m_sNodes.push_back(sNode);
254 catch(std::exception& e)
256 e.what(); // silence warnings
260 // -----------------------------------------------------------------------------
261 Sequence<Any> createSequence(const OUString &sUser, const OUString &sPasswd)
263 Sequence< Any > aCPArgs;
265 if (sUser.getLength() > 0)
267 aCPArgs.realloc(1);
268 aCPArgs[0] <<= configmgr::createPropertyValue(ASCII("user"), sUser);
270 if (sPasswd.getLength() > 0)
272 aCPArgs.realloc(2);
273 aCPArgs[1] <<= configmgr::createPropertyValue(ASCII("password"), sPasswd);
275 return aCPArgs;
278 //=============================================================================
279 #include <string.h>
280 #if (defined UNX) || (defined OS2)
281 #else
282 #include <conio.h>
283 #endif
285 OString input(const char* pDefaultText, char cEcho)
287 // PRE: a Default Text would be shown, cEcho is a Value which will show if a key is pressed.
288 const int MAX_INPUT_LEN = 500;
289 char aBuffer[MAX_INPUT_LEN];
291 strcpy(aBuffer, pDefaultText);
292 int nLen = strlen(aBuffer);
294 #ifdef WNT
295 char ch = '\0';
297 COUT << aBuffer;
298 cout.flush();
300 while(ch != 13)
302 ch = getch();
303 if (ch == 8)
305 if (nLen > 0)
307 COUT << "\b \b";
308 cout.flush();
309 --nLen;
310 aBuffer[nLen] = '\0';
312 else
314 COUT << "\a";
315 cout.flush();
318 else if (ch != 13)
320 if (nLen < MAX_INPUT_LEN)
322 if (cEcho == 0)
324 COUT << ch;
326 else
328 COUT << cEcho;
330 cout.flush();
331 aBuffer[nLen++] = ch;
332 aBuffer[nLen] = '\0';
334 else
336 COUT << "\a";
337 cout.flush();
341 #else
342 if (!cin.getline(aBuffer,sizeof aBuffer))
343 return OString();
344 #endif
345 return OString(aBuffer);
349 // -----------------------------------------------------------------------------
350 rtl::OUString enterValue(const char* _aStr, const char* _aDefault, bool _bIsAPassword)
352 COUT << _aStr;
353 cout.flush();
355 OUString sValue;
356 if (m_bInteractive)
358 sValue <<= input(_aDefault, _bIsAPassword ? '*' : 0);
360 else
362 sValue <<= _aDefault;
364 return sValue;
369 void ask_for_a_node_and_test_it(const Reference< XMultiServiceFactory > &xCfgProvider,
370 const OUString& sUser, const OUString &sPasswd,
371 const OUString& sPath, bool bLocal, const OUString &sLocale);
373 // -----------------------------------------------------------------------------
374 // ---------------------------------- M A I N ----------------------------------
375 // -----------------------------------------------------------------------------
377 #if (defined UNX) || (defined OS2)
378 int main( int argc, char * argv[] )
379 #else
380 int _cdecl main( int argc, char * argv[] )
381 #endif
383 TimeValue aTimeout;
384 aTimeout.Seconds = 5;
385 aTimeout.Nanosec = 0;
387 // COUT << " Please insert Text: ";
388 // cout.flush();
389 // OString aTxt = input("Der Text", 0);
390 // COUT << endl << "You inserted: " << aTxt.getStr() << endl;
392 // COUT << "Please insert Password: ";
393 // cout.flush();
394 // OString aPasswd = input("", '*');
395 // COUT << endl << "You inserted: " << aPasswd.getStr() << endl;
397 loadDefaults();
399 m_bInteractive = false;
400 //if (argc > 1)
402 // OString aParam(argv[1]);
403 // if (aParam.equals("ask"))
404 // {
405 // m_bInteractive = true;
406 // }
411 OUString const sServiceRegistry = OUString::createFromAscii( argc > 1 ? argv[1] : "applicat.rdb" );
412 Reference< XMultiServiceFactory > xORB = createRegistryServiceFactory(
413 sServiceRegistry,
414 ::rtl::OUString()
416 if (!xORB.is())
418 ::flush(cout);
419 cerr << "Could not create the service factory !\n\n";
420 return 1;
422 COUT << "Service factory created !\n---------------------------------------------------------------" << endl;
424 Sequence< Any > aCPArgs;
426 OUString sServerType = enterValue("servertype: ", s_pServerType, false);
427 COUT << endl;
430 rtl::OUString sUser, sPasswd;
432 bool bLocal = sServerType.equalsIgnoreAsciiCase(ASCII("local")) || sServerType.equalsIgnoreAsciiCase(ASCII("setup"));
433 if (!bLocal)
435 rtl::OUString sServer;
436 sServer = enterValue("server : ", s_pServer,false);
437 COUT << endl;
439 sUser = enterValue("user : ", s_pUser, false);
440 COUT << endl;
442 sPasswd = enterValue("password: ", s_pPassword, true);
443 COUT << endl;
445 aCPArgs = createSequence(sUser, sPasswd);
447 aCPArgs.realloc(aCPArgs.getLength() + 1);
448 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("server"), sServer);
450 long nTimeout = 10000;
451 aCPArgs.realloc(aCPArgs.getLength() + 1);
452 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("timeout"), nTimeout);
454 long nPort = 9205;
455 aCPArgs.realloc(aCPArgs.getLength() + 1);
456 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("port"), nPort);
458 else
460 rtl::OUString sSharePath, sUserPath;
461 sSharePath = enterValue("share path: ", s_pSourcePath, false);
462 COUT << endl;
463 sUserPath = enterValue("user path : ", s_pUpdatePath, false);
464 COUT << endl;
466 aCPArgs.realloc(aCPArgs.getLength() + 1);
467 Any* pAny;
468 pAny = &aCPArgs[aCPArgs.getLength() - 1];
469 *pAny <<= configmgr::createPropertyValue(ASCII("sourcepath"), sSharePath);
470 aCPArgs.realloc(aCPArgs.getLength() + 1);
471 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("updatepath"), sUserPath);
474 aCPArgs.realloc(aCPArgs.getLength() + 1);
475 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("servertype"), sServerType);
477 Reference< XMultiServiceFactory > xCfgProvider(
478 xORB->createInstanceWithArguments(
479 ::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"),
480 aCPArgs),
481 UNO_QUERY);
482 if (!xCfgProvider.is())
484 ::flush(cout);
485 cerr << "Could not create the configuration provider !\n\n";
486 return 3;
489 cout << "---------------------------------------------------------------\n Configuration Provider created !\n---------------------------------------------------------------" << endl;
491 OUString sPath;
492 sPath <<= s_pRootNode;
493 OUString sLocale;
494 sLocale <<= s_pLocale;
496 if (m_bInteractive)
498 sPath = enterValue("nodepath: ", s_pRootNode, false);
499 COUT << endl;
500 if (bLocal)
502 sLocale = enterValue("locale : ", s_pLocale, false);
503 COUT << endl;
505 ask_for_a_node_and_test_it(xCfgProvider, sUser, sPasswd, sPath, bLocal, sLocale);
507 else
509 sUser <<= "";
510 for(std::vector<OString>::const_iterator it = m_sNodes.begin();
511 it != m_sNodes.end();
512 ++it)
514 OUString sPath;
515 sPath <<= *it;
516 if (sPath.getLength() > 0)
517 ask_for_a_node_and_test_it(xCfgProvider, sUser, sPasswd, sPath, bLocal, sLocale);
521 catch (Exception& e)
523 ::flush(cout);
524 cerr << "Caught exception: " << e.Message << endl;
525 return 1;
527 return 0;
530 // -----------------------------------------------------------------------------
531 void ask_for_a_node_and_test_it(const Reference< XMultiServiceFactory > &xCfgProvider,
532 const OUString& sUser, const OUString &sPasswd,
533 const OUString& sPath, bool bLocal, const OUString &sLocale)
537 Sequence< Any > aArgs;
538 aArgs = createSequence(sUser, sPasswd);
540 aArgs.realloc(aArgs.getLength() + 1);
541 aArgs[aArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("nodepath"), sPath);
543 if (!bLocal)
545 aArgs.realloc(aArgs.getLength() + 1);
546 aArgs[aArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("locale"), sLocale);
549 Reference< XInterface > xIFace = xCfgProvider->createInstanceWithArguments(
550 OUString::createFromAscii("com.sun.star.configuration.ConfigurationUpdateAccess"),
551 aArgs);
552 cout << "Configuration Read/Write Access created for :" << sPath << endl;
554 xChangesBatch = Reference< XChangesBatch >(xIFace, UNO_QUERY);
556 Sequence<OUString> aSeq = xCfgProvider->getAvailableServiceNames();
557 showSequence(aSeq);
559 test_read_access(xIFace, xCfgProvider);
561 catch (Exception& e)
563 ::flush(cout);
564 cerr << "Caught exception: " << e.Message << endl;
568 ///////////////////////////////////////////////////////////////////////////////////////////
569 void test(Reference< XHierarchicalName >& xAccessName)
571 if (xAccessName.is())
573 COUT << "Accessing Node: " << xAccessName->getHierarchicalName() << endl;
575 else
577 cerr << "BUG: XHierarchicalName not available" << endl;
580 // -----------------------------------------------------------------------------
581 void test(Reference< XNamed >& xAccess)
583 if (xAccess.is())
585 COUT << "Node is named: " << xAccess->getName() << endl;
587 else
588 cerr << "BUG: XNamed not available" << endl;
591 ///////////////////////////////////////////////////////////////////////////////////////////
592 void write(Reference<XNameAccess >& xAccess)
594 if (xAccess.is())
596 Sequence<OUString> aNames( xAccess->getElementNames() );
598 COUT << "Element Names: (" << aNames.getLength() << ")";
599 for (int i = 0; i < aNames.getLength(); ++i)
601 COUT << "\n[" << i << "] -\t" << aNames[i];
603 COUT << endl;
605 else
606 cerr << "BUG: XNameAccess not available" << endl;
608 // -----------------------------------------------------------------------------
609 void write(Reference< XChild >& xChild)
611 if (xChild.is())
613 COUT << "\n[ P ] -\tParent" << endl;
615 else
616 cerr << "BUG: Parent not available (no XChild)" << endl;
618 ///////////////////////////////////////////////////////////////////////////////////////////
620 bool ask(Reference< XInterface >& xIface, const Reference<XMultiServiceFactory> &);
622 void test_read_access(Reference< XInterface >& xIface, const Reference< XMultiServiceFactory > &xMSF)
624 using com::sun::star::uno::UNO_QUERY;
627 COUT << "\n\n---------------------------------------------------------------" << endl;
628 Reference< XNameAccess > xAccess(xIface, UNO_QUERY);
629 Reference< XChild > xChild(xIface, UNO_QUERY);
630 Reference< XHierarchicalName > xAccessPath(xIface,UNO_QUERY);
631 Reference< XNamed > xAccessName(xIface,UNO_QUERY);
632 // Reference< XHierarchicalNameAccess >& xAccess(xIface, UNO_QUERY);
634 test(xAccessPath);
635 test(xAccessName);
636 write(xAccess);
637 write(xChild);
639 if (!m_bInteractive) break;
641 while (ask(xIface, xMSF));
644 bool ask(Reference< XInterface >& xIface, const Reference< XMultiServiceFactory > &xMSF)
646 COUT << "\n[ Q ] -> <Quit>";
647 COUT << "\n[ S ] -> <SetValue> ";
648 COUT << endl;
650 COUT << "\n:> " << flush;
651 char buf[200] = {0};
654 bool bHandled = false;
655 bool bInserted = false;
657 if (cin.getline(buf,sizeof buf))
659 Reference< XInterface > xNext;
660 if ((buf[0] == 'q' || buf[0] == 'Q') && (0 == buf[1]))
662 return false;
664 else if (buf[0] == 0)
666 return true;
668 else if((buf[0] == 0 || buf[0] == 'o' || buf[0] == 'O') && (0 == buf[1]))
671 COUT << "work Offline" << endl;
672 Reference<com::sun::star::configuration::XConfigurationSync> xSync(xMSF, UNO_QUERY);
674 Sequence< Any > aArgs2(5);
675 sal_Int32 n=0;
676 aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Setup"));
677 // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Common"));
678 // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Java"));
679 // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Writer"));
680 // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.ucb.Hierarchy"));
681 xSync->offline(aArgs2);
682 bHandled = true;
685 else if((buf[0] == 0 || buf[0] == 's' || buf[0] == 'S') && (0 == buf[1]))
687 // Replace a Value
688 Reference< XNameAccess > xAccess(xIface, UNO_QUERY);
690 COUT << "SetMode, insert a Number" << endl;
691 cin.getline(buf,sizeof buf);
692 bInserted = true;
695 else if ((buf[0] == 'p' || buf[0] == 'P') && (0 == buf[1]))
697 Reference< XChild > xChild(xIface, UNO_QUERY);
698 if (xChild.is())
699 xNext = xChild->getParent();
700 bHandled = true;
703 if (bHandled == false)
705 Reference< XNameAccess > xAccess(xIface, UNO_QUERY);
706 Reference< XHierarchicalNameAccess > xDeepAccess(xIface, UNO_QUERY);
707 Reference< XExactName > xExactName(xIface, UNO_QUERY);
709 if (xAccess.is() || xDeepAccess.is())
711 OUString aName;
712 OUString aInput = OUString::createFromAscii(buf);
714 if (xExactName.is())
716 ::rtl::OUString sTemp = xExactName->getExactName(aInput);
717 if (sTemp.getLength())
718 aInput = sTemp;
721 if (xAccess.is() && xAccess->hasByName(aInput))
723 aName = aInput;
725 else if (xDeepAccess.is() && xDeepAccess->hasByHierarchicalName(aInput))
727 aName = aInput;
729 else if ('0' <= buf[0] && buf[0] <= '9' && xAccess.is())
731 unsigned int n = unsigned(atoi(buf));
732 Sequence<OUString> aNames = xAccess->getElementNames();
733 if (n < aNames.getLength())
734 aName = aNames[n];
737 if (aName.getLength())
739 bool bNest = aInput.indexOf(sal_Unicode('/')) >= 0;
741 Any aElement = bNest ? ( xDeepAccess.is() ? xDeepAccess->getByHierarchicalName(aName) : Any())
742 : ( xAccess. is() ? xAccess-> getByName(aName) : Any() );
744 while (aElement.getValueTypeClass() == TypeClass_ANY)
746 Any aWrap(aElement);
747 aWrap >>= aElement;
749 sal_Bool bValue = true;
750 sal_Bool bValueOk = false;
752 switch (aElement.getValueTypeClass() )
754 case TypeClass_INTERFACE: bValue = false; break;
755 case TypeClass_BOOLEAN:
757 sal_Bool* pVal = (sal_Bool*)aElement.getValue();
758 bValueOk = (pVal != 0);
760 COUT << "VALUE '" << aName << "' is a BOOLEAN = ";
761 if (!bValueOk)
763 COUT << "NULL (error!!)";
765 else if (*pVal)
767 COUT << "'TRUE'";
769 else
771 COUT << "'FALSE'";
773 COUT << endl;
775 break;
776 case TypeClass_SHORT:
778 sal_Int16 aValue;
779 COUT << "VALUE '" << aName << "' is a SHORT (16 bit) = ";
780 if (bValueOk = (aElement >>= aValue))
782 COUT << aValue;
784 else
785 cerr << "ERROR RETRIEVING VALUE";
786 COUT << endl;
788 break;
789 case TypeClass_LONG:
792 sal_Int32 aValue;
793 COUT << "VALUE '" << aName << "' is a INT (32 bit) = ";
794 if (bValueOk = (aElement >>= aValue))
796 COUT << aValue;
798 else
799 cerr << "ERROR RETRIEVING VALUE";
800 COUT << endl;
802 break;
803 case TypeClass_HYPER:
805 sal_Int64 aValue;
806 COUT << "VALUE '" << aName << "' is a LONG (64 bit) = ";
807 if (bValueOk = (aElement >>= aValue))
809 COUT << double(aValue);
811 else
812 cerr << "ERROR RETRIEVING VALUE";
813 COUT << endl;
815 break;
816 case TypeClass_DOUBLE:
818 double aValue;
819 COUT << "VALUE '" << aName << "' is a DOUBLE = ";
820 if (bValueOk = (aElement >>= aValue))
822 COUT << aValue;
824 else
825 cerr << "ERROR RETRIEVING VALUE";
826 COUT << endl;
828 break;
829 case TypeClass_STRING:
831 OUString aValue;
832 COUT << "VALUE '" << aName << "' is a STRING = ";
833 if (bValueOk = (aElement >>= aValue))
835 COUT << "\"" << aValue << "\"";
837 else
838 cerr << "ERROR RETRIEVING VALUE";
839 COUT << endl;
841 break;
842 case TypeClass_SEQUENCE:
844 COUT << "VALUE '" << aName << "' is a SEQUENCE or BINARY" << endl;
846 Type aTypeS = configmgr::getSequenceElementType(aElement.getValueType());
847 OUString sType = configmgr::toTypeName(aTypeS.getTypeClass());
848 COUT << "Real type is Sequence<" << sType << ">" << endl;
849 bValueOk = true;
851 break;
852 case TypeClass_VOID:
853 COUT << "ELEMENT '" << aName << "' is NULL and VOID " << endl;
854 bValueOk = true;
855 break;
856 default:
857 cerr << "Error: ELEMENT '" << aName << "' is of unknown or unrecognized type" << endl;
858 break;
860 if (bValue)
862 if (bInserted)
864 if (aElement.getValueTypeClass() == TypeClass_BOOLEAN ||
865 aElement.getValueTypeClass() == TypeClass_VOID)
867 COUT << "Set Value (Type=BOOL) to :";
868 cout.flush();
869 cin.getline(buf,sizeof buf);
870 OUString aInput = OUString::createFromAscii(buf);
871 sal_Bool bValue = false;
873 Any aValueAny;
874 if (aInput.equalsIgnoreAsciiCase(ASCII("true")))
876 bValue = true;
877 aValueAny <<= bValue;
879 else if (aInput.equalsIgnoreAsciiCase(ASCII("false")))
881 bValue = false;
882 aValueAny <<= bValue;
884 else if (aInput.equalsIgnoreAsciiCase(ASCII("null")))
888 Reference< XNameReplace > xNameReplace(xAccess, UNO_QUERY);
889 if (xNameReplace.is())
891 xNameReplace->replaceByName(aName, aValueAny);
892 commit();
894 bInserted = false;
896 else if (aElement.getValueTypeClass() == TypeClass_STRING)
898 COUT << "set value (type = string) to : ";
899 cout.flush();
900 cin.getline(buf,sizeof buf);
901 Any aValue;
902 aValue <<= buf;
904 Reference< XNameReplace > xNameReplace(xAccess, UNO_QUERY);
905 if (xNameReplace.is())
907 xNameReplace->replaceByName(aName, aValue);
908 commit();
910 bInserted = false;
912 else
914 cerr << "Sorry, only BOOLEAN Values can changed today." << endl;
917 prompt_and_wait();
918 return bValueOk ? true : false;
921 if (aElement >>= xNext)
923 COUT << "Got an Interface for '" << aName << "'" << endl;
925 else
926 cerr << "Error: Cannot get an Interface for '" << aName << "'" << endl;
928 else
930 cerr << "Error: No element \"" << aInput << "\" found." <<endl;
935 if (xNext.is())
937 xIface = xNext;
938 return true;
940 cerr << "Error: could not obtain the requested Object " << endl;
942 else
944 COUT << "Input Error " << endl;
945 return true;
948 catch (Exception& e)
950 cerr << "An Exception occurred: " << e.Message << endl;
953 catch (...)
955 cerr << "An UNKNOWN Exception occurred !" << endl;
958 prompt_and_wait();
959 return true;