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;
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations