All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.leopard.web.freemarker.FreeMarkerUtil Maven / Gradle / Ivy

The newest version!
package io.leopard.web.freemarker;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import freemarker.template.TemplateException;

public class FreeMarkerUtil {

	// 
	// 

	// 
	// 
	// 
	// 
	// 

	// 
	// 
	// 1
	// UTF-8
	// 
	// 
	// 
	private static final FreeMarkerConfigurer configurer = getFreeMarkerConfigurer();

	protected static FreeMarkerConfigurer getFreeMarkerConfigurer() {
		Map freemarkerVariables = new HashMap();
		freemarkerVariables.put("xml_escape", "fmXmlEscape");
		freemarkerVariables.put("replaceParam", new ReplaceParamMethod());

		Properties freemarkerSettings = new Properties();
		freemarkerSettings.put("template_update_delay", "1");
		freemarkerSettings.put("defaultEncoding", "UTF-8");

		FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
		configurer.setTemplateLoaderPath("/WEB-INF/ftl/");
		configurer.setFreemarkerVariables(freemarkerVariables);
		configurer.setFreemarkerSettings(freemarkerSettings);

		try {
			configurer.afterPropertiesSet();
		}
		catch (IOException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
		catch (TemplateException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
		return configurer;
	}

	public static FreeMarkerConfig getFreeMarkerConfig() {
		return configurer;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy