All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.hutool.extra.template.engine.rythm.RythmEngine Maven / Gradle / Ivy

There is a newer version: 5.8.33
Show newest version
package cn.hutool.extra.template.engine.rythm;

import cn.hutool.extra.template.Template;
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;

import java.util.Properties;

/**
 * Rythm模板引擎
* 文档:http://rythmengine.org/doc/index * * @author looly * */ public class RythmEngine implements TemplateEngine { org.rythmengine.RythmEngine engine; // --------------------------------------------------------------------------------- Constructor start /** * 默认构造 */ public RythmEngine() {} /** * 构造 * * @param config 模板配置 */ public RythmEngine(TemplateConfig config) { init(config); } /** * 构造 * * @param engine {@link org.rythmengine.RythmEngine} */ public RythmEngine(org.rythmengine.RythmEngine engine) { init(engine); } // --------------------------------------------------------------------------------- Constructor end @Override public TemplateEngine init(TemplateConfig config) { if(null == config){ config = TemplateConfig.DEFAULT; } init(createEngine(config)); return this; } /** * 获取原始引擎的钩子方法,用于自定义特殊属性,如插件等 * * @return {@link org.rythmengine.RythmEngine} * @since 5.8.7 */ public org.rythmengine.RythmEngine getRawEngine() { return this.engine; } /** * 初始化引擎 * @param engine 引擎 */ private void init(org.rythmengine.RythmEngine engine){ this.engine = engine; } @Override public Template getTemplate(String resource) { if(null == this.engine){ init(TemplateConfig.DEFAULT); } return RythmTemplate.wrap(this.engine.getTemplate(resource)); } /** * 创建引擎 * * @param config 模板配置 * @return {@link org.rythmengine.RythmEngine} */ private static org.rythmengine.RythmEngine createEngine(TemplateConfig config) { if (null == config) { config = new TemplateConfig(); } final Properties props = new Properties(); final String path = config.getPath(); if (null != path) { props.put("home.template", path); } return new org.rythmengine.RythmEngine(props); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy