Search in sources :

Example 6 with ClasspathResourceLoader

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

the class PairDLTest method getGt.

public GroupTemplate getGt() {
    ClasspathResourceLoader rs = new ClasspathResourceLoader("/template");
    Configuration cfg;
    try {
        cfg = Configuration.defaultConfiguration();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    cfg.setStatementEnd("%>");
    cfg.setStatementStart("<%");
    GroupTemplate gt = new GroupTemplate(rs, cfg);
    return gt;
}
Also used : Configuration(org.beetl.core.Configuration) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) IOException(java.io.IOException) GroupTemplate(org.beetl.core.GroupTemplate)

Example 7 with ClasspathResourceLoader

use of org.beetl.core.resource.ClasspathResourceLoader 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 8 with ClasspathResourceLoader

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

use of org.beetl.core.resource.ClasspathResourceLoader in project docx4j-template by vindell.

the class WordprocessingMLBeetlTemplate method getInternalEngine.

protected GroupTemplate getInternalEngine() throws IOException {
    ClasspathResourceLoader loader = new ClasspathResourceLoader();
    // 加载默认参数
    Configuration cfg = Configuration.defaultConfiguration();
    // 模板字符集
    cfg.setCharset(Docx4jProperties.getProperty("docx4j.beetl.charset", Docx4jConstants.DEFAULT_CHARSETNAME));
    // 模板占位起始符号
    cfg.setPlaceholderStart(Docx4jProperties.getProperty("docx4j.beetl.placeholderStart", "${"));
    // 模板占位结束符号
    cfg.setPlaceholderEnd(Docx4jProperties.getProperty("docx4j.beetl.placeholderEnd", "<%"));
    // 控制语句起始符号
    cfg.setStatementStart(Docx4jProperties.getProperty("docx4j.beetl.statementStart", "%>"));
    // 控制语句结束符号
    cfg.setStatementEnd(Docx4jProperties.getProperty("docx4j.beetl.statementEnd", "}"));
    // 是否允许html tag,在web编程中,有可能用到html tag,最好允许
    cfg.setHtmlTagSupport(Docx4jProperties.getProperty("docx4j.beetl.htmlTagSupport", false));
    // html tag 标示符号
    cfg.setHtmlTagFlag(Docx4jProperties.getProperty("docx4j.beetl.htmlTagFlag", "#"));
    // html 绑定的属性,如&lt;aa var="customer">
    cfg.setHtmlTagBindingAttribute(Docx4jProperties.getProperty("docx4j.beetl.htmlTagBindingAttribute", "var"));
    // 是否允许直接调用class
    cfg.setNativeCall(Docx4jProperties.getProperty("docx4j.beetl.nativeCall", false));
    // 输出模式,默认是字符集输出,改成byte输出提高性能
    cfg.setDirectByteOutput(Docx4jProperties.getProperty("docx4j.beetl.directByteOutput", true));
    // 严格mvc应用,只有变态的的人才打开此选项
    cfg.setStrict(Docx4jProperties.getProperty("docx4j.beetl.strict", false));
    // 是否忽略客户端的网络异常
    cfg.setIgnoreClientIOError(Docx4jProperties.getProperty("docx4j.beetl.ignoreClientIOError", true));
    // 错误处理类
    cfg.setErrorHandlerClass(Docx4jProperties.getProperty("docx4j.beetl.errorHandlerClass", "org.beetl.core.ConsoleErrorHandler"));
    // 资源参数
    Map<String, String> resourceMap = cfg.getResourceMap();
    // classpath 跟路径
    resourceMap.put("root", Docx4jProperties.getProperty("docx4j.beetl.resource.root", "/"));
    // 是否检测文件变化
    resourceMap.put("autoCheck", Docx4jProperties.getProperty("docx4j.beetl.resource.autoCheck", "true"));
    // 自定义脚本方法文件位置
    resourceMap.put("functionRoot", Docx4jProperties.getProperty("docx4j.beetl.resource.functionRoot", "functions"));
    // 自定义脚本方法文件的后缀
    resourceMap.put("functionSuffix", Docx4jProperties.getProperty("docx4j.beetl.resource.functionSuffix", "html"));
    // 自定义标签文件位置
    resourceMap.put("tagRoot", Docx4jProperties.getProperty("docx4j.beetl.resource.tagRoot", "htmltag"));
    // 自定义标签文件后缀
    resourceMap.put("tagSuffix", Docx4jProperties.getProperty("docx4j.beetl.resource.tagSuffix", "tag"));
    cfg.setResourceMap(resourceMap);
    return new GroupTemplate(loader, cfg);
}
Also used : Configuration(org.beetl.core.Configuration) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate)

Example 10 with ClasspathResourceLoader

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

the class SingleDLTest method getGt.

public GroupTemplate getGt() {
    ClasspathResourceLoader rs = new ClasspathResourceLoader("/template");
    Configuration cfg;
    try {
        cfg = Configuration.defaultConfiguration();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    cfg.setStatementEnd(null);
    cfg.setStatementStart("@");
    GroupTemplate gt = new GroupTemplate(rs, cfg);
    return gt;
}
Also used : Configuration(org.beetl.core.Configuration) ClasspathResourceLoader(org.beetl.core.resource.ClasspathResourceLoader) IOException(java.io.IOException) GroupTemplate(org.beetl.core.GroupTemplate)

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