Search in sources :

Example 6 with ActionRunner

use of app.hongs.action.ActionRunner in project HongsCORE by ihongs.

the class ActsAction method service.

/**
 * 服务方法
 * Servlet Mapping: *.act<br/>
 * 注意: 不支持请求URI的路径中含有"."(句点), 且必须区分大小写;
 * 其目的是为了防止产生多种形式的请求路径, 影响动作过滤, 产生安全隐患.
 *
 * @param req
 * @param rsp
 * @throws javax.servlet.ServletException
 */
@Override
public void service(HttpServletRequest req, HttpServletResponse rsp) throws ServletException {
    String act = ActionDriver.getRecentPath(req);
    Core core = ActionDriver.getActualCore(req);
    ActionHelper helper = core.get(ActionHelper.class);
    Core.THREAD_CORE.set(core);
    if (act == null || act.length() == 0) {
        senderr(helper, 0x1104, null, "Action URI can not be empty.", "");
        return;
    }
    // 去掉根和扩展名
    act = act.substring(1);
    int pos = act.lastIndexOf('.');
    if (pos != -1)
        act = act.substring(0, pos);
    // 获取并执行动作
    try {
        ActionRunner runner = new ActionRunner(helper, act);
        runner.doAction();
    } catch (ClassCastException ex) {
        // 类型转换失败按 400 错误处理
        senderr(helper, new HongsException(0x1100, ex));
    } catch (HongsException ex) {
        senderr(helper, ex);
    } catch (HongsExpedient ex) {
        senderr(helper, ex);
    } catch (HongsError ex) {
        senderr(helper, ex);
    }
}
Also used : ActionRunner(app.hongs.action.ActionRunner) HongsError(app.hongs.HongsError) HongsException(app.hongs.HongsException) ActionHelper(app.hongs.action.ActionHelper) HongsExpedient(app.hongs.HongsExpedient) Core(app.hongs.Core)

Example 7 with ActionRunner

use of app.hongs.action.ActionRunner in project HongsCORE by ihongs.

the class DataAction method list.

@Action("revert/search")
public void list(ActionHelper helper) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String ent = runner.getEntity();
    String mod = runner.getModule();
    Data sr = (Data) getEntity(helper);
    Model mo = sr.getModel();
    Map rd = helper.getRequestData();
    rd.remove("user_id");
    rd.put("form_id", sr.getFormId());
    Map sd = mo.search(rd);
    // 详情数据转换
    if (sd.containsKey("info")) {
        Map df = (Map) sd.remove("info");
        Map dt = (Map) app.hongs.util.Data.toObject((String) df.remove("data"));
        sd.put("logs", df);
        sd.put("info", dt);
        // 补充枚举和关联
        Set ab = Synt.toTerms(rd.get(Cnst.AB_KEY));
        if (ab != null) {
            byte md = 0;
            if (ab.contains("_enum")) {
                md += 2;
            }
            if (ab.contains("_time")) {
                md += 4;
            }
            if (ab.contains("_link")) {
                md += 8;
            }
            if (md != 0) {
                new SelectHelper().addItemsByForm(mod, ent).select(sd, md);
            }
            if (ab.contains("_fork")) {
                new SpreadHelper().addItemsByForm(mod, ent).spread(sd);
            }
        }
    }
    helper.reply(sd);
}
Also used : ActionRunner(app.hongs.action.ActionRunner) FormSet(app.hongs.action.FormSet) Set(java.util.Set) Model(app.hongs.db.Model) Data(app.hongs.serv.matrix.Data) SpreadHelper(app.hongs.action.SpreadHelper) HashMap(java.util.HashMap) Map(java.util.Map) SelectHelper(app.hongs.action.SelectHelper) Action(app.hongs.action.anno.Action) SearchAction(app.hongs.dh.search.SearchAction)

Example 8 with ActionRunner

use of app.hongs.action.ActionRunner in project HongsCORE by ihongs.

the class Common method execAction.

@Cmdlet("exec-action")
public static void execAction(String[] args) throws HongsException {
    Map<String, Object> opts;
    opts = CmdletHelper.getOpts(args, "request:s", "context:s", "session:s", "cookies:s");
    args = (String[]) opts.get("");
    if (args.length == 0) {
        System.err.println("Action name required!\r\nUsage: ACTION_NAME --request QUERY_STRING --cookies QUERY_STRING --session QUERY_STRING --context QUERY_STRING");
        return;
    }
    ActionHelper helper = Core.getInstance(ActionHelper.class);
    helper.setRequestData(data((String) opts.get("request")));
    helper.setContextData(data((String) opts.get("context")));
    helper.setSessionData(data((String) opts.get("session")));
    helper.setCookiesData(data((String) opts.get("cookies")));
    ActionRunner runner = new ActionRunner(helper, args[0]);
    runner.doAction();
    CmdletHelper.preview(helper.getResponseData());
}
Also used : ActionRunner(app.hongs.action.ActionRunner) ActionHelper(app.hongs.action.ActionHelper) Cmdlet(app.hongs.cmdlet.anno.Cmdlet)

Example 9 with ActionRunner

use of app.hongs.action.ActionRunner 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 10 with ActionRunner

use of app.hongs.action.ActionRunner in project HongsCORE by ihongs.

the class JointGate 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());
    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";
        String tit = getName(locale, mod, ent);
        return locale.translate(key, tit, cnt);
    } else {
        return locale.translate(key, /**/
        cnt);
    }
}
Also used : ActionRunner(app.hongs.action.ActionRunner) CoreLocale(app.hongs.CoreLocale)

Aggregations

ActionRunner (app.hongs.action.ActionRunner)10 Map (java.util.Map)6 ActionHelper (app.hongs.action.ActionHelper)4 Action (app.hongs.action.anno.Action)4 HashMap (java.util.HashMap)4 Set (java.util.Set)3 CoreLocale (app.hongs.CoreLocale)2 FormSet (app.hongs.action.FormSet)2 LuceneAction (app.hongs.dh.lucene.LuceneAction)2 LuceneRecord (app.hongs.dh.lucene.LuceneRecord)2 SearchAction (app.hongs.dh.search.SearchAction)2 Data (app.hongs.serv.matrix.Data)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Core (app.hongs.Core)1 HongsError (app.hongs.HongsError)1 HongsException (app.hongs.HongsException)1 HongsExpedient (app.hongs.HongsExpedient)1 SelectHelper (app.hongs.action.SelectHelper)1 SpreadHelper (app.hongs.action.SpreadHelper)1