Search in sources :

Example 16 with CoreLocale

use of app.hongs.CoreLocale in project HongsCORE by ihongs.

the class UnitAction method doSave.

@Action("save")
@Verify(conf = "matrix", form = "unit")
@CommitSuccess
public void doSave(ActionHelper helper) throws HongsException {
    Map data = helper.getRequestData();
    String id = model.set(data);
    Map info = new HashMap();
    info.put("id", id);
    info.put("name", data.get("name"));
    CoreLocale lang = CoreLocale.getInstance().clone();
    lang.load("matrix");
    String ms = lang.translate("core.save.unit.success");
    helper.reply(ms, info);
}
Also used : CoreLocale(app.hongs.CoreLocale) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Action(app.hongs.action.anno.Action) CommitSuccess(app.hongs.action.anno.CommitSuccess) Verify(app.hongs.action.anno.Verify)

Example 17 with CoreLocale

use of app.hongs.CoreLocale in project HongsCORE by ihongs.

the class UnitAction method doDelete.

@Action("delete")
@CommitSuccess
public void doDelete(ActionHelper helper) throws HongsException {
    Map data = helper.getRequestData();
    int rows = model.delete(data);
    CoreLocale lang = CoreLocale.getInstance().clone();
    lang.load("matrix");
    String ms = lang.translate("core.delete.unit.success", Integer.toString(rows));
    helper.reply(ms, rows);
}
Also used : CoreLocale(app.hongs.CoreLocale) Map(java.util.Map) HashMap(java.util.HashMap) Action(app.hongs.action.anno.Action) CommitSuccess(app.hongs.action.anno.CommitSuccess)

Example 18 with CoreLocale

use of app.hongs.CoreLocale in project HongsCORE by ihongs.

the class CmdletRunner method main.

public static void main(String[] args) throws IOException, HongsException {
    args = init(args);
    Core core = Core.getInstance();
    String act = Core.ACTION_NAME.get();
    if (null == act || act.length() == 0) {
        System.err.println("ERROR: Cmdlet name can not be empty.");
        System.exit(2);
        return;
    }
    // 获取方法
    Method method = getCmdlets().get(act);
    if (null == method) {
        System.err.println("ERROR: Cmdlet " + act + " is not exists.");
        System.exit(2);
        return;
    }
    // 执行方法
    try {
        if (0 < Core.DEBUG && 8 != (8 & Core.DEBUG)) {
            CmdletHelper.println("Starting...");
        }
        method.invoke(null, new Object[] { args });
        if (0 < Core.DEBUG && 8 != (8 & Core.DEBUG)) {
            CmdletHelper.println("Finished!!!");
        }
    } catch (IllegalAccessException ex) {
        CoreLogger.error("Illegal access for method '" + method.getClass().getName() + "." + method.getName() + "(String[]).");
        System.exit(3);
    } catch (IllegalArgumentException ex) {
        CoreLogger.error("Illegal params for method '" + method.getClass().getName() + "." + method.getName() + "(String[]).");
        System.exit(3);
    } catch (InvocationTargetException ex) {
        Throwable ta = ex.getCause();
        if (0 < Core.DEBUG) {
            CoreLogger.error(ta);
            return;
        }
        /**
         * 构建错误消息
         */
        String error = ta.getLocalizedMessage();
        if (!(ta instanceof HongsException) && !(ta instanceof HongsExpedient) && !(ta instanceof HongsError)) {
            CoreLocale lang = Core.getInstance(CoreLocale.class);
            if (error == null || error.length() == 0) {
                error = lang.translate("core.error.unkwn", ta.getClass().getName());
            } else {
                error = lang.translate("core.error.label", ta.getClass().getName()) + ": " + error;
            }
        }
        CoreLogger.error(error);
        System.exit(4);
    } finally {
        try {
            core.close();
        } catch (Throwable er) {
            CoreLogger.error(er);
            System.exit(5);
        }
        /**
         * 输出总的运行时间
         * 并清除参数及核心
         */
        if (0 < Core.DEBUG && 8 != (8 & Core.DEBUG)) {
            CmdletHelper.println("Total exec time: " + (Tool.humanTime(System.currentTimeMillis() - Core.STARTS_TIME)));
        }
    }
}
Also used : CoreLocale(app.hongs.CoreLocale) HongsError(app.hongs.HongsError) HongsException(app.hongs.HongsException) HongsExpedient(app.hongs.HongsExpedient) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Core(app.hongs.Core)

Example 19 with CoreLocale

use of app.hongs.CoreLocale in project HongsCORE by ihongs.

the class DBAction method getRspMsg.

/**
 * 获取返回消息
 * @param helper
 * @param ett
 * @param opr
 * @param num
 * @return
 * @throws HongsException
 */
protected String getRspMsg(ActionHelper helper, Model ett, String opr, int num) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    CoreLocale locale = CoreLocale.getInstance().clone();
    String mod = runner.getModule();
    String ent = runner.getEntity();
    String cnt = Integer.toString(num);
    String key = "fore." + opr + "." + ent + ".success";
    locale.fill(mod);
    if (!locale.containsKey(key)) {
        key = "fore." + opr + ".success";
        Mview view = new Mview(ett);
        String tit = view.getTitle();
        return locale.translate(key, tit, cnt);
    } else {
        return locale.translate(key, /**/
        cnt);
    }
}
Also used : ActionRunner(app.hongs.action.ActionRunner) CoreLocale(app.hongs.CoreLocale)

Example 20 with CoreLocale

use of app.hongs.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);
}
Also used : CoreLocale(app.hongs.CoreLocale)

Aggregations

CoreLocale (app.hongs.CoreLocale)22 HashMap (java.util.HashMap)15 Map (java.util.Map)15 Action (app.hongs.action.anno.Action)12 CommitSuccess (app.hongs.action.anno.CommitSuccess)7 NaviMap (app.hongs.action.NaviMap)5 IAction (app.hongs.dh.IAction)4 RoleMap (app.hongs.serv.auth.RoleMap)4 File (java.io.File)4 LinkedHashMap (java.util.LinkedHashMap)4 HongsException (app.hongs.HongsException)3 ActionRunner (app.hongs.action.ActionRunner)2 Verify (app.hongs.action.anno.Verify)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Core (app.hongs.Core)1 HongsError (app.hongs.HongsError)1 HongsExpedient (app.hongs.HongsExpedient)1 FetchCase (app.hongs.db.util.FetchCase)1 Wrong (app.hongs.util.verify.Wrong)1