Example usage for org.springframework.ui.freemarker FreeMarkerConfigurationFactoryBean FreeMarkerConfigurationFactoryBean

List of usage examples for org.springframework.ui.freemarker FreeMarkerConfigurationFactoryBean FreeMarkerConfigurationFactoryBean

Introduction

In this page you can find the example usage for org.springframework.ui.freemarker FreeMarkerConfigurationFactoryBean FreeMarkerConfigurationFactoryBean.

Prototype

FreeMarkerConfigurationFactoryBean

Source Link

Usage

From source file:nl.surfnet.coin.selfservice.service.impl.EmailServiceImplTest.java

@Before
public void setUp() throws Exception {
    emailService = new EmailServiceImpl();
    FreeMarkerConfigurationFactoryBean freemarkerFactory = new FreeMarkerConfigurationFactoryBean();
    freemarkerFactory.setTemplateLoaderPath("classpath:/ftl/");
    freemarkerConfiguration = freemarkerFactory.createConfiguration();
    emailService.setFreemarkerConfiguration(freemarkerConfiguration);

    MockitoAnnotations.initMocks(this);
}

From source file:com.sisrni.config.FreeMarkerConfig.java

@Bean
public FreeMarkerConfigurationFactoryBean getFreeMarkerConfiguration() {
    FreeMarkerConfigurationFactoryBean bean = new FreeMarkerConfigurationFactoryBean();
    bean.setTemplateLoaderPath("/WEB-INF/freemarker/");
    return bean;//from w w  w .ja  v  a  2 s  . co  m
}

From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerConfigurerTests.java

public void testFreemarkerConfigurationFactoryBeanWithConfigLocation() throws TemplateException {
    FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
    fcfb.setConfigLocation(new FileSystemResource("myprops.properties"));
    Properties props = new Properties();
    props.setProperty("myprop", "/mydir");
    fcfb.setFreemarkerSettings(props);//www . j a v a2 s. com
    try {
        fcfb.afterPropertiesSet();
        fail("Should have thrown IOException");
    } catch (IOException ex) {
        // expected
    }
}

From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerConfigurerTests.java

public void testFreeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
    FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
    fcfb.setTemplateLoaderPath("file:/mydir");
    fcfb.afterPropertiesSet();//from  w  w  w  .ja  v  a  2 s.co m
    Configuration cfg = (Configuration) fcfb.getObject();
    assertTrue(cfg.getTemplateLoader() instanceof SpringTemplateLoader);
}

From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerConfigurerTests.java

public void testFreemarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath()
        throws IOException, TemplateException {
    FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
    fcfb.setTemplateLoaderPath("file:/mydir");
    Properties settings = new Properties();
    settings.setProperty("localized_lookup", "false");
    fcfb.setFreemarkerSettings(settings);
    fcfb.setResourceLoader(new ResourceLoader() {
        public Resource getResource(String location) {
            if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
                throw new IllegalArgumentException(location);
            }//  w  w  w  .j  av a2 s .  c  om
            return new ByteArrayResource("test".getBytes(), "test");
        }

        public ClassLoader getClassLoader() {
            return getClass().getClassLoader();
        }
    });
    fcfb.afterPropertiesSet();
    assertTrue(fcfb.getObject() instanceof Configuration);
    Configuration fc = (Configuration) fcfb.getObject();
    Template ft = fc.getTemplate("test");
    assertEquals("test", FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap()));
}

From source file:br.eti.danielcamargo.backend.common.config.context.CoreConfig.java

@Bean
public FreeMarkerConfigurationFactoryBean freemarkerMailConfiguration() throws PropertyVetoException {

    FreeMarkerConfigurationFactoryBean bean = new FreeMarkerConfigurationFactoryBean();
    bean.setTemplateLoaderPaths("classpath:/");
    bean.setDefaultEncoding("UTF-8");

    Properties properties = new Properties();
    properties.put("locale", "pt_BR");
    bean.setFreemarkerSettings(properties);

    return bean;/* w  w w .j a va 2  s .  c o  m*/
}

From source file:com.teradata.benchto.driver.DriverApp.java

@Bean
public FreeMarkerConfigurationFactoryBean freemarkerConfiguration() throws IOException, TemplateException {
    FreeMarkerConfigurationFactoryBean factory = new FreeMarkerConfigurationFactoryBean();
    factory.setDefaultEncoding("UTF-8");
    return factory;
}