Search in sources :

Example 1 with TemplateException

use of cn.hutool.extra.template.TemplateException in project hutool by looly.

the class TemplateFactory method doCreate.

/**
 * 根据用户引入的模板引擎jar,自动创建对应的模板引擎对象<br>
 * 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎
 *
 * @param config 模板配置,包括编码、模板文件path等信息
 * @return {@link TemplateEngine}
 */
private static TemplateEngine doCreate(TemplateConfig config) {
    final Class<? extends TemplateEngine> customEngineClass = config.getCustomEngine();
    final TemplateEngine engine;
    if (null != customEngineClass) {
        engine = ReflectUtil.newInstance(customEngineClass);
    } else {
        engine = ServiceLoaderUtil.loadFirstAvailable(TemplateEngine.class);
    }
    if (null != engine) {
        return engine.init(config);
    }
    throw new TemplateException("No template found ! Please add one of template jar to your project !");
}
Also used : TemplateEngine(cn.hutool.extra.template.TemplateEngine) TemplateException(cn.hutool.extra.template.TemplateException)

Aggregations

TemplateEngine (cn.hutool.extra.template.TemplateEngine)1 TemplateException (cn.hutool.extra.template.TemplateException)1