当前位置: 首页>>代码示例>>Java>>正文


Java Environment.setGlobalVariable方法代码示例

本文整理汇总了Java中freemarker.core.Environment.setGlobalVariable方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.setGlobalVariable方法的具体用法?Java Environment.setGlobalVariable怎么用?Java Environment.setGlobalVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在freemarker.core.Environment的用法示例。


在下文中一共展示了Environment.setGlobalVariable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resetRequestVars

import freemarker.core.Environment; //导入方法依赖的package包/类
/**
 * Wipes all request vars and sets a new holder map.
 * <p>
 * Attempts to set the same map for as many contexts present as possible, for compatibility.
 * <p>
 * <em>NOTE:</em> in some cases this call is not necessary, but it's a good idea anyway
 * because it will set the same map for request and context (but not ftl - FIXME?),
 * which might prevent problems in odd rendering cases.
 * This should be called at beginning of rendering at a point where as many of the parameters 
 * are non-null as possible (but env will probably usually be null).
 */
public static void resetRequestVars(HttpServletRequest request, 
        Map<String, Object> context, Environment env) throws TemplateModelException {
    RequestVarMapWrapper mapWrapper = new RequestVarMapWrapper();
    if (request != null) {
        request.setAttribute(ContextFtlUtil.REQUEST_VAR_MAP_NAME_REQATTRIBS, mapWrapper);
    }
    Map<String, Object> globalContext = getGlobalContext(context, env);
    if (globalContext != null) {
        globalContext.put(ContextFtlUtil.REQUEST_VAR_MAP_NAME_GLOBALCONTEXT, mapWrapper);
    }
    if (env != null) {
        // Here we "hide" our variables in freemarker globals
        env.setGlobalVariable(ContextFtlUtil.REQUEST_VAR_MAP_NAME_FTLGLOBALS, new RequestVarMapWrapperModel(mapWrapper.getRawMap()));
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:27,代码来源:ContextFtlUtil.java

示例2: appendFormPageScripts

import freemarker.core.Environment; //导入方法依赖的package包/类
/**
 * SCIPIO: appends special page scripts to macro call.
 * New 2017-04-21.
 */
private void appendFormPageScripts(Appendable writer, Appendable sr, Map<String, Object> context, ModelForm modelForm) throws IOException {
    // SCIPIO: 2017-04-21: special pageScripts
    List<Object> pageScripts = new ArrayList<>();
    for(ModelPageScript pageScript : modelForm.getPageScripts()) {
        pageScripts.add(pageScript.getScript(context));
    }
    Environment env;
    try {
        env = getEnvironment(writer);
        freemarker.template.TemplateModel pageScriptsModel = env.getObjectWrapper().wrap(pageScripts);
        env.setGlobalVariable("_scpFormRenPageScripts", pageScriptsModel);
    } catch (TemplateException e) {
        throw new IOException(e);
    }
    sr.append(" pageScripts=_scpFormRenPageScripts");
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:21,代码来源:MacroFormRenderer.java

示例3: removeRequestVars

import freemarker.core.Environment; //导入方法依赖的package包/类
/**
 * Removes the whole request vars map.
 */
public static void removeRequestVars(HttpServletRequest request, 
        Map<String, Object> context, Environment env) throws TemplateModelException {
    if (request != null) {
        request.removeAttribute(ContextFtlUtil.REQUEST_VAR_MAP_NAME_REQATTRIBS);
    }
    Map<String, Object> globalContext = getGlobalContext(context, env);
    if (globalContext != null) {
        globalContext.remove(ContextFtlUtil.REQUEST_VAR_MAP_NAME_GLOBALCONTEXT);
    }
    if (env != null) {
        env.setGlobalVariable(ContextFtlUtil.REQUEST_VAR_MAP_NAME_FTLGLOBALS, null);
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:17,代码来源:ContextFtlUtil.java

示例4: getRequestVarMapFromFtlGlobals

import freemarker.core.Environment; //导入方法依赖的package包/类
private static Map<String, Object> getRequestVarMapFromFtlGlobals(Environment env) {
    RequestVarMapWrapperModel mapWrapper = null;
    try {
        mapWrapper = (RequestVarMapWrapperModel) env.getGlobalVariable(ContextFtlUtil.REQUEST_VAR_MAP_NAME_FTLGLOBALS);
    } catch (TemplateModelException e) {
        Debug.logError(e, "Scipio: Error getting request var map from FTL globals", module);
    }
    if (mapWrapper == null) {
        // FIXME: should try to get underlying map from request or globalContext
        mapWrapper = new RequestVarMapWrapperModel();
        env.setGlobalVariable(ContextFtlUtil.REQUEST_VAR_MAP_NAME_FTLGLOBALS, mapWrapper);
    }
    return mapWrapper.getRawMap();
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:15,代码来源:ContextFtlUtil.java


注:本文中的freemarker.core.Environment.setGlobalVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。