Search in sources :

Example 21 with Action

use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.

the class AutoFilter method getacts.

private Set<String> getacts() {
    if (null != actset) {
        return actset;
    }
    // 总是通过 search 获取动作 class
    // 即使无需 search 也要存在 search 方法才行
    Class cls;
    try {
        cls = ActionRunner.getActions().get(action.substring(1) + "/search").getMclass();
    } catch (NullPointerException ex) {
        throw new HongsExemption(1130, "Auto action '" + action.substring(1) + "/search' is not exists", ex);
    }
    cstset = new HashSet();
    actset = new TreeSet(new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            // 对比两个动作路径层级数
            // 优先匹配层级更深的动作
            int i, c1 = 0, c2 = 0;
            i = 0;
            while ((i = o1.indexOf('/', i)) != -1) {
                i++;
                c1++;
            }
            i = 0;
            while ((i = o2.indexOf('/', i)) != -1) {
                i++;
                c2++;
            }
            i = Integer.compare(c2, c1);
            return i != 0 ? i : 1;
        }
    });
    for (Method mtd : cls.getMethods()) {
        Action ann = mtd.getAnnotation(Action.class);
        if (null != ann) {
            String uri;
            if (!"".equals(ann.value())) {
                uri = "/" + ann.value();
            } else {
                uri = "/" + mtd.getName();
            }
            if (mtd.isAnnotationPresent(CustomReplies.class)) {
                cstset.add(uri);
            }
            actset.add(uri);
        }
    }
    return actset;
}
Also used : Action(io.github.ihongs.action.anno.Action) TreeSet(java.util.TreeSet) HongsExemption(io.github.ihongs.HongsExemption) Method(java.lang.reflect.Method) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Comparator(java.util.Comparator)

Example 22 with Action

use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.

the class MoreAction method exec.

@Action("exec")
public void exec(ActionHelper helper) throws HongsException {
    CoreConfig cnf = CoreConfig.getInstance();
    HttpServletRequest req = helper.getRequest();
    HttpServletResponse rsp = helper.getResponse();
    // 许可及IP白名单
    boolean sw = cnf.getProperty("core.exec.more.enable", false);
    String ia = cnf.getProperty("core.exec.more.allows");
    String ip = ActionDriver.getClientAddr(req);
    Set ias = Synt.toTerms(ia);
    if (ias == null || ias.isEmpty()) {
        ias = new HashSet();
        ias.add("::1");
        ias.add("127.0.0.1");
        ias.add("0:0:0:0:0:0:0:1");
    }
    if (!sw) {
        throw new HongsException(400, "Illegal request!");
    }
    if (!ias.contains(ip)) {
        throw new HongsException(400, "Illegal request.");
    }
    Map map = helper.getRequestData();
    String act = Core.ACTION_NAME.get();
    String cmd = (String) map.get("cmd");
    try {
        exec(helper, cmd, req, rsp);
    } finally {
        Core.ACTION_NAME.set(act);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashSet(java.util.HashSet) Set(java.util.Set) CoreConfig(io.github.ihongs.CoreConfig) HongsException(io.github.ihongs.HongsException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Action(io.github.ihongs.action.anno.Action)

Example 23 with Action

use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.

the class SearchAction method assort.

@Action("assort")
@Preset(conf = "", form = "")
@Select(conf = "", form = "")
public void assort(ActionHelper helper) throws HongsException {
    SearchEntity sr = (SearchEntity) getEntity(helper);
    StatisHelper sh = new StatisHelper(sr);
    Map rd = helper.getRequestData();
    rd = getReqMap(helper, sr, "assort", rd);
    // 检查参数
    acheck(sr, rd, 3);
    int rn = Synt.declare(rd.get(Cnst.RN_KEY), 0);
    int pn = Synt.declare(rd.get(Cnst.PN_KEY), 1);
    Map sd = sh.assort(rd, rn, pn);
    sd = getRspMap(helper, sr, "assort", sd);
    helper.reply(sd);
}
Also used : Map(java.util.Map) JAction(io.github.ihongs.dh.JAction) Action(io.github.ihongs.action.anno.Action) Preset(io.github.ihongs.action.anno.Preset) Select(io.github.ihongs.action.anno.Select)

Example 24 with Action

use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.

the class MenuAction method list.

@Action("list")
public void list(ActionHelper helper) throws HongsException {
    String m = helper.getParameter("m");
    String n = helper.getParameter("n");
    String d = helper.getParameter("d");
    List l;
    int b;
    if (m == null || m.length() == 0) {
        m = "default";
    }
    if (d != null && d.length() != 0) {
        b = Integer.parseInt(d);
    } else {
        b = 1;
    }
    if (n != null && n.length() != 0) {
        l = NaviMap.getInstance(m).getMenuTranslated(n, b);
    } else {
        l = NaviMap.getInstance(m).getMenuTranslated(b);
    }
    Map data = new HashMap();
    data.put("list", l);
    helper.reply(data);
}
Also used : HashMap(java.util.HashMap) List(java.util.List) NaviMap(io.github.ihongs.action.NaviMap) Map(java.util.Map) HashMap(java.util.HashMap) Action(io.github.ihongs.action.anno.Action)

Example 25 with Action

use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.

the class FormAction method getInfo.

@Action("info")
@Select(conf = "matrix", form = "form")
public void getInfo(ActionHelper helper) throws HongsException {
    Map rd = helper.getRequestData();
    Map sd = model.getInfo(rd);
    helper.reply(sd);
}
Also used : Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) Select(io.github.ihongs.action.anno.Select)

Aggregations

Action (io.github.ihongs.action.anno.Action)64 Map (java.util.Map)53 HashMap (java.util.HashMap)26 CommitSuccess (io.github.ihongs.action.anno.CommitSuccess)22 Preset (io.github.ihongs.action.anno.Preset)15 HongsException (io.github.ihongs.HongsException)14 CoreLocale (io.github.ihongs.CoreLocale)12 NaviMap (io.github.ihongs.action.NaviMap)12 Verify (io.github.ihongs.action.anno.Verify)10 IAction (io.github.ihongs.dh.IAction)10 CoreConfig (io.github.ihongs.CoreConfig)9 Select (io.github.ihongs.action.anno.Select)8 Set (java.util.Set)8 List (java.util.List)7 File (java.io.File)6 HashSet (java.util.HashSet)6 FetchCase (io.github.ihongs.db.util.FetchCase)5 JAction (io.github.ihongs.dh.JAction)4 UserAction (io.github.ihongs.serv.master.UserAction)3 ArrayList (java.util.ArrayList)3