use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.
the class ThymeleafReactiveViewTest method testSeveralConversionServices.
@Test
public void testSeveralConversionServices() throws Exception {
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring5/view/applicationContextConversionService.xml");
final SpringWebFluxTemplateEngine templateEngine = new SpringWebFluxTemplateEngine();
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("spring5/view/");
templateResolver.setSuffix(".html");
templateEngine.setTemplateResolver(templateResolver);
final ThymeleafReactiveViewResolver resolver = new ThymeleafReactiveViewResolver();
resolver.setApplicationContext(context);
resolver.setTemplateEngine(templateEngine);
resolver.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML));
// testview2 does not exist as a declared bean at the application context
final Mono<View> view = resolver.resolveViewName("testSeveralConversionServices", Locale.US);
final Map<String, Object> model = new ModelMap();
model.put("one", "one");
final TestingServerWebExchange exchange = new TestingServerWebExchange("/testing", new HashMap<>(), new HashMap<>(), new HashMap<>());
view.flatMap(v -> v.render(model, MediaType.TEXT_HTML, exchange)).block();
}
use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project jlineup by otto-de.
the class HTMLReportWriter method renderReport.
String renderReport(String template, List<ScreenshotComparisonResult> screenshotComparisonResults) throws FileNotFoundException {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode("HTML");
templateResolver.setPrefix("templates/");
templateResolver.setSuffix(".html");
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
final Map<String, Object> variables = prepareVariablesForReportTemplate(screenshotComparisonResults);
return templateEngine.process(template, new Context(Locale.US, variables));
}
use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project zhcet-web by zhcet-amu.
the class TemplateConfig method htmlTemplateResolver.
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;
}
use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project DisCal-Discord-Bot by NovaFox161.
the class ThymeleafTemplateEngine method createDefaultTemplateResolver.
private static ITemplateResolver createDefaultTemplateResolver(String prefix, String suffix) {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setPrefix(prefix != null ? prefix : DEFAULT_PREFIX);
templateResolver.setSuffix(suffix != null ? suffix : DEFAULT_SUFFIX);
templateResolver.setCacheTTLMs(DEFAULT_CACHE_TTL_MS);
return templateResolver;
}
use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project docx4j-template by vindell.
the class WordprocessingMLThymeleafTemplate method getInternalEngine.
protected TemplateEngine getInternalEngine() throws IOException {
// 初始化模板解析器
AbstractConfigurableTemplateResolver templateResolver = getTemplateResolver();
if (getTemplateResolver() == null) {
String resolver = Docx4jProperties.getProperty("docx4j.thymeleaf.templateResolver", "org.thymeleaf.templateresolver.FileTemplateResolver");
if ("org.thymeleaf.templateresolver.FileTemplateResolver".equalsIgnoreCase(resolver)) {
templateResolver = new FileTemplateResolver();
} else if ("org.thymeleaf.templateresolver.ClassLoaderTemplateResolver".equalsIgnoreCase(resolver)) {
templateResolver = new ClassLoaderTemplateResolver();
} else if ("org.thymeleaf.templateresolver.UrlTemplateResolver".equalsIgnoreCase(resolver)) {
templateResolver = new UrlTemplateResolver();
} else {
templateResolver = new FileTemplateResolver();
}
}
templateResolver.setCacheable(Docx4jProperties.getProperty("docx4j.thymeleaf.cacheable", true));
templateResolver.setCacheablePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.cacheablePatterns", ""))));
String cacheTTLMs = Docx4jProperties.getProperty("docx4j.thymeleaf.cacheTTLMs");
templateResolver.setCacheTTLMs(cacheTTLMs == null ? null : Long.valueOf(cacheTTLMs));
templateResolver.setCharacterEncoding(Docx4jProperties.getProperty("docx4j.thymeleaf.charset", "UTF-8"));
templateResolver.setCheckExistence(Docx4jProperties.getProperty("docx4j.thymeleaf.checkExistence", false));
templateResolver.setCSSTemplateModePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.newCSSTemplateModePatterns", ""))));
templateResolver.setHtmlTemplateModePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.newHtmlTemplateModePatterns", ""))));
templateResolver.setJavaScriptTemplateModePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.newJavaScriptTemplateModePatterns", ""))));
templateResolver.setName(Docx4jProperties.getProperty("docx4j.thymeleaf.name", templateResolver.getClass().getName()));
templateResolver.setNonCacheablePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.nonCacheablePatterns", ""))));
templateResolver.setOrder(Integer.valueOf(Docx4jProperties.getProperty("docx4j.thymeleaf.order", "1")));
templateResolver.setPrefix(Docx4jProperties.getProperty("docx4j.thymeleaf.prefix"));
templateResolver.setRawTemplateModePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.newRawTemplateModePatterns", ""))));
templateResolver.setResolvablePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.resolvablePatterns", ""))));
templateResolver.setSuffix(Docx4jProperties.getProperty("docx4j.thymeleaf.suffix", ".tpl"));
// templateResolver.setTemplateAliases(templateAliases);
templateResolver.setTemplateMode(Docx4jProperties.getProperty("docx4j.thymeleaf.templateMode", "XHTML"));
templateResolver.setTextTemplateModePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.newTextTemplateModePatterns", ""))));
templateResolver.setUseDecoupledLogic(Docx4jProperties.getProperty("docx4j.thymeleaf.useDecoupledLogic", false));
templateResolver.setXmlTemplateModePatterns(ArrayUtils.asSet(StringUtils.tokenizeToStringArray(Docx4jProperties.getProperty("docx4j.thymeleaf.newXmlTemplateModePatterns", ""))));
// 初始化引擎对象
TemplateEngine engine = new TemplateEngine();
engine.setTemplateResolver(templateResolver);
// 调用getConfiguration初始化引擎
engine.getConfiguration();
return engine;
}
Aggregations