freemarker.ext.beans.BeansWrapperBuilder Java Examples

The following examples show how to use freemarker.ext.beans.BeansWrapperBuilder. 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: TemplateHelper.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected static Map<String, Object> prepareParams(Map<String, ?> parameterValues) {
    Map<String, Object> parameterValuesWithStats = new HashMap<>(parameterValues);
    BeansWrapper beansWrapper = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build();
    parameterValuesWithStats.put("statics", beansWrapper.getStaticModels());

    @SuppressWarnings("unchecked")
    Map<String, Object> params = LazyMap.lazyMap(parameterValuesWithStats, propertyName -> {
        for (String appProperty : AppContext.getPropertyNames()) {
            if (appProperty.replace(".", "_").equals(propertyName)) {
                return AppContext.getProperty(propertyName);
            }
        }
        return null;
    });

    return params;
}
 
Example #3
Source File: FreeMarkerConfigFactory.java    From youran with Apache License 2.0 5 votes vote down vote up
public FreeMarkerConfigFactory() {
    this.cache = new ConcurrentHashMap<>();
    this.beansWrapperBuilder = new BeansWrapperBuilder(Configuration.VERSION_2_3_21);
    this.beansWrapperBuilder.setExposeFields(true);
    this.metaConstTypeModel = getStaticModel(MetaConstType.class);
    this.jFieldTypeModel = getStaticModel(JFieldType.class);
    this.queryTypeModel = getStaticModel(QueryType.class);
    this.editTypeModel = getStaticModel(EditType.class);
    this.metaSpecialFieldModel = getStaticModel(MetaSpecialField.class);
    this.primaryKeyStrategyModel = getStaticModel(PrimaryKeyStrategy.class);
    this.commonTemplateFunctionModel = getStaticModel(CommonTemplateFunction.class);
    this.javaTemplateFunctionModel = getStaticModel(JavaTemplateFunction.class);
    this.sqlTemplateFunctionModel = getStaticModel(SqlTemplateFunction.class);
}
 
Example #4
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 #5
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;
}
 
Example #6
Source File: TemplateWrapperFactory.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public TemplateWrapperFactory(String templatesPackagePath) {
    configuration = new Configuration(Configuration.VERSION_2_3_24);

    configuration.setTemplateLoader(new ClassTemplateLoader(HtmlReport.class, templatesPackagePath));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setAPIBuiltinEnabled(true);
    configuration.setObjectWrapper(new BeansWrapperBuilder(Configuration.VERSION_2_3_24).build());
    configuration.setRecognizeStandardFileExtensions(true);
}
 
Example #7
Source File: FreemarkerConfigurationBuilder.java    From ogham with Apache License 2.0 5 votes vote down vote up
private static BeansWrapper getBeansWrapper(Configuration configuration) {
	ObjectWrapper objectWrapper = configuration.getObjectWrapper();
	if (objectWrapper instanceof BeansWrapper) {
		return (BeansWrapper) objectWrapper;
	}
	return new BeansWrapperBuilder(configuration.getIncompatibleImprovements()).build();
}
 
Example #8
Source File: FreemarkerConfigurer.java    From ogham with Apache License 2.0 5 votes vote down vote up
private static BeansWrapper getBeansWrapper(Configuration configuration) {
	ObjectWrapper objectWrapper = configuration.getObjectWrapper();
	if (objectWrapper instanceof BeansWrapper) {
		return (BeansWrapper) objectWrapper;
	}
	return new BeansWrapperBuilder(configuration.getIncompatibleImprovements()).build();
}
 
Example #9
Source File: TableThDirective.java    From scaffold-cloud with MIT License 4 votes vote down vote up
public static BeansWrapper getBeansWrapper(){
    BeansWrapper beansWrapper =
            new BeansWrapperBuilder(Configuration.VERSION_2_3_21).build();
    return beansWrapper;
}