📄 langmanager.java
字号:
/*****************************************************************************
* (C) Copyright 2004 。
* 保留对所有使用、复制、修改和发布整个软件和相关文档的权利。
* 本计算机程序受著作权法和国际公约的保护,未经授权擅自复制或
* 传播本程序的全部或部分,可能受到严厉的民事和刑事制裁,并
* 在法律允许的范围内受到最大可能的起诉。
*/
/*****************************************************************************
* @作者:Golden Peng
* @版本: 1.0
* @时间: 2002-10-08
*/
/*****************************************************************************
* 修改记录清单
* 修改人 :
* 修改记录:
* 修改时间:
* 修改描述:
*
*/
package com.corp.bisc.ebiz.base;
/**
* 此处插入类型描述。
* 创建日期:(2002-5-15 16:50:28)
* @author:Administrator
*/
import java.util.*;
import org.w3c.dom.*;
import com.corp.bisc.ebiz.exception.*;
import java.io.*;
public class LangManager extends ObjectBase
{
protected String defaultLang = null;
protected Hashtable langMap = new Hashtable();
protected PropertyResourceBundle resourcebundle = null;
/**
* LangManager 构造子注解。
*/
public LangManager() {
super();
}
static public String AsciiToUnicode(String ab) {
String ad=null;
try{
byte[] ac = ab.getBytes("8859_1");
ad = new String(ac,"GB2312");
}
catch(Exception e){
}
return ad;
}
/**
* 此处插入方法描述。
* 创建日期:(2002-5-15 16:52:20)
* @return java.lang.String
*/
public java.lang.String getDefaultLang()
{
return defaultLang;
}
public LangConfig getLangConfig(String lang)
{
enter("getLangDir(String)");
if (lang == null) lang = defaultLang;
LangConfig langCfg = (LangConfig)langMap.get(lang);
if (langCfg == null)
{
langCfg = (LangConfig)langMap.get(defaultLang);
}
leave("getLangDir(String)");
return langCfg;
}
/**
* 此处插入方法描述。
* 创建日期:(2002-5-27 19:50:35)
* @return java.lang.String
* @param lang java.lang.String
* @param key java.lang.String
*/
public String getLangString(String key) throws LangFileException{
//LangConfig langconf = getLangConfig(lang);
String language="";
String country="";
StringTokenizer st = new StringTokenizer(defaultLang,"-");
language = st.nextToken();
country = st.nextToken();
String result = "";
try{
PropertyResourceBundle config = (PropertyResourceBundle)ResourceBundle.getBundle("LangManager",new Locale(language, country));
result = config.getString(key);
}catch(Exception e){
System.out.println(e);
throw new LangFileException();
}
return result;
}
/**
* 此处插入方法描述。
* 创建日期:(2002-5-27 19:50:35)
* @return java.lang.String
* @param lang java.lang.String
* @param key java.lang.String
*/
public static String getLangString(String lang, String key) {
//LangConfig langconf = getLangConfig(lang);
String language="";
String country="";
String result = "";
try{
StringTokenizer st = new StringTokenizer(lang,"-");
language = st.nextToken();
country = st.nextToken();
PropertyResourceBundle config = (PropertyResourceBundle)ResourceBundle.getBundle("language");
config = (PropertyResourceBundle)ResourceBundle.getBundle("language",new Locale(language, country));
result = config.getString(key);
if(language.equalsIgnoreCase("zh")){
result = AsciiToUnicode(result);
}
}catch(Exception e){
System.out.println(e);
}
System.out.println(result);
return result;
}
public void init(Node _node) throws InvalidConfigException
{
enter("init(Node)");
Node defNode = _node.getAttributes().getNamedItem("default");
if (defNode == null)
{
throw new InvalidConfigException("Languages/@default");
}
defaultLang = defNode.getNodeValue();
NodeList nodes = _node.getChildNodes();
boolean hasDefLang = false;
int size = nodes.getLength();
for(int i = 0 ; i < size ; i ++)
{
Node node = nodes.item(i);
if (node.getNodeType() != Node.ELEMENT_NODE) continue;
String nodeName = node.getNodeName();
if (nodeName == null ||
!nodeName.equals("lang"))
{
throw new InvalidConfigException("Languages/lang");
}
LangConfig langConfig = new LangConfig();
langConfig.init(node);
String langName = langConfig.getName();
if (langName.equals(defaultLang))
hasDefLang = true;
langMap.put(langConfig.getName() , langConfig);
}
if (!hasDefLang)
{
throw new InvalidConfigException("Languages/@default");
}
leave("init(Node)");
}
static public String UnicodeToAscii(String ab) {
byte[] ac=null;
try {
ac = ab.getBytes("GB2312");
} catch (UnsupportedEncodingException e) {
}
int xxx;
char yyy;
String tempresult="";
try{
InputStream fis=new ByteArrayInputStream(ac);
while ((xxx=fis.read())!=-1){
yyy=(char)xxx;
tempresult=tempresult+String.valueOf(yyy);
}
fis.close();
}
catch(IOException e){
System.out.println(e);
}
return tempresult;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -