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

cn.luues.tool.template.engine.rythm.RythmEngine Maven / Gradle / Ivy

There is a newer version: 2.0.1.RELEASE
Show newest version
package cn.luues.tool.template.engine.rythm;

import cn.luues.tool.template.Template;
import cn.luues.tool.template.TemplateConfig;
import cn.luues.tool.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; } /** * 初始化引擎 * @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