package cn.palmte.work.utils;

import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.beans.BeansWrapperBuilder;
import freemarker.template.TemplateHashModel;
import freemarker.template.Version;

/**
 * @author xiongshiyan at 2021/11/5 , contact me with email yanshixiong@126.com or phone 15208384257
 */
public class FreeMarkerUtil {
    public static TemplateHashModel fromStaticPackage(String packageName) {
        try
        {
            BeansWrapperBuilder beansWrapperBuilder = new BeansWrapperBuilder(new Version(2,3,26));
            //BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
            BeansWrapper wrapper = beansWrapperBuilder.build();
            TemplateHashModel staticModels = wrapper.getStaticModels();
            return (TemplateHashModel) staticModels.get(packageName);
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
