use of org.thymeleaf.templateresolver.TemplateResolution in project thymeleaf-tests by thymeleaf.
the class ParsingDecoupled01Test method testParsingDecoupled.
private static void testParsingDecoupled(final String decoupledTemplate, final TemplateMode templateMode, final String expectedResult) throws Exception {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("templateparser/markup/");
templateResolver.setSuffix(templateMode == TemplateMode.HTML ? ".html" : ".xml");
templateResolver.setTemplateMode(templateMode);
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
// We only to this in order to initialize the engine
templateEngine.process("parsingdecoupled", new Context());
final IEngineConfiguration configuration = templateEngine.getConfiguration();
final TemplateResolution templateResolution = templateResolver.resolveTemplate(configuration, null, decoupledTemplate, null);
final ITemplateResource templateResource = templateResolution.getTemplateResource();
final DecoupledTemplateLogic decoupledTemplateLogic = DecoupledTemplateLogicUtils.computeDecoupledTemplateLogic(configuration, null, decoupledTemplate, null, templateResource, templateMode, (templateMode == TemplateMode.HTML ? htmlParser : xmlParser));
Assert.assertEquals(expectedResult, decoupledTemplateLogic.toString());
}
use of org.thymeleaf.templateresolver.TemplateResolution 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.templateresolver.TemplateResolution 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.templateresolver.TemplateResolution 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