@Override public Object exec(List arguments) throws TemplateModelException { if (arguments.size() != 2) { throw new TemplateModelException("getCharactersByGroup needs two arguments - page and group"); } try { Page page = (Page) DeepUnwrap.unwrap((TemplateModel) arguments.get(0)); TemplateScalarModel groupScalar = (TemplateScalarModel) arguments.get(1); return objectWrapper.wrap(getCharactersByGroup(page, groupScalar.getAsString())); } catch (ClassCastException e) { throw new TemplateModelException("Error: Expecting Page and String arguments"); } }
static String getString(TemplateScalarModel model, Expression expr, Environment env) throws TemplateException { String value = model.getAsString(); if (value == null) { if (env.isClassicCompatible()) { return ""; } else { throw new TemplateException(expr + " evaluated to null string.", env); } } return value; }