add win32.LocaleInfo
This commit is contained in:
parent
eda91e1e8a
commit
8f70da2dd3
|
@ -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 */
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<tests.length; i++) {
|
||||
Integer id = (Integer)tests[i][0];
|
||||
String lang = (String)tests[i][1];
|
||||
LocaleInfo info = new LocaleInfo(id);
|
||||
checkInfo(info, lang);
|
||||
}
|
||||
|
||||
checkInfo(new LocaleInfo(), "");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue