Search in sources :

Example 6 with FreeMarkerConfigurer

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;
}
Also used : Properties(java.util.Properties) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) Bean(org.springframework.context.annotation.Bean)

Example 7 with FreeMarkerConfigurer

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;
}
Also used : Properties(java.util.Properties) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) FactoryBean(org.springframework.beans.factory.FactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with FreeMarkerConfigurer

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;
}
Also used : HasPermissionDirective(org.molgenis.security.freemarker.HasPermissionDirective) NotHasPermissionDirective(org.molgenis.security.freemarker.NotHasPermissionDirective) Configuration(freemarker.template.Configuration) NotHasPermissionDirective(org.molgenis.security.freemarker.NotHasPermissionDirective) Properties(java.util.Properties) LimitMethod(org.molgenis.core.ui.freemarker.LimitMethod) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) MolgenisFreemarkerObjectWrapper(org.molgenis.core.ui.freemarker.MolgenisFreemarkerObjectWrapper) Bean(org.springframework.context.annotation.Bean)

Example 9 with FreeMarkerConfigurer

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");
}
Also used : StringWriter(java.io.StringWriter) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) Test(org.junit.Test)

Example 10 with FreeMarkerConfigurer

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;
}
Also used : RepositoryTemplateLoader(org.molgenis.core.ui.freemarker.RepositoryTemplateLoader) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer)

Aggregations

FreeMarkerConfigurer (org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer)18 Bean (org.springframework.context.annotation.Bean)13 Properties (java.util.Properties)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Iso8601DateDirective (org.ambraproject.wombat.freemarker.Iso8601DateDirective)3 ReplaceParametersDirective (org.ambraproject.wombat.freemarker.ReplaceParametersDirective)3 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 SiteTemplateLoader (org.ambraproject.wombat.config.site.SiteTemplateLoader)2 AbbreviatedNameDirective (org.ambraproject.wombat.freemarker.AbbreviatedNameDirective)2 CssLinkDirective (org.ambraproject.wombat.freemarker.asset.CssLinkDirective)2 JsDirective (org.ambraproject.wombat.freemarker.asset.JsDirective)2 RenderJsDirective (org.ambraproject.wombat.freemarker.asset.RenderJsDirective)2 Test (org.junit.jupiter.api.Test)2 FileTemplateLoader (freemarker.cache.FileTemplateLoader)1 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 TemplateLoader (freemarker.cache.TemplateLoader)1 BeansWrapper (freemarker.ext.beans.BeansWrapper)1 Configuration (freemarker.template.Configuration)1 TemplateException (freemarker.template.TemplateException)1