use of io.dropwizard.views.ViewRenderException in project dropwizard by dropwizard.
the class FreemarkerViewRenderer method render.
@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);
}
}
use of io.dropwizard.views.ViewRenderException in project dropwizard by dropwizard.
the class MustacheViewRenderer method render.
@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);
}
}
Aggregations