Search in sources :

Example 1 with TemplateProcessingParameters

use of org.thymeleaf.TemplateProcessingParameters in project thymeleaf-tests by thymeleaf.

the class SpringResourceResourceResolverSpring4Test method testGetResourceAsStream.

@Test
public void testGetResourceAsStream() throws Exception {
    final String templateLocation = "spring421/view/test.html";
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring421/view/applicationContext.xml");
    final SpringResourceResourceResolver resolver = (SpringResourceResourceResolver) context.getBean("springResourceResourceResolver");
    final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "test", new Context());
    final InputStream is = resolver.getResourceAsStream(parameters, "classpath:" + templateLocation);
    final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
    final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceResourceResolverSpring4Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
    Assert.assertEquals(expected, testResource);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Context(org.thymeleaf.context.Context) TemplateProcessingParameters(org.thymeleaf.TemplateProcessingParameters) Configuration(org.thymeleaf.Configuration) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 2 with TemplateProcessingParameters

use of org.thymeleaf.TemplateProcessingParameters in project thymeleaf-tests by thymeleaf.

the class TemplateParserTest method createOutput.

private String createOutput(final Document document) throws IOException {
    final TemplateProcessingParameters templateProcessingParameters = new TemplateProcessingParameters(this.configuration, "test", new Context());
    final TemplateResolution templateResolution = new TemplateResolution("test", "test", new ClassLoaderResourceResolver(), "UTF-8", "XHTML", new NonCacheableCacheEntryValidity());
    final Arguments arguments = new Arguments(new TemplateEngine(), templateProcessingParameters, templateResolution, new TemplateRepository(this.configuration), document);
    final StringWriter stringWriter = new StringWriter();
    final ITemplateWriter templateWriter = this.configuration.getTemplateModeHandler("XHTML").getTemplateWriter();
    templateWriter.write(arguments, stringWriter, document);
    return stringWriter.toString();
}
Also used : Context(org.thymeleaf.context.Context) TemplateEngine(org.thymeleaf.TemplateEngine) TemplateRepository(org.thymeleaf.TemplateRepository) TemplateProcessingParameters(org.thymeleaf.TemplateProcessingParameters) StringWriter(java.io.StringWriter) TemplateResolution(org.thymeleaf.templateresolver.TemplateResolution) Arguments(org.thymeleaf.Arguments) ITemplateWriter(org.thymeleaf.templatewriter.ITemplateWriter) ClassLoaderResourceResolver(org.thymeleaf.resourceresolver.ClassLoaderResourceResolver) NonCacheableCacheEntryValidity(org.thymeleaf.cache.NonCacheableCacheEntryValidity)

Example 3 with TemplateProcessingParameters

use of org.thymeleaf.TemplateProcessingParameters 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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Context(org.thymeleaf.context.Context) IResourceResolver(org.thymeleaf.resourceresolver.IResourceResolver) TemplateProcessingParameters(org.thymeleaf.TemplateProcessingParameters) Configuration(org.thymeleaf.Configuration) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TemplateResolution(org.thymeleaf.templateresolver.TemplateResolution) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with TemplateProcessingParameters

use of org.thymeleaf.TemplateProcessingParameters in project thymeleaf-tests by thymeleaf.

the class SpringResourceResourceResolverSpring3Test method testGetResourceAsStream.

@Test
public void testGetResourceAsStream() throws Exception {
    final String templateLocation = "spring321/view/test.html";
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring321/view/applicationContext.xml");
    final SpringResourceResourceResolver resolver = (SpringResourceResourceResolver) context.getBean("springResourceResourceResolver");
    final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "test", new Context());
    final InputStream is = resolver.getResourceAsStream(parameters, "classpath:" + templateLocation);
    final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
    final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceResourceResolverSpring3Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
    Assert.assertEquals(expected, testResource);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Context(org.thymeleaf.context.Context) TemplateProcessingParameters(org.thymeleaf.TemplateProcessingParameters) Configuration(org.thymeleaf.Configuration) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 5 with TemplateProcessingParameters

use of org.thymeleaf.TemplateProcessingParameters 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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Context(org.thymeleaf.context.Context) IResourceResolver(org.thymeleaf.resourceresolver.IResourceResolver) TemplateProcessingParameters(org.thymeleaf.TemplateProcessingParameters) Configuration(org.thymeleaf.Configuration) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TemplateResolution(org.thymeleaf.templateresolver.TemplateResolution) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

TemplateProcessingParameters (org.thymeleaf.TemplateProcessingParameters)5 Context (org.thymeleaf.context.Context)5 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 Configuration (org.thymeleaf.Configuration)4 TemplateResolution (org.thymeleaf.templateresolver.TemplateResolution)3 IResourceResolver (org.thymeleaf.resourceresolver.IResourceResolver)2 StringWriter (java.io.StringWriter)1 Arguments (org.thymeleaf.Arguments)1 TemplateEngine (org.thymeleaf.TemplateEngine)1 TemplateRepository (org.thymeleaf.TemplateRepository)1 NonCacheableCacheEntryValidity (org.thymeleaf.cache.NonCacheableCacheEntryValidity)1 ClassLoaderResourceResolver (org.thymeleaf.resourceresolver.ClassLoaderResourceResolver)1 ITemplateWriter (org.thymeleaf.templatewriter.ITemplateWriter)1