Search in sources :

Example 1 with ParamExtractor

use of org.nutz.mvc.adaptor.ParamExtractor in project nutz by nutzam.

the class ObjectNavlPairInjector method get.

public Object get(ServletContext sc, HttpServletRequest req, HttpServletResponse resp, Object refer) {
    ObjectNaviNode no = new ObjectNaviNode();
    String pre = "";
    if ("".equals(prefix))
        pre = "node.";
    ParamExtractor pe = Params.makeParamExtractor(req, refer);
    for (Object name : pe.keys()) {
        String na = (String) name;
        if (na.startsWith(prefix)) {
            no.put(pre + na, pe.extractor(na));
        }
    }
    Object model = no.get();
    return Mapl.maplistToObj(model, type);
//        return no.inject(mirror);
}
Also used : ParamExtractor(org.nutz.mvc.adaptor.ParamExtractor)

Example 2 with ParamExtractor

use of org.nutz.mvc.adaptor.ParamExtractor in project nutz by nutzam.

the class PropertiesIocLoader method reload.

@SuppressWarnings("rawtypes")
public void reload() {
    List<String> beanNames = new ArrayList<String>();
    for (String key : keys()) {
        if (!key.startsWith("ioc.") || key.length() < 5)
            continue;
        String[] tmp = key.split("[.]");
        if (tmp.length == 3) {
            if (tmp[2].equals("type") || tmp[2].equals("factory")) {
                beanNames.add(tmp[1]);
            }
        }
    }
    for (String beanName : beanNames) {
        ObjectNaviNode no = new ObjectNaviNode();
        String prefix = "ioc." + beanName + ".";
        String pre = "";
        ParamExtractor pe = Params.makeParamExtractor(null, this.toMap());
        for (Object name : pe.keys()) {
            String na = (String) name;
            if (na.startsWith(prefix)) {
                no.put(pre + na, pe.extractor(na));
            }
        }
        Object model = no.get();
        Object re = Mapl.maplistToObj(((Map) model).get(beanName), IocObject.class);
        this.objs.put(beanName, (IocObject) re);
    }
// 插入自身
//this.objs.put("conf", Iocs.wrap(this));
}
Also used : ArrayList(java.util.ArrayList) IocObject(org.nutz.ioc.meta.IocObject) ObjectNaviNode(org.nutz.mvc.adaptor.injector.ObjectNaviNode) ParamExtractor(org.nutz.mvc.adaptor.ParamExtractor)

Example 3 with ParamExtractor

use of org.nutz.mvc.adaptor.ParamExtractor in project nutz by nutzam.

the class MaplTest method test_complex_prefix.

@Test
public void test_complex_prefix() throws Exception {
    String params = "draw=1&columns%5B0%5D%5Bdata%5D=userId&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=loginname&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=nickname&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false";
    //String params = "columns%5B0%5D%5Bdata%5D=userId&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true";
    NutMap map = new NutMap();
    for (String kv : params.split("&")) {
        //System.out.println(kv);
        String[] tmp = kv.split("=");
        String key = URLDecoder.decode(tmp[0], "UTF-8");
        String value = URLDecoder.decode(tmp.length > 1 ? tmp[1] : "", "UTF-8");
        map.put(key, value);
    }
    System.out.println(map);
    String prefix = "columns";
    Object refer = map;
    HttpServletRequest req = new MockHttpServletRequest();
    ObjectNaviNode no = new ObjectNaviNode();
    String pre = "";
    if ("".equals(prefix))
        pre = "node.";
    ParamExtractor pe = Params.makeParamExtractor(req, refer);
    for (Object name : pe.keys()) {
        String na = (String) name;
        if (na.startsWith(prefix)) {
            String[] val = pe.extractor(na);
            no.put(pre + na, val);
        }
    }
    Object model = no.get();
    System.out.println(Json.toJson(model));
    Object re = Mapl.maplistToObj(model, NutType.list(DataTableColumn.class));
    System.out.println(Json.toJson(re));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) ObjectNaviNode(org.nutz.mvc.adaptor.injector.ObjectNaviNode) ParamExtractor(org.nutz.mvc.adaptor.ParamExtractor) NutMap(org.nutz.lang.util.NutMap) Test(org.junit.Test)

Example 4 with ParamExtractor

use of org.nutz.mvc.adaptor.ParamExtractor in project nutz by nutzam.

the class ObjectPairInjector method get.

public Object get(ServletContext sc, HttpServletRequest req, HttpServletResponse resp, Object refer) {
    ParamExtractor pe = Params.makeParamExtractor(req, refer);
    Object obj = borning.born();
    for (int i = 0; i < injs.length; i++) {
        Object param = converters[i].convert(pe.extractor(names[i]));
        if (null != param)
            injs[i].inject(obj, param);
    }
    return obj;
}
Also used : ParamExtractor(org.nutz.mvc.adaptor.ParamExtractor)

Aggregations

ParamExtractor (org.nutz.mvc.adaptor.ParamExtractor)4 ObjectNaviNode (org.nutz.mvc.adaptor.injector.ObjectNaviNode)2 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Test (org.junit.Test)1 IocObject (org.nutz.ioc.meta.IocObject)1 NutMap (org.nutz.lang.util.NutMap)1 MockHttpServletRequest (org.nutz.mock.servlet.MockHttpServletRequest)1