当前位置: 首页>>代码示例>>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;未经允许,请勿转载。