diff --git a/bindings/java/src/jni/win32/nls.cpp b/bindings/java/src/jni/win32/nls.cpp new file mode 100644 index 00000000..67d9dbb2 --- /dev/null +++ b/bindings/java/src/jni/win32/nls.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. + * This file is part of SIGAR. + * + * SIGAR is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program is distributed + * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +#ifdef WIN32 + +#include "win32bindings.h" +#include "javasigar.h" + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT jint SIGAR_JNI(win32_LocaleInfo_getSystemDefaultLCID) +(JNIEnv *env, jclass objcls) +{ + return GetSystemDefaultLCID(); +} + +JNIEXPORT jstring SIGAR_JNI(win32_LocaleInfo_getAttribute) +(JNIEnv *env, jclass objcls, jint lcid, jint attr) +{ + char value[8192]; + int retval = + GetLocaleInfo(lcid, + attr, + value, sizeof(value)); + + if (retval) { + return env->NewStringUTF(value); + } + else { + return NULL; + } +} + +#ifdef __cplusplus +} +#endif +#endif /* WIN32 */ diff --git a/bindings/java/src/org/hyperic/sigar/cmd/Version.java b/bindings/java/src/org/hyperic/sigar/cmd/Version.java index e8dd3e44..0243bade 100644 --- a/bindings/java/src/org/hyperic/sigar/cmd/Version.java +++ b/bindings/java/src/org/hyperic/sigar/cmd/Version.java @@ -26,8 +26,10 @@ import java.net.UnknownHostException; import org.hyperic.sigar.OperatingSystem; import org.hyperic.sigar.Sigar; import org.hyperic.sigar.SigarException; - import org.hyperic.sigar.SigarLoader; + +import org.hyperic.sigar.win32.LocaleInfo; + /** * Display Sigar, java and system version information. */ @@ -88,6 +90,13 @@ public class Version extends SigarCommandBase { if (!fqdn.equals(host)) { os.println("Hostname............" + host); } + + if (SigarLoader.IS_WIN32) { + LocaleInfo info = new LocaleInfo(); + os.println("Language............" + info); + os.println("Perflib lang id....." + + info.getPerflibLangId()); + } } public static void printInfo(PrintStream os) { diff --git a/bindings/java/src/org/hyperic/sigar/test/SigarTestCase.java b/bindings/java/src/org/hyperic/sigar/test/SigarTestCase.java index 5d30cb39..654adec0 100644 --- a/bindings/java/src/org/hyperic/sigar/test/SigarTestCase.java +++ b/bindings/java/src/org/hyperic/sigar/test/SigarTestCase.java @@ -133,6 +133,12 @@ public abstract class SigarTestCase extends TestCase { assertTrue(msg, value.length() > 0); } + public void assertIndexOfTrace(String msg, String value, + String substr) { + assertTrueTrace(msg, value); + assertTrue(msg, value.indexOf(substr) != -1); + } + public void assertGtZeroTrace(String msg, long value) { traceln(msg + "=" + value); assertTrue(msg, value > 0); diff --git a/bindings/java/src/org/hyperic/sigar/test/SigarTestRunner.java b/bindings/java/src/org/hyperic/sigar/test/SigarTestRunner.java index cd0e2a9f..0662334f 100644 --- a/bindings/java/src/org/hyperic/sigar/test/SigarTestRunner.java +++ b/bindings/java/src/org/hyperic/sigar/test/SigarTestRunner.java @@ -28,6 +28,7 @@ import org.hyperic.sigar.cmd.SigarCommandBase; import org.hyperic.sigar.cmd.Shell; import org.hyperic.sigar.win32.test.TestEventLog; +import org.hyperic.sigar.win32.test.TestLocaleInfo; import org.hyperic.sigar.win32.test.TestMetaBase; import org.hyperic.sigar.win32.test.TestPdh; import org.hyperic.sigar.win32.test.TestRegistryKey; @@ -75,6 +76,7 @@ public class SigarTestRunner extends SigarCommandBase { private static final Class[] WIN32_TESTS = { TestEventLog.class, + TestLocaleInfo.class, TestPdh.class, TestMetaBase.class, TestRegistryKey.class, diff --git a/bindings/java/src/org/hyperic/sigar/win32/LocaleInfo.java b/bindings/java/src/org/hyperic/sigar/win32/LocaleInfo.java new file mode 100644 index 00000000..c40471fb --- /dev/null +++ b/bindings/java/src/org/hyperic/sigar/win32/LocaleInfo.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. + * This file is part of SIGAR. + * + * SIGAR is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program is distributed + * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +package org.hyperic.sigar.win32; + +public class LocaleInfo extends Win32 { + + /** + * Localized name of language + */ + public static final int LOCALE_SLANGUAGE = 0x00000002; + + /** + * English primary language id + */ + public static final int LANG_ENGLISH = 0x09; + + private int id; + + private static native int getSystemDefaultLCID(); + + private static native String getAttribute(int id, int attr); + + public LocaleInfo() { + this(getSystemDefaultLCID()); + } + + public static final int makeLangId(int primary, int sub) { + return (sub << 10) | primary; + } + + public LocaleInfo(Integer id) { + this(id.intValue()); + } + + public LocaleInfo(int id) { + this.id = id; + } + + public LocaleInfo(int primary, int sub) { + this(makeLangId(primary, sub)); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public int getPrimaryLangId() { + return this.id & 0x3ff; + } + + public String getPerflibLangId() { + String id = + Integer.toHexString(getPrimaryLangId()).toUpperCase(); + + //length always == 3 + int pad = 3 - id.length(); + StringBuffer fid = new StringBuffer(3); + while (pad-- > 0) { + fid.append("0"); + } + fid.append(id); + + return fid.toString(); + } + + public int getSubLangId() { + return this.id >> 10; + } + + public String getAttribute(int attr) { + return getAttribute(this.id, attr); + } + + public String getLocalizedLanguageName() { + return getAttribute(LOCALE_SLANGUAGE); + } + + public String toString() { + return getId() + ":" + getLocalizedLanguageName(); + } +} diff --git a/bindings/java/src/org/hyperic/sigar/win32/test/TestLocaleInfo.java b/bindings/java/src/org/hyperic/sigar/win32/test/TestLocaleInfo.java new file mode 100644 index 00000000..38d3d637 --- /dev/null +++ b/bindings/java/src/org/hyperic/sigar/win32/test/TestLocaleInfo.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. + * This file is part of SIGAR. + * + * SIGAR is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program is distributed + * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ + +package org.hyperic.sigar.win32.test; + +import org.hyperic.sigar.test.SigarTestCase; +import org.hyperic.sigar.win32.LocaleInfo; + +public class TestLocaleInfo extends SigarTestCase { + + public TestLocaleInfo(String name) { + super(name); + } + + private void checkInfo(LocaleInfo info, String match) + throws Exception { + + assertGtZeroTrace("id", info.getId()); + assertGtZeroTrace("primary lang", info.getPrimaryLangId()); + assertGtEqZeroTrace("sub lang", info.getSubLangId()); + assertLengthTrace("perflib id", info.getPerflibLangId()); + assertIndexOfTrace("lang", + info.getLocalizedLanguageName(), match); + } + + public void testInfo() throws Exception { + Object[][] tests = { + { new Integer(0x16), "Portuguese" }, + { new Integer(LocaleInfo.makeLangId(0x09,0x05)), "New Zealand" }, + { new Integer(0x07), "German" }, + { new Integer(LocaleInfo.makeLangId(0x0a,0x14)), "Puerto Rico" }, + }; + + for (int i=0; i