本文整理汇总了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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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("");
}
示例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("");
}
示例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("");
}
示例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");
}
示例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");
}
示例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);
}
}
}
示例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());
}
}
};
}
示例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());
}
}
};
}
示例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());
}
}
};
}
示例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;
}
示例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;
}