Search in sources :

Example 1 with ClasspathResourceLoader

use of org.beetl.core.resource.ClasspathResourceLoader in project swift by luastar.

the class BeetlUtils method init.

private void init() {
    try {
        ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
        Configuration cfg = Configuration.defaultConfiguration();
        groupTemplate = new GroupTemplate(resourceLoader, cfg);
    } catch (Exception e) {
        logger.error("转换为文件时异常", e);
    }
}
Also used : Configuration(org.beetl.core.Configuration) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate)

Example 2 with ClasspathResourceLoader

use of org.beetl.core.resource.ClasspathResourceLoader in project vip by guangdada.

the class BeetlConfig method beetlConfiguration.

/**
 * beetl的配置
 */
@Bean(initMethod = "init")
public BeetlConfiguration beetlConfiguration() {
    BeetlConfiguration beetlConfiguration = new BeetlConfiguration();
    beetlConfiguration.setResourceLoader(new ClasspathResourceLoader(BeetlConfig.class.getClassLoader(), beetlProperties.getPrefix()));
    beetlConfiguration.setConfigProperties(beetlProperties.getProperties());
    return beetlConfiguration;
}
Also used : BeetlConfiguration(com.ikoori.vip.server.core.beetl.BeetlConfiguration) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) Bean(org.springframework.context.annotation.Bean)

Example 3 with ClasspathResourceLoader

use of org.beetl.core.resource.ClasspathResourceLoader in project vip by guangdada.

the class GunsTemplateEngine method initBeetlEngine.

public void initBeetlEngine() {
    Properties properties = new Properties();
    properties.put("RESOURCE.root", "");
    properties.put("DELIMITER_STATEMENT_START", "<%");
    properties.put("DELIMITER_STATEMENT_END", "%>");
    properties.put("HTML_TAG_FLAG", "##");
    Configuration cfg = null;
    try {
        cfg = new Configuration(properties);
    } catch (IOException e) {
        e.printStackTrace();
    }
    ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
    groupTemplate = new GroupTemplate(resourceLoader, cfg);
    groupTemplate.registerFunctionPackage("tool", new ToolUtil());
}
Also used : ToolUtil(com.ikoori.vip.server.core.util.ToolUtil) Configuration(org.beetl.core.Configuration) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) IOException(java.io.IOException) GroupTemplate(org.beetl.core.GroupTemplate) Properties(java.util.Properties)

Example 4 with ClasspathResourceLoader

use of org.beetl.core.resource.ClasspathResourceLoader in project vip by guangdada.

the class BeetlConfig method beetlConfiguration.

/**
 * beetl的配置
 */
@Bean(initMethod = "init")
public BeetlGroupUtilConfiguration beetlConfiguration() {
    BeetlGroupUtilConfiguration beetlConfiguration = new BeetlGroupUtilConfiguration();
    beetlConfiguration.setResourceLoader(new ClasspathResourceLoader(BeetlConfig.class.getClassLoader(), beetlProperties.getPrefix()));
    beetlConfiguration.setConfigProperties(beetlProperties.getProperties());
    return beetlConfiguration;
}
Also used : BeetlGroupUtilConfiguration(org.beetl.ext.spring.BeetlGroupUtilConfiguration) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) Bean(org.springframework.context.annotation.Bean)

Example 5 with ClasspathResourceLoader

use of org.beetl.core.resource.ClasspathResourceLoader in project beetl2.0 by javamonkey.

the class Test method main.

public static void main(String[] args) throws Exception {
    ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader("org/beetl/core/lab/");
    Configuration cfg = Configuration.defaultConfiguration();
    cfg.setDirectByteOutput(true);
    cfg.getResourceMap().put("tagRoot", "/");
    cfg.getPkgList().add("org.beetl.core.lab.");
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    // cfg.setStatementStart("@");
    // cfg.setStatementEnd(null);
    // cfg.setPlaceholderStart("{{");
    // cfg.setPlaceholderEnd("}}");
    // 
    gt.registerFunction("test", new TestFun());
    gt.registerTag("test", TestTag.class);
    List list = new ArrayList();
    list.add(null);
    list.add(new TestUser("abc"));
    HashMap map = new HashMap();
    map.put("key", 123);
    gt.enableStrict();
    for (int i = 0; i < 1; i++) {
        Template t = gt.getTemplate("/hello.txt");
        t.binding("user", new TestUser("jo"));
        t.binding("id", 2);
        t.binding("list", list);
        ByteArrayOutputStream bs = new ByteArrayOutputStream();
        try {
            t.renderTo(bs);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // TestUser test = new TestUser("a");
        // test.setLover(new TestUser("b"));
        // t.binding("user", test);
        System.out.println(t.render());
    }
}
Also used : Configuration(org.beetl.core.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) List(java.util.List) ArrayList(java.util.ArrayList) GroupTemplate(org.beetl.core.GroupTemplate) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Aggregations

ClasspathResourceLoader (org.beetl.core.resource.ClasspathResourceLoader)12 Configuration (org.beetl.core.Configuration)9 GroupTemplate (org.beetl.core.GroupTemplate)9 Template (org.beetl.core.Template)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)2 Bean (org.springframework.context.annotation.Bean)2 BeetlConfiguration (com.ikoori.vip.server.core.beetl.BeetlConfiguration)1 ToolUtil (com.ikoori.vip.server.core.util.ToolUtil)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 FileResourceLoader (org.beetl.core.resource.FileResourceLoader)1 BeetlGroupUtilConfiguration (org.beetl.ext.spring.BeetlGroupUtilConfiguration)1 Test (org.testng.annotations.Test)1