Search in sources :

Example 1 with FilteredTreeNode

use of act.cli.tree.FilteredTreeNode in project actframework by actframework.

the class RouterAdmin method listRoutes.

@Command(name = "act.route.list, act.route.print", help = "list routes")
@PropertySpec("method,path,compactHandler")
public Object listRoutes(@Optional("list routes in tree view") boolean tree, @Optional("specify the port name") String name, @Optional("specify route filter") String q) {
    final Router router = S.blank(name) ? app.router() : app.router(name);
    if (S.notBlank(q)) {
        if (q.contains(".") || q.contains("[") || q.contains("*")) {
        // already regex
        } else {
            // make it a regex
            q = ".*" + q + ".*";
        }
    }
    if (tree) {
        TreeNode root = new TreeNode() {

            @Override
            public String id() {
                return "root";
            }

            @Override
            public String label() {
                return "Router";
            }

            @Override
            public List<TreeNode> children() {
                List<TreeNode> l = new ArrayList<>();
                l.add(router._GET);
                l.add(router._POST);
                l.add(router._PUT);
                l.add(router._DEL);
                return l;
            }
        };
        return S.blank(q) ? root : new FilteredTreeNode(root, TreeNodeFilter.Common.pathMatches(q));
    } else {
        return routeInfoList(name, q);
    }
}
Also used : FilteredTreeNode(act.cli.tree.FilteredTreeNode) TreeNode(act.cli.tree.TreeNode) ArrayList(java.util.ArrayList) FilteredTreeNode(act.cli.tree.FilteredTreeNode) PropertySpec(act.util.PropertySpec) Command(act.cli.Command)

Aggregations

Command (act.cli.Command)1 FilteredTreeNode (act.cli.tree.FilteredTreeNode)1 TreeNode (act.cli.tree.TreeNode)1 PropertySpec (act.util.PropertySpec)1 ArrayList (java.util.ArrayList)1