Search in sources :

Example 31 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project gs-spring-security-3.2 by rwinch.

the class WebMvcConfiguration method templateResolver.

@Bean
public ClassLoaderTemplateResolver templateResolver() {
    ClassLoaderTemplateResolver result = new ClassLoaderTemplateResolver();
    result.setPrefix("views/");
    result.setSuffix(".html");
    result.setTemplateMode("HTML5");
    return result;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) Bean(org.springframework.context.annotation.Bean)

Example 32 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver 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());
}
Also used : Context(org.thymeleaf.context.Context) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateEngine(org.thymeleaf.TemplateEngine) IEngineConfiguration(org.thymeleaf.IEngineConfiguration) DecoupledTemplateLogic(org.thymeleaf.templateparser.markup.decoupled.DecoupledTemplateLogic) TemplateResolution(org.thymeleaf.templateresolver.TemplateResolution) ITemplateResource(org.thymeleaf.templateresource.ITemplateResource)

Example 33 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.

the class OfflineTest method testOffline01.

@Test
public void testOffline01() throws Exception {
    final Context ctx = new Context();
    ctx.setVariable("one", "This is one");
    final TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver());
    final String result = templateEngine.process("offline/offline01.html", ctx);
    final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(OfflineTest.class).getResourceAsStream("offline/offlinespring01-result.html"), "UTF-8", true);
    Assert.assertEquals(expected, ResourceUtils.normalize(result));
}
Also used : Context(org.thymeleaf.context.Context) SpringTemplateEngine(org.thymeleaf.spring5.SpringTemplateEngine) TemplateEngine(org.thymeleaf.TemplateEngine) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) Test(org.junit.Test)

Example 34 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.

the class OfflineTest method testOfflineSpring01.

@Test
public void testOfflineSpring01() throws Exception {
    final Context ctx = new Context();
    ctx.setVariable("one", "This is one");
    final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver());
    final String result = templateEngine.process("offline/offlinespring01.html", ctx);
    final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(OfflineTest.class).getResourceAsStream("offline/offlinespring01-result.html"), "UTF-8", true);
    Assert.assertEquals(expected, ResourceUtils.normalize(result));
}
Also used : Context(org.thymeleaf.context.Context) SpringTemplateEngine(org.thymeleaf.spring5.SpringTemplateEngine) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) Test(org.junit.Test)

Example 35 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.

the class Parsing03Test method testParsing.

@Test
public void testParsing() throws Exception {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode("HTML5");
    templateResolver.setCharacterEncoding("UTF-16");
    final TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    final String result = templateEngine.process("parsing/parsingtest03.bulk", new Context());
    final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(Parsing03Test.class).getResourceAsStream("parsing/parsingtest03-result.bulk"), "ISO-8859-1", true);
    Assert.assertEquals(expected, ResourceUtils.normalize(result));
}
Also used : Context(org.thymeleaf.context.Context) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateEngine(org.thymeleaf.TemplateEngine) Test(org.junit.Test)

Aggregations

ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)50 Test (org.junit.Test)18 SpringTemplateEngine (org.thymeleaf.spring5.SpringTemplateEngine)17 ArrayList (java.util.ArrayList)13 TemplateEngine (org.thymeleaf.TemplateEngine)13 Context (org.thymeleaf.context.Context)12 ITemplateResolver (org.thymeleaf.templateresolver.ITemplateResolver)12 FileTemplateResolver (org.thymeleaf.templateresolver.FileTemplateResolver)8 DefaultTemplateResolver (org.thymeleaf.templateresolver.DefaultTemplateResolver)4 Bean (org.springframework.context.annotation.Bean)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 IExpressionContext (org.thymeleaf.context.IExpressionContext)2 StandardLinkBuilder (org.thymeleaf.linkbuilder.StandardLinkBuilder)2 SpringWebFluxTemplateEngine (org.thymeleaf.spring5.SpringWebFluxTemplateEngine)2 AbstractConfigurableTemplateResolver (org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver)2 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1