本文整理汇总了Java中org.nutz.mvc.View类的典型用法代码示例。如果您正苦于以下问题:Java View类的具体用法?Java View怎么用?Java View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
View类属于org.nutz.mvc包,在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: make
import org.nutz.mvc.View; //导入依赖的package包/类
public View make(Ioc ioc, String type, String value) {
if ("fm".equalsIgnoreCase(type) || "ftl".equalsIgnoreCase(type)) {
if (freeMarkerConfigurer == null) {
for (String name : ioc.getNames()) {
if (iocName.equals(name)) {
freeMarkerConfigurer = ioc.get(FreeMarkerConfigurer.class);
break;
}
}
if (freeMarkerConfigurer == null) {
Configuration configuration = new Configuration();
freeMarkerConfigurer = new FreeMarkerConfigurer(configuration, Mvcs.getServletContext(),"WEB-INF", ".html", null);
freeMarkerConfigurer.init();
}
}
return new WindowsFreemarkerView(freeMarkerConfigurer, value);
}
return null;
}
示例2: handle
import org.nutz.mvc.View; //导入依赖的package包/类
/**
* 用一个wxHandler处理对应的用户请求
*/
public static View handle(WxHandler wxHandler, HttpServletRequest req, String key) throws IOException {
if (wxHandler == null) {
log.info("WxHandler is NULL");
return HttpStatusView.HTTP_502;
}
if (!wxHandler.check(req.getParameter("signature"), req.getParameter("timestamp"), req.getParameter("nonce"), key)) {
log.info("token is invalid");
return HttpStatusView.HTTP_502;
}
if ("GET".equalsIgnoreCase(req.getMethod())) {
log.info("GET? return echostr=" + req.getParameter("echostr"));
return new ViewWrapper(new RawView(null), req.getParameter("echostr"));
}
WxInMsg in = Wxs.convert(req.getInputStream());
in.setExtkey(key);
WxOutMsg out = wxHandler.handle(in);
if (out != null)
Wxs.fix(in, out);
return new ViewWrapper(WxView.me, out);
}
示例3: match
import org.nutz.mvc.View; //导入依赖的package包/类
public View match(ActionContext ac) {
String apikey = ac.getRequest().getHeader("U-ApiKey");
if (apikey == null) {
apikey = ac.getRequest().getHeader("ApiKey");
}
if (apikey != null) {
IotUser itokey = dao.fetch(IotUser.class, apikey);
if (itokey != null) {
ac.getRequest().setAttribute(Zs.UID, itokey.getUserId());
return null;
}
}
if ("GET".equals(ac.getRequest().getMethod()) && !ac.getRequest().getRequestURI().endsWith("devices"))
return null;
return new HttpStatusView(403);
}
示例4: test_view_render
import org.nutz.mvc.View; //导入依赖的package包/类
public void test_view_render() throws Throwable {
// 存入模板
loader.put("/hello", "${obj.array.~size},${obj.array[0]},${json(obj.user)}");
// 创建视图
View view = maker.make(null, "beetl", "/hello");
// 准备好返回值
Map<String, Object> map = new HashMap<String, Object>();
map.put("array", new String[]{"http://wendal.net"});
map.put("user", new NutMap().setv("name", "wendal"));
// 用于接收视图渲染的结果
ByteArrayOutputStream out = new ByteArrayOutputStream();
// mock出req和resp
HttpServletRequest req = mockReq(map);
HttpServletResponse resp = mockResp(out);
// 渲染
view.render(req, resp, map);
// 对比结果
assertEquals("1,http://wendal.net,{\"name\":\"wendal\"}", new String(out.toByteArray()));
}
示例5: make
import org.nutz.mvc.View; //导入依赖的package包/类
@Override
public View make(Ioc ioc, String type, String value) {
if (VIEW_FREEMAKER.equals(type)) {
return new FreeMakerView(value);
}
return super.make(ioc, type, value);
}
示例6: match
import org.nutz.mvc.View; //导入依赖的package包/类
@Override
public View match(ActionContext actionContext) {
HttpServletRequest request = actionContext.getRequest();
AuthenticationToken authenticationToken = createToken(request);
request.setAttribute("loginToken", authenticationToken);
return null;
}
示例7: user
import org.nutz.mvc.View; //导入依赖的package包/类
@At("/user")
@Ok("void")
public View user(@Param("username")String username, @Param("password")String password) {
log.infof("u=%s p=%s", username, password);;
if (Strings.isBlank(username))
return HTTP_403;
if (dao.count(IotUser.class, Cnd.where("name", "=", username).and("apikey", "=", password)) == 1) {
return null;
}
return HTTP_403;
}
示例8: isSuperUser
import org.nutz.mvc.View; //导入依赖的package包/类
@At("/super")
@Ok("void")
public View isSuperUser(@Param("username")String username) {
if ("admin".equals(username))
return null;
return HTTP_403;
}
示例9: acl
import org.nutz.mvc.View; //导入依赖的package包/类
@At("/acl")
@Ok("void")
@Fail("http:403")
public View acl(@Param("username")String username, @Param("topic")String topic, @Param("acc")String acc) {
if (!"1".equals(acc))
return HTTP_403; // TODO 支持mqtt发布, 即通过mqtt更新传感器的值
if (Strings.isBlank(topic) || !topic.matches("^iot2/sensor/[0-9]+$"))
return HTTP_403;
long sensor_id = Long.parseLong(topic.substring("iot2/sensor/".length()));
IotSensor sensor = dao.fetch(IotSensor.class, Cnd.where("name", "=", username).and("id", "=", sensor_id));
if (sensor == null)
return HTTP_403;
return null;
}
示例10: get_user
import org.nutz.mvc.View; //导入依赖的package包/类
@At("/user")
@Ok("void")
public View get_user(@Param("username")String username, @Param("password")String password) {
log.infof("u=%s p=%s", username, password);;
if (Strings.isBlank(username))
return HTTP_403;
if (dao.count(IotUser.class, Cnd.where(Zs.UID, "=", userService.userId(username)).and("apikey", "=", password)) == 1)
return null;
return HTTP_403;
}
示例11: isSuperUser
import org.nutz.mvc.View; //导入依赖的package包/类
@At("/super")
@Ok("void")
public View isSuperUser(@Param("username")String username) {
if ("root".equals(username))
return null;
return HTTP_403;
}
示例12: acl
import org.nutz.mvc.View; //导入依赖的package包/类
@At("/acl")
@Ok("void")
public View acl(@Param("username")String username, @Param("topic")String topic, @Param("acc")String acc) {
if (!"1".equals(acc))
return HTTP_403; // TODO 支持mqtt发布, 即通过mqtt更新传感器的值
if (Strings.isBlank(topic) || !topic.matches("^iot/sensor/[0-9]+$"))
return HTTP_403;
long sensor_id = Long.parseLong(topic.substring("iot/sensor/".length()));
IotSensor sensor = dao.fetch(IotSensor.class, Cnd.where(Zs.UID, "=", userService.userId(username)).and("id", "=", sensor_id));
if (sensor == null)
return HTTP_403;
return null;
}
示例13: index
import org.nutz.mvc.View; //导入依赖的package包/类
@At("/home")
public View index() {
HttpSession session = Mvcs.getHttpSession();
if (session.getAttribute("usr") == null)
return usrLogin;
return USER_HOME_PAGE;
}
示例14: make
import org.nutz.mvc.View; //导入依赖的package包/类
/**
* @param ioc ioc容器
* @param type 类型
* @param value 值
* @return 视图
*/
public View make(Ioc ioc, String type, String value) {
if ("fm".equalsIgnoreCase(type)) {
return new FreemarkerView(value);
}
return null;
}
示例15: make
import org.nutz.mvc.View; //导入依赖的package包/类
public View make(Ioc ioc, String type, String value) {
if (!"wx".equals(type))
return null;
return WxView.me;
}