Java Code Examples for freemarker.template.TemplateModel#toString()

The following examples show how to use freemarker.template.TemplateModel#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformUtil.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: DateRangeDirective.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
		TemplateModel from = FtlUtils.getRequiredParameter(params, PARAMS_FROM);
		TemplateModel to = FtlUtils.getRequiredParameter(params, PARAMS_TO);
		String joiner = FtlUtils.getParameterByString(params, PARAMS_JOINER, "");
		String type = FtlUtils.getParameterByString(params, PARAMS_TYPE, DateType.date.toString());
//		String format = FtlUtils.getParameterByString(params, PARAMS_FORMAT, DateUtil.Date_Only);
		boolean includeEnd = FtlUtils.getParameterByBoolean(params, PARAMS_INCLUDE_END, false);

		List<?> listDatas = null;
		DateType datetype = DateType.valueOf(type);
		String fromStr = from.toString();
		String toStr = to.toString();
		DateInterval interval = DateInterval.in(fromStr, toStr);
		listDatas = interval.getInterval(datetype, 1, includeEnd);
		
		int index = 0;
		for(Object data : listDatas){
			if(loopVars.length>=1)
				loopVars[0] = FtlUtils.wrapAsModel(data);
			if(loopVars.length>=2)
				loopVars[1] = FtlUtils.wrapAsModel(index);
			
			if(index!=0)
				env.getOut().write(joiner);
			
			body.render(env.getOut());
			index++;
		}
	}
 
Example 3
Source File: FtlUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static String getRequiredParameterByString(Map<?, ?> params, String name){
	TemplateModel val = getParameter(params, name, true);
	return val.toString();
}
 
Example 4
Source File: FtlUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static String getParameterByString(Map<?, ?> params, String name, String def){
	TemplateModel attr = getParameter(params, name, false);
	if(attr!=null)
		return attr.toString();
	return def;
}
 
Example 5
Source File: FtlUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static String getParameter(Map<?, ?> params, String name, String defVal){
	TemplateModel val = getParameter(params, name, false);
	if(val==null)
		return defVal;
	return val.toString();
}