use of io.leopard.web.freemarker.template.TimeAgoTemplateMethod in project leopard by tanhaichao.
the class FreeMarkerUtil method listTemplateMethod.
public static Map<String, Object> listTemplateMethod(ListableBeanFactory applicationContext) {
Map<String, TemplateVariable> map = applicationContext.getBeansOfType(TemplateVariable.class);
Map<String, Object> freemarkerVariables = new HashMap<String, Object>();
for (Entry<String, TemplateVariable> entry : map.entrySet()) {
TemplateVariable variable = entry.getValue();
// System.err.println("key:" + method.getKey() + " method:" + method);
freemarkerVariables.put(variable.getKey(), variable);
}
freemarkerVariables.put("timeAgo", new TimeAgoTemplateMethod());
return freemarkerVariables;
}
use of io.leopard.web.freemarker.template.TimeAgoTemplateMethod in project leopard by tanhaichao.
the class FreeMarkerUtil method getFreeMarkerConfigurer.
protected static FreeMarkerConfigurer getFreeMarkerConfigurer(ApplicationContext applicationContext, String templateLoaderPath) {
Map<String, Object> freemarkerVariables = new HashMap<String, Object>();
freemarkerVariables.put("xml_escape", "fmXmlEscape");
freemarkerVariables.put("replaceParam", new ReplaceParamTemplateMethod());
freemarkerVariables.put("timeAgo", new TimeAgoTemplateMethod());
freemarkerVariables.putAll(listTemplateMethod(applicationContext));
Properties freemarkerSettings = new Properties();
freemarkerSettings.put("template_update_delay", "1");
freemarkerSettings.put("defaultEncoding", "UTF-8");
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPath(templateLoaderPath);
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;
}
Aggregations