/** * Creates a new view. * * @param templateName the name of the template resource * @param charset the character set for {@code templateName} */ protected View(String templateName, @Nullable Charset charset) { this.templateName = resolveName(templateName); this.charset = charset; }
@Override public void run(T configuration, Environment environment) throws Exception { final Map<String, Map<String, String>> options = getViewConfiguration(configuration); for (ViewRenderer viewRenderer : viewRenderers) { final Map<String, String> viewOptions = options.get(viewRenderer.getConfigurationKey()); viewRenderer.configure(viewOptions == null ? Collections.emptyMap() : viewOptions); } environment.jersey().register(new ViewMessageBodyWriter(environment.metrics(), viewRenderers)); } }
@Override public boolean isRenderable(View view) { return FILE_PATTERN.matcher(view.getTemplateName()).find(); }
@Override public void initialize(Bootstrap<BithubServerConfiguration> bootstrap) { bootstrap.addBundle(new ViewBundle()); }
@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 writeTo(View t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { final Timer.Context context = metricRegistry.timer(name(t.getClass(), "rendering")).time(); try { for (ViewRenderer renderer : renderers) { if (renderer.isRenderable(t)) { renderer.render(t, detectLocale(requireNonNull(headers)), entityStream); return; } } throw new ViewRenderException("Unable to find a renderer for " + t.getTemplateName()); } catch (ViewRenderException e) { throw new WebApplicationException(e); } finally { context.stop(); } }
@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 initialize(Bootstrap<SupportServerConfiguration> bootstrap) { bootstrap.addBundle(new ViewBundle()); }
@Override public void writeTo(View t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { final Timer.Context context = metricRegistry.timer(name(t.getClass(), "rendering")).time(); try { for (ViewRenderer renderer : renderers) { if (renderer.isRenderable(t)) { renderer.render(t, detectLocale(requireNonNull(headers)), entityStream); return; } } throw new ViewRenderException("Unable to find a renderer for " + t.getTemplateName()); } catch (ViewRenderException e) { throw new WebApplicationException(e); } finally { context.stop(); } }
@Override public boolean isRenderable(View view) { return FILE_PATTERN.matcher(view.getTemplateName()).find(); }
@Override public void run(T configuration, Environment environment) throws Exception { final Map<String, Map<String, String>> options = getViewConfiguration(configuration); for (ViewRenderer viewRenderer : viewRenderers) { final Map<String, String> viewOptions = options.get(viewRenderer.getConfigurationKey()); viewRenderer.configure(firstNonNull(viewOptions, Collections.emptyMap())); } environment.jersey().register(new ViewMessageBodyWriter(environment.metrics(), viewRenderers)); }
/** * Creates a new view. * * @param templateName the name of the template resource * @param charset the character set for {@code templateName} */ protected View(String templateName, @Nullable Charset charset) { this.templateName = resolveName(templateName); this.charset = charset; }
@Override public void initialize(Bootstrap<HelloConfiguration> bootstrap) { bootstrap.addBundle(new ViewBundle()); }
/** * {@inheritDoc} * * <p/>Templates ending with ".hbs" are rendered by this. */ public boolean isRenderable(View view) { return view.getTemplateName().endsWith(".hbs"); }
bootstrap.addBundle(new ViewBundle<>()); bootstrap.addBundle(new AssetsBundle("/assets/static/", "/static/")); bootstrap.addBundle(new MigrationsBundle<SingularityConfiguration>() {
@Override public boolean isRenderable(View view) { return FILE_PATTERN.matcher(view.getTemplateName()).find(); }
@Override public void initialize(Bootstrap<Config> bootstrap) { bootstrap.addBundle(new ViewBundle()); bootstrap.addBundle(new AssetsBundle()); }
@Override public boolean isRenderable(View view) { return FILE_PATTERN.matcher(view.getTemplateName()).find(); }
@Override public void initialize(Bootstrap<Config> bootstrap) { bootstrap.addBundle(new ViewBundle()); bootstrap.addBundle(new AssetsBundle()); }
@Override public void initialize(Bootstrap<LotteryConfiguration> bootstrap) { // set up folders for static content bootstrap.addBundle(new AssetsBundle("/assets/css", "/css", null, "css")); bootstrap.addBundle(new AssetsBundle("/assets/js", "/js", null, "js")); bootstrap.addBundle(new AssetsBundle("/assets/fonts", "/fonts", null, "fonts")); bootstrap.addBundle(new AssetsBundle("/assets/html", "/html", null, "html")); // setup Freemarker views. bootstrap.addBundle(new ViewBundle()); }