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

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

Introduction

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

Prototype

public void setFreemarkerSettings(Properties settings) 

Source Link

Document

Set properties that contain well-known FreeMarker keys which will be passed to FreeMarker's Configuration.setSettings method.

Usage

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);
    try {//from   w w w  . jav a  2  s  . c o m
        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);
            }// w ww  .j a v  a2s .  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()));
}

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  v  a2 s .c om*/
}