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

The following examples show how to use org.thymeleaf.templateresolver.ClassLoaderTemplateResolver#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: HttpResourceThymeleaf.java    From ext-opensource-netty with Mozilla Public License 2.0 6 votes vote down vote up
@Override
protected ByteBuf buildRes(String resPath, Map<String, Object> parameters) {
	if (!isThymeleafFile(resPath)) {
		
		return super.buildRes(resPath, parameters);
	} else {
		try {
			Context context = new Context();
			context.setVariables(parameters);

			if (!engine.isInitialized()) {
				ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
				resolver.setPrefix(this.getRootDir());
				//设置不缓存
				resolver.setCacheable(false);
				engine.setTemplateResolver(resolver);
			}

			String htmlContext = engine.process(resPath, context);
			return Unpooled.copiedBuffer(htmlContext, CharsetUtil.UTF_8);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return null;
	}
}
 
Example 2
Source File: SpringMailTestConfiguration.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
@Bean
  public SpringTemplateEngine templateEngine() {
  	SpringTemplateEngine mock = spy(SpringTemplateEngine.class);
  	
  	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setOrder(2);
templateResolver.setResolvablePatterns(Collections.singleton("html/*"));
templateResolver.setPrefix("/mail/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCharacterEncoding("UTF-8");
templateResolver.setCacheable(false);
  	mock.addTemplateResolver(templateResolver);
  	
  	final ClassLoaderTemplateResolver templateResolverTxt = new ClassLoaderTemplateResolver();
templateResolverTxt.setOrder(1);
templateResolverTxt.setResolvablePatterns(Collections.singleton("text/*"));
templateResolverTxt.setPrefix("/mail/");
templateResolverTxt.setSuffix(".txt");
templateResolverTxt.setTemplateMode(TemplateMode.TEXT);
templateResolverTxt.setCharacterEncoding("UTF-8");
templateResolverTxt.setCacheable(false);
mock.addTemplateResolver(templateResolverTxt);
  	
return mock;
  }
 
Example 3
Source File: GithubPullRequestReporter.java    From cover-checker with Apache License 2.0 5 votes vote down vote up
private void templateInit() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode(TemplateMode.TEXT);
    templateResolver.setPrefix("/templates/");
    templateResolver.setSuffix(".md");
    templateResolver.setCacheable(false);

    templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
}
 
Example 4
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver textTemplateResolver() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setOrder(1);
    templateResolver.setResolvablePatterns(Collections.singleton("text/*"));
    templateResolver.setPrefix(TEMPLATE_PREFIX);
    templateResolver.setSuffix(".txt");
    templateResolver.setTemplateMode(TemplateMode.TEXT);
    templateResolver.setCharacterEncoding(TEMPLATE_ENCODING);
    templateResolver.setCacheable(thymeleafProperties.isCache());
    return templateResolver;
}
 
Example 5
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver htmlTemplateResolver() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setOrder(2);
    templateResolver.setResolvablePatterns(Collections.singleton("html/*"));
    templateResolver.setPrefix(TEMPLATE_PREFIX);
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode(TemplateMode.HTML);
    templateResolver.setCharacterEncoding(TEMPLATE_ENCODING);
    templateResolver.setCacheable(thymeleafProperties.isCache());
    return templateResolver;
}
 
Example 6
Source File: TemplateConfig.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver jsTemplateResolver() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setOrder(3);
    templateResolver.setResolvablePatterns(Collections.singleton("js/*"));
    templateResolver.setPrefix(TEMPLATE_PREFIX);
    templateResolver.setSuffix(".js");
    templateResolver.setTemplateMode(TemplateMode.JAVASCRIPT);
    templateResolver.setCharacterEncoding(TEMPLATE_ENCODING);
    templateResolver.setCacheable(thymeleafProperties.isCache());
    return templateResolver;
}
 
Example 7
Source File: SpringMailConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver textTemplateResolver() {
	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
	templateResolver.setOrder(1);
	templateResolver.setResolvablePatterns(Collections.singleton("text/*"));
	templateResolver.setPrefix("/mail/");
	templateResolver.setSuffix(".txt");
	templateResolver.setTemplateMode(TemplateMode.TEXT);
	templateResolver.setCharacterEncoding("UTF-8");
	templateResolver.setCacheable(false);
	return templateResolver;
}
 
Example 8
Source File: SpringMailConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver htmlTemplateResolver() {
	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
	templateResolver.setOrder(2);
	templateResolver.setResolvablePatterns(Collections.singleton("html/*"));
	templateResolver.setPrefix("/mail/");
	templateResolver.setSuffix(".html");
	templateResolver.setTemplateMode(TemplateMode.HTML);
	templateResolver.setCharacterEncoding("UTF-8");
	templateResolver.setCacheable(false);
	return templateResolver;
}
 
Example 9
Source File: SpringMailConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private ITemplateResolver stringTemplateResolver() {
	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
	templateResolver.setOrder(3);
	templateResolver.setTemplateMode(TemplateMode.HTML5);
	templateResolver.setCacheable(false);
	return templateResolver;
}
 
Example 10
Source File: ShiroDialectTest.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
private static void setupThymeleaf() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setCacheable(false);
    templateResolver.setCharacterEncoding("UTF-8");
    templateResolver.setTemplateMode(TemplateMode.HTML);

    templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    templateEngine.addDialect("shiro", new ShiroDialect());

}
 
Example 11
Source File: AbstractThymeleafShiroDialectTest.java    From thymeleaf-extras-shiro with Apache License 2.0 5 votes vote down vote up
private static void setupThymeleaf() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setCacheable(false);
    templateResolver.setCharacterEncoding(Charsets.UTF_8.name());
    templateResolver.setTemplateMode(TemplateMode.HTML);

    templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    final ShiroDialect dialect = new ShiroDialect();
    templateEngine.addDialect(dialect.getPrefix(), dialect);

}