use of org.thymeleaf.spring6.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testTemplateResolverConfiguration06.
@Test
public void testTemplateResolverConfiguration06() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver());
templateEngine.addTemplateResolver(new FileTemplateResolver());
templateEngine.initialize();
final List<ITemplateResolver> templateResolvers = new ArrayList<ITemplateResolver>(templateEngine.getTemplateResolvers());
Assert.assertEquals(2, templateResolvers.size());
Assert.assertEquals("org.thymeleaf.templateresolver.ClassLoaderTemplateResolver", templateResolvers.get(0).getName());
Assert.assertEquals("org.thymeleaf.templateresolver.FileTemplateResolver", templateResolvers.get(1).getName());
}
use of org.thymeleaf.spring6.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testDefaultTemplateResolver04.
@Test
public void testDefaultTemplateResolver04() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
final Context context = new Context();
context.setLocale(Locale.ENGLISH);
context.setVariable("one", "this value");
final ClassLoaderTemplateResolver classLoaderTemplateResolver = new ClassLoaderTemplateResolver();
classLoaderTemplateResolver.setCheckExistence(true);
templateEngine.addTemplateResolver(classLoaderTemplateResolver);
final DefaultTemplateResolver defaultTemplateResolver = new DefaultTemplateResolver();
defaultTemplateResolver.setTemplate("<p th:text=\"${one}\">something</p>");
templateEngine.addTemplateResolver(defaultTemplateResolver);
templateEngine.initialize();
final List<ITemplateResolver> templateResolvers = new ArrayList<ITemplateResolver>(templateEngine.getTemplateResolvers());
Assert.assertEquals(2, templateResolvers.size());
Assert.assertEquals("org.thymeleaf.templateresolver.ClassLoaderTemplateResolver", templateResolvers.get(0).getName());
Assert.assertEquals("org.thymeleaf.templateresolver.DefaultTemplateResolver", templateResolvers.get(1).getName());
Assert.assertEquals("<p>this value</p>", templateEngine.process("nonexisting", context));
}
use of org.thymeleaf.spring6.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class SpringResourceTemplateResolverSpring4Test method testResolveTemplate.
@Test
public void testResolveTemplate() throws Exception {
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
final IEngineConfiguration configuration = templateEngine.getConfiguration();
final String templateLocation = "spring5/templateresolver/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring5/templateresolver/applicationContext.xml");
final SpringResourceTemplateResolver resolver = (SpringResourceTemplateResolver) context.getBean("springResourceTemplateResolver");
final TemplateMode templateMode = resolver.getTemplateMode();
Assert.assertEquals(TemplateMode.HTML, templateMode);
final TemplateResolution resolution = resolver.resolveTemplate(configuration, null, "classpath:" + templateLocation, null);
final ITemplateResource templateResource = resolution.getTemplateResource();
final String templateResourceStr = IOUtils.toString(templateResource.reader());
final String testResource = templateResourceStr.replace("\r", "");
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceTemplateResolverSpring4Test.class).getResourceAsStream(templateLocation), "US-ASCII", true).replace("\r", "");
Assert.assertEquals(expected, testResource);
}
use of org.thymeleaf.spring6.SpringTemplateEngine in project cas by apereo.
the class CasThemesConfiguration method nonCachingThymeleafViewResolver.
private ThymeleafViewResolver nonCachingThymeleafViewResolver() {
final ThymeleafViewResolver r = new ThymeleafViewResolver();
r.setAlwaysProcessRedirectAndForward(this.thymeleafViewResolver.getAlwaysProcessRedirectAndForward());
r.setApplicationContext(this.thymeleafViewResolver.getApplicationContext());
r.setCacheUnresolved(this.thymeleafViewResolver.isCacheUnresolved());
r.setCharacterEncoding(this.thymeleafViewResolver.getCharacterEncoding());
r.setContentType(this.thymeleafViewResolver.getContentType());
r.setExcludedViewNames(this.thymeleafViewResolver.getExcludedViewNames());
r.setOrder(this.thymeleafViewResolver.getOrder());
r.setRedirectContextRelative(this.thymeleafViewResolver.isRedirectContextRelative());
r.setRedirectHttp10Compatible(this.thymeleafViewResolver.isRedirectHttp10Compatible());
r.setStaticVariables(this.thymeleafViewResolver.getStaticVariables());
r.setForceContentType(this.thymeleafViewResolver.getForceContentType());
final SpringTemplateEngine engine = SpringTemplateEngine.class.cast(this.thymeleafViewResolver.getTemplateEngine());
engine.addDialect(new IPostProcessorDialect() {
@Override
public int getDialectPostProcessorPrecedence() {
return Integer.MAX_VALUE;
}
@Override
public Set<IPostProcessor> getPostProcessors() {
return CollectionUtils.wrapSet(new PostProcessor(TemplateMode.parse(thymeleafProperties.getMode()), CasThymeleafOutputTemplateHandler.class, Integer.MAX_VALUE));
}
@Override
public String getName() {
return CasThymeleafOutputTemplateHandler.class.getSimpleName();
}
});
r.setTemplateEngine(engine);
r.setViewNames(this.thymeleafViewResolver.getViewNames());
// disable the cache
r.setCache(false);
// return this ViewResolver
return r;
}
use of org.thymeleaf.spring6.SpringTemplateEngine in project yqq by yeycfri.
the class WebConfig method templateEngine.
@Bean
public TemplateEngine templateEngine(TemplateResolver templateResolver) {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
return templateEngine;
}
Aggregations