Java Code Examples for freemarker.template.Configuration#setWrapUncheckedExceptions()

The following examples show how to use freemarker.template.Configuration#setWrapUncheckedExceptions() . 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: FreemarkerConfig.java    From t-io with Apache License 2.0 5 votes vote down vote up
/**
	 * 
	 * @param httpConfig
	 * @param root
	 * @return
	 * @throws IOException
	 */
	private Configuration createConfiguration(HttpConfig httpConfig, String root) throws IOException {
		if (httpConfig.getPageRoot() == null) {
			return null;
		}

		if (configurationCreater != null) {
			return configurationCreater.createConfiguration(httpConfig, root);
		}

		Configuration cfg = new Configuration(Configuration.getVersion());

		if (httpConfig.isPageInClasspath()) {
			cfg.setClassForTemplateLoading(this.getClass(), "/" + root/**.substring("classpath:".length())*/
			);
			//cfg.setClassForTemplateLoading(FreemarkerUtil.class, "/template");
		} else {
			cfg.setDirectoryForTemplateLoading(new File(root));
		}
		cfg.setDefaultEncoding(httpConfig.getCharset());
		//		cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
		cfg.setLogTemplateExceptions(false);
		cfg.setWrapUncheckedExceptions(true);
		cfg.setTemplateExceptionHandler(ShortMessageTemplateExceptionHandler.me);
		cfg.setLocale(Locale.SIMPLIFIED_CHINESE);
		cfg.setNumberFormat("#");
//		cfg.setClassicCompatible(true);
		return cfg;
	}
 
Example 2
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 3
Source File: PreprocessorImpl.java    From maven-confluence-plugin with Apache License 2.0 5 votes vote down vote up
public PreprocessorImpl() {
    cfg = new Configuration(VERSION);
    cfg.setDefaultEncoding(StandardCharsets.UTF_8.name());
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    cfg.setWrapUncheckedExceptions(true);
    cfg.setFallbackOnNullLoopVariable(false);
}
 
Example 4
Source File: TemplateConfiguration.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
private static Configuration createConfiguration() {
    final Configuration cfg = new Configuration(Configuration.getVersion());
    cfg.setClassForTemplateLoading(TemplateConfiguration.class, "/megamek/common/templates");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    cfg.setWrapUncheckedExceptions(true);
    return cfg;
}
 
Example 5
Source File: AbstractRunningGenerator.java    From skywalking with Apache License 2.0 5 votes vote down vote up
protected AbstractRunningGenerator() {
    cfg = new Configuration(Configuration.VERSION_2_3_28);
    try {
        cfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), "/");
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        cfg.setLogTemplateExceptions(false);
        cfg.setWrapUncheckedExceptions(true);
    } catch (Exception e) {
        // never to do this
    }
}
 
Example 6
Source File: FreemarkerTransformer.java    From tutorials with MIT License 5 votes vote down vote up
public String html() throws IOException, TemplateException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_29);
    cfg.setDirectoryForTemplateLoading(new File(templateDirectory));
    cfg.setDefaultEncoding(StandardCharsets.UTF_8.toString());
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    cfg.setWrapUncheckedExceptions(true);
    cfg.setFallbackOnNullLoopVariable(false);
    Template temp = cfg.getTemplate(templateFile);
    try (Writer output = new StringWriter()) {
        temp.process(staxTransformer.getMap(), output);
        return output.toString();
    }
}