Search in sources :

Example 1 with UrlTemplateResolver

use of org.thymeleaf.templateresolver.UrlTemplateResolver 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

TemplateEngine (org.thymeleaf.TemplateEngine)1 AbstractConfigurableTemplateResolver (org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver)1 ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)1 FileTemplateResolver (org.thymeleaf.templateresolver.FileTemplateResolver)1 UrlTemplateResolver (org.thymeleaf.templateresolver.UrlTemplateResolver)1