本文整理汇总了Java中org.beetl.core.GroupTemplate类的典型用法代码示例。如果您正苦于以下问题:Java GroupTemplate类的具体用法?Java GroupTemplate怎么用?Java GroupTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GroupTemplate类属于org.beetl.core包,在下文中一共展示了GroupTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
@Override
public String render(String templatePath, Map<String, Object> data) throws Exception {
GroupTemplate gt = getGroupTemplate();
// set template global shared vars
Map<String, Object> sharedVars = new HashMap<>();
sharedVars.put("REQUEST", HttpContext.request());
Session session = HttpContext.request().session();
sharedVars.put("SESSION", session != null ? session.attributes() : new HashMap<String, Object>());
gt.setSharedVars(sharedVars);
Template template = gt.getTemplate(templatePath);
template.binding(data);
return template.render();
}
示例2: main
import org.beetl.core.GroupTemplate; //导入依赖的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());
}
示例3: init
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
@Override
public void init(GroupTemplate gt)
{
Map<String, String> resourceMap = gt.getConf().getResourceMap();
//如果配置文件也配置了root
if (resourceMap.get("root") != null)
{
String temp = resourceMap.get("root");
temp = checkRoot(temp);
this.root = this.getChildPath(root, temp);
}
if (this.charset == null)
{
this.charset = resourceMap.get("charset");
}
this.functionSuffix = resourceMap.get("functionSuffix");
this.autoCheck = Boolean.parseBoolean(resourceMap.get("autoCheck"));
this.functionRoot = resourceMap.get("functionRoot");
}
示例4: createProgram
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
@Override
public Program createProgram(Resource rs, Reader reader, Map<Integer, String> textMap, String cr, GroupTemplate gt)
{
Program orginalProgram = super.createProgram(rs, reader, textMap, cr, gt);
//copy 一个出来分析
ProgramMetaData metaData = orginalProgram.metaData.copy();
Program copyProgram = new Program();
copyProgram.metaData = metaData;
copyProgram.res = orginalProgram.res;
copyProgram.gt = orginalProgram.gt;
copyProgram.rs = orginalProgram.rs;
Probe nextFilter = new BasicProgramOptProbe();
nextFilter.setProgram(copyProgram);
TypeBindingProbe firstFilter = new TypeBindingProbe(copyProgram, nextFilter);
//在能优化前,按照原有的program执行,但每次都会执行fitler以看看是否能优化
FilterProgram filterProgram = new FilterProgram(orginalProgram, copyProgram, firstFilter);
return filterProgram;
}
示例5: autoFileFunctionRegister
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
public static void autoFileFunctionRegister(GroupTemplate gt,File funtionRoot, String ns, String path,String functionSuffix){
File[] files = funtionRoot.listFiles();
for (File f : files)
{
if (f.isDirectory())
{
autoFileFunctionRegister(gt,f, f.getName().concat("."), path.concat(f.getName()).concat("/"),functionSuffix);
}
else if (f.getName().endsWith(functionSuffix))
{
String resourceId = path + f.getName();
String fileName = f.getName();
fileName = fileName.substring(0, (fileName.length() - functionSuffix.length() - 1));
String functionName = ns.concat(fileName);
FileFunctionWrapper fun = new FileFunctionWrapper(resourceId);
gt.registerFunction(functionName, fun);
}
}
}
示例6: createAAClass
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
public static AttributeAccess createAAClass(Class c, String name, String methodName, Class returnType,
Class parameterType,GroupTemplate gt)
{
try
{
BCW bcw = BCWFactory.defaultFactory.getAttribyteBCW(c, name, methodName, returnType, parameterType);
byte[] bs = bcw.getClassByte();
String clsName = c.getName() + "_" + name;
return instance(bs, clsName,gt);
}
catch (Exception ex)
{
throw new RuntimeException(ex);
}
}
示例7: instance
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
private static AttributeAccess instance(byte[] bs, String clsName,GroupTemplate gt)
{
// javap -c xxxx
// try{
// FileOutputStream fos = new FileOutputStream(new File("d:/"+clsName+".class"));
// fos.write(bs);
// fos.close();
// }catch(Exception ex){
// ex.printStackTrace();
// }
Class fieldAccessorClass = gt.getByteLoader().defineClass(clsName, bs);
AttributeAccess ac;
try
{
ac = (AttributeAccess) fieldAccessorClass.newInstance();
return ac;
}
catch (Exception e)
{
// TODO Auto-generated catch block
throw new RuntimeException(e);
}
}
示例8: ServletGroupTemplate
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
private ServletGroupTemplate()
{
try
{
Configuration cfg = Configuration.defaultConfiguration();
WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
groupTemplate = new GroupTemplate(resourceLoader, cfg);
}
catch (Exception ex)
{
ex.printStackTrace();
throw new RuntimeException("加载GroupTemplate失败", ex);
}
}
示例9: BeetlActionResult
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
public BeetlActionResult()
{
try
{
Configuration cfg = Configuration.defaultConfiguration();
WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
groupTemplate = new GroupTemplate(resourceLoader, cfg);
}
catch (IOException e)
{
throw new RuntimeException("加载GroupTemplate失败", e);
}
}
示例10: getGt
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
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;
}
示例11: getGt
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
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;
}
示例12: main
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
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);
}
示例13: TempletGenerate
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
public TempletGenerate(String generateRootPath, String generateConfigRootPath, String generateDbName) {
WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
Configuration cfg = null;
try {
cfg = Configuration.defaultConfiguration();
} catch ( IOException e ) {
e.printStackTrace();
}
gt = new GroupTemplate(resourceLoader, cfg);
this.generateCodeRootPath = generateRootPath;
// this.generateConfigRootPath = generateConfigRootPath;
this.generateDbName = generateDbName;
init();
}
示例14: init
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
@BeforeClass
public static void init() throws IOException {
WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
String root = "E:\\workspace\\WALL-E\\src\\main\\webapp";
resourceLoader.setRoot(root);
Configuration cfg = Configuration.defaultConfiguration();
gt = new GroupTemplate(resourceLoader, cfg);
PluginFactory.startActiveRecordPlugin();
}
示例15: configConstant
import org.beetl.core.GroupTemplate; //导入依赖的package包/类
public void configConstant(Constants me) {
me.setDevMode(false);
me.setMainRenderFactory(new BeetlRenderFactory());
// 获取GroupTemplate ,可置共享变量等操作
GroupTemplate group = BeetlRenderFactory.groupTemplate;
Map<String, Object> shared = new HashMap<String, Object>();
group.setSharedVars(shared);
}