freemarker.core.HTMLOutputFormat Java Examples

The following examples show how to use freemarker.core.HTMLOutputFormat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrillRestServer.java    From Bats with Apache License 2.0 7 votes vote down vote up
/**
 * Creates freemarker configuration settings,
 * default output format to trigger auto-escaping policy
 * and template loaders.
 *
 * @param servletContext servlet context
 * @return freemarker configuration settings
 */
private Configuration getFreemarkerConfiguration(ServletContext servletContext) {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);

  List<TemplateLoader> loaders = new ArrayList<>();
  loaders.add(new WebappTemplateLoader(servletContext));
  loaders.add(new ClassTemplateLoader(DrillRestServer.class, "/"));
  try {
    loaders.add(new FileTemplateLoader(new File("/")));
  } catch (IOException e) {
    logger.error("Could not set up file template loader.", e);
  }
  configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
  return configuration;
}
 
Example #2
Source File: FreeMarkerOnlineViewTest.java    From freemarker-online-tester with Apache License 2.0 6 votes vote down vote up
@Test
public void testViewWhenAllOK() {
    FreeMarkerOnlineView view = new FreeMarkerOnlineView();
    
    view.setTemplate(TEMPLATE);
    view.setDataModel(DATA_MODEL);
    String outputFormatStr = HTMLOutputFormat.INSTANCE.getName();
    view.setOutputFormat(outputFormatStr);
    String localeStr = Locale.GERMAN.toString();
    view.setLocale(localeStr);
    String timeZoneStr = TimeZone.getTimeZone("GMT+01").getID();
    view.setTimeZone(timeZoneStr);
    
    assertEquals(view.getTemplate(), TEMPLATE);
    assertEquals(view.getDataModel(), DATA_MODEL);
    assertEquals(view.getOutputFormat(), outputFormatStr);
    assertEquals(view.getLocale(), localeStr);
    assertEquals(view.getTimeZone(), timeZoneStr);
}
 
Example #3
Source File: EmailConfiguration.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Bean
public freemarker.template.Configuration getConfiguration() {
    final freemarker.template.Configuration configuration =
            new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_22);
    configuration.setLocalizedLookup(false);
    configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
    TemplateConfiguration tcHTML = new TemplateConfiguration();
    tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);

    configuration.setTemplateConfigurations(
            new ConditionalTemplateConfigurationFactory(new FileExtensionMatcher(HTML_TEMPLATE_EXTENSION), tcHTML));

    try {
        TemplateLoader[] templateLoaders = { overrideTemplateLoader(), new FileTemplateLoader(new File(templatesPath)) };
        configuration.setTemplateLoader(new MultiTemplateLoader(templateLoaders));
    } catch (final IOException e) {
        LOGGER.warn("Error occurred while trying to read email templates", e);
    }
    return configuration;
}
 
Example #4
Source File: EmailConfiguration.java    From gravitee-management-rest-api with Apache License 2.0 6 votes vote down vote up
@Bean
public freemarker.template.Configuration getConfiguration() {
    final freemarker.template.Configuration configuration =
            new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_22);

    TemplateConfiguration tcHTML = new TemplateConfiguration();
    tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);

    configuration.setTemplateConfigurations(
            new ConditionalTemplateConfigurationFactory(new FileExtensionMatcher(HTML_TEMPLATE_EXTENSION), tcHTML));

    try {
        configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
        configuration.setTemplateLoader(new FileTemplateLoader(new File(templatesPath)));
    } catch (final IOException e) {
        LOGGER.warn("Error occurred while trying to read email templates directory", e);
    }
    return configuration;
}
 
Example #5
Source File: EmailConfiguration.java    From gravitee-management-rest-api with Apache License 2.0 6 votes vote down vote up
@Bean
public freemarker.template.Configuration getConfiguration() {
    final freemarker.template.Configuration configuration =
            new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_22);

    TemplateConfiguration tcHTML = new TemplateConfiguration();
    tcHTML.setOutputFormat(HTMLOutputFormat.INSTANCE);

    configuration.setTemplateConfigurations(
            new ConditionalTemplateConfigurationFactory(new FileExtensionMatcher(HTML_TEMPLATE_EXTENSION), tcHTML));

    try {
        configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
        configuration.setTemplateLoader(new FileTemplateLoader(new File(templatesPath)));
    } catch (final IOException e) {
        LOGGER.warn("Error occurred while trying to read email templates directory", e);
    }
    return configuration;
}
 
Example #6
Source File: TemplateEngine.java    From mangooio with Apache License 2.0 6 votes vote down vote up
public TemplateEngine() {
    this.configuration.setClassForTemplateLoading(this.getClass(), Default.TEMPLATES_FOLDER.toString());
    this.configuration.setDefaultEncoding(StandardCharsets.UTF_8.name());
    this.configuration.setOutputEncoding(StandardCharsets.UTF_8.name());
    this.configuration.setLocalizedLookup(false);
    this.configuration.setNumberFormat(Default.NUMBER_FORMAT.toString());
    this.configuration.setAPIBuiltinEnabled(true);
    this.configuration.setObjectWrapper(new Java8ObjectWrapper(VERSION));
    this.configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);
    this.configuration.setRecognizeStandardFileExtensions(false);

    if (Application.inDevMode()) {
        this.configuration.setTemplateUpdateDelayMilliseconds(ONE_SECOND_MS);
    } else {
        this.configuration.setTemplateUpdateDelayMilliseconds(Integer.MAX_VALUE);
        this.configuration.setCacheStorage(new MruCacheStorage(STRONG_SIZE_LIMIT, Integer.MAX_VALUE));
    }
}
 
Example #7
Source File: FreeMarkerConfiguration.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Bean
public freemarker.template.Configuration getConfiguration() {
    final freemarker.template.Configuration configuration =
            new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_22);
    configuration.setLocalizedLookup(false);
    configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);
    configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
    try {
        TemplateLoader[] templateLoaders = { overrideTemplateLoader(), new FileTemplateLoader(new File(templatesPath)) };
        configuration.setTemplateLoader(new MultiTemplateLoader(templateLoaders));
    } catch (final IOException e) {
        LOGGER.warn("Error occurred while trying to read email templates", e);
    }
    return configuration;
}
 
Example #8
Source File: FreeMarkerUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private Template getTemplate(String templateName, Theme theme) throws IOException {
    Configuration cfg = new Configuration();

    // Assume *.ftl files are html.  This lets freemarker know how to
    // sanitize and prevent XSS attacks.
    if (templateName.toLowerCase().endsWith(".ftl")) {
        cfg.setOutputFormat(HTMLOutputFormat.INSTANCE);
    }
    
    cfg.setTemplateLoader(new ThemeTemplateLoader(theme));
    return cfg.getTemplate(templateName, "UTF-8");
}
 
Example #9
Source File: RestServerV2.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private Configuration getFreemarkerConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);
  configuration.setClassForTemplateLoading(getClass(), "/");
  return configuration;
}