use of io.github.ihongs.CoreLocale in project HongsCORE by ihongs.
the class Table method getDtfmt.
/**
* 获取日期(时间)格式
* <p>
* 也可在 values 中通过 __type_format__,__name__format__ 来告知格式;
* 其中的 type 为 date,time,datetime; name 为 values 中的键
* </p>
* @param type
* @param name
* @param values
* @return
*/
protected String getDtfmt(String name, String type, Map values) {
String key;
key = name + "_format__";
if (values.containsKey(key)) {
if (values.get(key) instanceof String) {
return (String) values.get(key);
}
}
key = type + "_format__";
if (values.containsKey(key)) {
if (values.get(key) instanceof String) {
return (String) values.get(key);
}
}
String fmt;
if ("time".equals(type)) {
fmt = "HH:mm:ss";
} else if ("date".equals(type)) {
fmt = "yyyy/MM/dd";
} else {
fmt = "yyyy/MM/dd HH:mm:ss";
}
CoreLocale conf = Core.getInstance(CoreLocale.class);
return conf.getProperty("core.default." + type + ".format", fmt);
}
use of io.github.ihongs.CoreLocale in project HongsCORE by ihongs.
the class JAction method getRspMsg.
/**
* 获取返回消息
* @param helper
* @param ett
* @param opr
* @param num
* @return
* @throws HongsException
*/
protected String getRspMsg(ActionHelper helper, IEntity ett, String opr, int num) throws HongsException {
ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
String mod = runner.getModule();
String ent = runner.getEntity();
String cnt = Integer.toString(num);
CoreLocale locale = CoreLocale.getInstance().clone();
locale.fill(mod);
String key = "fore." + opr + "." + ent + ".success";
if (!locale.containsKey(key)) {
key = "fore." + opr + /**/
".success";
}
return locale.translate(key, null, cnt);
}
use of io.github.ihongs.CoreLocale in project HongsCORE by ihongs.
the class FormSet method getFormTranslated.
public Map getFormTranslated(String namc) throws HongsException {
Map items = getForm(namc);
Map itemz = new LinkedHashMap();
CoreLocale lang = getCurrTranslator();
for (Object o : items.entrySet()) {
Map.Entry e = (Map.Entry) o;
Map m = (Map) e.getValue();
String k = (String) e.getKey();
String n = (String) m.get("__text__");
String h = (String) m.get("__hint__");
Map u = new LinkedHashMap();
u.putAll(m);
if (n != null || !"".equals(n)) {
u.put("__text__", lang.translate(n));
}
if (h != null && !"".equals(n)) {
u.put("__hint__", lang.translate(h));
}
itemz.put(k, u);
}
return itemz;
}
use of io.github.ihongs.CoreLocale in project HongsCORE by ihongs.
the class AuthFilter method doFailed.
private void doFailed(Core core, ActionHelper hlpr, byte type, String esg, String erl) {
HttpServletResponse rsp = hlpr.getResponse();
HttpServletRequest req = hlpr.getRequest();
CoreLocale lang = core.got(CoreLocale.class);
String uri;
String msg;
switch(type) {
case 3:
uri = this.indexPage;
if (uri == null || uri.length() == 0) {
uri = null;
msg = lang.translate("core.error.no.power");
} else {
msg = lang.translate("core.error.no.power.redirect");
}
break;
case 2:
uri = this.loginPage;
if (uri == null || uri.length() == 0) {
uri = null;
msg = lang.translate("core.error.no.place");
} else {
msg = lang.translate("core.error.no.place.redirect");
}
break;
case 0:
// 登录超时, 删除会话标识
hlpr.setSessibute(Cnst.UID_SES, null);
hlpr.setSessibute(Cnst.UST_SES, null);
if (siteMap.session != null) {
hlpr.setSessibute(siteMap.session, null);
}
default:
uri = this.loginPage;
if (uri == null || uri.length() == 0) {
if (0 == type) {
type = 1;
msg = lang.translate("core.error.un.login");
} else {
msg = lang.translate("core.error.no.login");
}
} else {
if (0 == type) {
type = 1;
msg = lang.translate("core.error.un.login.redirect");
} else {
msg = lang.translate("core.error.no.login.redirect");
}
/**
* 追加来源路径, 登录后跳回.
*
* WEB 正常发起的异步请求等,
* Referer 总是当前页面 URL.
* APP 和小程序可能不带这个.
*/
String src = null;
String oth;
if (isAjax(req) || isJsop(req)) {
src = req.getHeader("Referer");
oth = req.getHeader("Host");
if (src != null && src.length() != 0 && oth != null && oth.length() != 0) {
Matcher mat = RM_HOST.matcher(src);
if (mat.find() && mat.group(1).equals(oth)) {
src = src.substring(mat.end());
}
}
} else if (isHtml(req)) {
src = req.getRequestURI();
oth = req.getQueryString();
if (oth != null && oth.length() != 0) {
src += "?" + oth;
}
}
if (src != null) {
try {
src = URLEncoder.encode(src, "UTF-8");
} catch (UnsupportedEncodingException e) {
src = "";
}
if (uri.contains("?")) {
uri += "&r=" + src;
} else {
uri += "?r=" + src;
}
}
}
}
if (esg != null) {
msg = esg;
}
if (erl != null) {
uri = erl;
}
if (inAjax(req)) {
Map rep = new HashMap();
rep.put("ok", false);
rep.put("msg", msg);
rep.put("ern", "Er40" + type);
if (uri != null && uri.length() != 0) {
rep.put("err", "Goto " + uri);
}
// 错误状态
if (type == 3) {
rsp.setStatus(HttpServletResponse.SC_FORBIDDEN);
} else {
rsp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
// forward 后可能会失效
// 必须立即输出错误信息
hlpr.reply(rep);
hlpr.flush();
} else {
/**
* 如果从收藏或历史打开一个页面
* 而此区域并没有提供跳转的路径
* 则从全局错误跳转构建响应代码
*/
if (uri == null || uri.length() == 0) {
uri = CoreConfig.getInstance().getProperty("fore.Er40" + type + ".redirect");
if (uri == null || uri.length() == 0) {
uri = Core.SERV_PATH + "/";
}
}
// 跳转页面
hlpr.ensue(type + 400, uri, msg);
}
}
use of io.github.ihongs.CoreLocale in project HongsCORE by ihongs.
the class FormAction method doSave.
@Action("save")
public void doSave(ActionHelper helper) throws HongsException {
Map rd = helper.getRequestData();
String id = model.set(rd);
CoreLocale ln = CoreLocale.getInstance().clone();
ln.load("matrix");
String ms = ln.translate("core.save.form.success");
helper.reply(ms, id);
}
Aggregations