Java Code Examples for org.beetl.core.Configuration#setStatementStart()

The following examples show how to use org.beetl.core.Configuration#setStatementStart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupTemplateTest.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws Exception {

		String home = System.getProperty("user.dir") + File.separator
				+ "template" + File.separator;
		Configuration cf = Configuration.defaultConfiguration();
		cf.setStatementStart("<!--:");
		cf.setStatementEnd("-->");
		FileResourceLoader rs = new FileResourceLoader(home, cf.getCharset());
		GroupTemplate gt = new GroupTemplate(rs, cf);

		List<StockModel> list = StockModel.dummyItems();

		Template t = gt.getTemplate("/helloworld.html");
		t.binding("items", list);
		StringWriter sw = new StringWriter();
		t.renderTo(sw);
		System.out.println(sw.toString());

		// 第二次
		t = gt.getTemplate("/helloworld.html");
		t.binding("items", list);
		sw = new StringWriter();
		t.renderTo(sw);
		System.out.println(sw.toString());

	}
 
Example 2
Source File: GroupTemplateTest.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws Exception {

		String home = System.getProperty("user.dir") + File.separator
				+ "template" + File.separator;
		Configuration cf = Configuration.defaultConfiguration();
		cf.setStatementStart("<!--:");
		cf.setStatementEnd("-->");
		FileResourceLoader rs = new FileResourceLoader(home, cf.getCharset());
		GroupTemplate gt = new GroupTemplate(rs, cf);

		List<StockModel> list = StockModel.dummyItems();

		Template t = gt.getTemplate("/helloworld.html");
		t.binding("items", list);
		StringWriter sw = new StringWriter();
		t.renderTo(sw);
		System.out.println(sw.toString());

		// 第二次
		t = gt.getTemplate("/helloworld.html");
		t.binding("items", list);
		sw = new StringWriter();
		t.renderTo(sw);
		System.out.println(sw.toString());

	}
 
Example 3
Source File: SingleDLTest.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example 4
Source File: PairDLTest.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example 5
Source File: WordprocessingMLBeetlTemplate.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
protected synchronized 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);
       GroupTemplate engine = new GroupTemplate(loader, cfg);
       // 设置模板引擎,减少重复初始化消耗
       this.setEngine(engine);
       return engine;
}