提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.gen.core.engine; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.gen.core.util.TemplateUtil; |
|
4 |
import org.beetl.core.GroupTemplate; |
|
5 |
import org.beetl.core.resource.ClasspathResourceLoader; |
|
6 |
|
|
7 |
import java.io.IOException; |
|
8 |
import java.util.Properties; |
|
9 |
|
|
10 |
/** |
|
11 |
* beetl模板引擎的实例 |
|
12 |
* |
|
13 |
* @author fengshuonan |
|
14 |
* @date 2018-12-13-9:02 AM |
|
15 |
*/ |
|
16 |
public class BeetlEngine { |
|
17 |
|
|
18 |
private static BeetlEngine beetlEngine = new BeetlEngine(); |
|
19 |
|
|
20 |
private static GroupTemplate groupTemplate; |
|
21 |
|
|
22 |
private BeetlEngine() { |
|
23 |
Properties properties = new Properties(); |
|
24 |
properties.put("RESOURCE.root", ""); |
|
25 |
properties.put("DELIMITER_STATEMENT_START", "<%"); |
|
26 |
properties.put("DELIMITER_STATEMENT_END", "%>"); |
|
27 |
properties.put("HTML_TAG_FLAG", "##"); |
|
28 |
org.beetl.core.Configuration cfg = null; |
|
29 |
|
|
30 |
try { |
|
31 |
cfg = new org.beetl.core.Configuration(properties); |
|
32 |
} catch (IOException e) { |
|
33 |
e.printStackTrace(); |
|
34 |
} |
|
35 |
|
|
36 |
ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(); |
|
37 |
groupTemplate = new GroupTemplate(resourceLoader, cfg); |
|
38 |
groupTemplate.registerFunctionPackage("tool", new TemplateUtil()); |
|
39 |
} |
|
40 |
|
|
41 |
public static GroupTemplate getInstance() { |
|
42 |
return groupTemplate; |
|
43 |
} |
|
44 |
|
|
45 |
} |