Java 类freemarker.template.WrappingTemplateModel 实例源码

项目:elpi    文件:FreeMarkerViewRenderer.java   
protected Object createViewContext(JPublishContext context, String path) throws ViewRenderException {
    HttpServletRequest request = context.getRequest();
    HttpServletResponse response = context.getResponse();

    WrappingTemplateModel.setDefaultObjectWrapper(FreeMarkerWorker.getDefaultOfbizWrapper());
    Map contextMap = new HashMap();
    SimpleHash root = new SimpleHash(FreeMarkerWorker.getDefaultOfbizWrapper());
    try {
        Object[] keys = context.getKeys();
        for (int i = 0; i < keys.length; i++) {
            String key = (String) keys[i];
            Object value = context.get(key);
            if (value != null) {
                contextMap.put(key, value);
                //no longer wrapping; let FM do it if needed, more efficient
                //root.put(key, FreeMarkerWorker.getDefaultOfbizWrapper().wrap(value));
                root.put(key, value);
            }
        }
        root.put("context", FreeMarkerWorker.getDefaultOfbizWrapper().wrap(contextMap));
        root.put("cachedInclude", new JpCacheIncludeTransform()); // only adding this in for JP!
        //root.put("jpublishContext", FreeMarkerWorker.getDefaultOfbizWrapper().wrap(context));
        FreeMarkerViewHandler.prepOfbizRoot(root, request, response);
    } catch (Exception e) {
        throw new ViewRenderException(e);
    }
    return root;
}
项目:o3erp    文件:FreeMarkerViewRenderer.java   
protected Object createViewContext(JPublishContext context, String path) throws ViewRenderException {
    HttpServletRequest request = context.getRequest();
    HttpServletResponse response = context.getResponse();

    WrappingTemplateModel.setDefaultObjectWrapper(FreeMarkerWorker.getDefaultOfbizWrapper());
    Map contextMap = new HashMap();
    SimpleHash root = new SimpleHash(FreeMarkerWorker.getDefaultOfbizWrapper());
    try {
        Object[] keys = context.getKeys();
        for (int i = 0; i < keys.length; i++) {
            String key = (String) keys[i];
            Object value = context.get(key);
            if (value != null) {
                contextMap.put(key, value);
                //no longer wrapping; let FM do it if needed, more efficient
                //root.put(key, FreeMarkerWorker.getDefaultOfbizWrapper().wrap(value));
                root.put(key, value);
            }
        }
        root.put("context", FreeMarkerWorker.getDefaultOfbizWrapper().wrap(contextMap));
        root.put("cachedInclude", new JpCacheIncludeTransform()); // only adding this in for JP!
        //root.put("jpublishContext", FreeMarkerWorker.getDefaultOfbizWrapper().wrap(context));
        FreeMarkerViewHandler.prepOfbizRoot(root, request, response);
    } catch (Exception e) {
        throw new ViewRenderException(e);
    }
    return root;
}