use of org.thymeleaf.resourceresolver.IResourceResolver in project ratpack by ratpack.
the class ThymeleafModule method provideTemplateResolver.
@Provides
@Singleton
ITemplateResolver provideTemplateResolver(ServerConfig serverConfig, Config config) {
IResourceResolver resourceResolver = new FileSystemBindingThymeleafResourceResolver(serverConfig.getBaseDir());
TemplateResolver templateResolver = new TemplateResolver();
templateResolver.setResourceResolver(resourceResolver);
templateResolver.setTemplateMode(getTemplatesModeSetting(config));
templateResolver.setPrefix(getTemplatesPrefixSetting(config));
templateResolver.setSuffix(getTemplatesSuffixSetting(config));
templateResolver.setCacheable(getCacheSizeSetting(config) > 0);
// Never use TTL expiration
templateResolver.setCacheTTLMs(null);
return templateResolver;
}
use of org.thymeleaf.resourceresolver.IResourceResolver in project thymeleaf-tests by thymeleaf.
the class TestTemplateResolver method resolveTemplate.
public TemplateResolution resolveTemplate(final TemplateProcessingParameters templateProcessingParameters) {
final String templateName = templateProcessingParameters.getTemplateName();
final int placeholderPos = this.template.indexOf("{%%}");
final String result = this.template.substring(0, placeholderPos) + templateName + this.template.substring(placeholderPos + 4);
final IResourceResolver resourceResolver = new TestResourceResolver(result);
final TemplateResolution templateResolution = new TemplateResolution(templateName, "TEST", resourceResolver, "UTF-8", "HTML5", new NonCacheableCacheEntryValidity());
return templateResolution;
}
use of org.thymeleaf.resourceresolver.IResourceResolver in project thymeleaf-tests by thymeleaf.
the class SpringResourceTemplateResolverSpring3Test method testResolveTemplate.
@Test
public void testResolveTemplate() throws Exception {
final String templateLocation = "spring321/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring321/view/applicationContext.xml");
final SpringResourceTemplateResolver resolver = (SpringResourceTemplateResolver) context.getBean("springResourceTemplateResolver");
resolver.initialize();
final String templateMode = resolver.getTemplateMode();
Assert.assertEquals("HTML5", templateMode);
final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "classpath:" + templateLocation, new Context());
final TemplateResolution resolution = resolver.resolveTemplate(parameters);
final IResourceResolver resourceResolver = resolution.getResourceResolver();
final InputStream is = resourceResolver.getResourceAsStream(parameters, resolution.getResourceName());
final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceTemplateResolverSpring3Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
use of org.thymeleaf.resourceresolver.IResourceResolver in project thymeleaf-tests by thymeleaf.
the class SpringResourceTemplateResolverSpring4Test method testResolveTemplate.
@Test
public void testResolveTemplate() throws Exception {
final String templateLocation = "spring421/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring421/view/applicationContext.xml");
final SpringResourceTemplateResolver resolver = (SpringResourceTemplateResolver) context.getBean("springResourceTemplateResolver");
resolver.initialize();
final String templateMode = resolver.getTemplateMode();
Assert.assertEquals("HTML5", templateMode);
final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "classpath:" + templateLocation, new Context());
final TemplateResolution resolution = resolver.resolveTemplate(parameters);
final IResourceResolver resourceResolver = resolution.getResourceResolver();
final InputStream is = resourceResolver.getResourceAsStream(parameters, resolution.getResourceName());
final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceTemplateResolverSpring4Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
Aggregations