mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
support spi
This commit is contained in:
@@ -1,30 +1,23 @@
|
||||
package cn.hutool.extra.template.engine;
|
||||
|
||||
import com.jfinal.template.Engine;
|
||||
|
||||
import cn.hutool.core.util.ServiceLoaderUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.template.TemplateConfig;
|
||||
import cn.hutool.extra.template.TemplateEngine;
|
||||
import cn.hutool.extra.template.TemplateException;
|
||||
import cn.hutool.extra.template.engine.beetl.BeetlEngine;
|
||||
import cn.hutool.extra.template.engine.enjoy.EnjoyEngine;
|
||||
import cn.hutool.extra.template.engine.freemarker.FreemarkerEngine;
|
||||
import cn.hutool.extra.template.engine.rythm.RythmEngine;
|
||||
import cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine;
|
||||
import cn.hutool.extra.template.engine.velocity.VelocityEngine;
|
||||
import cn.hutool.log.StaticLog;
|
||||
import com.jfinal.template.Engine;
|
||||
|
||||
/**
|
||||
* 简单模板工厂,用于根据用户引入的模板引擎jar,自动创建对应的模板引擎对象
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class TemplateFactory {
|
||||
/**
|
||||
* 根据用户引入的模板引擎jar,自动创建对应的模板引擎对象<br>
|
||||
* 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎
|
||||
*
|
||||
*
|
||||
* @param config 模板配置,包括编码、模板文件path等信息
|
||||
* @return {@link Engine}
|
||||
*/
|
||||
@@ -37,41 +30,16 @@ public class TemplateFactory {
|
||||
/**
|
||||
* 根据用户引入的模板引擎jar,自动创建对应的模板引擎对象<br>
|
||||
* 推荐创建的引擎单例使用,此方法每次调用会返回新的引擎
|
||||
*
|
||||
*
|
||||
* @param config 模板配置,包括编码、模板文件path等信息
|
||||
* @return {@link Engine}
|
||||
*/
|
||||
private static TemplateEngine doCreate(TemplateConfig config) {
|
||||
try {
|
||||
return new BeetlEngine(config);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new FreemarkerEngine(config);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new VelocityEngine(config);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new RythmEngine(config);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new EnjoyEngine(config);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new ThymeleafEngine(config);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
final TemplateEngine engine = ServiceLoaderUtil.loadFirstAvailable(TemplateEngine.class);
|
||||
if(null != engine){
|
||||
return engine;
|
||||
}
|
||||
|
||||
throw new TemplateException("No template found ! Please add one of template jar to your project !");
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,9 @@
|
||||
package cn.hutool.extra.tokenizer.engine;
|
||||
|
||||
import cn.hutool.core.util.ServiceLoaderUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import cn.hutool.extra.tokenizer.TokenizerException;
|
||||
import cn.hutool.extra.tokenizer.engine.analysis.SmartcnEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.ansj.AnsjEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.hanlp.HanLPEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.ikanalyzer.IKAnalyzerEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.jcseg.JcsegEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.jieba.JiebaEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.mmseg.MmsegEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.mynlp.MynlpEngine;
|
||||
import cn.hutool.extra.tokenizer.engine.word.WordEngine;
|
||||
import cn.hutool.log.StaticLog;
|
||||
|
||||
/**
|
||||
@@ -38,51 +30,11 @@ public class TokenizerFactory {
|
||||
* @return {@link TokenizerEngine}
|
||||
*/
|
||||
private static TokenizerEngine doCreate() {
|
||||
try {
|
||||
return new AnsjEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new HanLPEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new IKAnalyzerEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new JcsegEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new JiebaEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new MmsegEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new WordEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new SmartcnEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return new MynlpEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
// ignore
|
||||
final TokenizerEngine engine = ServiceLoaderUtil.loadFirstAvailable(TokenizerEngine.class);
|
||||
if(null != engine){
|
||||
return engine;
|
||||
}
|
||||
|
||||
throw new TokenizerException("No tokenizer found ! Please add some tokenizer jar to your project !");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,6 @@
|
||||
cn.hutool.extra.template.engine.beetl.BeetlEngine
|
||||
cn.hutool.extra.template.engine.freemarker.FreemarkerEngine
|
||||
cn.hutool.extra.template.engine.velocity.VelocityEngine
|
||||
cn.hutool.extra.template.engine.rythm.RythmEngine
|
||||
cn.hutool.extra.template.engine.enjoy.EnjoyEngine
|
||||
cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine
|
@@ -0,0 +1,9 @@
|
||||
cn.hutool.extra.tokenizer.engine.ansj.AnsjEngine
|
||||
cn.hutool.extra.tokenizer.engine.hanlp.HanLPEngine
|
||||
cn.hutool.extra.tokenizer.engine.ikanalyzer.IKAnalyzerEngine
|
||||
cn.hutool.extra.tokenizer.engine.jcseg.JcsegEngine
|
||||
cn.hutool.extra.tokenizer.engine.jieba.JiebaEngine
|
||||
cn.hutool.extra.tokenizer.engine.mmseg.MmsegEngine
|
||||
cn.hutool.extra.tokenizer.engine.word.WordEngine
|
||||
cn.hutool.extra.tokenizer.engine.analysis.SmartcnEngine
|
||||
cn.hutool.extra.tokenizer.engine.mynlp.MynlpEngine
|
Reference in New Issue
Block a user