@Test public void testCustomDialect() { MyDialect dialect = new MyDialect(); final WisdomTemplateEngine engine = createWisdomEngine(ImmutableSet.<IDialect>of(dialect)); engine.initialize(); final Template template = mock(Template.class); when(template.fullName()).thenReturn("templates/dialect.thl.html"); final FakeRouter router = new FakeRouter(); final Controller controller = new FakeController(); router.addController(controller); final Assets assets = mock(Assets.class); Action.ActionResult result = action(new Invocation() { @Override public Result invoke() throws Throwable { return ok(engine.process(template, controller, router, assets, ImmutableMap.<String, Object>of())); } }).parameter("key", "param").invoke(); String content = (String) result.getResult().getRenderable().content(); assertThat(content).contains("Hello, World!"); }
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);  }