Java Code Examples for org.thymeleaf.templateresolver.StringTemplateResolver#setCacheable()

The following examples show how to use org.thymeleaf.templateresolver.StringTemplateResolver#setCacheable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateUtilsTest.java    From SkaETL with Apache License 2.0 6 votes vote down vote up
@Test
public void astext() {

    StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setOrder(1);
    templateResolver.setTemplateMode(TemplateMode.TEXT);
    // TODO Cacheable or Not ?
    templateResolver.setCacheable(false);
    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context context = new Context();

    context.setVariable("mavar","cela");
    String process = templateEngine.process("ceci [[${mavar}]]", context);
    assertThat(process).isEqualTo("ceci cela");

    String notInterpreted = templateEngine.process("ceci <span th:text=\"${mavar}\"></span>", context);
    assertThat(notInterpreted).isEqualTo("ceci <span th:text=\"${mavar}\"></span>");
}
 
Example 2
Source File: TemplateUtilsTest.java    From SkaETL with Apache License 2.0 6 votes vote down vote up
@Test
public void ashtml() {

    StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setOrder(1);
    templateResolver.setTemplateMode(TemplateMode.HTML);
    // TODO Cacheable or Not ?
    templateResolver.setCacheable(false);
    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context context = new Context();

    context.setVariable("mavar","cela");
    String process = templateEngine.process("ceci [[${mavar}]]", context);
    assertThat(process).isEqualTo("ceci cela");

    String variant = templateEngine.process("ceci <span th:text=\"${mavar}\"></span>", context);
    assertThat(variant).isEqualTo("ceci <span>cela</span>");
}
 
Example 3
Source File: TemplateUtils.java    From SkaETL with Apache License 2.0 5 votes vote down vote up
private TemplateUtils() {
    StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setTemplateMode(TemplateMode.HTML);
    // TODO Cacheable or Not ?
    templateResolver.setCacheable(false);
    stringTemplateEngine = new TemplateEngine();
    stringTemplateEngine.addTemplateResolver(templateResolver);
}
 
Example 4
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver stringTemplateResolver() {
    final StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setOrder(4);
    // No resolvable pattern, will simply process as a String template everything not previously matched
    templateResolver.setTemplateMode(TemplateMode.HTML);
    templateResolver.setCacheable(thymeleafProperties.isCache());
    return templateResolver;
}