Search in sources :

Example 21 with Action

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));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Part(javax.servlet.http.Part) UploadHelper(app.hongs.action.UploadHelper) Action(app.hongs.action.anno.Action)

Example 22 with Action

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;
}
Also used : Action(app.hongs.action.anno.Action) HongsError(app.hongs.HongsError) TreeSet(java.util.TreeSet) Method(java.lang.reflect.Method) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Comparator(java.util.Comparator)

Example 23 with Action

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);
}
Also used : NaviMap(app.hongs.action.NaviMap) NaviMap(app.hongs.action.NaviMap) Map(java.util.Map) HashMap(java.util.HashMap) Action(app.hongs.action.anno.Action)

Example 24 with Action

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) Action(app.hongs.action.anno.Action)

Example 25 with Action

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Set(java.util.Set) HashSet(java.util.HashSet) CoreConfig(app.hongs.CoreConfig) HongsException(app.hongs.HongsException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Action(app.hongs.action.anno.Action)

Aggregations

Action (app.hongs.action.anno.Action)63 Map (java.util.Map)52 HashMap (java.util.HashMap)38 NaviMap (app.hongs.action.NaviMap)16 CommitSuccess (app.hongs.action.anno.CommitSuccess)14 CoreLocale (app.hongs.CoreLocale)12 Preset (app.hongs.action.anno.Preset)12 IAction (app.hongs.dh.IAction)10 RoleMap (app.hongs.serv.auth.RoleMap)10 Verify (app.hongs.action.anno.Verify)9 FetchCase (app.hongs.db.util.FetchCase)8 CoreConfig (app.hongs.CoreConfig)7 Select (app.hongs.action.anno.Select)7 Set (java.util.Set)6 File (java.io.File)5 List (java.util.List)5 HongsException (app.hongs.HongsException)4 ActionRunner (app.hongs.action.ActionRunner)4 LuceneAction (app.hongs.dh.lucene.LuceneAction)3 SearchAction (app.hongs.dh.search.SearchAction)3