Search in sources :

Example 16 with ClassLoaderTemplateResolver

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();
}
Also used : ThymeleafReactiveViewResolver(org.thymeleaf.spring5.view.reactive.ThymeleafReactiveViewResolver) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) MediaType(org.springframework.http.MediaType) HashMap(java.util.HashMap) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) ModelMap(org.springframework.ui.ModelMap) Locale(java.util.Locale) Map(java.util.Map) SpringWebFluxTemplateEngine(org.thymeleaf.spring5.SpringWebFluxTemplateEngine) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) View(org.springframework.web.reactive.result.view.View) Collections(java.util.Collections) TestingServerWebExchange(org.thymeleaf.spring5.reactive.exchange.TestingServerWebExchange) SpringWebFluxTemplateEngine(org.thymeleaf.spring5.SpringWebFluxTemplateEngine) ModelMap(org.springframework.ui.ModelMap) View(org.springframework.web.reactive.result.view.View) ThymeleafReactiveViewResolver(org.thymeleaf.spring5.view.reactive.ThymeleafReactiveViewResolver) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TestingServerWebExchange(org.thymeleaf.spring5.reactive.exchange.TestingServerWebExchange) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 17 with ClassLoaderTemplateResolver

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));
}
Also used : Context(org.thymeleaf.context.Context) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateEngine(org.thymeleaf.TemplateEngine)

Example 18 with ClassLoaderTemplateResolver

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;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)

Example 19 with ClassLoaderTemplateResolver

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;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)

Example 20 with ClassLoaderTemplateResolver

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;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateEngine(org.thymeleaf.TemplateEngine) FileTemplateResolver(org.thymeleaf.templateresolver.FileTemplateResolver) UrlTemplateResolver(org.thymeleaf.templateresolver.UrlTemplateResolver) AbstractConfigurableTemplateResolver(org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver)

Aggregations

ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)50 Test (org.junit.Test)18 SpringTemplateEngine (org.thymeleaf.spring5.SpringTemplateEngine)17 ArrayList (java.util.ArrayList)13 TemplateEngine (org.thymeleaf.TemplateEngine)13 Context (org.thymeleaf.context.Context)12 ITemplateResolver (org.thymeleaf.templateresolver.ITemplateResolver)12 FileTemplateResolver (org.thymeleaf.templateresolver.FileTemplateResolver)8 DefaultTemplateResolver (org.thymeleaf.templateresolver.DefaultTemplateResolver)4 Bean (org.springframework.context.annotation.Bean)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 IExpressionContext (org.thymeleaf.context.IExpressionContext)2 StandardLinkBuilder (org.thymeleaf.linkbuilder.StandardLinkBuilder)2 SpringWebFluxTemplateEngine (org.thymeleaf.spring5.SpringWebFluxTemplateEngine)2 AbstractConfigurableTemplateResolver (org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver)2 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1