@Test public void testObjects() { FakeContext http = new FakeContext(); http.session().put("value", "session"); http.flash().put("value", "flash"); http.request().data().put("value", "request"); org.wisdom.api.http.Context.CONTEXT.set(http); TemplateEngine engine = createWisdomEngine(); engine.initialize(); Context context = new Context(); context.setVariable("test", "test"); FakeRouter router = new FakeRouter(); Controller controller = new FakeController(); router.addController(controller); Assets assets = mock(Assets.class); context.setVariable(Routes.ROUTES_VAR, new Routes(router, assets, controller)); String processed = engine.process("templates/objects.thl.html", context); assertThat(processed) .contains("<span>session</span>") .contains("<span>flash</span>") .contains("<span>request</span>"); }
public RenderableString process(Template template, Controller controller, Router router, Assets assets, Map<String, Object> variables) { Context ctx = new Context(); final org.wisdom.api.http.Context http = org.wisdom.api.http.Context.CONTEXT.get(); ctx.setVariables(http.session().getData()); ctx.setVariables(http.flash().getCurrentFlashCookieData()); ctx.setVariables(http.flash().getOutgoingFlashCookieData()); for (Map.Entry<String, List<String>> entry : http.parameters().entrySet()) { if (entry.getValue().size() == 1) { ctx.setVariable(entry.getKey(), entry.getValue().get(0)); } else { ctx.setVariable(entry.getKey(), entry.getValue()); } } for (Map.Entry<String, Object> entry : http.request().data().entrySet()) { ctx.setVariable(entry.getKey(), entry.getValue()); } ctx.setVariables(variables); ctx.setVariable(Routes.ROUTES_VAR, new Routes(router, assets, controller)); ctx.setVariable("__TEMPLATE__", template); StringWriter writer = new StringWriter(); try { this.process(template.fullName(), ctx, writer); } catch (TemplateProcessingException e) { if (e.getCause() != null && e.getCause().getCause() != null) { throw new TemplateProcessingException(e.getCause().getCause().getMessage(), e.getTemplateName(), e.getLineNumber(), e.getCause().getCause()); } else { throw e; } } return new RenderableString(writer, MimeTypes.HTML); }
WisdomTemplateEngine extends TemplateEngine { public RenderableString process(Template template, Controller controller, Router router, Assets assets, Map<String, Object> variables) { Context ctx = new Context(); final org.wisdom.api.http.Context http = org.wisdom.api.http.Context.CONTEXT.get(); ctx.setVariables(http.session().getData()); ctx.setVariables(http.flash().getCurrentFlashCookieData()); ctx.setVariables(http.flash().getOutgoingFlashCookieData()); for (Map.Entry<String, List<String>> entry : http.parameters().entrySet()) { if (entry.getValue().size() == 1) { ctx.setVariable(entry.getKey(), entry.getValue().get(0)); } else { ctx.setVariable(entry.getKey(), entry.getValue()); } } for (Map.Entry<String, Object> entry : http.request().data().entrySet()) { ctx.setVariable(entry.getKey(), entry.getValue()); } ctx.setVariables(variables); ctx.setVariable(Routes.ROUTES_VAR, new Routes(router, assets, controller)); ctx.setVariable("__TEMPLATE__", template); StringWriter writer = new StringWriter(); try { this.process(template.fullName(), ctx, writer); } catch (TemplateProcessingException e) { if (e.getCause() != null && e.getCause().getCause() != null) { throw new TemplateProcessingException(e.getCause().getCause().getMessage(), e.getTemplateName(), e.getLineNumber(), e.getCause().getCause()); } else { throw e; } } return new RenderableString(writer, MimeTypes.HTML); } }
WisdomTemplateEngine extends TemplateEngine { public RenderableString process(Template template, Controller controller, Router router, Assets assets, Map<String, Object> variables) { Context ctx = new Context(); final org.wisdom.api.http.Context http = org.wisdom.api.http.Context.CONTEXT.get(); ctx.setVariables(http.session().getData()); ctx.setVariables(http.flash().getCurrentFlashCookieData()); ctx.setVariables(http.flash().getOutgoingFlashCookieData()); for (Map.Entry<String, List<String>> entry : http.parameters().entrySet()) { if (entry.getValue().size() == 1) { ctx.setVariable(entry.getKey(), entry.getValue().get(0)); } else { ctx.setVariable(entry.getKey(), entry.getValue()); } } for (Map.Entry<String, Object> entry : http.request().data().entrySet()) { ctx.setVariable(entry.getKey(), entry.getValue()); } ctx.setVariables(variables); ctx.setVariable(Routes.ROUTES_VAR, new Routes(router, assets, controller)); ctx.setVariable("__TEMPLATE__", template); StringWriter writer = new StringWriter(); try { this.process(template.fullName(), ctx, writer); } catch (TemplateProcessingException e) { if (e.getCause() != null && e.getCause().getCause() != null) { throw new TemplateProcessingException(e.getCause().getCause().getMessage(), e.getTemplateName(), e.getLineNumber(), e.getCause().getCause()); } else { throw e; } } return new RenderableString(writer, MimeTypes.HTML); } WisdomTemplateEngine(Set<IDialect> dialects); }
WisdomTemplateEngine extends TemplateEngine { public RenderableString process(Template template, Controller controller, Router router, Assets assets, Map<String, Object> variables) { Context ctx = new Context(); final org.wisdom.api.http.Context http = org.wisdom.api.http.Context.CONTEXT.get(); ctx.setVariables(http.session().getData()); ctx.setVariables(http.flash().getCurrentFlashCookieData()); ctx.setVariables(http.flash().getOutgoingFlashCookieData()); for (Map.Entry<String, List<String>> entry : http.parameters().entrySet()) { if (entry.getValue().size() == 1) { ctx.setVariable(entry.getKey(), entry.getValue().get(0)); } else { ctx.setVariable(entry.getKey(), entry.getValue()); } } for (Map.Entry<String, Object> entry : http.request().data().entrySet()) { ctx.setVariable(entry.getKey(), entry.getValue()); } ctx.setVariables(variables); ctx.setVariable(Routes.ROUTES_VAR, new Routes(router, assets, controller)); ctx.setVariable("__TEMPLATE__", template); StringWriter writer = new StringWriter(); try { this.process(template.fullName(), ctx, writer); } catch (TemplateProcessingException e) { if (e.getCause() != null && e.getCause().getCause() != null) { throw new TemplateProcessingException(e.getCause().getCause().getMessage(), e.getTemplateName(), e.getLineNumber(), e.getCause().getCause()); } else { throw e; } } return new RenderableString(writer, MimeTypes.HTML); } WisdomTemplateEngine(Set<IDialect> dialects); RenderableString process(Template template, Controller controller, Router router, Assets assets, Map<String,
            Object> variables); }
WisdomTemplateEngine extends TemplateEngine { public RenderableString process(Template template, Controller controller, Router router, Assets assets, Map<String, Object> variables) { Context ctx = new Context(); final org.wisdom.api.http.Context http = org.wisdom.api.http.Context.CONTEXT.get(); ctx.setVariables(http.session().getData()); ctx.setVariables(http.flash().getCurrentFlashCookieData()); ctx.setVariables(http.flash().getOutgoingFlashCookieData()); for (Map.Entry<String, List<String>> entry : http.parameters().entrySet()) { if (entry.getValue().size() == 1) { ctx.setVariable(entry.getKey(), entry.getValue().get(0)); } else { ctx.setVariable(entry.getKey(), entry.getValue()); } } for (Map.Entry<String, Object> entry : http.request().data().entrySet()) { ctx.setVariable(entry.getKey(), entry.getValue()); } ctx.setVariables(variables); ctx.setVariable(Routes.ROUTES_VAR, new Routes(router, assets, controller)); ctx.setVariable("__TEMPLATE__", template); StringWriter writer = new StringWriter(); try { this.process(template.fullName(), ctx, writer); } catch (TemplateProcessingException e) { if (e.getCause() != null && e.getCause().getCause() != null) { throw new TemplateProcessingException(e.getCause().getCause().getMessage(), e.getTemplateName(), e.getLineNumber(), e.getCause().getCause()); } else { throw e; } } return new RenderableString(writer, MimeTypes.HTML); } WisdomTemplateEngine(Set<IDialect> dialects); RenderableString process(Template template, Controller controller, Router router, Assets assets, Map<String,
            Object> variables);  }