Java Code Examples for org.thymeleaf.templateresolver.StringTemplateResolver

The following examples show how to use org.thymeleaf.templateresolver.StringTemplateResolver. These examples are extracted from open source projects. 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 Project: SkaETL   Source File: TemplateUtilsTest.java    License: Apache License 2.0 7 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 Project: SkaETL   Source File: TemplateUtilsTest.java    License: 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
/**
 * 使用 Thymeleaf 渲染 HTML
 * @param template  HTML模板
 * @param params 参数
 * @return  渲染后的HTML
 */
public static String render(String template,Map<String,Object> params){
    Context context = new Context();
    context.setVariables(params);
    TemplateEngine engine=new TemplateEngine();
    
    StringTemplateResolver  resolver = new StringTemplateResolver();
    engine.setTemplateResolver(resolver);
    return engine.process(template,context);
}
 
Example 4
Source Project: SkaETL   Source File: TemplateUtils.java    License: 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 5
Source Project: zhcet-web   Source File: TemplateConfig.java    License: 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;
}
 
Example 6
Source Project: EDDI   Source File: TemplateEngineModule.java    License: Apache License 2.0 5 votes vote down vote up
private TemplateEngine createTemplateEngine(TemplateMode templateMode) {
    TemplateEngine templateEngine = new TemplateEngine();
    StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setTemplateMode(templateMode);
    templateEngine.addTemplateResolver(templateResolver);

    return templateEngine;
}
 
Example 7
Source Project: spring-boot-doma2-sample   Source File: SendMailHelper.java    License: Apache License 2.0 4 votes vote down vote up
protected ITemplateResolver templateResolver() {
    val resolver = new StringTemplateResolver();
    resolver.setTemplateMode("TEXT");
    resolver.setCacheable(false); // 安全をとってキャッシュしない
    return resolver;
}
 
Example 8
Source Project: ogham   Source File: StringResolverAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public ITemplateResolver adapt(ResourceResolver resolver) {
	StringTemplateResolver templateResolver = new StringTemplateResolver();
	applyOptions(templateResolver);
	return templateResolver;
}