Search in sources :

Example 16 with Action

use of app.hongs.action.anno.Action in project HongsCORE by ihongs.

the class CoreRoster method addActs.

private static void addActs(Map<String, Mathod> acts, Action anno, String clsn, Class clso) {
    String actn = anno.value();
    if (actn == null || actn.length() == 0) {
        actn = clsn.replace('.', '/');
    }
    Method[] mtds = clso.getMethods();
    for (Method mtdo : mtds) {
        String mtdn = mtdo.getName();
        // 从注解提取动作名
        Action annx = (Action) mtdo.getAnnotation(Action.class);
        if (annx == null) {
            continue;
        }
        String actx = annx.value();
        if (actx == null || actx.length() == 0) {
            actx = mtdn;
        }
        // 检查方法是否合法
        Class[] prms = mtdo.getParameterTypes();
        if (prms == null || prms.length != 1 || !prms[0].isAssignableFrom(ActionHelper.class)) {
            throw new HongsError(0x3c, "Can not find action method '" + clsn + "." + mtdn + "(ActionHelper)'.");
        }
        Mathod mtdx = new Mathod();
        mtdx.method = mtdo;
        mtdx.mclass = clso;
        if ("__main__".equals(actx)) {
            acts.put(actn, /*__main__*/
            mtdx);
        } else {
            acts.put(actn + "/" + actx, mtdx);
        }
    }
}
Also used : Action(app.hongs.action.anno.Action) Method(java.lang.reflect.Method)

Example 17 with Action

use of app.hongs.action.anno.Action in project HongsCORE by ihongs.

the class SearchAction method counts.

@Action("counts/search")
public void counts(ActionHelper helper) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String ent = runner.getEntity();
    String mod = runner.getModule();
    LuceneRecord sr = (LuceneRecord) getEntity(helper);
    SearchHelper sh = new SearchHelper(sr);
    Map rd = helper.getRequestData();
    rd = getReqMap(helper, sr, "counts", rd);
    Map sd = sh.counts(rd);
    sd = getRspMap(helper, sr, "counts", sd);
    // sr.close (  ); // 应用容器可自行关闭
    // 增加标题
    titled(rd, sd, mod, ent);
    helper.reply(sd);
}
Also used : ActionRunner(app.hongs.action.ActionRunner) LuceneRecord(app.hongs.dh.lucene.LuceneRecord) Map(java.util.Map) Action(app.hongs.action.anno.Action) LuceneAction(app.hongs.dh.lucene.LuceneAction)

Example 18 with Action

use of app.hongs.action.anno.Action in project HongsCORE by ihongs.

the class SearchAction method statis.

@Action("statis/search")
public void statis(ActionHelper helper) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String ent = runner.getEntity();
    String mod = runner.getModule();
    LuceneRecord sr = (LuceneRecord) getEntity(helper);
    SearchHelper sh = new SearchHelper(sr);
    Map rd = helper.getRequestData();
    rd = getReqMap(helper, sr, "statis", rd);
    Map sd = sh.statis(rd);
    sd = getRspMap(helper, sr, "statis", sd);
    // sr.close (  ); // 应用容器可自行关闭
    // 增加标题
    titled(rd, sd, mod, ent);
    helper.reply(sd);
}
Also used : ActionRunner(app.hongs.action.ActionRunner) LuceneRecord(app.hongs.dh.lucene.LuceneRecord) Map(java.util.Map) Action(app.hongs.action.anno.Action) LuceneAction(app.hongs.dh.lucene.LuceneAction)

Example 19 with Action

use of app.hongs.action.anno.Action in project HongsCORE by ihongs.

the class FileAction method search.

@Override
@Action("search")
public void search(ActionHelper helper) throws HongsException {
    MimetypesFileTypeMap nmap = new MimetypesFileTypeMap();
    CoreLocale lang = CoreLocale.getInstance("manage");
    String type = helper.getParameter("type");
    String path = helper.getParameter("path");
    String pxth = path;
    File file;
    // 根目录
    if ("".equals(path) || "/".equals(path)) {
        if ("file".equals(type)) {
            helper.reply(Synt.mapOf("page", Synt.mapOf("ern", 1), "list", new ArrayList()));
        } else {
            helper.reply(Synt.mapOf("page", Synt.mapOf("ern", 0), "list", ROOT_LIST));
        }
        return;
    }
    if (path == null) {
        helper.fault(lang.translate("core.manage.file.path.required"));
        return;
    }
    path = realPath(path);
    if (path == null) {
        helper.fault(lang.translate("core.manage.file.path.is.error"));
        return;
    }
    file = new File(path);
    if (!file.exists()) {
        helper.fault(lang.translate("core.manage.file.path.is.not.exist"));
        return;
    }
    byte t = 0;
    if ("dir".equals(type)) {
        t = 1;
    } else if ("file".equals(type)) {
        t = 2;
    }
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        Set<Map> filez;
        // 排序规则, 默认按名称排序
        final boolean ds;
        String ob = helper.getParameter("ob");
        if (ob != null && ob.startsWith("-")) {
            ob = ob.substring(1);
            ds = true;
        } else {
            ds = false;
        }
        if ("type".equals(ob)) {
            filez = new TreeSet(new Comparator<Map>() {

                @Override
                public int compare(Map f1, Map f2) {
                    String t1 = (String) f1.get("type");
                    String t2 = (String) f2.get("type");
                    byte s1 = Synt.declare(TYPE_SORT.get(t1), (byte) 0);
                    byte s2 = Synt.declare(TYPE_SORT.get(t2), (byte) 0);
                    if (s1 != s2)
                        if (ds)
                            return s1 < s2 ? 1 : -1;
                        else
                            return s1 > s2 ? 1 : -1;
                    String n1 = (String) f1.get("name");
                    String n2 = (String) f2.get("name");
                    if (ds)
                        return n2.compareTo(n1);
                    else
                        return n1.compareTo(n2);
                }
            });
        } else if ("size".equals(ob)) {
            filez = new TreeSet(new Comparator<Map>() {

                @Override
                public int compare(Map f1, Map f2) {
                    long s1 = Synt.declare(f1.get("size"), 0L);
                    long s2 = Synt.declare(f2.get("size"), 0L);
                    if (s1 != s2)
                        if (ds)
                            return s1 < s2 ? 1 : -1;
                        else
                            return s1 > s2 ? 1 : -1;
                    String n1 = (String) f1.get("name");
                    String n2 = (String) f2.get("name");
                    if (ds)
                        return n2.compareTo(n1);
                    else
                        return n1.compareTo(n2);
                }
            });
        } else {
            filez = new TreeSet(new Comparator<Map>() {

                @Override
                public int compare(Map f1, Map f2) {
                    String n1 = (String) f1.get("name");
                    String n2 = (String) f2.get("name");
                    if (ds)
                        return n2.compareTo(n1);
                    else
                        return n1.compareTo(n2);
                }
            });
        }
        for (File item : files) {
            if (t == 1) {
                if (!item.isDirectory()) {
                    continue;
                }
            } else if (t == 2) {
                if (!item.isFile()) {
                    continue;
                }
            }
            String name = item.getName();
            String extn = name.replaceFirst("^.*/", "");
            String mime = nmap.getContentType(extn);
            Map xxxx = new HashMap();
            xxxx.put("path", pxth + "/" + name);
            xxxx.put("name", name);
            xxxx.put("mime", mime);
            xxxx.put("type", item.isDirectory() ? "dir" : (isTextFile(item) ? "txt" : "bin"));
            xxxx.put("size", item.isDirectory() ? item.list().length : item.length());
            xxxx.put("mtime", item.lastModified());
            filez.add(xxxx);
        }
        Map rsp = new HashMap();
        rsp.put("list", filez);
        rsp.put("page", Synt.mapOf("ern", filez.size() > 0 ? 0 : 1));
        helper.reply(rsp);
    } else if (isTextFile(file)) {
        String name = file.getName();
        String extn = name.replaceFirst("^.*/", "");
        String mime = nmap.getContentType(extn);
        Map xxxx = new HashMap();
        xxxx.put("path", pxth);
        xxxx.put("name", name);
        xxxx.put("mime", mime);
        xxxx.put("type", "txt");
        xxxx.put("size", file.length());
        xxxx.put("text", readFile(file));
        xxxx.put("mtime", file.lastModified());
        helper.reply("", xxxx);
    } else {
        helper.fault(lang.translate("core.manage.file.unsupported"));
    }
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) CoreLocale(app.hongs.CoreLocale) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) TreeSet(java.util.TreeSet) File(java.io.File) HashMap(java.util.HashMap) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) Map(java.util.Map) IAction(app.hongs.dh.IAction) Action(app.hongs.action.anno.Action)

Example 20 with Action

use of app.hongs.action.anno.Action in project HongsCORE by ihongs.

the class FileAction method create.

@Override
@Action("create")
public void create(ActionHelper helper) throws HongsException {
    CoreLocale lang = CoreLocale.getInstance("manage");
    String path = helper.getParameter("path");
    String type = helper.getParameter("type");
    String text = helper.getParameter("text");
    File file;
    if (path == null) {
        helper.fault(lang.translate("core.manage.file.path.required"));
        return;
    }
    path = realPath(path);
    if (path == null) {
        helper.fault(lang.translate("core.manage.file.path.is.error"));
        return;
    }
    file = new File(path);
    if (file.exists()) {
        helper.fault(lang.translate("core.manage.file.path.is.exist"));
        return;
    }
    if (isDenyFile(file)) {
        helper.fault(lang.translate("core.manage.file.interdicted"));
        return;
    }
    // 创建目录
    if ("dir".equals(type)) {
        new File(path).mkdirs();
        helper.reply("");
        return;
    }
    // 写入文件
    try {
        saveFile(file, text);
    } catch (Exception ex) {
        CoreLogger.error(ex);
        helper.fault(lang.translate("core.manage.file.create.failed"));
        return;
    }
    helper.reply("");
}
Also used : CoreLocale(app.hongs.CoreLocale) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HongsException(app.hongs.HongsException) IAction(app.hongs.dh.IAction) 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