freemarker.template.TemplateExceptionHandler Java Examples

The following examples show how to use freemarker.template.TemplateExceptionHandler. 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: WebMvcAutoConfiguration.java    From halo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Configuring freemarker template file path.
 *
 * @return new FreeMarkerConfigurer
 */
@Bean
public FreeMarkerConfigurer freemarkerConfig(HaloProperties haloProperties) throws IOException, TemplateException {
    FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
    configurer.setTemplateLoaderPaths(FILE_PROTOCOL + haloProperties.getWorkDir() + "templates/", "classpath:/templates/");
    configurer.setDefaultEncoding("UTF-8");

    Properties properties = new Properties();
    properties.setProperty("auto_import", "/common/macro/common_macro.ftl as common,/common/macro/global_macro.ftl as global");

    configurer.setFreemarkerSettings(properties);

    // Predefine configuration
    freemarker.template.Configuration configuration = configurer.createConfiguration();

    configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);

    if (haloProperties.isProductionEnv()) {
        configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    }

    // Set predefined freemarker configuration
    configurer.setConfiguration(configuration);

    return configurer;
}
 
Example #2
Source File: FreemarkerTemplateEngineFactory.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
    Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
    configuration.setDefaultEncoding("utf-8");
    configuration.setLogTemplateExceptions(true);
    configuration.setNumberFormat("computer");
    configuration.setOutputFormat(XHTMLOutputFormat.INSTANCE);
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setTemplateLoader(new SpringTemplateLoader(this.resourceLoader, this.resourceLoaderPath));

    if (this.shouldCheckForTemplateModifications) {
        configuration.setTemplateUpdateDelayMilliseconds(1000);
    } else {
        configuration.setTemplateUpdateDelayMilliseconds(Long.MAX_VALUE);
    }

    this.configuration = configuration;
}
 
Example #3
Source File: FreemarkerRenderer.java    From act with GNU General Public License v3.0 6 votes vote down vote up
private void init(String dbHost, Integer dbPort, String dbName, String dnaCollection, String pathwayCollection) throws IOException {
  cfg = new Configuration(Configuration.VERSION_2_3_23);

  cfg.setClassLoaderForTemplateLoading(
      this.getClass().getClassLoader(), "/act/installer/reachablesexplorer/templates");
  cfg.setDefaultEncoding("UTF-8");

  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  cfg.setLogTemplateExceptions(true);

  reachableTemplate = cfg.getTemplate(reachableTemplateName);
  pathwayTemplate = cfg.getTemplate(pathwayTemplateName);

  // TODO: move this elsewhere.
  MongoClient client = new MongoClient(new ServerAddress(dbHost, dbPort));
  DB db = client.getDB(dbName);

  dnaDesignCollection = JacksonDBCollection.wrap(db.getCollection(dnaCollection), DNADesign.class, String.class);
  Cascade.setCollectionName(pathwayCollection);
}
 
Example #4
Source File: SchemaMaker.java    From raml-module-builder with Apache License 2.0 6 votes vote down vote up
/**
 * @param onTable
 */
public SchemaMaker(String tenant, String module, TenantOperation mode, String previousVersion, String newVersion){
  if(SchemaMaker.cfg == null){
    //do this ONLY ONCE
    SchemaMaker.cfg = new Configuration(new Version(2, 3, 26));
    // Where do we load the templates from:
    cfg.setClassForTemplateLoading(SchemaMaker.class, "/templates/db_scripts");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  }
  this.tenant = tenant;
  this.module = module;
  this.mode = mode;
  this.previousVersion = previousVersion;
  this.newVersion = newVersion;
  this.rmbVersion = PomReader.INSTANCE.getRmbVersion();
}
 
Example #5
Source File: CodeRenderer.java    From jpa-entity-generator with MIT License 6 votes vote down vote up
/**
 * Renders source code by using Freemarker template engine.
 */
public static String render(String templatePath, RenderingData data) throws IOException, TemplateException {
    Configuration config = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
    StringTemplateLoader templateLoader = new StringTemplateLoader();
    String source;
    try (InputStream is = ResourceReader.getResourceAsStream(templatePath);
         BufferedReader buffer = new BufferedReader(new InputStreamReader(is))) {
        source = buffer.lines().collect(Collectors.joining("\n"));
    }
    templateLoader.putTemplate("template", source);
    config.setTemplateLoader(templateLoader);
    config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    config.setObjectWrapper(new BeansWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS));
    config.setWhitespaceStripping(true);

    try (Writer writer = new java.io.StringWriter()) {
        Template template = config.getTemplate("template");
        template.process(data, writer);
        return writer.toString();
    }
}
 
Example #6
Source File: JiraContentFormatter.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private String buildDescription(String jiraTemplate, Map<String, Object> templateValues) {
  String description;

  // Render the values in templateValues map to the jira ftl template file
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try (Writer out = new OutputStreamWriter(baos, CHARSET)) {
    Configuration freemarkerConfig = new Configuration(Configuration.VERSION_2_3_21);
    freemarkerConfig.setClassForTemplateLoading(getClass(), "/org/apache/pinot/thirdeye/detector");
    freemarkerConfig.setDefaultEncoding(CHARSET);
    freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    Template template = freemarkerConfig.getTemplate(jiraTemplate);
    template.process(templateValues, out);

    description = new String(baos.toByteArray(), CHARSET);
  } catch (Exception e) {
    description = "Found an exception while constructing the description content. Pls report & reach out"
        + " to the Thirdeye team. Exception = " + e.getMessage();
  }

  return description;
}
 
Example #7
Source File: SpringBootTmplFreemarkApplication.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@Bean
public freemarker.template.Configuration freemarkConfig() {
    /* ------------------------------------------------------------------------ */
    /* You should do this ONLY ONCE in the whole application life-cycle: */

    /* Create and adjust the configuration singleton */
    freemarker.template.Configuration cfg = new freemarker.template.Configuration(
        freemarker.template.Configuration.VERSION_2_3_22);

    File folder;
    try {
        folder = ResourceUtils.getFile("classpath:templates");
        cfg.setDirectoryForTemplateLoading(folder);
    } catch (IOException e) {
        e.printStackTrace();
    }

    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    return cfg;
}
 
Example #8
Source File: IndexServlet.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void init(ServletConfig servletConfig) throws ServletException {
  this.servletConfig = servletConfig;

  //templateCfg.setClassForTemplateLoading(getClass(), "/");
  Resource baseResource;
  try {
    baseResource = Resource.newResource(servletConfig.getInitParameter("resourceBase"));
  } catch (IOException e) {
    throw new ServletException(e);
  }
  templateCfg.setTemplateLoader(new ResourceTemplateLoader(baseResource));
  templateCfg.setDefaultEncoding("UTF-8");

  // Sets how errors will appear.
  // During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER
  // is better.
  // cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  templateCfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
}
 
Example #9
Source File: Freemarker.java    From freeacs with MIT License 6 votes vote down vote up
/**
 * Inits the freemarker.
 *
 * @return the configuration
 */
public static Configuration initFreemarker() {
  try {
    Configuration config = new Configuration();
    config.setTemplateLoader(new ClassTemplateLoader(Freemarker.class, "/templates"));
    config.setTemplateUpdateDelay(0);
    config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
    config.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
    config.setDefaultEncoding("ISO-8859-1");
    config.setOutputEncoding("ISO-8859-1");
    config.setNumberFormat("0");
    config.setSetting("url_escaping_charset", "ISO-8859-1");
    config.setLocale(Locale.ENGLISH);
    setAutoImport(config);
    setSharedVariables(config);
    return config;
  } catch (Throwable e) {
    throw new RuntimeException("Could not initialise Freemarker configuration", e);
  }
}
 
Example #10
Source File: HeaderSampler.java    From log-synth with Apache License 2.0 6 votes vote down vote up
private void setupTemplate() throws IOException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setTemplateLoader(new ClassTemplateLoader(getClass(), "/web-headers"));
    String templateName = "header";
    switch (headerType) {
        case MAL3:
            templateName = "mal3";
            break;
        case ABABIL:
            templateName = "ababil";
            break;
        default:
            break;
    }
    template = cfg.getTemplate(templateName);
}
 
Example #11
Source File: FreemarkerEngine.java    From helidon-build-tools with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new instance of {@link FreemarkerEngine}.
 * @param backend the backend name
 * @param directives custom directives to register
 * @param model some model attributes to set for each rendering invocation
 */
public FreemarkerEngine(String backend,
                        Map<String, String> directives,
                        Map<String, String> model) {
    checkNonNullNonEmpty(backend, BACKEND_PROP);
    this.backend = backend;
    this.directives = directives == null ? Collections.emptyMap() : directives;
    this.model = model == null ? Collections.emptyMap() : model;
    freemarker = new Configuration(FREEMARKER_VERSION);
    freemarker.setTemplateLoader(new TemplateLoader());
    freemarker.setDefaultEncoding(DEFAULT_ENCODING);
    freemarker.setObjectWrapper(OBJECT_WRAPPER);
    freemarker.setTemplateExceptionHandler(
            TemplateExceptionHandler.RETHROW_HANDLER);
    freemarker.setLogTemplateExceptions(false);
}
 
Example #12
Source File: FreeMarkerFormatter.java    From ofexport2 with Apache License 2.0 6 votes vote down vote up
public FreeMarkerFormatter(String templateName) throws IOException {
    // If the resource doesn't exist abort so we can look elsewhere
    try (
        InputStream in = this.getClass().getResourceAsStream(TEMPLATES + "/" + templateName)) {
        if (in == null) {
            throw new IOException("Resource not found:" + templateName);
        }
    }

    this.templateName = templateName;

    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    TemplateLoader templateLoader = new ClassTemplateLoader(this.getClass(), TEMPLATES);
    cfg.setTemplateLoader(templateLoader);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    // This is fatal - bomb out of application
    try {
        template = cfg.getTemplate(templateName);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #13
Source File: AbstractTestExecutorService.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
	super.setUp();
	try {
		Configuration config = new Configuration();
		DefaultObjectWrapper wrapper = new DefaultObjectWrapper();
		config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
		config.setObjectWrapper(wrapper);
		config.setTemplateExceptionHandler(TemplateExceptionHandler.DEBUG_HANDLER);
		TemplateModel templateModel = this.createModel(wrapper);
		ExecutorBeanContainer ebc = new ExecutorBeanContainer(config, templateModel);
		super.getRequestContext().addExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER, ebc);
	} catch (Throwable t) {
		throw new Exception(t);
	}
}
 
Example #14
Source File: FreemarkerConfigBuilder.java    From ymate-platform-v2 with Apache License 2.0 6 votes vote down vote up
public Configuration build() throws IOException {
    Configuration _config = new Configuration(getVersion());
    _config.setDefaultEncoding(getEncoding());
    _config.setTemplateExceptionHandler(templateExceptionHandler != null ? templateExceptionHandler : TemplateExceptionHandler.HTML_DEBUG_HANDLER);
    //
    for (File _tplFileDir : templateFiles) {
        templateLoaders.add(new FileTemplateLoader(_tplFileDir));
    }
    if (!templateSources.isEmpty()) {
        StringTemplateLoader _stringTplLoader = new StringTemplateLoader();
        for (Map.Entry<String, String> _entry : templateSources.entrySet()) {
            _stringTplLoader.putTemplate(_entry.getKey(), _entry.getValue());
        }
        templateLoaders.add(_stringTplLoader);
    }
    //
    if (!templateLoaders.isEmpty()) {
        if (templateLoaders.size() > 1) {
            _config.setTemplateLoader(new MultiTemplateLoader(templateLoaders.toArray(new TemplateLoader[0])));
        } else {
            _config.setTemplateLoader(templateLoaders.get(0));
        }
    }
    //
    return _config;
}
 
Example #15
Source File: TemplateProcessor.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Generates output file with release notes using FreeMarker.
 *
 * @param variables the map which represents template variables.
 * @param outputFile output file.
 * @param templateFileName the optional file name of the template.
 * @param defaultResource the resource file name to use if no file name was given.
 * @throws IOException if I/O error occurs.
 * @throws TemplateException if an error occurs while generating freemarker template.
 */
public static void generateWithFreemarker(Map<String, Object> variables, String outputFile,
        String templateFileName, String defaultResource) throws IOException, TemplateException {

    final Configuration configuration = new Configuration(Configuration.VERSION_2_3_22);
    configuration.setDefaultEncoding("UTF-8");
    configuration.setLocale(Locale.US);
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setNumberFormat("0.######");

    final StringTemplateLoader loader = new StringTemplateLoader();
    loader.putTemplate(TEMPLATE_NAME, loadTemplate(templateFileName, defaultResource));
    configuration.setTemplateLoader(loader);

    final Template template = configuration.getTemplate(TEMPLATE_NAME);
    try (Writer fileWriter = new OutputStreamWriter(
            new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
        template.process(variables, fileWriter);
    }
}
 
Example #16
Source File: HtmlTriplePatternFragmentWriterImpl.java    From Server.Java with MIT License 5 votes vote down vote up
/**
 *
 * @param prefixes
 * @param datasources
 * @throws IOException
 */
public HtmlTriplePatternFragmentWriterImpl(Map<String, String> prefixes, HashMap<String, IDataSource> datasources) throws IOException {
    super(prefixes, datasources);
    
    cfg = new Configuration(Configuration.VERSION_2_3_22);
    cfg.setClassForTemplateLoading(getClass(), "/views");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    
    indexTemplate = cfg.getTemplate("index.ftl.html");
    datasourceTemplate = cfg.getTemplate("datasource.ftl.html");
    notfoundTemplate = cfg.getTemplate("notfound.ftl.html");
    errorTemplate = cfg.getTemplate("error.ftl.html");
}
 
Example #17
Source File: TrainModule.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * TrainModule
 */
public TrainModule() {
    String maxChartPointsProp = System.getProperty(DL4JSystemProperties.CHART_MAX_POINTS_PROPERTY);
    int value = DEFAULT_MAX_CHART_POINTS;
    if (maxChartPointsProp != null) {
        try {
            value = Integer.parseInt(maxChartPointsProp);
        } catch (NumberFormatException e) {
            log.warn("Invalid system property: {} = {}", DL4JSystemProperties.CHART_MAX_POINTS_PROPERTY, maxChartPointsProp);
        }
    }
    if (value >= 10) {
        maxChartPoints = value;
    } else {
        maxChartPoints = DEFAULT_MAX_CHART_POINTS;
    }

    configuration = new Configuration(new Version(2, 3, 23));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setLocale(Locale.US);
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    configuration.setClassForTemplateLoading(TrainModule.class, "");
    try {
        File dir = Resources.asFile("templates/TrainingOverview.html.ftl").getParentFile();
        configuration.setDirectoryForTemplateLoading(dir);
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
}
 
Example #18
Source File: ControllerServlet.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void initFreemarker(HttpServletRequest request,
		HttpServletResponse response, RequestContext reqCtx)
		throws TemplateModelException {
	Configuration config = new Configuration();
	DefaultObjectWrapper wrapper = new DefaultObjectWrapper();
	config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
	config.setObjectWrapper(wrapper);
	config.setTemplateExceptionHandler(TemplateExceptionHandler.DEBUG_HANDLER);
	TemplateModel templateModel = this.createModel(wrapper, this.getServletContext(), request, response);
	ExecutorBeanContainer ebc = new ExecutorBeanContainer(config, templateModel);
	reqCtx.addExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER, ebc);
}
 
Example #19
Source File: Templates.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static Configuration createConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
  configuration.setClassForTemplateLoading(Templates.class, "/templates/appengine");
  configuration.setDefaultEncoding(StandardCharsets.UTF_8.name());
  configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  configuration.setLogTemplateExceptions(false);
  return configuration;
}
 
Example #20
Source File: FreemarkerServiceImpl.java    From jframe with Apache License 2.0 5 votes vote down vote up
private Configuration createConfiguration(String id) throws IOException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
    File dir = new File(_conf.getConf(id, FtlPropsConf.P_ftl_dir));
    dir.mkdirs();
    cfg.setDirectoryForTemplateLoading(dir);
    cfg.setDefaultEncoding(_conf.getConf(id, FtlPropsConf.P_ftl_encoding, "UTF-8"));
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    return cfg;
}
 
Example #21
Source File: WelcomePage.java    From yuzhouwan with Apache License 2.0 5 votes vote down vote up
/**
 * 创建 Configuration 实例.
 *
 * @return
 * @throws IOException
 */
private Configuration config(String ftlDir) throws IOException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
    cfg.setDirectoryForTemplateLoading(new File(ftlDir));
    cfg.setDefaultEncoding(StandardCharsets.UTF_8.name());
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    return cfg;
}
 
Example #22
Source File: FacetManager.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
/**
 * indicate the table name to query + facet on
 * @param onTable
 */
public FacetManager(String onTable){
  this.table = onTable;
  if(FacetManager.cfg == null){
    //do this ONLY ONCE
    FacetManager.cfg = new Configuration(new Version(2, 3, 26));
    // Where do we load the templates from:
    cfg.setClassForTemplateLoading(FacetManager.class, "/templates/facets");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  }
}
 
Example #23
Source File: ViewBuilder.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
private ViewBuilder() {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setLogTemplateExceptions(false);
    configuration.setDateTimeFormat("iso");
}
 
Example #24
Source File: PluginStatusReportViewBuilder.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 5 votes vote down vote up
private PluginStatusReportViewBuilder() {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setLogTemplateExceptions(false);
    configuration.setDateTimeFormat("iso");
}
 
Example #25
Source File: ObjectRenderer.java    From Repeat with Apache License 2.0 5 votes vote down vote up
public ObjectRenderer(File templateDir) {
	config = new Configuration(Configuration.VERSION_2_3_28);
	try {
		config.setDirectoryForTemplateLoading(templateDir);
	} catch (IOException e) {
		LOGGER.log(Level.SEVERE, "Error setting template directory to " + templateDir.getAbsolutePath(), e);
	}
	config.setDefaultEncoding("UTF-8");
	config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
	config.setLogTemplateExceptions(false);
	config.setWrapUncheckedExceptions(true);
}
 
Example #26
Source File: Templates.java    From live-chat-engine with Apache License 2.0 5 votes vote down vote up
public Templates(String dirPath) throws IOException {
	this.dirPath = dirPath;
	
	cfg = new Configuration();
	cfg.setLocalizedLookup(false);
       cfg.setDirectoryForTemplateLoading(new File(this.dirPath));
       cfg.setObjectWrapper(new DefaultObjectWrapper());
       cfg.setDefaultEncoding("UTF-8");
       cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
       cfg.setIncompatibleImprovements(new Version(2, 3, 20));
}
 
Example #27
Source File: TelegramNotificator.java    From teamcity-telegram-plugin with Apache License 2.0 5 votes vote down vote up
private Configuration createFreeMarkerConfig(@NotNull Path configDir) throws IOException {
  Configuration cfg = new Configuration();
  cfg.setDefaultEncoding("UTF-8");
  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  cfg.setDirectoryForTemplateLoading(configDir.toFile());
  cfg.setTemplateUpdateDelay(TeamCityProperties.getInteger(
      "teamcity.notification.template.update.interval", 60));
  return cfg;
}
 
Example #28
Source File: ViewFreemarker.java    From baratine with GNU General Public License v2.0 5 votes vote down vote up
@PostConstruct
public void init()
{
  Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
  
  cfg.setDefaultEncoding("UTF-8");
  
  String templatePath = _config.get("view.freemarker.templates",
                                   "classpath:/templates");
  
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  
  if (templatePath.startsWith("classpath:")) {
    String path = templatePath.substring(("classpath:").length());
    
    cfg.setClassLoaderForTemplateLoading(loader, path);
  }
  else {
    throw new UnsupportedOperationException();
  }
  
  cfg.setAutoFlush(false);
  
  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
  
  _cfg = cfg;
}
 
Example #29
Source File: LoadPane.java    From pattypan with MIT License 5 votes vote down vote up
public LoadPane(Stage stage) {
  super(stage, 1.01);
  this.stage = stage;

  cfg.setDefaultEncoding("UTF-8");
  cfg.setTemplateExceptionHandler(TemplateExceptionHandler.DEBUG_HANDLER);

  setContent();
  setActions();
}
 
Example #30
Source File: StructTemplate.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
public StructTemplate() {
  this.configuration = new Configuration(Configuration.getVersion());
  this.loader = new StringTemplateLoader();
  this.configuration.setTemplateLoader(this.loader);
  this.configuration.setDefaultEncoding("UTF-8");
  this.configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  this.configuration.setLogTemplateExceptions(false);
  this.configuration.setObjectWrapper(new ConnectObjectWrapper());
}