Java Code Examples for freemarker.ext.beans.BeansWrapperBuilder#build()

The following examples show how to use freemarker.ext.beans.BeansWrapperBuilder#build() . 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: FreemarkerStaticModels.java    From cms with Apache License 2.0 6 votes vote down vote up
public static TemplateHashModel useStaticPackage(String packageName) {
	try {
		// BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
		// Create the builder:
	    BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_23);
	    // Set desired BeansWrapper configuration properties:
	    builder.setUseModelCache(true);
	    builder.setExposeFields(true);
	    
	    // Get the singleton:
	    BeansWrapper wrapper = builder.build();
	    // You don't need the builder anymore.
		TemplateHashModel staticModels = wrapper.getStaticModels();
		TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
		return fileStatics;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 2
Source File: TemplateObjectMethods.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
private static BeansWrapper getBeansWrapper(){
	//创建builder:
    BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.getVersion());
    // 设置所需的beanswrapper属性
    //builder.setUseModelCache(true);是否启用缓存
    //builder.setExposeFields(true);//是否启用返回类的公共实例。
    builder.setSimpleMapWrapper(true);//模板能使用Map方法
    // Get the singleton:
    BeansWrapper beansWrapper = builder.build();
	
	return beansWrapper;
}
 
Example 3
Source File: TemplateCustomMethods.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
private static BeansWrapper getBeansWrapper(){	
	//创建builder:
    BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.getVersion());
    // 设置所需的beanswrapper属性
    //builder.setUseModelCache(true);是否启用缓存
    //builder.setExposeFields(true);//是否启用返回类的公共实例。
    builder.setSimpleMapWrapper(true);//模板能使用Map方法
    // Get the singleton:
    BeansWrapper beansWrapper = builder.build();
	
	return beansWrapper;
}