本文整理汇总了Java中freemarker.template.TemplateScalarModel类的典型用法代码示例。如果您正苦于以下问题:Java TemplateScalarModel类的具体用法?Java TemplateScalarModel怎么用?Java TemplateScalarModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateScalarModel类属于freemarker.template包,在下文中一共展示了TemplateScalarModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
/**
* @see freemarker.template.TemplateMethodModel#exec(java.util.List)
*/
public Object exec(List args) throws TemplateModelException
{
Object result = null;
if (args.size() == 1)
{
Object arg0 = args.get(0);
if (arg0 instanceof TemplateDateModel)
{
result = ISO8601DateFormat.format(((TemplateDateModel)arg0).getAsDate());
}
else if (arg0 instanceof TemplateScalarModel)
{
result = ISO8601DateFormat.parse(((TemplateScalarModel)arg0).getAsString());
}
}
return result != null ? result : "";
}
示例2: exec
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
/**
* @see freemarker.template.TemplateMethodModel#exec(java.util.List)
*/
public Object exec(List args) throws TemplateModelException
{
String result = "";
if (args.size() != 0)
{
String s = "";
Object arg0 = args.get(0);
if (arg0 instanceof TemplateScalarModel)
{
s = ((TemplateScalarModel)arg0).getAsString();
}
if (s != null)
{
result = URLDecoder.decode(s);
}
}
return result;
}
示例3: getArg
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static String getArg(Map args, String key) {
String result = "";
Object o = args.get(key);
if (o != null) {
if (Debug.verboseOn()) Debug.logVerbose("Arg Object : " + o.getClass().getName(), module);
if (o instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) o;
try {
// SCIPIO: This should bypass auto-escaping
result = LangFtlUtil.getAsStringNonEscaping(s);
} catch (TemplateModelException e) {
Debug.logError(e, "Template Exception", module);
}
} else {
result = o.toString();
}
}
return result;
}
示例4: getArg
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static String getArg(Map args, String key) {
String result = "";
Object o = args.get(key);
if (o != null) {
if (Debug.verboseOn()) Debug.logVerbose("Arg Object : " + o.getClass().getName(), module);
if (o instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) o;
try {
// SCIPIO: bypass auto-escaping on this
//result = s.getAsString();
result = LangFtlUtil.getAsStringNonEscaping(s);
} catch (TemplateModelException e) {
Debug.logError(e, "Template Exception", module);
}
} else {
result = o.toString();
}
}
return result;
}
示例5: getBooleanArg
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
/**
* Gets boolean arg.
* <p>
* Will automatically interpret string true/false as boolean.
*/
public static Boolean getBooleanArg(TemplateModel obj, Boolean defaultValue) throws TemplateModelException {
if (obj instanceof TemplateBooleanModel) {
return ((TemplateBooleanModel) obj).getAsBoolean();
}
else if (obj instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) obj;
String val = s.getAsString();
// SCIPIO: empty check is desirable and makes it so caller can request default by specifying ""
if (!val.isEmpty()) {
return "true".equalsIgnoreCase(s.getAsString());
}
} else if (obj != null) {
throw new TemplateModelException("Expected boolean model or string model representation of boolean, but got a " +
obj.getClass() + " instead");
}
return defaultValue;
}
示例6: getStringArg
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
/**
* Gets string arg.
* <p>
* If number or date passed, will be coerced to string. Other types such as maps or lists
* will throw TemplateModelException.
*/
public static String getStringArg(TemplateModel obj, String defaultValue, boolean useDefaultWhenEmpty, boolean nonEscaping) throws TemplateModelException {
String result = null;
if (obj instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) obj;
result = LangFtlUtil.getAsString(s, nonEscaping);
} else if (obj == null) {
return defaultValue;
} else if (obj instanceof TemplateNumberModel || obj instanceof TemplateDateModel) {
// TODO: optimize this call
result = LangFtlUtil.execStringBuiltIn(obj, FreeMarkerWorker.getCurrentEnvironment()).getAsString();
} else {
throw new TemplateModelException("Expected string model or something coercible to string, but got a " +
obj.getClass() + " instead");
}
if (useDefaultWhenEmpty && result.isEmpty()) {
return defaultValue;
}
return result;
}
示例7: getBooleanOrStringArg
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
public static Object getBooleanOrStringArg(TemplateModel obj, Object defaultValue, boolean useDefaultWhenEmpty, boolean nonEscaping) throws TemplateModelException {
Object result = null;
if (obj instanceof TemplateBooleanModel) {
return ((TemplateBooleanModel) obj).getAsBoolean();
} else if (obj instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) obj;
result = LangFtlUtil.getAsString(s, nonEscaping);
} else if (obj != null) {
result = obj.toString();
} else {
return defaultValue;
}
if (useDefaultWhenEmpty && (result instanceof String) && ((String) result).isEmpty()) {
return defaultValue;
}
return result;
}
示例8: getIntegerArg
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
/**
* Gets integer arg.
* <p>
* If string passed, will be parsed as integer. Other types such as maps or lists
* will throw TemplateModelException.
*/
public static Integer getIntegerArg(TemplateModel obj, Integer defaultValue) throws TemplateModelException, NumberFormatException {
if (obj instanceof TemplateNumberModel) {
return ((TemplateNumberModel) obj).getAsNumber().intValue();
} else if (obj instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) obj;
String strResult = LangFtlUtil.getAsString(s, true);
if (strResult.isEmpty()) {
return defaultValue;
} else {
return Integer.parseInt(strResult);
}
} else if (obj == null) {
return defaultValue;
} else {
throw new TemplateModelException("Expected integer model or string representing of integer, but got a " +
obj.getClass() + " instead");
}
}
示例9: exec
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object exec(List args) throws TemplateModelException {
if (args == null || args.size() != 1) {
throw new TemplateModelException("Invalid number of arguments (expected: 1)");
}
TemplateModel nameModel = (TemplateModel) args.get(0);
if (!(nameModel instanceof TemplateScalarModel)) {
throw new TemplateModelException("First argument not an instance of TemplateScalarModel (string)");
}
Environment env = CommonFtlUtil.getCurrentEnvironment();
Object res = ContextFtlUtil.getRequestVar(LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) nameModel)), env);
ObjectWrapper objectWrapper = getResultObjectWrapper(env);
return LangFtlUtil.wrap(res, objectWrapper);
}
示例10: execPush
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Object execPush(List args, boolean setLast) throws TemplateModelException {
if (args == null || args.size() != 2) {
throw new TemplateModelException("Invalid number of arguments (expected: 2)");
}
TemplateModel nameModel = (TemplateModel) args.get(0);
if (!(nameModel instanceof TemplateScalarModel)) {
throw new TemplateModelException("First argument not an instance of TemplateScalarModel (string)");
}
TemplateModel valueModel = (TemplateModel) args.get(1);
Environment env = CommonFtlUtil.getCurrentEnvironment();
ContextFtlUtil.pushRequestStack(LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) nameModel)), valueModel, setLast, env);
return new SimpleScalar("");
}
示例11: execRead
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Object execRead(List args, boolean pop) throws TemplateModelException {
if (args == null || args.size() != 1) {
throw new TemplateModelException("Invalid number of arguments (expected: 1)");
}
TemplateModel nameModel = (TemplateModel) args.get(0);
if (!(nameModel instanceof TemplateScalarModel)) {
throw new TemplateModelException("First argument not an instance of TemplateScalarModel (string)");
}
Environment env = CommonFtlUtil.getCurrentEnvironment();
Object res = ContextFtlUtil.readRequestStack(LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) nameModel)), pop, env);
ObjectWrapper objectWrapper = GetRequestVarMethod.getResultObjectWrapper(env);
return LangFtlUtil.wrap(res, objectWrapper);
}
示例12: exec
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
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 (string)");
if (!(args.get(1) instanceof TemplateScalarModel))
throw new TemplateModelException("Second argument not an instance of TemplateScalarModel (string)");
String resource = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
String name = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(1)));
String res = UtilProperties.getPropertyValue(resource, name);
// here we do opposite of UtilProperties and return null if empty, so ! operator can work
if (res != null && res.isEmpty()) {
res = null;
}
// Prevent escaping by EscapingObjectWrapper - values from properties are always coded
// by trusted people
return LangFtlUtil.wrapNonEscaping(res);
}
示例13: exec
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object exec(List args) throws TemplateModelException {
if (args == null || args.size() != 2) {
throw new TemplateModelException("Invalid number of arguments (expected: 2)");
}
String styleString = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
styleString = TemplateFtlUtil.getPlainClassArgNames(styleString);
String prefix = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(1)));
String[] names = StringUtils.split(styleString, ' ');
// NOTE: For emergency/safety reasons, use the current wrapper, which MAY be escaping.
// style strings contain only simple characters anyway.
ObjectWrapper objectWrapper = LangFtlUtil.getCurrentObjectWrapper();
SimpleSequence res = new SimpleSequence(names.length, objectWrapper);
for(String name : names) {
if (name.startsWith(prefix)) {
res.add(name);
}
}
// redundant
//return LangFtlUtil.wrap(res, objectWrapper);
return res;
}
示例14: execute
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
String name = null;
TemplateModel paramValue = (TemplateModel) params.get("name");
if (paramValue != null) {
name = ((TemplateScalarModel) paramValue).getAsString();
}
if (name == null || "".equals(name)) {
return;
}
try {
String url = fisRes.require(name);
} catch (FisException e) {
throw new TemplateException(e.getMessage(), e, env);
}
}
示例15: getLong
import freemarker.template.TemplateScalarModel; //导入依赖的package包/类
public static Long getLong(String name, Map<String, TemplateModel> params)
throws TemplateException {
TemplateModel model = params.get(name);
if (model == null) {
return null;
}
if (model instanceof TemplateScalarModel) {
String s = ((TemplateScalarModel) model).getAsString();
if (StringUtils.isBlank(s)) {
return null;
}
try {
return Long.parseLong(s);
} catch (NumberFormatException e) {
throw new MustNumberException(name);
}
} else if (model instanceof TemplateNumberModel) {
return ((TemplateNumberModel) model).getAsNumber().longValue();
} else {
throw new MustNumberException(name);
}
}