Search in sources :

Example 11 with GroupTemplate

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

the class HelloBeetl method main.

public static void main(String[] args) throws Exception {
    StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader();
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    Template t = gt.getTemplate("hello,${name}");
    t.binding("name", "beetl");
    String str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) StringTemplateResourceLoader(org.beetl.core.resource.StringTemplateResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 12 with GroupTemplate

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

the class SharedVars method main.

public static void main(String[] args) throws Exception {
    ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    Map<String, Object> shared = new HashMap<String, Object>();
    shared.put("name", "beetl");
    gt.setSharedVars(shared);
    Template t = gt.getTemplate("/org/beetl/sample/s0208/t1.txt");
    String str = t.render();
    System.out.println(str);
    t = gt.getTemplate("/org/beetl/sample/s0208/t2.txt");
    str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) HashMap(java.util.HashMap) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 13 with GroupTemplate

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

the class RegisterFunctionByFile method main.

public static void main(String[] args) throws Exception {
    String root = System.getProperty("user.dir") + File.separator + "template";
    FileResourceLoader resourceLoader = new FileResourceLoader(root, "utf-8");
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    gt.registerFunctionPackage("t", new FunctionPackage());
    Template t = gt.getTemplate("/s32/functionPackage.html");
    String str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) FileResourceLoader(org.beetl.core.resource.FileResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 14 with GroupTemplate

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

the class RegisterFunctionPackage method main.

public static void main(String[] args) throws Exception {
    String root = System.getProperty("user.dir") + File.separator + "template";
    FileResourceLoader resourceLoader = new FileResourceLoader(root, "utf-8");
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    Template t = gt.getTemplate("/s32/pagefunction.html");
    String str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) FileResourceLoader(org.beetl.core.resource.FileResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 15 with GroupTemplate

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

the class BeetlGroupUtilConfiguration method initGroupTemplate.

private void initGroupTemplate() throws IOException {
    // 配置数据加载
    Configuration configuration = null;
    // 如果都未设置,取默认的配置
    if ((configProperties == null) && (configFileResource == null)) {
        configuration = Configuration.defaultConfiguration();
    } else {
        Properties properties = new Properties();
        if (configFileResource != null) {
            InputStream in = null;
            try {
                // 如果指定了配置文件,先加载配置文件
                in = configFileResource.getInputStream();
                properties.load(in);
            } catch (IOException ex) {
                throw ex;
            } finally {
                if (in != null) {
                    in.close();
                    in = null;
                }
            }
        }
        if (configProperties != null) {
            for (Entry<Object, Object> entry : configProperties.entrySet()) {
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();
                properties.setProperty(key, value);
            }
        }
        // 使用配置项配置properties
        configuration = new Configuration(properties);
    }
    // 如果未指定,返回
    if (resourceLoader != null) {
        groupTemplate = new GroupTemplate(resourceLoader, configuration);
    } else {
        WebAppResourceLoader defaultLoader = new WebAppResourceLoader(root);
        groupTemplate = new GroupTemplate(defaultLoader, configuration);
    }
    if (errorHandler != null) {
        groupTemplate.setErrorHandler(errorHandler);
    }
    // 设置共享变量
    if (sharedVars != null) {
        groupTemplate.setSharedVars(sharedVars);
    }
}
Also used : Configuration(org.beetl.core.Configuration) InputStream(java.io.InputStream) IOException(java.io.IOException) GroupTemplate(org.beetl.core.GroupTemplate) Properties(java.util.Properties) WebAppResourceLoader(org.beetl.core.resource.WebAppResourceLoader)

Aggregations

GroupTemplate (org.beetl.core.GroupTemplate)31 Configuration (org.beetl.core.Configuration)22 Template (org.beetl.core.Template)19 ClasspathResourceLoader (org.beetl.core.resource.ClasspathResourceLoader)10 FileResourceLoader (org.beetl.core.resource.FileResourceLoader)7 IOException (java.io.IOException)5 Test (org.testng.annotations.Test)5 Map (java.util.Map)4 Properties (java.util.Properties)4 StringTemplateResourceLoader (org.beetl.core.resource.StringTemplateResourceLoader)4 WebRender (org.beetl.ext.web.WebRender)4 HashMap (java.util.HashMap)3 InputStream (java.io.InputStream)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 WebAppResourceLoader (org.beetl.core.resource.WebAppResourceLoader)2 ToolUtil (com.ikoori.vip.server.core.util.ToolUtil)1 ActionContext (com.opensymphony.xwork2.ActionContext)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1