當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。