/** * Equivalent to {@link * #removeTemplateFromCache(String, Locale, Object, String, boolean) * removeTemplateFromCache(name, locale, null, thisCfg.getEncoding(locale), true)}. * @since 2.3.19 */ public void removeTemplateFromCache(String name, Locale locale) throws IOException { removeTemplateFromCache(name, locale, null, getEncoding(locale), true); }
@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); } }
/** * Equivalent to {@link * #removeTemplateFromCache(String, Locale, Object, String, boolean) * removeTemplateFromCache(name, thisCfg.getLocale(), null, thisCfg.getEncoding(thisCfg.getLocale()), true)}. * @since 2.3.19 */ public void removeTemplateFromCache(String name) throws IOException { Locale loc = getLocale(); removeTemplateFromCache(name, loc, null, getEncoding(loc), true); }
private String getIncludedTemplateEncoding() { String encoding; // This branch shouldn't exist, as it doesn't make much sense to inherit encoding. But we have to keep BC. encoding = getTemplate().getEncoding(); if (encoding == null) { encoding = configuration.getEncoding(this.getLocale()); } return encoding; }
static Template getTemplate(String systemId) throws IOException { Environment env = Environment.getCurrentEnvironment(); String encoding = env.getTemplate().getEncoding(); if (encoding == null) { encoding = env.getConfiguration().getEncoding(env.getLocale()); } String templatePath = env.getTemplate().getName(); int lastSlash = templatePath.lastIndexOf('/'); templatePath = lastSlash == -1 ? "" : templatePath.substring(0, lastSlash + 1); systemId = env.toFullTemplateName(templatePath, systemId); Template raw = env.getConfiguration().getTemplate(systemId, env.getLocale(), encoding, false); return raw; }
encoding = getEncoding(locale);
/** * Equivalent to <tt>getTemplate(name, locale, thisCfg.getEncoding(locale), true)</tt>. */ public Template getTemplate(String name, Locale locale) throws IOException { return getTemplate(name, locale, getEncoding(locale), true); }
/** * Equivalent to <tt>getTemplate(name, thisCfg.getLocale(), thisCfg.getEncoding(thisCfg.getLocale()), true)</tt>. */ public Template getTemplate(String name) throws IOException { Locale loc = getLocale(); return getTemplate(name, loc, getEncoding(loc), true); }
/** * Equivalent to {@link * #removeTemplateFromCache(String, Locale, Object, String, boolean) * removeTemplateFromCache(name, locale, null, thisCfg.getEncoding(locale), true)}. * @since 2.3.19 */ public void removeTemplateFromCache(String name, Locale locale) throws IOException { removeTemplateFromCache(name, locale, null, getEncoding(locale), true); }
/** * Equivalent to {@link * #removeTemplateFromCache(String, Locale, Object, String, boolean) * removeTemplateFromCache(name, locale, null, thisCfg.getEncoding(locale), true)}. * @since 2.3.19 */ public void removeTemplateFromCache(String name, Locale locale) throws IOException { removeTemplateFromCache(name, locale, null, getEncoding(locale), true); }
@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, WebApplicationException { try { final Configuration configuration = configurationCache.getUnchecked(view.getClass()); final Charset charset = view.getCharset().or(Charset.forName(configuration.getEncoding(locale))); final Template template = configuration.getTemplate(view.getTemplateName(), locale, charset.name()); template.process(view, new OutputStreamWriter(output, template.getEncoding())); } catch (TemplateException e) { throw new ContainerException(e); } }
/** * Equivalent to {@link * #removeTemplateFromCache(String, Locale, Object, String, boolean) * removeTemplateFromCache(name, thisCfg.getLocale(), null, thisCfg.getEncoding(thisCfg.getLocale()), true)}. * @since 2.3.19 */ public void removeTemplateFromCache(String name) throws IOException { Locale loc = getLocale(); removeTemplateFromCache(name, loc, null, getEncoding(loc), true); }
/** * Equivalent to {@link * #removeTemplateFromCache(String, Locale, Object, String, boolean) * removeTemplateFromCache(name, thisCfg.getLocale(), null, thisCfg.getEncoding(thisCfg.getLocale()), true)}. * @since 2.3.19 */ public void removeTemplateFromCache(String name) throws IOException { Locale loc = getLocale(); removeTemplateFromCache(name, loc, null, getEncoding(loc), true); }
private String getIncludedTemplateEncoding() { String encoding; // This branch shouldn't exist, as it doesn't make much sense to inherit encoding. But we have to keep BC. encoding = getTemplate().getEncoding(); if (encoding == null) { encoding = configuration.getEncoding(this.getLocale()); } return encoding; }
private String getIncludedTemplateEncoding() { String encoding; // This branch shouldn't exist, as it doesn't make much sense to inherit encoding. But we have to keep BC. encoding = getTemplate().getEncoding(); if (encoding == null) { encoding = configuration.getEncoding(this.getLocale()); } return encoding; }
static Template getTemplate(String systemId) throws IOException { Environment env = Environment.getCurrentEnvironment(); String encoding = env.getTemplate().getEncoding(); if (encoding == null) { encoding = env.getConfiguration().getEncoding(env.getLocale()); } String templatePath = env.getTemplate().getName(); int lastSlash = templatePath.lastIndexOf('/'); templatePath = lastSlash == -1 ? "" : templatePath.substring(0, lastSlash + 1); systemId = TemplateCache.getFullTemplatePath(env, templatePath, systemId); Template raw = env.getConfiguration().getTemplate(systemId, env.getLocale(), encoding, false); return raw; }
static Template getTemplate(String systemId) throws IOException { Environment env = Environment.getCurrentEnvironment(); String encoding = env.getTemplate().getEncoding(); if (encoding == null) { encoding = env.getConfiguration().getEncoding(env.getLocale()); } String templatePath = env.getTemplate().getName(); int lastSlash = templatePath.lastIndexOf('/'); templatePath = lastSlash == -1 ? "" : templatePath.substring(0, lastSlash + 1); systemId = env.toFullTemplateName(templatePath, systemId); Template raw = env.getConfiguration().getTemplate(systemId, env.getLocale(), encoding, false); return raw; }
static Template getTemplate(String systemId) throws IOException { Environment env = Environment.getCurrentEnvironment(); String encoding = env.getTemplate().getEncoding(); if (encoding == null) { encoding = env.getConfiguration().getEncoding(env.getLocale()); } String templatePath = env.getTemplate().getName(); int lastSlash = templatePath.lastIndexOf('/'); templatePath = lastSlash == -1 ? "" : templatePath.substring(0, lastSlash + 1); systemId = env.toFullTemplateName(templatePath, systemId); Template raw = env.getConfiguration().getTemplate(systemId, env.getLocale(), encoding, false); return raw; }
@Test void properHtmlConfiguration() { final Configuration configuration = TemplateProcessor.getFreemarkerConfiguration(HtmlTemplate.class); final String targetEncoding = Defaults.CHARSET.toString(); assertSoftly(softly -> { softly.assertThat(configuration.getCustomNumberFormat("interest")) .isInstanceOf(InterestNumberFormatFactory.class); softly.assertThat(configuration.getLogTemplateExceptions()).isFalse(); softly.assertThat(configuration.getDefaultEncoding()).isEqualTo(targetEncoding); softly.assertThat(configuration.getEncoding(Locale.getDefault())).isEqualTo(targetEncoding); softly.assertThat(configuration.getEncoding(Locale.ENGLISH)).isEqualTo(targetEncoding); softly.assertThat(configuration.getEncoding(Defaults.LOCALE)).isEqualTo(targetEncoding); }); } }