本文整理匯總了Java中freemarker.core.Environment.setVariable方法的典型用法代碼示例。如果您正苦於以下問題:Java Environment.setVariable方法的具體用法?Java Environment.setVariable怎麽用?Java Environment.setVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類freemarker.core.Environment
的用法示例。
在下文中一共展示了Environment.setVariable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: reloadValues
import freemarker.core.Environment; //導入方法依賴的package包/類
public static void reloadValues(Map<String, Object> context, Map<String, Object> saveValues, Environment env) {
for (Map.Entry<String, Object> entry: saveValues.entrySet()) {
String key = entry.getKey();
Object o = entry.getValue();
if (o instanceof Map<?, ?>) {
context.put(key, UtilMisc.makeMapWritable(UtilGenerics.checkMap(o)));
} else if (o instanceof List<?>) {
List<Object> list = new ArrayList<Object>();
list.addAll(UtilGenerics.checkList(o));
context.put(key, list);
} else {
context.put(key, o);
}
env.setVariable(key, autoWrap(o, env));
}
}
示例2: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
System.out.println("################# Start env ##"+env);
try {
String check = RandTagProperty(params);
logger.info("## "+JSON.toJSON(params) );
// logger.info("## "+env.getOut());
// if(!"".equals(check))
} catch (Exception e) {
e.printStackTrace();
}
// System.out.println("################# Start params ##" + JSON.toJSON(params)+"- "+params.get("condition")+"- "+params.get("pagesize"));
// System.out.println("################# Start loopVars ##"+JSON.toJSON(loopVars));
List<Map> list = sqlMapper.getDataList(linkMapSql(params));
env.setVariable("list", DEFAULT_WRAPPER.wrap(list));
// 指令內容體不為空
if (body != null) {
// Executes the nested body. Same as <#nested> in FTL, except
// that we use our own writer instead of the current output writer.
// Writer out = env.getOut();
// out.write(env.getTemplate().toString());
body.render(env.getOut().append("<div style='height:50px;width:100px;border:1px solid red'>sss</div>"));
} else {
throw new RuntimeException("missing body");
}
}
示例3: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
SimpleScalar pVar = (SimpleScalar) params.get("var");
List<RetailStore> retailStoreList = retailStores.enabledRetailStores();
if (pVar != null) {
// Sets the result into the current template as if using <#assign
// name=model>.
env.setVariable(pVar.getAsString(), DefaultObjectWrapper.getDefaultInstance().wrap(retailStoreList));
} else {
// Sets the result into the current template as if using <#assign
// name=model>.
env.setVariable("retailStores", DefaultObjectWrapper.getDefaultInstance().wrap(retailStoreList));
}
}
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:19,代碼來源:FetchRetailStoresDirective.java
示例4: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@Override
public void execute(Environment environment, Map map, TemplateModel[] templateModels,
TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_26);
environment.setVariable("blogs", builder.build().wrap(fileUtil.getBlogs()));
templateDirectiveBody.render(environment.getOut());
}
示例5: 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");
}
示例6: 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");
}
示例7: execMacro
import freemarker.core.Environment; //導入方法依賴的package包/類
/**
* Executes an arbitrary FTL macro - non-abstracted version (for optimization only!).
*/
public static void execMacro(Template macroCall, Map<String, TemplateModel> args, Environment env) throws TemplateModelException {
if (args != null) {
for(Map.Entry<String, TemplateModel> entry : args.entrySet()) {
env.setVariable("_scpEfnArg_"+entry.getKey(), entry.getValue());
}
}
execFtlCode(macroCall, env);
}
示例8: setVariables
import freemarker.core.Environment; //導入方法依賴的package包/類
/**
* 設置變量
*
* @param variables
* 變量
* @param env
* Environment
*/
public static void setVariables(Map<String, Object> variables, Environment env) throws TemplateException {
Assert.notNull(variables);
Assert.notNull(env);
for (Entry<String, Object> entry : variables.entrySet()) {
String name = entry.getKey();
Object value = entry.getValue();
if (value instanceof TemplateModel) {
env.setVariable(name, (TemplateModel) value);
} else {
env.setVariable(name, ObjectWrapper.BEANS_WRAPPER.wrap(value));
}
}
}
示例9: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
List<Map> list = categoryMapper.selectCategoryList();
env.setVariable("list", DEFAULT_WRAPPER.wrap(list));
System.out.println("##:"+JSON.toJSON(params));
if (body != null) {
body.render(env.getOut());
} else {
throw new RuntimeException("missing body");
}
}
示例10: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
TemplateModel pValue = (TemplateModel) params.get("value");
SimpleScalar pVar = (SimpleScalar) params.get("var");
if (pVar == null)
throw new IllegalArgumentException("The var parameter cannot be null in set-directive");
String var = pVar.getAsString();
Object value = null;
if (pValue != null) {
if (pValue instanceof StringModel) {
value = ((StringModel) pValue).getWrappedObject();
} else if (pValue instanceof SimpleHash) {
value = ((SimpleHash) pValue).toMap();
} else {
value = DeepUnwrap.unwrap(pValue);
}
} else if (body != null) {
StringWriter sw = new StringWriter();
try {
body.render(sw);
value = sw.toString().trim();
} finally {
IOUtils.closeQuietly(sw);
}
}
env.setVariable(var, DefaultObjectWrapper.getDefaultInstance().wrap(value));
}
示例11: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "deprecation" })
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
if (log.isTraceEnabled()) {
log.trace(params);
}
SimpleNumber width = (SimpleNumber) params.get("width");
SimpleNumber height = (SimpleNumber) params.get("height");
SimpleScalar uri = (SimpleScalar) params.get("uri");
SimpleScalar var = (SimpleScalar) params.get("var");
BeanModel pSource = (BeanModel) params.get("src");
TemplateBooleanModel pParent = (TemplateBooleanModel) params.get("parent");
if (pSource != null && uri != null)
throw new IllegalArgumentException("The parameters 'src' and 'uri' cannot be set at the same time.");
if (pSource == null && uri == null)
throw new IllegalArgumentException("You must provide either a 'src' or 'uri' parameter.");
Product product = null;
String uriStr = null;
boolean fallbackToParent = false;
if (pParent != null) {
fallbackToParent = pParent.getAsBoolean();
}
if (pSource != null) {
if (!(pSource instanceof BeanModel))
throw new IllegalArgumentException("The parameter 'src' must be of type BeanModel (Product)");
Object beanModel = ((BeanModel) pSource).getWrappedObject();
if (beanModel instanceof Product) {
product = (Product) beanModel;
if (product.getMainImage() != null) {
uriStr = product.getMainImage().getPath();
}
if (uriStr == null && product.isVariant() && fallbackToParent) {
Product parent = product.getParent();
if (parent != null && parent.getMainImage() != null) {
uriStr = parent.getMainImage().getPath();
}
}
} else {
throw new IllegalArgumentException("The source-object must be of type Product");
}
}
if (uri != null || uriStr != null) {
if (uri != null) {
uriStr = uri.getAsString();
}
String varStr = null;
if (var != null)
varStr = var.getAsString();
if (!Str.isEmpty(uriStr)) {
String mediaAssetURL = catalogMediaHelper.toMediaAssetURL(uriStr,
width == null ? null : width.getAsNumber().intValue(),
height == null ? null : height.getAsNumber().intValue());
if (varStr != null) {
env.setVariable(varStr, DefaultObjectWrapper.getDefaultInstance().wrap(mediaAssetURL));
} else {
env.getOut().write(mediaAssetURL);
}
}
}
}
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:79,代碼來源:CatalogMediaAssetURLDirective.java
示例12: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
TemplateModel pItem = (TemplateModel) params.get("item");
SimpleScalar pVar = (SimpleScalar) params.get("var");
App app = App.get();
List<NavigationItem> navItems = app.registryGet(NavigationConstant.NAV_ITEMS);
List<Id> navItemIds = app.registryGet(NavigationConstant.NAV_ITEM_IDS);
boolean isActive = false;
String var = null;
if (pVar != null)
var = pVar.getAsString();
if (pItem != null && navItems != null) {
Object navItem = null;
if (pItem instanceof SimpleScalar) {
navItem = ((SimpleScalar) pItem).getAsString();
} else if (pItem instanceof SimpleNumber) {
navItem = Id.valueOf(((SimpleNumber) pItem).getAsNumber());
} else if (pItem instanceof StringModel) {
navItem = ((StringModel) pItem).getWrappedObject();
} else {
navItem = DeepUnwrap.unwrap(pItem);
}
if (navItem instanceof String) {
for (NavigationItem navigationItem : navItems) {
if ((navigationItem.getLabel() != null
&& Str.trimEqualsIgnoreCase((String) navItem, navigationItem.getLabel().str()))
|| Str.trimEqualsIgnoreCase((String) navItem, navigationItem.getDisplayURI())) {
isActive = true;
break;
}
}
} else if (navItem instanceof Id) {
isActive = navItemIds.contains(navItem);
} else if (navItem instanceof NavigationItem) {
isActive = navItemIds.contains(((NavigationItem) navItem).getId());
}
}
if (isActive && Str.isEmpty(var)) {
body.render(env.getOut());
} else {
env.setVariable(var, DefaultObjectWrapper.getDefaultInstance().wrap(isActive));
}
}
示例13: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
if (log.isTraceEnabled()) {
log.trace(params);
}
SimpleScalar pType = (SimpleScalar) params.get("type");
TemplateModel pId = (TemplateModel) params.get("id");
SimpleScalar pVar = (SimpleScalar) params.get("var");
String type = null;
String varName = null;
if (pType != null)
type = pType.getAsString();
if (pVar != null)
varName = pVar.getAsString();
if (pId != null && !Str.isEmpty(type)) {
Object beanModel = null;
if (pId instanceof SimpleScalar)
beanModel = ((SimpleScalar) pId).getAsString();
if (pId instanceof SimpleNumber)
beanModel = ((SimpleNumber) pId).getAsNumber();
else if (pId instanceof StringModel)
beanModel = ((StringModel) pId).getAsString();
else if (pId instanceof NumberModel)
beanModel = ((NumberModel) pId).getAsNumber();
else if (pId instanceof BeanModel)
beanModel = ((BeanModel) pId).getWrappedObject();
Id id = Id.valueOf(beanModel);
Class<? extends Model> modelClass = Models.findBy(type);
if (modelClass != null) {
Object obj = restService.get(modelClass, id);
if (obj != null)
env.setVariable(Str.isEmpty(varName) ? modelClass.getSimpleName() : varName,
DefaultObjectWrapper.getDefaultInstance().wrap(obj));
}
}
}
示例14: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
SimpleScalar pPath = (SimpleScalar) params.get("path");
TemplateModel pTarget = (TemplateModel) params.get("target");
SimpleScalar pVar = (SimpleScalar) params.get("var");
String path = null;
String varName = null;
App app = App.get();
// String path has precedence.
if (pPath != null) {
path = pPath.getAsString();
if (!Str.isEmpty(path) && !Str.SLASH.equals(path.trim())) {
UrlRewrite urlRewrite = urlRewrites.forTargetURI(path);
if (urlRewrite != null) {
String requestPath = ContextObjects.findCurrentLanguage(urlRewrite.getRequestURI());
if (!Str.isEmpty(requestPath))
path = requestPath;
}
}
}
// If no path was set, attempt other objects.
if (path == null && pTarget != null) {
Object target = DeepUnwrap.unwrap(pTarget);
if (target instanceof TargetSupport) {
path = app.helper(TargetSupportHelper.class).findURI((TargetSupport) target);
} else if (target instanceof ContextObject) {
path = ContextObjects.findCurrentLanguageOrGlobal((ContextObject<String>) target);
} else {
path = target.toString();
}
}
// Optionally put the result into a parameters map instead of outputting
// it.
if (pVar != null)
varName = pVar.getAsString();
if (path != null) {
HttpServletResponse response = app.servletResponse();
if (varName != null) {
// Sets the result into the current template as if using
// <#assign name=model>.
env.setVariable(varName, DefaultObjectWrapper.getDefaultInstance().wrap(response.encodeURL(path)));
} else {
// Simply writes the result to the template.
env.getOut().write(response.encodeURL(path));
}
}
}
示例15: setVariable
import freemarker.core.Environment; //導入方法依賴的package包/類
/**
* 設置全局參數
*
* @param name
* @param value
* @param env
* @throws TemplateException
*/
public static void setVariable(String name, Object value, Environment env) throws TemplateException {
if (value instanceof TemplateModel) {
env.setVariable(name, (TemplateModel) value);
} else {
env.setVariable(name, configuration.getObjectWrapper().wrap(value));
}
}