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


Java Environment.getVariable方法代碼示例

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


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

示例1: getWrappedObject

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
* Gets BeanModel from FreeMarker context and returns the object that it wraps.
* @param varName the name of the variable in the FreeMarker context.
* @param env the FreeMarker Environment
*/
public static <T> T getWrappedObject(String varName, Environment env) {
    Object obj = null;
    try {
        obj = env.getVariable(varName);
        if (obj != null) {
            if (obj == TemplateModel.NOTHING) {
                obj = null;
            } else if (obj instanceof BeanModel) {
                BeanModel bean = (BeanModel) obj;
                obj = bean.getWrappedObject();
            } else if (obj instanceof SimpleScalar) {
                obj = obj.toString();
            }
        }
    } catch (TemplateModelException e) {
        Debug.logInfo(e.getMessage(), module);
    }
    return UtilGenerics.<T>cast(obj);
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:25,代碼來源:FreeMarkerWorker.java

示例2: getTemplateVariable

import freemarker.core.Environment; //導入方法依賴的package包/類
private TemplateModel getTemplateVariable(RenderContext context)
{
	Environment environment = template.getEnvironment(context);
	try
	{
		return environment.getVariable("TEMP_" + name); //$NON-NLS-1$
	}
	catch( TemplateModelException e )
	{
		throw new SectionsRuntimeException(e);
	}

}
 
開發者ID:equella,項目名稱:Equella,代碼行數:14,代碼來源:FreemarkerTemplateResult.java

示例3: getRenderContext

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

示例4: getRenderContextGeneric

import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static Map<String, Object> getRenderContextGeneric(Environment env) throws TemplateModelException {
    TemplateModel pcm = env.getVariable("context");
    if (pcm != null && pcm instanceof WrapperTemplateModel) {
        Object obj = ((WrapperTemplateModel) pcm).getWrappedObject();
        if (obj instanceof MapStack) {
            return (Map<String, Object>) obj;
        }
    }
    return null;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:12,代碼來源:CmsRenderUtil.java

示例5: exec

import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 2)
        throw new TemplateModelException("Invalid number of arguements");
    if (!(args.get(0) instanceof TemplateScalarModel))
        throw new TemplateModelException("First argument not an instance of TemplateScalarModel");
    // SCIPIO: This is too limiting...
    //if (!(args.get(1) instanceof BeanModel) && !(args.get(1) instanceof TemplateNumberModel) && !(args.get(1) instanceof TemplateScalarModel))
    //    throw new TemplateModelException("Second argument not an instance of BeanModel nor TemplateNumberModel nor TemplateScalarModel");

    Environment env = FreeMarkerWorker.getCurrentEnvironment();
    BeanModel req = (BeanModel)env.getVariable("request");
    HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();

    // SCIPIO: name should not be escaped
    //String name = ((TemplateScalarModel) args.get(0)).getAsString();
    String name = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
    Object valueModel = args.get(1);
    Object value = null;
    // SCIPIO: Let DeepUnwrap handle this...
    //if (args.get(1) instanceof TemplateScalarModel)
    //    value = ((TemplateScalarModel) args.get(1)).getAsString();
    //if (args.get(1) instanceof TemplateNumberModel)
    //    value = ((TemplateNumberModel) args.get(1)).getAsNumber();
    //if (args.get(1) instanceof BeanModel)
    //    value = ((BeanModel) args.get(1)).getWrappedObject();
    // SCIPIO: NOTE: Unlike this above, this call will avoid the auto-escaping as implemented by Ofbiz (sensitive to DeepUnwrap implementation)
    value = LangFtlUtil.unwrapAlwaysUnlessNull(valueModel);
    
    request.setAttribute(name, value);
    return new SimpleScalar("");
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:33,代碼來源:SetRequestAttributeMethod.java

示例6: exec

import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 2)
        throw new TemplateModelException("Invalid number of arguements");
    if (!(args.get(0) instanceof TemplateScalarModel))
        throw new TemplateModelException("First argument not an instance of TemplateScalarModel");
    // SCIPIO: This is too limiting...
    //if (!(args.get(1) instanceof BeanModel) && !(args.get(1) instanceof TemplateNumberModel) && !(args.get(1) instanceof TemplateScalarModel))
    //    throw new TemplateModelException("Second argument not an instance of BeanModel nor TemplateNumberModel nor TemplateScalarModel");

    Environment env = FreeMarkerWorker.getCurrentEnvironment();
    BeanModel req = (BeanModel)env.getVariable("context");
    Map context = (Map) req.getWrappedObject();

    // SCIPIO: name should not be escaped
    //String name = ((TemplateScalarModel) args.get(0)).getAsString();
    String name = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
    Object valueModel = args.get(1);
    Object value = null;
    // SCIPIO: Let DeepUnwrap handle this...
    //if (args.get(1) instanceof TemplateNumberModel)
    //    value = ((TemplateNumberModel) args.get(1)).getAsNumber();
    //if (args.get(1) instanceof BeanModel)
    //    value = ((BeanModel) args.get(1)).getWrappedObject();
    // SCIPIO: NOTE: Unlike this above, this call will avoid the auto-escaping as implemented by Ofbiz (sensitive to DeepUnwrap implementation)
    value = LangFtlUtil.unwrapAlwaysUnlessNull(valueModel);
            
    context.put(name, value);
    return new SimpleScalar("");
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:31,代碼來源:SetContextFieldTransform.java

示例7: exec

import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 2)
        throw new TemplateModelException("Invalid number of arguments");
    if (!(args.get(0) instanceof TemplateScalarModel))
        throw new TemplateModelException("First argument not an instance of TemplateScalarModel");
    // SCIPIO: This is too limiting
    //if (!(args.get(1) instanceof BeanModel) && !(args.get(1) instanceof TemplateNumberModel) && !(args.get(1) instanceof TemplateScalarModel))
    //    throw new TemplateModelException("Second argument not an instance of BeanModel nor TemplateNumberModel nor TemplateScalarModel");

    Environment env = FreeMarkerWorker.getCurrentEnvironment();
    BeanModel globalContextModel = (BeanModel) env.getVariable("globalContext");
    Map<String, Object> globalContext = (Map<String, Object>) globalContextModel.getWrappedObject();

    String name = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
    Object valueModel = args.get(1);
    Object value = null;
    // SCIPIO: Let DeepUnwrap handle this...
    //if (args.get(1) instanceof TemplateScalarModel)
    //    value = ((TemplateScalarModel) args.get(1)).getAsString();
    //if (args.get(1) instanceof TemplateNumberModel)
    //    value = ((TemplateNumberModel) args.get(1)).getAsNumber();
    //if (args.get(1) instanceof BeanModel)
    //    value = ((BeanModel) args.get(1)).getWrappedObject();
    // SCIPIO: NOTE: Unlike this above, this call will avoid the auto-escaping as implemented by Ofbiz (sensitive to DeepUnwrap implementation)
    value = LangFtlUtil.unwrapAlwaysUnlessNull(valueModel);
    
    globalContext.put(name, value);
    return new SimpleScalar("");
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:32,代碼來源:SetGlobalContextFieldMethod.java

示例8: execBuiltIn

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
 * Executes an arbitrary FTL built-in - non-abstracted version (for optimization only!).
 */
public static TemplateModel execBuiltIn(Template builtInCall, TemplateModel value, TemplateModel[] builtInArgs, Environment env) throws TemplateModelException {
    final int argCount = (builtInArgs != null) ? builtInArgs.length : 0;
    env.setVariable("_scpEbiVal", value);
    for(int i=0; i < argCount; i++) {
        env.setVariable("_scpEbiArg"+i, builtInArgs[i]);
    }
    execFtlCode(builtInCall, env);
    return env.getVariable("_scpEbiRes");
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:13,代碼來源:LangFtlUtil.java

示例9: execFunction

import freemarker.core.Environment; //導入方法依賴的package包/類
/**
 * Executes an arbitrary FTL function - non-abstracted version (for optimization only!).
 */
public static TemplateModel execFunction(Template functionCall, TemplateModel[] args, Environment env) throws TemplateModelException {
    final int argCount = (args != null) ? args.length : 0;
    for(int i=0; i < argCount; i++) {
        env.setVariable("_scpEfnArg"+i, args[i]);
    }
    execFtlCode(functionCall, env);
    return env.getVariable("_scpEfnRes");
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:12,代碼來源:LangFtlUtil.java

示例10: finishedRender

import freemarker.core.Environment; //導入方法依賴的package包/類
@Override
protected void finishedRender(Writer writer, FreemarkerSectionResult result, Environment environment)
{
	if( writer instanceof SectionWriter )
	{
		SectionWriter sWriter = (SectionWriter) writer;
		try
		{
			TemplateModel var = environment.getVariable("PART_READY"); //$NON-NLS-1$
			if( var != null )
			{
				sWriter.addFooterStatements(new ScriptStatement(var.toString()));
			}
			var = environment.getVariable("PART_LOAD"); //$NON-NLS-1$
			if( var != null )
			{
				sWriter.getBody().addEventStatements(JSHandler.EVENT_LOAD, new ScriptStatement(var.toString()));
			}
			var = environment.getVariable("PART_SUBMIT"); //$NON-NLS-1$
			if( var != null )
			{
				sWriter.getBody()
					.addEventStatements(JSHandler.EVENT_PRESUBMIT, new ScriptStatement(var.toString()));
			}
			var = environment.getVariable("PART_HEAD"); //$NON-NLS-1$
			if( var != null )
			{
				sWriter.addHeaderMarkup(var.toString());
			}
			var = environment.getVariable("PART_FUNCTION_DEFINITIONS"); //$NON-NLS-1$
			if( var != null )
			{
				sWriter.addStatements(new ScriptStatement(var.toString()));
			}
			super.finishedRender(sWriter, result, environment);
		}
		catch( TemplateModelException tme )
		{
			throw new SectionsRuntimeException(tme);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:43,代碼來源:PluginFreemarkerFactory.java

示例11: getWriter

import freemarker.core.Environment; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public Writer getWriter(final Writer out, final Map args)
        throws TemplateModelException, IOException {
    final StringBuilder buf = new StringBuilder();
    return new Writer(out) {
        
        @Override
        public void write(char[] cbuf, int off, int len) throws IOException {
            buf.append(cbuf, off, len);
        }
        
        @Override
        public void flush() throws IOException {
            out.flush();
        }
        
        @Override
        public void close() throws IOException {
            try {
                Environment env = FreeMarkerWorker.getCurrentEnvironment();
                BeanModel req = (BeanModel) env.getVariable("request");
                BeanModel res = (BeanModel) env.getVariable("response");
                if (req != null) {
                    final String escapeAs = TransformUtil.getStringArg(args, "escapeAs"); // SCIPIO: new
                    boolean rawParamsDefault = UtilValidate.isNotEmpty(escapeAs) ? true : false; // SCIPIO: if we're post-escaping, we can assume we should get rawParams
                    boolean rawParams = TransformUtil.getBooleanArg(args, "rawParams", rawParamsDefault); // SCIPIO: new
                    boolean strictDefault = UtilValidate.isNotEmpty(escapeAs) ? true : false; // SCIPIO: if we're post-escaping, we can assume we want strict handling
                    final Boolean strict = TransformUtil.getBooleanArg(args, "strict", strictDefault); // SCIPIO: new
                    
                    String contentId = TransformUtil.getStringArg(args, "contentId", rawParams);
                    String viewContent = TransformUtil.getStringArg(args, "viewContent", rawParams);
                    Boolean urlDecode = TransformUtil.getBooleanArg(args, "urlDecode");
                    HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
                    HttpServletResponse response = null;
                    if (res != null) {
                        response = (HttpServletResponse) res.getWrappedObject();
                    }
                    String url = "";
                    if (UtilValidate.isNotEmpty(contentId)) {
                        url = ContentUrlFilter.makeContentAltUrl(request, response, contentId, viewContent, urlDecode);
                    }
                    out.write(TransformUtil.escapeGeneratedUrl(url, escapeAs, strict, env));
                }
            } catch (TemplateModelException e) {
                throw new IOException(e.getMessage());
            }
        }
    };
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:51,代碼來源:OfbizContentAltUrlTransforms.java

示例12: getWriter

import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public Writer getWriter(final Writer out, Map args) {
    final StringBuilder buf = new StringBuilder();

    final Double amount = OfbizAmountTransform.getAmount(args, "amount");
    final String locale = OfbizAmountTransform.getArg(args, "locale");
    final String format = OfbizAmountTransform.getArg(args, "format");

    return new Writer(out) {
        @Override
        public void write(char cbuf[], int off, int len) {
            buf.append(cbuf, off, len);
        }

        @Override
        public void flush() throws IOException {
            out.flush();
        }

        @Override
        public void close() throws IOException {
            try {
                if (Debug.verboseOn()) Debug.logVerbose("parms: " + amount + " " + format + " " + locale, module);
                Locale localeObj = null;
                if (locale.length() < 1) {
                    // Load the locale from the session
                    Environment env = FreeMarkerWorker.getCurrentEnvironment();
                    BeanModel req = (BeanModel) env.getVariable("request");
                    if (req != null) {
                        HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
                        localeObj = UtilHttp.getLocale(request);
                    } else {
                        localeObj = env.getLocale();
                    }
                } else {
                    localeObj = new Locale(locale);
                }
                if (format.equals(OfbizAmountTransform.SPELLED_OUT_FORMAT)) {
                    out.write(UtilFormatOut.formatSpelledOutAmount(amount.doubleValue(), localeObj));
                } else {
                    out.write(UtilFormatOut.formatAmount(amount.doubleValue(), localeObj));
                }
            } catch (TemplateModelException e) {
                throw new IOException(e.getMessage());
            }
        }
    };
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:49,代碼來源:OfbizAmountTransform.java

示例13: getWriter

import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public Writer getWriter(final Writer out, Map args) throws TemplateModelException {
    final StringBuilder buf = new StringBuilder();
    final String escapeAs = TransformUtil.getStringArg(args, "escapeAs"); // SCIPIO: new
    boolean rawParamsDefault = UtilValidate.isNotEmpty(escapeAs) ? true : false; // SCIPIO: if we're post-escaping, we can assume we should get rawParams
    final boolean rawParams = TransformUtil.getBooleanArg(args, "rawParams", rawParamsDefault); // SCIPIO: new
    boolean strictDefault = UtilValidate.isNotEmpty(escapeAs) ? true : false; // SCIPIO: if we're post-escaping, we can assume we want strict handling
    final Boolean strict = TransformUtil.getBooleanArg(args, "strict", strictDefault); // SCIPIO: new
    
    final String imgSize = TransformUtil.getStringArg(args, "variant", rawParams);
    final String uri = TransformUtil.getStringArg(args, "uri", rawParams); // SCIPIO: uri as alternative to nested
    final Boolean urlDecode = TransformUtil.getBooleanArg(args, "urlDecode"); // SCIPIO: new
    final Object ctxPrefixObj = TransformUtil.getBooleanOrStringArg(args, "ctxPrefix", null, false, rawParams); // SCIPIO: new
    
    // SCIPIO: autoVariant params: added 2017-08-08
    final String autoVariant = TransformUtil.getStringNonEscapingArg(args, "autoVariant");
    final Integer imgWidth = TransformUtil.getIntegerArg(args, "width");
    final Integer imgHeight = TransformUtil.getIntegerArg(args, "height");
    final String imgVariantCfg = TransformUtil.getStringNonEscapingArg(args, "variantCfg");
    
    return new Writer(out) {
        @Override
        public void write(char cbuf[], int off, int len) {
            buf.append(cbuf, off, len);
        }

        @Override
        public void flush() throws IOException {
            out.flush();
        }

        @Override
        public void close() throws IOException {
            try {
                Environment env = FreeMarkerWorker.getCurrentEnvironment();
                BeanModel req = (BeanModel)env.getVariable("request");
                HttpServletRequest request = req == null ? null : (HttpServletRequest) req.getWrappedObject();

                // SCIPIO: delegated to our new method
                BeanModel resp = (BeanModel) env.getVariable("response");
                HttpServletResponse response = (resp == null) ? null : (HttpServletResponse) resp.getWrappedObject();
                String ctxPrefix = getContentPathPrefix(ctxPrefixObj, rawParams, env); // SCIPIO: new
                String url = ContentRequestWorker.makeContentLink(request, response, UtilValidate.isNotEmpty(uri) ? uri : buf.toString(), imgSize, null, 
                        ctxPrefix, urlDecode, strict, autoVariant, imgWidth, imgHeight, imgVariantCfg);
                        
                out.write(TransformUtil.escapeGeneratedUrl(url, escapeAs, strict, env));
            } catch (TemplateModelException e) {
                throw new IOException(e.getMessage());
            }
        }
    };
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:53,代碼來源:OfbizContentTransform.java

示例14: getRequest

import freemarker.core.Environment; //導入方法依賴的package包/類
public static HttpServletRequest getRequest(Environment env) throws TemplateModelException {
    WrapperTemplateModel req = (WrapperTemplateModel) env.getVariable("request");
    return (req != null) ? (HttpServletRequest) req.getWrappedObject() : null;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:5,代碼來源:ContextFtlUtil.java

示例15: getResponse

import freemarker.core.Environment; //導入方法依賴的package包/類
public static HttpServletResponse getResponse(Environment env) throws TemplateModelException {
    WrapperTemplateModel req = (WrapperTemplateModel) env.getVariable("response");
    return (req != null) ? (HttpServletResponse) req.getWrappedObject() : null;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:5,代碼來源:ContextFtlUtil.java


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