
##定义配置文件 freemarkerstatic.properties
_Validator=com.longyou.util.Validator
_Functions=com.longyou.util.Functions
_EscapeUtils=com.longyou.util.EscapeUtils


//Java类实现
Configuration config = new Configuration();
BeansWrapper wrapper = BeansWrapper.BEANS_WRAPPER;
wrapper.setExposureLevel(BeansWrapper.EXPOSE_ALL);
InputStream in = null;
try{
      in = ClassLoaderUtils.getResourceAsStream("/freemarkerstatic.properties", FreemarkerUtils.class);
      if(in != null){
          Properties props = new Properties();
          props.load(in);
          Enumeration en = props.keys();
          String name, value;
          TemplateHashModel staticModels = wrapper.getStaticModels();
          while(en.hasMoreElements()){
        name = (String)en.nextElement();
        value = props.getProperty(name);
        TemplateHashModel tempStatics = (TemplateHashModel) staticModels.get(value);
        config.setSharedVariable(name, tempStatics);
          }
     }
}catch(Exception ex){
       log.error("Error while loading freemarker settings from /freemarkerstatic.properties", ex);
}finally{
      if(in != null){
        try{
        in.close();
        }catch(Exception ex){               
                ex.printStackTrace();
        }
        in = null;
     }
}
config.setObjectWrapper(wrapper);

//调用代码
${_Functions.toUpperCase("Hello")}<br>
${_EscapeUtils.escape("Java视线论坛")}

//输出结果
HELLO
Java%u89C6%u7EBF%u8BBA%u575B 