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


Java Environment.getCurrentEnvironment方法代碼示例

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


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

示例1: getCurrentEnvironment

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
 * SCIPIO: Returns the Freemarker environment associated with current thread, or null
 * if no rendering.
 * <em>All transforms should use this call instead of <code>Environment.getCurrentEnvironment</code> directly!</em>
 * <p>
 * <strong>IMPORTANT</strong>: This exists as a workaround for quirks in Freemarker/Ofbiz rendering.
 * Normally calling <code>Environment.getCurrentEnvironment</code> should be enough,
 * but Ofbiz macro renderer uses <code>Environment.include</code> to render macros as opposed to 
 * <code>Environment.process</code>, and in those cases the calls return null and inevitable crash.
 * So a patch to the renderer is required so the environment is accessible from macros, and
 * all transforms must use this method. This method uses a second local source for Environment.
 * <p>
 * <em>2015-12-15</em>: we now give our local source environment priority over the Freemarker source
 * because of problems rendering nested screens (otherwise may inadvertently return the wrong env).
 * Really the Freemarker one should have priority, but this order prevents more problems in practice
 * at current time (there is rarely/never a subscreen call done from the templates included
 * by #includeTemplate method below).
 * <p>
 * On top, an extra fix is added to {@link #renderTemplate(Template, Map, Appendable)} to
 * try to make it so - as much as possible - at most one of threadEnv OR the Freemarker-saved env
 * is non-null at any given time. We cannot guarantee this but this should cover most cases in Ofbiz.
 * 
 * @see #includeTemplate
 * @see #renderTemplate(Template, Map, Appendable)
 */
public static Environment getCurrentEnvironment() {
    Environment env = threadEnv.get();
    if (env == null) {
        env = Environment.getCurrentEnvironment();
    }
    return env;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:33,代碼來源:FreeMarkerWorker.java


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