resbundle.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 72 行

JAVA
72
字号
package cn.js.fan.util;import java.util.*;import org.apache.log4j.Logger;import cn.js.fan.web.Global;public class ResBundle {        Logger logger = Logger.getLogger(this.getClass().getName());    Locale locale;    ResourceBundle bundle;    String encode = "";    public ResBundle(String resName, Locale locale) {        if (locale == null) {            try {                locale = Global.locale;            } catch (Exception e) {                logger.error("ResBundle1:" + e.getMessage());                locale = Locale.getDefault();            }        }        this.locale = locale;        if (locale.getLanguage().equals("zh")) {            if (locale.getCountry().equals("TW"))                this.encode = "BIG5";            else if (locale.getCountry().equals("CN"))                this.encode = "gb2312";        }        this.resName = resName;        try {            bundle = ResourceBundle.getBundle(resName, locale);        } catch (MissingResourceException e) {            logger.error("ResBundle2:" + e.getMessage());                    }    }    public String get(String key) {        String str = bundle.getString(key);        if (str==null)            return "";        if (!encode.equals("")) {            try {                                                                                str = new String(str.getBytes("ISO8859-1"), "utf-8");            } catch (java.io.UnsupportedEncodingException ex) {                System.out.println("resName=" + resName + " key=" + key + " locale=" + locale);                ex.printStackTrace();            }        }        return str;    }    public void setResName(String resName) {        this.resName = resName;    }    public String getResName() {        return resName;    }    private String resName;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?