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