use of app.hongs.action.anno.Action in project HongsCORE by ihongs.
the class FileAction method create.
@Action("create")
public void create(ActionHelper helper) throws HongsException {
Part prt = (Part) helper.getRequestData().get("file");
String uid = (String) helper.getSessibute(Cnst.UID_SES);
String ext = prt.getSubmittedFileName();
String fid = Core.newIdentity();
int pos = ext.lastIndexOf('.');
if (pos > -1) {
ext = ext.substring(pos + 1);
} else {
ext = "";
}
// 传到临时目录
UploadHelper uh = new UploadHelper();
uh.setUploadPath("static/upload/temp");
uh.setUploadHref("static/upload/temp");
String name = uid + "-" + fid + "." + ext;
String href = uh.getResultHref();
uh.upload(prt, name);
// 组织绝对路径
HttpServletRequest sr = helper.getRequest();
String host = sr.getServerName();
int port = sr.getServerPort();
if (port != 80 && port != 443) {
host += ":" + port;
}
String link = sr.getScheme() + "://" + host + sr.getContextPath() + "/" + href;
helper.reply("", Synt.mapOf("name", name, "href", href, "link", link));
}
use of app.hongs.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 HongsError(0x3e, "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 app.hongs.action.anno.Action in project HongsCORE by ihongs.
the class MenuAction method menu.
@Action("__main__")
public void menu(ActionHelper helper) throws HongsException {
// 配置名称
String m = helper.getParameter("m");
// 活动区域
String n = helper.getParameter("n");
// 附加标识
String x = helper.getParameter("x");
String u = MENU_ACT_URI;
if (m == null || "".equals(m)) {
m = "default";
}
u += "?m=" + m;
if (n != null) {
u += "&n=" + n;
}
if (x != null) {
u += "&x=" + x;
}
// 检查是否有可以进入的下级菜单
NaviMap site = NaviMap.getInstance(m);
if (site.chkMenu(u)) {
String href;
Map<String, Map> menu = site.getMenu(u);
if (menu != null) {
menu = menu.get("menus");
if (menu != null) {
href = getRedirect(site, menu);
if (href != null) {
helper.redirect(Core.BASE_HREF + "/" + href);
return;
}
}
}
}
// 没有权限则跳到指定目录或首页
if (n == null) {
if (!"default".equals(m)) {
n = m;
} else {
n = "";
}
}
helper.redirect(Core.BASE_HREF + "/" + n);
}
use of app.hongs.action.anno.Action in project HongsCORE by ihongs.
the class MoreAction method pack.
@Action("__main__")
public void pack(ActionHelper helper) {
HttpServletRequest req = helper.getRequest();
HttpServletResponse rsp = helper.getResponse();
Map<String, Object> re0 = helper.getRequestData();
Map<String, String> acs = Synt.asMap(re0.get("a"));
Map<String, Object> res = Synt.asMap(re0.get("e"));
Map<String, Object> rs0 = new HashMap();
Map re1;
Map rs1;
String key;
String uri;
if (acs == null) {
acs = new HashMap();
}
if (res == null) {
res = new HashMap();
}
for (Map.Entry<String, String> et : acs.entrySet()) {
key = et.getKey();
uri = et.getValue();
re1 = new HashMap(re0);
uri = "/" + uri + Cnst.ACT_EXT;
re1.putAll(data(res.get(key)));
helper.setRequestData(re1);
rs1 = call(helper, uri, req, rsp);
rs0.put(key, rs1);
}
helper.reply(/**/
rs0);
}
use of app.hongs.action.anno.Action in project HongsCORE by ihongs.
the class MoreAction method call.
@Action("call")
public void call(ActionHelper helper) throws HongsException {
CoreConfig cnf = CoreConfig.getInstance();
HttpServletRequest req = helper.getRequest();
HttpServletResponse rsp = helper.getResponse();
// 许可及IP白名单
boolean sw = cnf.getProperty("core.call.more.enable", false);
String ia = cnf.getProperty("core.call.more.allows");
String ip = addr(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(0x1100, "Illegal request!");
}
if (!ias.contains(ip)) {
throw new HongsException(0x1100, "Illegal request.");
}
// 从参数提取参数
Map map = helper.getRequestData();
helper.setRequestData(data(map.get("request")));
helper.setContextData(data(map.get("context")));
helper.setSessionData(data(map.get("session")));
helper.setCookiesData(data(map.get("cookies")));
String uri = "/" + map.get("act") + Cnst.ACT_EXT;
call(helper, uri, req, rsp);
}
Aggregations