/**
* 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;
}
TransformUtil.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:scipio-erp
作者:
评论列表
文章目录