org.springframework.ui.freemarker.SpringTemplateLoader Java Examples

The following examples show how to use org.springframework.ui.freemarker.SpringTemplateLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FtlUtils.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public static TemplateLoader getTemplateLoaderForPath(ResourceLoader resourceLoader, String templateLoaderPath) {
	try {
		Resource path = resourceLoader.getResource(templateLoaderPath);
		File file = path.getFile();  // will fail if not resolvable in the file system
		if (logger.isDebugEnabled()) {
			logger.debug(
					"Template loader path [" + path + "] resolved to file path [" + file.getAbsolutePath() + "]");
		}
		return new FileTemplateLoader(file);
	}
	catch (IOException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("Cannot resolve template loader path [" + templateLoaderPath +
					"] to [java.io.File]: using SpringTemplateLoader as fallback", ex);
		}
		return new SpringTemplateLoader(resourceLoader, templateLoaderPath);
	}
	
}
 
Example #2
Source File: FreemarkerTemplateEngineFactory.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
    Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
    configuration.setDefaultEncoding("utf-8");
    configuration.setLogTemplateExceptions(true);
    configuration.setNumberFormat("computer");
    configuration.setOutputFormat(XHTMLOutputFormat.INSTANCE);
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setTemplateLoader(new SpringTemplateLoader(this.resourceLoader, this.resourceLoaderPath));

    if (this.shouldCheckForTemplateModifications) {
        configuration.setTemplateUpdateDelayMilliseconds(1000);
    } else {
        configuration.setTemplateUpdateDelayMilliseconds(Long.MAX_VALUE);
    }

    this.configuration = configuration;
}
 
Example #3
Source File: FreeMarkerConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
	FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
	fcfb.setTemplateLoaderPath("file:/mydir");
	fcfb.afterPropertiesSet();
	Configuration cfg = fcfb.getObject();
	assertTrue(cfg.getTemplateLoader() instanceof SpringTemplateLoader);
}
 
Example #4
Source File: FreeMarkerConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test  // SPR-12448
public void freeMarkerConfigurationAsBean() {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	RootBeanDefinition loaderDef = new RootBeanDefinition(SpringTemplateLoader.class);
	loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new DefaultResourceLoader());
	loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker");
	RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class);
	configDef.getPropertyValues().add("templateLoader", loaderDef);
	beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
	beanFactory.getBean(Configuration.class);
}
 
Example #5
Source File: FreeMarkerConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
	FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
	fcfb.setTemplateLoaderPath("file:/mydir");
	fcfb.afterPropertiesSet();
	Configuration cfg = fcfb.getObject();
	assertTrue(cfg.getTemplateLoader() instanceof SpringTemplateLoader);
}
 
Example #6
Source File: FreeMarkerConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test  // SPR-12448
public void freeMarkerConfigurationAsBean() {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	RootBeanDefinition loaderDef = new RootBeanDefinition(SpringTemplateLoader.class);
	loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new DefaultResourceLoader());
	loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker");
	RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class);
	configDef.getPropertyValues().add("templateLoader", loaderDef);
	beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
	beanFactory.getBean(Configuration.class);
}
 
Example #7
Source File: FreeMarkerConfigurerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void freeMarkerConfigurationFactoryBeanWithResourceLoaderPath() throws Exception {
	FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
	fcfb.setTemplateLoaderPath("file:/mydir");
	fcfb.afterPropertiesSet();
	Configuration cfg = fcfb.getObject();
	assertTrue(cfg.getTemplateLoader() instanceof SpringTemplateLoader);
}
 
Example #8
Source File: FreeMarkerConfigurerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test  // SPR-12448
public void freeMarkerConfigurationAsBean() {
	DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	RootBeanDefinition loaderDef = new RootBeanDefinition(SpringTemplateLoader.class);
	loaderDef.getConstructorArgumentValues().addGenericArgumentValue(new DefaultResourceLoader());
	loaderDef.getConstructorArgumentValues().addGenericArgumentValue("/freemarker");
	RootBeanDefinition configDef = new RootBeanDefinition(Configuration.class);
	configDef.getPropertyValues().add("templateLoader", loaderDef);
	beanFactory.registerBeanDefinition("freeMarkerConfig", configDef);
	beanFactory.getBean(Configuration.class);
}