@Override public void render(View view, Locale locale, OutputStream output) throws IOException { final Configuration configuration = configurationCache.get(view.getClass()); if (configuration == null) { throw new ViewRenderException("Couldn't find view class " + view.getClass()); } try { final Charset charset = view.getCharset().orElseGet(() -> Charset.forName(configuration.getEncoding(locale))); final Template template = configuration.getTemplate(view.getTemplateName(), locale, charset.name()); template.process(view, new OutputStreamWriter(output, template.getEncoding())); } catch (Exception e) { throw new ViewRenderException(e); } }
@Override public void render(View view, Locale locale, OutputStream output) throws IOException { try { final MustacheFactory mustacheFactory = useCache ? factories.get(view.getClass()) : createNewMustacheFactory(view.getClass()); final Mustache template = mustacheFactory.compile(view.getTemplateName()); final Charset charset = view.getCharset().orElse(StandardCharsets.UTF_8); try (OutputStreamWriter writer = new OutputStreamWriter(output, charset)) { template.execute(writer, view); } } catch (Throwable e) { throw new ViewRenderException("Mustache template error: " + view.getTemplateName(), e); } }
@Override public void render(View view, Locale locale, OutputStream output) throws IOException { try { final Configuration configuration = configurationCache.getUnchecked(view.getClass()); final Charset charset = view.getCharset().orElseGet(() -> Charset.forName(configuration.getEncoding(locale))); final Template template = configuration.getTemplate(view.getTemplateName(), locale, charset.name()); template.process(view, new OutputStreamWriter(output, template.getEncoding())); } catch (Exception e) { throw new ViewRenderException(e); } }
@Override public void render(View view, Locale locale, OutputStream output) throws IOException { try { final MustacheFactory mustacheFactory = useCache ? factories.get(view.getClass()) : createNewMustacheFactory(view.getClass()); final Mustache template = mustacheFactory.compile(view.getTemplateName()); final Charset charset = view.getCharset().orElse(StandardCharsets.UTF_8); try (OutputStreamWriter writer = new OutputStreamWriter(output, charset)) { template.execute(writer, view); } } catch (Throwable e) { throw new ViewRenderException("Mustache template error: " + view.getTemplateName(), e); } }
/** {@inheritDoc} */ public void render(View view, Locale locale, OutputStream output) throws IOException, WebApplicationException { try(Writer writer = new OutputStreamWriter(output, view.getCharset().or(Charsets.UTF_8))) { if (view instanceof Layout) { Writer buffer = new StringWriter(); Layout layout = (Layout) view; Template layoutTemplate = loadTemplate(layout.getLayoutTemplateName()); Template viewTemplate = loadTemplate(layout.getTemplateName()); viewTemplate.apply(view, buffer); layout.setBody(buffer.toString()); layoutTemplate.apply(layout, writer); } else { loadTemplate(view.getTemplateName()).apply(view, writer); } } catch (IOException | WebApplicationException e) { // The exception handling in dropwizard view renderer is so bad. So rethrowing this as an illegal state // - system exception. throw new IllegalStateException(e); } }