public void set(String key, Object value) { modelMap.add(key, value); } }
public boolean has (String key) { return containsKey(key); }
public Object map(String key) { if (MODEL.equals(key)) return modelMap; else return modelMap.get(key); }
@Override protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Adding model information JtwigModelMap modelMap = new JtwigModelMap() .add(model) .add("beans", new BeanResolver(getApplicationContext())) .add("theme", getThemeName(request)) .add("request", request); Object token = request.getAttribute("org.springframework.security.web.csrf.CsrfToken"); if(token != null){ modelMap.add("csrf", token); }else{ modelMap.add("csrf", Undefined.UNDEFINED); } if (log.isDebugEnabled()) { log.debug("Rendering Jtwig templates [" + getUrl() + "] in JtwigView '" + getBeanName() + "'"); log.debug("Model: " + modelMap); } if (this.getEncoding() != null) { response.setCharacterEncoding(this.getEncoding()); } getContent().render(RenderContext.create(getConfiguration().render(), modelMap, getViewResolver().functionResolver(), response.getOutputStream())); response.getOutputStream().flush(); response.getOutputStream().close(); }
public String toString () { StringBuilder builder = new StringBuilder().append("{"); Iterator<String> keys = keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); builder.append(key).append(" = ").append(get(key)); if (keys.hasNext()) builder.append(", "); } builder.append("}"); return builder.toString(); } }
public JtwigContext() { this.functionRepository = new DefaultFunctionRepository(); this.modelMap = new JtwigModelMap(); }
public JtwigModelMap add (String key, Object object) { put(key, object); return this; }
public JtwigModelMap add(Map<String, Object> model) { putAll(model); return this; }
@Override public void render(Path templatePath, Map<String, Object> data, OutputStream outputStream) throws TemplateRenderingException { JtwigTemplate template = new JtwigTemplate(new JailedPathJtwigResource(fileManager.resolvePermanentFilePath(Paths.get(".")), templatePath), new JtwigConfiguration()); JtwigModelMap model = new JtwigModelMap(); model.add(data); try { template.output(outputStream, model); } catch (CompileException | RenderException | ParseException e) { throw new TemplateRenderingException(e); } }
public String toString () { StringBuilder builder = new StringBuilder().append("{"); Iterator<String> keys = keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); builder.append(key).append(" = ").append(get(key)); if (keys.hasNext()) builder.append(", "); } builder.append("}"); return builder.toString(); } }
public JtwigContext() { this.functionRepository = new DefaultFunctionRepository(); this.modelMap = new JtwigModelMap(); }
public JtwigModelMap add (String key, Object object) { put(key, object); return this; }
public JtwigModelMap add(Map<String, Object> model) { putAll(model); return this; }
@Override public String renderAsString(Path templatePath, Map<String, Object> data) throws TemplateRenderingException { JtwigTemplate template = new JtwigTemplate(new JailedPathJtwigResource(fileManager.resolvePermanentFilePath(Paths.get(".")), templatePath), new JtwigConfiguration()); JtwigModelMap model = new JtwigModelMap(); model.add(data); try { return template.output(model); } catch (CompileException | RenderException | ParseException e) { throw new TemplateRenderingException(e); } } }
public JtwigContext withModelAttribute(String key, Object value) { this.modelMap.add(key, value); return this; }
public Object map(String key) { if (MODEL.equals(key)) return modelMap; else return modelMap.get(key); }
public boolean has (String key) { return containsKey(key); }
public JtwigContext withModelAttribute(String key, Object value) { this.modelMap.add(key, value); return this; }
public void set(String key, Object value) { modelMap.add(key, value); } }