📄 internationalmanager.java
字号:
package com.trulytech.mantis.system;
import com.trulytech.mantis.result.DBResult;
import java.util.HashMap;
import java.util.ArrayList;
import com.trulytech.mantis.result.DBColumn;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import com.trulytech.mantis.util.ClientInfo;
import javax.servlet.jsp.PageContext;
import javax.servlet.ServletRequest;
/**
*
* <p>Title: Mantis</p>
*
* <p>Description: 国际化资源处理类</p>
*
* <p>Copyright: Copyright (c) 2002</p>
*
* <p>Company: </p>
*
* @author Wang Xian
* @version 1.0
*/
public class InternationalManager {
//是否初始化
public static boolean isInited = false;
/**
* 初始化资源
* @throws Exception
*/
public static void init() throws Exception {
if (isInited)
return;
logWriter.Info("读取国际化资源...");
DBResult Result = CacheManager.getCache(com.trulytech.mantis.system.
Properties.InternationalResource);
int nSize=Result.ResultBuffer.size();
for (int i = 0; i < nSize; i++) {
ArrayList rec = (ArrayList) Result.ResultBuffer.get(i);
setResources( ( (DBColumn) rec.get(0)).Value.toUpperCase(),
( (DBColumn) rec.get(1)).Value.toUpperCase(),
( (DBColumn) rec.get(2)).Value);
}
logWriter.Info("读取国际化资源成功");
isInited = true;
}
/**
* 设置资源
* @param Language String
* @param Key String
* @param Message String
*/
private static void setResources(String Language, String Key, String Message) {
HashMap map = (HashMap) com.trulytech.mantis.system.Properties.Message.get(
Language);
if (map == null) {
HashMap rec = new HashMap();
rec.put(Key, Message);
com.trulytech.mantis.system.Properties.Message.put(Language, rec);
}
else {
map.put(Key, Message);
com.trulytech.mantis.system.Properties.Message.put(Language, map);
}
}
/**
* 读取资源
* @param Language String
* @param Key String
* @return String
*/
public static String getResource(String Language, String Key) {
if (!isInited)
return "%" + Language + "." + Key + "%";
else {
HashMap map = (HashMap) com.trulytech.mantis.system.Properties.Message.
get(Language);
if (map == null) {
map = (HashMap) com.trulytech.mantis.system.Properties.Message.
get(com.trulytech.mantis.system.Properties.DefaultLanguage);
if (map == null)
return "%" + Language + "." + Key + "%";
else {
if ( (String) map.get(Key) == null)
return "%" + Language + "." + Key + "%";
else
return (String) map.get(Key);
}
}
else {
if ( (String) map.get(Key) == null)
return "%" + Language + "." + Key + "%";
else
return (String) map.get(Key);
}
}
}
/**
* 通过PageContext中的语言读取资源
* @param context PageContext
* @param Key String
* @return String
*/
public static String getResource(PageContext context, String Key) {
HttpSession session = context.getSession();
ServletRequest req = context.getRequest();
String Language = null;
if (session == null) {
Language = req.getLocale().toString();
}
//获得Session中的Language对象
if (session.getAttribute(com.trulytech.mantis.system.Properties.
Session_Language) == null)
Language = req.getLocale().toString();
else
Language = (String) session.getAttribute(com.trulytech.mantis.system.
Properties.
Session_Language);
return getResource(Language.toUpperCase(), Key.toUpperCase());
}
/**
* 获得资源信息
* @param req HttpServletRequest
* @param Key String
* @return String
*/
public static String getResource(HttpServletRequest req, String Key) {
HttpSession session = req.getSession(false);
String Language = null;
if (session == null) {
Language = req.getLocale().toString();
}
//获得Session中的Language对象
if (session.getAttribute(com.trulytech.mantis.system.Properties.
Session_Language) == null)
Language = req.getLocale().toString();
else
Language = (String) session.getAttribute(com.trulytech.mantis.system.
Properties.
Session_Language);
return getResource(Language.toUpperCase(), Key.toUpperCase());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -