/* * Special constructor for comparing a variable to 0. */ public TemplateConstraint(TemplateVariable v, InfixReln R) { TemplateTerm t = new TemplateTerm(v.getFormulaType()); t.setParameter(v); TemplateTerm z = TemplateTerm.makeZero(v.getFormulaType()); LHS = t; reln = R; RHS = z; }
private static <T> String applyTemplate(T t, String template) { List<TemplateVariable> vars = TemplateUtil.getVariables(template); Map<String, String> map = genItemFieldMap(t); for (TemplateVariable var : vars) { String name = var.getName(); if (map.containsKey(name)) { var.setValue(map.get(name)); } } return TemplateUtil.getResult(vars, template); }
public static Map<String, Object> listTemplateMethod(ListableBeanFactory applicationContext) { Map<String, TemplateVariable> map = applicationContext.getBeansOfType(TemplateVariable.class); Map<String, Object> freemarkerVariables = new HashMap<String, Object>(); for (Entry<String, TemplateVariable> entry : map.entrySet()) { TemplateVariable variable = entry.getValue(); // System.err.println("key:" + method.getKey() + " method:" + method); freemarkerVariables.put(variable.getKey(), variable); } freemarkerVariables.put("timeAgo", new TimeAgoTemplateMethod()); return freemarkerVariables; }
private static <T> String applyTextPager(long offset, long size, String template, String text) { List<TemplateVariable> vars = TemplateUtil.getVariables(template); for (TemplateVariable var : vars) { String name = var.getName(); if (name.equals("page")) { var.setValue(text); } else if (name.equals("offset")) { var.setValue(String.valueOf(offset)); } else if (name.equals("size")) { var.setValue(String.valueOf(size)); } } return TemplateUtil.getResult(vars, template); }