use of org.thymeleaf.context.WebContext in project nutzboot by nutzam.
the class MainLauncher method _render.
protected String _render(String name, NutMap params) {
WebContext ctx = new WebContext(Mvcs.getReq(), Mvcs.getResp(), Mvcs.getServletContext());
ctx.setVariable("params", params);
return engine.process("thymeleaf/" + name, ctx);
}
use of org.thymeleaf.context.WebContext in project nutzboot by nutzam.
the class ThymeleafView method render.
@Override
public void render(HttpServletRequest request, HttpServletResponse response, Object value) throws Exception {
String path = evalPath(request, value);
response.setContentType(contentType);
response.setCharacterEncoding(encoding);
try {
Context ctx = createContext(request, value);
WebContext context = new WebContext(request, response, Mvcs.getServletContext(), Locale.getDefault(), ctx.getInnerMap());
templateEngine.process(path, context, response.getWriter());
} catch (Exception e) {
log.error("模板引擎错误", e);
throw e;
}
}
use of org.thymeleaf.context.WebContext in project ff4j by ff4j.
the class AbstractController method get.
/**
* Invoked by dispatcher.
*
* @param req
* current request
* @param res
* current response
* @throws IOException
* error occured.
*/
public void get(HttpServletRequest req, HttpServletResponse res) throws IOException {
i18n(req, res);
WebContext ctx = new WebContext(req, res, req.getSession().getServletContext(), res.getLocale());
ctx.setVariable("uptime", getUptime());
ctx.setVariable("version", ff4j.getVersion());
// Security
ctx.setVariable("secure", false);
if (getFf4j().getAuthorizationsManager() != null) {
ctx.setVariable("secure", true);
ctx.setVariable("userName", getFf4j().getAuthorizationsManager().getCurrentUserName());
Set<String> permissions = getFf4j().getAuthorizationsManager().getCurrentUserPermissions();
ctx.setVariable("userPermissions", permissions);
// Not the responsability of ff4j but in Spring Security
/* If no role FF4J_CONSOLE_READ => 403
if (!permissions.contains(WebConstants.ROLE_USER)) {
res.setStatus(WebConstants.STATUS_FORBIDDEN);
res.getWriter().println("You cannot access FF4J console, insuffisant permissions");
return;
}*/
}
try {
get(req, res, ctx);
} catch (Throwable t) {
ctx.setVariable("msgType", "error");
ctx.setVariable("msgInfo", t.getMessage());
}
// Render to view
templateEngine.process(getSuccessView(), ctx, res.getWriter());
}
use of org.thymeleaf.context.WebContext in project ff4j by ff4j.
the class AbstractController method post.
/**
* Invoked by dispatcher.
*
* @param req
* current request
* @param res
* current response
* @throws IOException
* error occured.
*/
public void post(HttpServletRequest req, HttpServletResponse res) throws IOException {
WebContext ctx = new WebContext(req, res, req.getSession().getServletContext(), req.getLocale());
ctx.setVariable("uptime", getUptime());
ctx.setVariable("version", ff4j.getVersion());
// Adding attribute to response
try {
post(req, res, ctx);
} catch (Throwable t) {
ctx.setVariable("msgType", "error");
ctx.setVariable("msgInfo", t.getMessage());
}
// Render to view
templateEngine.process(getSuccessView(), ctx, res.getWriter());
}
Aggregations