diff options
author | Lars Langhans <lla@openoffice.org> | 2000-10-16 10:33:04 +0000 |
---|---|---|
committer | Lars Langhans <lla@openoffice.org> | 2000-10-16 10:33:04 +0000 |
commit | f771f7650d3f6a1172f5ddd20d01e8c221dad453 (patch) | |
tree | 69634ddccc26be2d2f89352c73d2f70887ad1cfa /configmgr | |
parent | b9dcc2b3572099fa164ec34535bd16cefaf58b3a (diff) |
#79255# type any
Diffstat (limited to 'configmgr')
-rw-r--r-- | configmgr/source/inc/strdecl.hxx | 5 | ||||
-rw-r--r-- | configmgr/source/inc/typeconverter.hxx | 5 | ||||
-rw-r--r-- | configmgr/source/misc/strimpl.cxx | 5 | ||||
-rw-r--r-- | configmgr/source/xml/typeconverter.cxx | 10 | ||||
-rw-r--r-- | configmgr/workben/apitest/cfgapi.cxx | 272 |
5 files changed, 255 insertions, 42 deletions
diff --git a/configmgr/source/inc/strdecl.hxx b/configmgr/source/inc/strdecl.hxx index deb11d0e07ff..3e2677077449 100644 --- a/configmgr/source/inc/strdecl.hxx +++ b/configmgr/source/inc/strdecl.hxx @@ -2,9 +2,9 @@ * * $RCSfile: strdecl.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: lla $ $Date: 2000-09-22 14:32:46 $ + * last change: $Author: lla $ $Date: 2000-10-16 11:32:59 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -88,6 +88,7 @@ namespace configmgr DECLARE_CONSTASCII_USTRING(TYPE_DOUBLE); DECLARE_CONSTASCII_USTRING(TYPE_STRING); DECLARE_CONSTASCII_USTRING(TYPE_BINARY); + DECLARE_CONSTASCII_USTRING(TYPE_ANY); DECLARE_CONSTASCII_USTRING(TYPE_SET); DECLARE_CONSTASCII_USTRING(TYPE_GROUP); diff --git a/configmgr/source/inc/typeconverter.hxx b/configmgr/source/inc/typeconverter.hxx index 7c72df9c2587..ed27a0364d22 100644 --- a/configmgr/source/inc/typeconverter.hxx +++ b/configmgr/source/inc/typeconverter.hxx @@ -2,9 +2,9 @@ * * $RCSfile: typeconverter.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $ + * last change: $Author: lla $ $Date: 2000-10-16 11:32:59 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -105,6 +105,7 @@ namespace configmgr } inline staruno::Type getBinaryType() { return ::getCppuType(static_cast<staruno::Sequence<sal_Int8> const*>(0)); } + inline staruno::Type getAnyType() { return ::getCppuType(static_cast<staruno::Any const*>(0)); } } // namespace configmgr diff --git a/configmgr/source/misc/strimpl.cxx b/configmgr/source/misc/strimpl.cxx index 4ecebe0f9cf8..a77558c35d87 100644 --- a/configmgr/source/misc/strimpl.cxx +++ b/configmgr/source/misc/strimpl.cxx @@ -2,9 +2,9 @@ * * $RCSfile: strimpl.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: lla $ $Date: 2000-09-22 14:32:28 $ + * last change: $Author: lla $ $Date: 2000-10-16 11:33:01 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -84,6 +84,7 @@ namespace configmgr IMPLEMENT_CONSTASCII_USTRING(TYPE_LONG, "long"); IMPLEMENT_CONSTASCII_USTRING(TYPE_DOUBLE, "double"); IMPLEMENT_CONSTASCII_USTRING(TYPE_STRING, "string"); + IMPLEMENT_CONSTASCII_USTRING(TYPE_ANY, "any"); // Type: Sequence<bytes> IMPLEMENT_CONSTASCII_USTRING(TYPE_BINARY, "binary"); diff --git a/configmgr/source/xml/typeconverter.cxx b/configmgr/source/xml/typeconverter.cxx index 7834fa8345f8..d16fe1b56a7c 100644 --- a/configmgr/source/xml/typeconverter.cxx +++ b/configmgr/source/xml/typeconverter.cxx @@ -2,9 +2,9 @@ * * $RCSfile: typeconverter.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: lla $ $Date: 2000-10-10 14:57:14 $ + * last change: $Author: lla $ $Date: 2000-10-16 11:33:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -157,6 +157,8 @@ namespace configmgr case staruno::TypeClass_DOUBLE: aRet = ::rtl::OUString::createFromAscii("double"); break; case staruno::TypeClass_STRING: aRet = ::rtl::OUString::createFromAscii("string"); break; case staruno::TypeClass_SEQUENCE: aRet = ::rtl::OUString::createFromAscii("binary"); break; + + case staruno::TypeClass_ANY: aRet = ::rtl::OUString::createFromAscii("any"); break; default: { ::rtl::OString aStr("Wrong typeclass! "); @@ -179,6 +181,8 @@ namespace configmgr else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("double"))) aRet = staruno::TypeClass_DOUBLE; else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string"))) aRet = staruno::TypeClass_STRING; else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary"))) aRet = staruno::TypeClass_SEQUENCE; + + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("any"))) aRet = staruno::TypeClass_ANY; else { ::rtl::OString aStr("Wrong typeclass! "); @@ -275,6 +279,8 @@ namespace configmgr else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("string"))) aRet = getStringType(); else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("binary"))) aRet = getBinaryType(); // else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("sequence"))) aRet = staruno::TypeClass_SEQUENCE; + + else if(_rType.equalsIgnoreCase(::rtl::OUString::createFromAscii("any"))) aRet = getAnyType(); else { ::rtl::OString aStr("Unknown type! "); diff --git a/configmgr/workben/apitest/cfgapi.cxx b/configmgr/workben/apitest/cfgapi.cxx index 757f2675a937..8ac39ec45856 100644 --- a/configmgr/workben/apitest/cfgapi.cxx +++ b/configmgr/workben/apitest/cfgapi.cxx @@ -2,9 +2,9 @@ * * $RCSfile: cfgapi.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 16:13:43 $ + * last change: $Author: lla $ $Date: 2000-10-16 11:33:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,8 +71,13 @@ using namespace std; #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/container/XHierarchicalName.hpp> #include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/container/XNameReplace.hpp> #include <com/sun/star/container/XChild.hpp> #include <com/sun/star/beans/XExactName.hpp> +#ifndef _COM_SUN_STAR_UTIL_XCHANGESBATCH_HPP_ +#include <com/sun/star/util/XChangesBatch.hpp> +#endif + #include <rtl/ustring.hxx> #include <rtl/string.hxx> @@ -83,11 +88,14 @@ using namespace std; #include "createpropertyvalue.hxx" +// #include <com/sun/star/configuration/XConfigurationSync.hpp> + using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::container; using namespace ::com::sun::star::beans; //using namespace ::com::sun::star::util; +using namespace ::com::sun::star::util; using ::rtl::OUString; using ::rtl::OString; @@ -108,9 +116,23 @@ ostream& operator << (ostream& out, rtl::OUString const& aStr) out << "[\\u" << hex << *p << "]"; return out; } + +void showSequence(const Sequence<OUString> &aSeq) +{ + OUString aArray; + const OUString *pStr = aSeq.getConstArray(); + for (int i=0;i<aSeq.getLength();i++) + { + OUString aStr = pStr[i]; + // aArray += aStr + ASCII(", "); + cout << aStr << endl; + } + volatile int dummy = 0; +} + //============================================================================= //============================================================================= -void test_read_access(Reference< XInterface >& xIface); +void test_read_access(Reference< XInterface >& xIface, Reference< XMultiServiceFactory > &xMSF); //============================================================================= struct prompt_and_wait { @@ -128,22 +150,122 @@ struct prompt_and_wait }; static prompt_and_wait exit_prompt("Quitting\nQ"); + +Reference< XChangesBatch > xChangesBatch = NULL; +void commit() +{ + if (xChangesBatch.is()) + { + xChangesBatch->commitChanges(); + } +} + + // ----------------------------------------------------------------------------- -rtl::OUString enterValue(const char* aStr) +Sequence<Any> createSequence(const OUString &sUser, const OUString &sPasswd) +{ + Sequence< Any > aCPArgs; + + if (sUser.getLength() > 0) + { + aCPArgs.realloc(1); + aCPArgs[0] <<= configmgr::createPropertyValue(ASCII("user"), sUser); + } + if (sPasswd.getLength() > 0) + { + aCPArgs.realloc(2); + aCPArgs[1] <<= configmgr::createPropertyValue(ASCII("password"), sPasswd); + } + return aCPArgs; +} + +//============================================================================= +#include <string.h> +#if (defined UNX) || (defined OS2) +#else +#include <conio.h> +#endif + +OString input(const char* pDefaultText, char cEcho) { - char aValue[300] = "com.sun.star."; - cout << aStr << flush; - if (!cin.getline(aValue, 200)) + // PRE: a Default Text would be shown, cEcho is a Value which will show if a key is pressed. + const int MAX_INPUT_LEN = 500; + char aBuffer[MAX_INPUT_LEN]; + + strcpy(aBuffer, pDefaultText); + int nLen = strlen(aBuffer); + +#ifdef WNT + char ch = '\0'; + + cout << aBuffer; + cout.flush(); + + while(ch != 13) { - cerr << "\nInput error\n"; - return OUString(); + ch = getch(); + if (ch == 8) + { + if (nLen > 0) + { + cout << "\b \b"; + cout.flush(); + --nLen; + aBuffer[nLen] = '\0'; + } + else + { + cout << "\a"; + cout.flush(); + } + } + else if (ch != 13) + { + if (nLen < MAX_INPUT_LEN) + { + if (cEcho == 0) + { + cout << ch; + } + else + { + cout << cEcho; + } + cout.flush(); + aBuffer[nLen++] = ch; + aBuffer[nLen] = '\0'; + } + else + { + cout << "\a"; + cout.flush(); + } + } } +#else + if (!cin.getline(aBuffer,sizeof aBuffer)) + return OString(); +#endif + return OString(aBuffer); +} - OUString sValue = OUString::createFromAscii(aValue); +// ----------------------------------------------------------------------------- +rtl::OUString enterValue(const char* _aStr, const char* _aDefault, bool _bIsAPassword) +{ + cout << _aStr; + cout.flush(); + OString aTxt = input(_aDefault, _bIsAPassword ? 0 : '*'); + + OUString sValue = OUString::createFromAscii(aTxt); return sValue; } -//============================================================================= + + +// ----------------------------------------------------------------------------- +// ---------------------------------- M A I N ---------------------------------- +// ----------------------------------------------------------------------------- + #if (defined UNX) || (defined OS2) int main( int argc, char * argv[] ) #else @@ -154,6 +276,16 @@ int _cdecl main( int argc, char * argv[] ) aTimeout.Seconds = 5; aTimeout.Nanosec = 0; + // cout << " Please insert Text: "; + // cout.flush(); + // OString aTxt = input("Der Text", 0); + // cout << endl << "You inserted: " << aTxt.getStr() << endl; + // + // cout << "Please insert Password: "; + // cout.flush(); + // OString aPasswd = input("", '*'); + // cout << endl << "You inserted: " << aPasswd.getStr() << endl; + try { OUString const sServiceRegistry = OUString::createFromAscii( argc > 1 ? argv[1] : "applicat.rdb" ); @@ -169,12 +301,13 @@ int _cdecl main( int argc, char * argv[] ) } cout << "Service factory created !\n---------------------------------------------------------------" << endl; - OUString sUser = enterValue(" Enter User: "); - OUString sPasswd = enterValue("Enter Password: "); + OUString sUser = enterValue(" Enter User: ", "lars", false); + cout << endl; + OUString sPasswd = enterValue("Enter Password: ", "", true); + cout << endl; - Sequence< Any > aCPArgs(2); - aCPArgs[0] <<= configmgr::createPropertyValue(ASCII("user"), sUser); - aCPArgs[1] <<= configmgr::createPropertyValue(ASCII("password"), sPasswd); + Sequence< Any > aCPArgs; + aCPArgs = createSequence(sUser, sPasswd); Reference< XMultiServiceFactory > xCfgProvider( xORB->createInstanceWithArguments( @@ -195,18 +328,25 @@ int _cdecl main( int argc, char * argv[] ) cout << "Configuration Provider created !\n---------------------------------------------------------------" << endl; - OUString sPath = enterValue("Enter RootPath: "); + OUString sPath = enterValue("Enter RootPath: ", "org.openoffice.Setup", false); + cout << endl; - Sequence< Any > aArgs(2); - aArgs[0] <<= configmgr::createPropertyValue(ASCII("user"), sUser); - aArgs[1] <<= configmgr::createPropertyValue(ASCII("nodepath"), sPath); + Sequence< Any > aArgs; + aArgs = createSequence(sUser, ASCII("")); + aArgs.realloc(aArgs.getLength() + 1); + aArgs[aArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("nodepath"), sPath); Reference< XInterface > xIFace = xCfgProvider->createInstanceWithArguments( - OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"), + OUString::createFromAscii("com.sun.star.configuration.ConfigurationUpdateAccess"), aArgs); - cout << "Configuration Read Access created !\n---------------------------------------------------------------" << endl; + cout << "Configuration Read/Write Access created !\n---------------------------------------------------------------" << endl; + + xChangesBatch = Reference< XChangesBatch >(xIFace, UNO_QUERY); - test_read_access(xIFace); + Sequence<OUString> aSeq = xCfgProvider->getAvailableServiceNames(); + showSequence(aSeq); + + test_read_access(xIFace, xCfgProvider); } catch (Exception& e) { @@ -266,9 +406,9 @@ void write(Reference< XChild >& xChild) } /////////////////////////////////////////////////////////////////////////////////////////// -bool ask(Reference< XInterface >& xIface); +bool ask(Reference< XInterface >& xIface, Reference<XMultiServiceFactory> &); -void test_read_access(Reference< XInterface >& xIface) +void test_read_access(Reference< XInterface >& xIface, Reference< XMultiServiceFactory > &xMSF) { using com::sun::star::uno::UNO_QUERY; do @@ -285,10 +425,10 @@ void test_read_access(Reference< XInterface >& xIface) write(xAccess); write(xChild); } - while (ask(xIface)); + while (ask(xIface, xMSF)); } -bool ask(Reference< XInterface >& xIface) +bool ask(Reference< XInterface >& xIface, Reference< XMultiServiceFactory > &xMSF) { cout << "\n[ Q ] -> <Quit>"; cout << endl; @@ -297,21 +437,56 @@ bool ask(Reference< XInterface >& xIface) char buf[200] = {0}; try { + bool bHandled = false; + bool bInserted = false; + if (cin.getline(buf,sizeof buf)) { Reference< XInterface > xNext; - if ((buf[0] == 0 || buf[0] == 'q' || buf[0] == 'Q') && (0 == buf[1])) + if ((buf[0] == 'q' || buf[0] == 'Q') && (0 == buf[1])) { return false; } + else if (buf[0] == 0) + { + return true; + } + else if((buf[0] == 0 || buf[0] == 'o' || buf[0] == 'O') && (0 == buf[1])) + { +/* + cout << "work Offline" << endl; + Reference<com::sun::star::configuration::XConfigurationSync> xSync(xMSF, UNO_QUERY); + + Sequence< Any > aArgs2(5); + sal_Int32 n=0; + aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Setup")); + // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Common")); + // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Java")); + // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.Writer")); + // aArgs2[n++] <<= configmgr::createPropertyValue(ASCII("path"), ASCII("org.openoffice.Office.ucb.Hierarchy")); + xSync->offline(aArgs2); + bHandled = true; +*/ + } + else if((buf[0] == 0 || buf[0] == 's' || buf[0] == 'S') && (0 == buf[1])) + { + // Replace a Value + Reference< XNameAccess > xAccess(xIface, UNO_QUERY); + + cout << "SetMode, insert a Number" << endl; + cin.getline(buf,sizeof buf); + bInserted = true; + } + else if ((buf[0] == 'p' || buf[0] == 'P') && (0 == buf[1])) { Reference< XChild > xChild(xIface, UNO_QUERY); if (xChild.is()) xNext = xChild->getParent(); - + bHandled = true; } - else + + if (bHandled == false) { Reference< XNameAccess > xAccess(xIface, UNO_QUERY); Reference< XHierarchicalNameAccess > xDeepAccess(xIface, UNO_QUERY); @@ -442,7 +617,8 @@ bool ask(Reference< XInterface >& xIface) } break; case TypeClass_VOID: - cout << "Error: ELEMENT '" << aName << "' is NULL and VOID " << endl; + cout << "ELEMENT '" << aName << "' is NULL and VOID " << endl; + bValueOk = true; break; default: cout << "Error: ELEMENT '" << aName << "' is of unknown or unrecognized type" << endl; @@ -450,6 +626,36 @@ bool ask(Reference< XInterface >& xIface) } if (bValue) { + if (bInserted) + { + if (aElement.getValueTypeClass() == TypeClass_BOOLEAN || + aElement.getValueTypeClass() == TypeClass_VOID) + { + cout << "Set Value (Type=BOOL) to :"; + cout.flush(); + cin.getline(buf,sizeof buf); + OUString aInput = OUString::createFromAscii(buf); + sal_Bool bValue = false; + if (aInput.equalsIgnoreCase(ASCII("true"))) + bValue = true; + + OUString aStr = ASCII("false"); + Any aValueAny; + aValueAny <<= bValue; + + Reference< XNameReplace > xNameReplace(xAccess, UNO_QUERY); + if (xNameReplace.is()) + { + xNameReplace->replaceByName(aName, aValueAny); + commit(); + } + bInserted = false; + } + else + { + cout << "Sorry, only BOOLEAN Values can changed today." << endl; + } + } prompt_and_wait(); return bValueOk; } @@ -476,7 +682,7 @@ bool ask(Reference< XInterface >& xIface) else { cout << "Input Error " << endl; - return false; + return true; } } catch (Exception& e) @@ -487,10 +693,8 @@ bool ask(Reference< XInterface >& xIface) catch (...) { cout << "An UNKNOWN Exception occurred !" << endl; - } - prompt_and_wait(); return true; } |