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

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

Introduction

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

Prototype

@Override
    public void afterPropertiesSet() throws IOException, TemplateException 

Source Link

Usage

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();
    Configuration cfg = (Configuration) fcfb.getObject();
    assertTrue(cfg.getTemplateLoader() instanceof SpringTemplateLoader);
}

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);// w  w w.j av  a  2s .c  om
    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 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   ww  w .j  a v a  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()));
}