Search in sources :

Example 6 with Configuration

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

the class ClasspathRL method main.

public static void main(String[] args) throws Exception {
    ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
    URL url = resourceLoader.getClass().getResource("/org/beetl/sample/s01/hello.txt");
    Configuration cfg = Configuration.defaultConfiguration();
    GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
    Template t = gt.getTemplate("/org/beetl/sample/s01/hello.txt");
    String str = t.render();
    System.out.println(str);
}
Also used : Configuration(org.beetl.core.Configuration) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) URL(java.net.URL) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 7 with Configuration

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

the class FilePathRL 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("/s01/hello.txt");
    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 8 with Configuration

use of org.beetl.core.Configuration 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 9 with Configuration

use of org.beetl.core.Configuration 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 10 with Configuration

use of org.beetl.core.Configuration 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)

Aggregations

Configuration (org.beetl.core.Configuration)23 GroupTemplate (org.beetl.core.GroupTemplate)22 Template (org.beetl.core.Template)13 ClasspathResourceLoader (org.beetl.core.resource.ClasspathResourceLoader)10 FileResourceLoader (org.beetl.core.resource.FileResourceLoader)7 IOException (java.io.IOException)6 Properties (java.util.Properties)4 HashMap (java.util.HashMap)3 StringTemplateResourceLoader (org.beetl.core.resource.StringTemplateResourceLoader)3 InputStream (java.io.InputStream)2 WebAppResourceLoader (org.beetl.core.resource.WebAppResourceLoader)2 Program (org.beetl.core.statement.Program)2 ProgramMetaData (org.beetl.core.statement.ProgramMetaData)2 Test (org.testng.annotations.Test)2 ToolUtil (com.ikoori.vip.server.core.util.ToolUtil)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1