|
|
|
|
@ -24,7 +24,12 @@ import freemarker.template.Configuration;
@@ -24,7 +24,12 @@ import freemarker.template.Configuration;
|
|
|
|
|
import freemarker.template.Template; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
|
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
|
|
|
|
import org.springframework.core.io.ByteArrayResource; |
|
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
|
import org.springframework.core.io.DefaultResourceLoader; |
|
|
|
|
import org.springframework.core.io.FileSystemResource; |
|
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
|
import org.springframework.core.io.ResourceLoader; |
|
|
|
|
@ -42,7 +47,7 @@ import static org.junit.Assert.*;
@@ -42,7 +47,7 @@ import static org.junit.Assert.*;
|
|
|
|
|
public class FreeMarkerConfigurerTests { |
|
|
|
|
|
|
|
|
|
@Test(expected = IOException.class) |
|
|
|
|
public void freemarkerConfigurationFactoryBeanWithConfigLocation() throws Exception { |
|
|
|
|
public void freeMarkerConfigurationFactoryBeanWithConfigLocation() throws Exception { |
|
|
|
|
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean(); |
|
|
|
|
fcfb.setConfigLocation(new FileSystemResource("myprops.properties")); |
|
|
|
|
Properties props = new Properties(); |
|
|
|
|
@ -62,14 +67,13 @@ public class FreeMarkerConfigurerTests {
@@ -62,14 +67,13 @@ public class FreeMarkerConfigurerTests {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@SuppressWarnings("rawtypes") |
|
|
|
|
public void freemarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception { |
|
|
|
|
public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception { |
|
|
|
|
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean(); |
|
|
|
|
fcfb.setTemplateLoaderPath("file:/mydir"); |
|
|
|
|
Properties settings = new Properties(); |
|
|
|
|
settings.setProperty("localized_lookup", "false"); |
|
|
|
|
fcfb.setFreemarkerSettings(settings); |
|
|
|
|
fcfb.setResourceLoader(new ResourceLoader() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Resource getResource(String location) { |
|
|
|
|
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) { |
|
|
|
|
@ -77,7 +81,6 @@ public class FreeMarkerConfigurerTests {
@@ -77,7 +81,6 @@ public class FreeMarkerConfigurerTests {
|
|
|
|
|
} |
|
|
|
|
return new ByteArrayResource("test".getBytes(), "test"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ClassLoader getClassLoader() { |
|
|
|
|
return getClass().getClassLoader(); |
|
|
|
|
@ -90,4 +93,16 @@ public class FreeMarkerConfigurerTests {
@@ -90,4 +93,16 @@ public class FreeMarkerConfigurerTests {
|
|
|
|
|
assertEquals("test", FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|