use of org.thymeleaf.templateresolver.StringTemplateResolver in project thymeleaf-tests by thymeleaf.
the class LinkBuilderTest method testLinkBuilder01.
@Test
public void testLinkBuilder01() throws Exception {
final Context ctx = new Context();
ctx.setVariable("one", "This is one");
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(new StringTemplateResolver());
templateEngine.setLinkBuilder(new TestLinkBuilder());
final String result = templateEngine.process("<a th:href='@{/something}'>", ctx);
final String expected = "<a href='[/fromthebuilder/something]'>";
Assert.assertEquals(expected, result);
}
use of org.thymeleaf.templateresolver.StringTemplateResolver in project thymeleaf-tests by thymeleaf.
the class LinkBuilderTest method testLinkBuilderSpringWithECFactory01.
@Test
public void testLinkBuilderSpringWithECFactory01() throws Exception {
final Context ctx = new Context();
ctx.setVariable("one", "This is one");
final TemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(new StringTemplateResolver());
templateEngine.setLinkBuilder(new TestLinkBuilder());
templateEngine.setEngineContextFactory(new TestEngineContextFactory());
final String result = templateEngine.process("<a th:href='@{/something}'>", ctx);
final String expected = "<a href='[ENGINE: /fromthebuilder/something]'>";
Assert.assertEquals(expected, result);
}
use of org.thymeleaf.templateresolver.StringTemplateResolver in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testDefaultTemplateResolver05.
@Test
public void testDefaultTemplateResolver05() {
final TemplateEngine templateEngine = new TemplateEngine();
final Context context = new Context();
context.setLocale(Locale.ENGLISH);
context.setVariable("one", "this value");
final StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();
stringTemplateResolver.setResolvablePatterns(Collections.singleton("<div*"));
templateEngine.addTemplateResolver(stringTemplateResolver);
final DefaultTemplateResolver defaultTemplateResolver = new DefaultTemplateResolver();
defaultTemplateResolver.setTemplate("<p>inserted!</p>");
templateEngine.addTemplateResolver(defaultTemplateResolver);
templateEngine.initialize();
Assert.assertEquals("<div>some text <p><p>inserted!</p></p> other text</div>", templateEngine.process("<div>some text <p th:insert=\"nonexisting\">...</p> other text</div>", context));
}
use of org.thymeleaf.templateresolver.StringTemplateResolver in project ArachneCentralAPI by OHDSI.
the class ThymeleafConfig method getStringTemplateResolver.
private StringTemplateResolver getStringTemplateResolver() {
final StringTemplateResolver templateResolver = new StringTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(false);
return templateResolver;
}
use of org.thymeleaf.templateresolver.StringTemplateResolver in project ArachneCentralAPI by OHDSI.
the class ThymeleafConfig method postConstruct.
@PostConstruct
private void postConstruct() {
Set<ITemplateResolver> resolverSet = new LinkedHashSet<>();
// At first, try to load template from resources by given name
defaultTemplateResolver.setOrder(0);
resolverSet.add(defaultTemplateResolver);
// If there was founf no such template, use the string as template by itself
StringTemplateResolver stringTemplateResolver = getStringTemplateResolver();
stringTemplateResolver.setOrder(1);
resolverSet.add(stringTemplateResolver);
templateEngine.setTemplateResolvers(resolverSet);
}
Aggregations