當前位置: 首頁>>代碼示例>>Java>>正文


Java Environment.getGlobalVariable方法代碼示例

本文整理匯總了Java中freemarker.core.Environment.getGlobalVariable方法的典型用法代碼示例。如果您正苦於以下問題:Java Environment.getGlobalVariable方法的具體用法?Java Environment.getGlobalVariable怎麽用?Java Environment.getGlobalVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在freemarker.core.Environment的用法示例。


在下文中一共展示了Environment.getGlobalVariable方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getContextFromEnvironment

import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static MapStack<String> getContextFromEnvironment(Environment env) {
    if (env != null) {
        try {
            TemplateModel model = env.getGlobalVariable("context");
            if (model != null && model instanceof WrapperTemplateModel) {
                Object obj = ((WrapperTemplateModel) model).getWrappedObject();
                if (obj instanceof MapStack) {
                    return (MapStack<String>) obj;
                }
            }
        } catch (Exception e) {
            ;
        }
    }
    return null;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:18,代碼來源:FtlContextFetcher.java

示例2: 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

示例3: getMainNsOrGlobalVar

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
 * Gets a var from main namespace with fallback on globals/data-model, or null if doesn't exit or null.
 * <p>
 * Avoids local variables and emulates a simple Freemarker var read in the main namespace.
 * <p>
 * Similar to {@link freemarker.core.Environment.getVariable(String)} but skips local
 * variables and always main namespace instead of current namespace.
 * <p>
 * NOTE: This probably makes the most sense to call from transforms as a means to read
 * "context/global" variables (using term loosely, while providing possibility for
 * templates to override using both #assign and #global directives.
 */
public static TemplateModel getMainNsOrGlobalVar(String name, Environment env) throws TemplateModelException {
    TemplateModel result = env.getMainNamespace().get(name);
    if (result == null) {
        result = env.getGlobalVariable(name);
    }
    return result;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:20,代碼來源:LangFtlUtil.java

示例4: getCurrentNsOrGlobalVar

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
 * Gets a var from current namespace with fallback on globals/data-model, or null if doesn't exit or null.
 * <p>
 * Avoids local variables and emulates a simple Freemarker var read in the current namespace.
 * <p>
 * Similar to {@link freemarker.core.Environment.getVariable(String)} but skips local
 * variables.
 */
public static TemplateModel getCurrentNsOrGlobalVar(String name, Environment env) throws TemplateModelException {
    TemplateModel result = env.getCurrentNamespace().get(name);
    if (result == null) {
        result = env.getGlobalVariable(name);
    }
    return result;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:16,代碼來源:LangFtlUtil.java

示例5: getFtlContextGlobalVar

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
 * Abstracted method to retrieve a "context/global" var (loosely-defined) from the Freemarker environment.
 * At minimum, always include Freemarker globals and data model, encompassing Ofbiz context and globalContext.
 * In addition - SUBJECT TO CHANGE - may read from current or main namespace.
 * <p>
 * NOTE: 2016-10-13: Currently this only reads from globals and data model, ignoring main
 * and current namespaces. So it will only respond to changes made using #global directive and not #assign.
 * TODO: REVIEW: We will start with this more restrictive/safer behavior first and see in future if main
 * or current namespace should be considered. This should be made to match the FTL macro implementations.
 * Some of the more common variable names (such as "locale") can cause problematic conflicts.
 * 
 * @see freemarker.core.Environment#getGlobalVariable(String)
 * @see com.ilscipio.scipio.ce.webapp.ftl.lang.LangFtlUtil#getMainNsOrGlobalVar(String, Environment)
 * @see com.ilscipio.scipio.ce.webapp.ftl.lang.LangFtlUtil#getCurrentNsOrGlobalVar(String, Environment)
 */
public static TemplateModel getFtlContextGlobalVar(String name, Environment env) throws TemplateModelException {
    //return LangFtlUtil.getMainNsOrGlobalVar(name, env);
    return env.getGlobalVariable(name);
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:20,代碼來源:TransformUtil.java

示例6: getContextLocale

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
 * Attempts to get the current "user" or "screen" locale normally found in screen context
 * as the simple "locale" variable.
 * TODO: REVIEW: this is currently using getGlobalVariable as most likely the fastest that
 * will avoid problems from macros - unclear if more or less reliable than trying to read
 * out of "context" map (which not guaranteed present).
 */
public static Locale getContextLocale(Environment env) throws TemplateModelException {
    WrapperTemplateModel model = (WrapperTemplateModel) env.getGlobalVariable("locale");
    if (model != null) return (Locale) ((WrapperTemplateModel) model).getWrappedObject();
    return null;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:13,代碼來源:ContextFtlUtil.java


注:本文中的freemarker.core.Environment.getGlobalVariable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。