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

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

Introduction

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

Prototype

public void setTemplateLoaderPath(String templateLoaderPath) 

Source Link

Document

Set the Freemarker template loader path via a Spring resource location.

Usage

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

@Bean
public FreeMarkerConfigurationFactoryBean getFreeMarkerConfiguration() {
    FreeMarkerConfigurationFactoryBean bean = new FreeMarkerConfigurationFactoryBean();
    bean.setTemplateLoaderPath("/WEB-INF/freemarker/");
    return bean;//from ww w  .j ava2s . c  o  m
}

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: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  . j a  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);
            }//from   w  ww  .j  a va  2  s.c  o  m
            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()));
}