本文整理匯總了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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}