use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project shijie by tengxing.
the class FreemarkerConfig method freeMarkerConfigurer.
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPath("classpath:/templates");
Properties settings = new Properties();
settings.setProperty("default_encoding", "utf-8");
settings.setProperty("number_format", "0.##");
configurer.setFreemarkerSettings(settings);
return configurer;
}
use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project PublicCMS-preview by sanluan.
the class ApplicationConfig method freeMarkerConfigurer.
/**
* FreeMarker配置工厂
*
* @return freemarker configuration factory
* @throws IOException
*/
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException {
FreeMarkerConfigurer bean = new FreeMarkerConfigurer();
bean.setTemplateLoaderPath("classpath:/templates/");
Properties properties = PropertiesLoaderUtils.loadAllProperties(env.getProperty("cms.freemarker.configFilePath"));
bean.setFreemarkerSettings(properties);
return bean;
}
use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project molgenis by molgenis.
the class MolgenisWebAppConfig method freeMarkerConfigurer.
/**
* Configure freemarker. All freemarker templates should be on the classpath in a package called 'freemarker'
*/
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() {
FreeMarkerConfigurer result = new FreeMarkerConfigurer() {
@Override
protected void postProcessConfiguration(Configuration config) throws IOException, TemplateException {
config.setObjectWrapper(new MolgenisFreemarkerObjectWrapper(VERSION_2_3_23));
}
};
result.setPreferFileSystemAccess(false);
result.setTemplateLoaderPath("classpath:/templates/");
result.setDefaultEncoding("UTF-8");
Properties freemarkerSettings = new Properties();
freemarkerSettings.setProperty(Configuration.LOCALIZED_LOOKUP_KEY, Boolean.FALSE.toString());
result.setFreemarkerSettings(freemarkerSettings);
Map<String, Object> freemarkerVariables = Maps.newHashMap();
freemarkerVariables.put("limit", new LimitMethod());
freemarkerVariables.put("hasPermission", new HasPermissionDirective(permissionService));
freemarkerVariables.put("notHasPermission", new NotHasPermissionDirective(permissionService));
addFreemarkerVariables(freemarkerVariables);
result.setFreemarkerVariables(freemarkerVariables);
return result;
}
use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project spring-boot by spring-projects.
the class FreeMarkerAutoConfigurationTests method renderTemplate.
@Test
public void renderTemplate() throws Exception {
registerAndRefreshContext();
FreeMarkerConfigurer freemarker = this.context.getBean(FreeMarkerConfigurer.class);
StringWriter writer = new StringWriter();
freemarker.getConfiguration().getTemplate("message.ftl").process(this, writer);
assertThat(writer.toString()).contains("Hello World");
}
use of org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer in project molgenis by molgenis.
the class WebAppConfig method freeMarkerConfigurer.
/**
* Configures Freemarker
*/
@Override
public FreeMarkerConfigurer freeMarkerConfigurer() {
FreeMarkerConfigurer result = super.freeMarkerConfigurer();
// Look up unknown templates in the FreemarkerTemplate repository
result.setPostTemplateLoaders(new RepositoryTemplateLoader(dataService));
return result;
}
Aggregations