本文整理汇总了Java中org.beetl.core.Template.renderTo方法的典型用法代码示例。如果您正苦于以下问题:Java Template.renderTo方法的具体用法?Java Template.renderTo怎么用?Java Template.renderTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.beetl.core.Template
的用法示例。
在下文中一共展示了Template.renderTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.beetl.core.Template; //导入方法依赖的package包/类
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());
}
示例2: callHtmlTag
import org.beetl.core.Template; //导入方法依赖的package包/类
protected void callHtmlTag(String path)
{
Template t = null;
t = gt.getHtmlFunctionOrTagTemplate(path, this.ctx.getResourceId());
t.binding(ctx.globalVar);
t.dynamic(ctx.objectKeys);
if (args.length == 2)
{
Map<String, Object> map = (Map<String, Object>) args[1];
for (Entry<String, Object> entry : map.entrySet())
{
t.binding(entry.getKey(), entry.getValue());
}
}
BodyContent bodyContent = super.getBodyContent();
t.binding("tagBody", bodyContent);
t.renderTo(ctx.byteWriter);
}
示例3: render
import org.beetl.core.Template; //导入方法依赖的package包/类
/**
* ���浽ָ��λ��
*
* @param t
* @param path
* @throws IOException
*/
private static void render(Template t, String path) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(path), "UTF-8");
t.renderTo(writer);
writer.close();
}
示例4: render
import org.beetl.core.Template; //导入方法依赖的package包/类
@Override
public void render()
{
if (args.length == 0 || args.length > 3)
{
throw new RuntimeException("参数错误,期望child,map");
}
String layoutFile = getRelResourceId();
Template t = this.gt.getTemplate(layoutFile, this.ctx.getResourceId());
t.binding(ctx.globalVar);
t.dynamic(ctx.objectKeys);
if (args.length >= 2)
{
Map<String, Object> map = (Map<String, Object>) args[1];
for (Entry<String, Object> entry : map.entrySet())
{
t.binding(entry.getKey(), entry.getValue());
}
}
BodyContent content = this.getBodyContent();
if (args.length == 3)
{
t.binding((String) args[2], content);
}
else
{
t.binding(defaultLayoutName, content);
}
t.renderTo(ctx.byteWriter);
}
示例5: render
import org.beetl.core.Template; //导入方法依赖的package包/类
@Override
public void render()
{
String resourceId = getRelResourceId();
;
Template t = gt.getTemplate(resourceId, this.ctx.getResourceId());
//快速复制父模板的变量
t.binding(this.ctx.globalVar);
if (ctx.objectKeys != null && ctx.objectKeys.size() != 0)
{
t.dynamic(ctx.objectKeys);
}
if (this.args.length == 2)
{
Map<String, Object> map = (Map<String, Object>) this.args[1];
for (Entry<String, Object> entry : map.entrySet())
{
Object value = entry.getValue();
if (value instanceof Map || value instanceof Collection)
{
t.binding((String) entry.getKey(), value, true);
}
else
{
t.binding((String) entry.getKey(), value);
}
}
}
ByteWriter bw = ctx.byteWriter;
t.renderTo(bw);
}
示例6: generate
import org.beetl.core.Template; //导入方法依赖的package包/类
public static void generate(RunPlanBean rpb) {
try {
System.out.println(rpb.toString());
String root = TPController.class.getClassLoader().getResource("").getPath() + "beetl";
FileResourceLoader resourceLoader = new FileResourceLoader(root, "utf-8");
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Template t = gt.getTemplate("/http_request.jmx");
t.binding("v_duration", rpb.getDuration());
t.binding("v_users_num", rpb.getUsersNum());
t.binding("v_ramp_up", rpb.getRampUp());
TestPlanBean tpb = rpb.getTestPlanBean(); // TODO: [email protected]/3/13 不够优雅,改成解析成map,直接binding map
if (null != tpb) {
t.binding("v_server_name", tpb.getServerNameIp());
t.binding("v_port", tpb.getPortNum());
t.binding("v_prol", tpb.getProtocol());
t.binding("v_path", tpb.getPath());
} else {
t.binding("v_server_name", "111");
t.binding("v_port", "222");
t.binding("v_prol", "333");
t.binding("v_path", "444");
}
String jmxRoot = System.getProperty("user.dir")+JMX_PATH;//系统(项目)路径,结尾无斜杠
//jmx在系统(项目)中的存在路径,斜杠开头,结尾无斜杠
String fullPath = jmxRoot+StringUtils.creAndGetDir(jmxRoot); //返回的应该是 c:/jmx/2017/03 ,并创建这个目录
//文件名,斜杠开头
String fileName = new StringBuilder(File.separator)
.append(JMX_NAME_PREFIX)
.append(StringUtils.getDate("yyyyMMddHHmmssSSS"))
.append(JMX_NAME_SUFFIX)
.toString();
String jmxFilePath = fullPath+fileName;
rpb.setJmxPath(jmxFilePath);
OutputStream ops = new FileOutputStream(jmxFilePath);
t.renderTo(ops);
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: render
import org.beetl.core.Template; //导入方法依赖的package包/类
public void render(String key, HttpServletRequest request, HttpServletResponse response, Object... args) {
PrintWriter writer = null;
ServletOutputStream os = null;
String ajaxId = null;
Template template = null;
try {
int e = key.lastIndexOf("#");
if(e != -1) {
ajaxId = key.substring(e + 1);
key = key.substring(0, e);
template = this.gt.getAjaxTemplate(key, ajaxId);
} else {
template = this.gt.getTemplate(key);
}
Enumeration attrs = request.getAttributeNames();
while(attrs.hasMoreElements()) {
String webVariable = (String)attrs.nextElement();
template.binding(webVariable, request.getAttribute(webVariable));
}
WebVariable webVariable1 = new WebVariable();
webVariable1.setRequest(request);
webVariable1.setResponse(response);
template.binding("session", new SessionWrapper(webVariable1.getRequest(),webVariable1.getSession()));
template.binding("servlet", webVariable1);
template.binding("request", request);
template.binding("ctxPath", request.getContextPath());
this.modifyTemplate(template, key, request, response, args);
if(this.gt.getConf().isDirectByteOutput()) {
os = response.getOutputStream();
template.renderTo(os);
} else {
writer = response.getWriter();
template.renderTo(writer);
}
} catch (IOException var22) {
this.handleClientError(var22);
} catch (BeetlException var23) {
this.handleBeetlException(var23);
}
}
示例8: main
import org.beetl.core.Template; //导入方法依赖的package包/类
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);
for (int i = 0; i < 1; i++) {
Template t = gt.getTemplate("/hello.txt");
t.binding("user", new TestUser("jo"));
t.binding("id", 2);
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());
}
}