Search in sources :

Example 6 with WebContext

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);
}
Also used : WebContext(org.thymeleaf.context.WebContext)

Example 7 with WebContext

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;
    }
}
Also used : WebContext(org.thymeleaf.context.WebContext) Context(org.nutz.lang.util.Context) WebContext(org.thymeleaf.context.WebContext) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with WebContext

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());
}
Also used : WebContext(org.thymeleaf.context.WebContext)

Example 9 with WebContext

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());
}
Also used : WebContext(org.thymeleaf.context.WebContext)

Aggregations

WebContext (org.thymeleaf.context.WebContext)9 TreeMap (java.util.TreeMap)3 AppIdentityService (com.google.appengine.api.appidentity.AppIdentityService)2 ApiProxy (com.google.apphosting.api.ApiProxy)2 Enumeration (java.util.Enumeration)2 Properties (java.util.Properties)2 ServletContext (javax.servlet.ServletContext)2 Cookie (javax.servlet.http.Cookie)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Context (org.nutz.lang.util.Context)1 ConversionService (org.springframework.core.convert.ConversionService)1 WebDataBinder (org.springframework.web.bind.WebDataBinder)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)1