use of freemarker.template.SimpleSequence in project freemarker by apache.
the class VisitNode method accept.
@Override
TemplateElement[] accept(Environment env) throws IOException, TemplateException {
TemplateModel node = targetNode.eval(env);
if (!(node instanceof TemplateNodeModel)) {
throw new NonNodeException(targetNode, node, env);
}
TemplateModel nss = namespaces == null ? null : namespaces.eval(env);
if (namespaces instanceof StringLiteral) {
nss = env.importLib(((TemplateScalarModel) nss).getAsString(), null);
} else if (namespaces instanceof ListLiteral) {
nss = ((ListLiteral) namespaces).evaluateStringsToNamespaces(env);
}
if (nss != null) {
if (nss instanceof Environment.Namespace) {
SimpleSequence ss = new SimpleSequence(1);
ss.add(nss);
nss = ss;
} else if (!(nss instanceof TemplateSequenceModel)) {
if (namespaces != null) {
throw new NonSequenceException(namespaces, nss, env);
} else {
// Should not occur
throw new _MiscTemplateException(env, "Expecting a sequence of namespaces after \"using\"");
}
}
}
env.invokeNodeHandlerFor((TemplateNodeModel) node, (TemplateSequenceModel) nss);
return null;
}
use of freemarker.template.SimpleSequence in project freemarker by apache.
the class ListLiteral method _eval.
@Override
TemplateModel _eval(Environment env) throws TemplateException {
SimpleSequence list = new SimpleSequence(items.size());
for (Iterator it = items.iterator(); it.hasNext(); ) {
Expression exp = (Expression) it.next();
TemplateModel tm = exp.eval(env);
if (env == null || !env.isClassicCompatible()) {
exp.assertNonNull(tm, env);
}
list.add(tm);
}
return list;
}
use of freemarker.template.SimpleSequence in project freemarker by apache.
the class RecurseNode method accept.
@Override
TemplateElement[] accept(Environment env) throws IOException, TemplateException {
TemplateModel node = targetNode == null ? null : targetNode.eval(env);
if (node != null && !(node instanceof TemplateNodeModel)) {
throw new NonNodeException(targetNode, node, "node", env);
}
TemplateModel nss = namespaces == null ? null : namespaces.eval(env);
if (namespaces instanceof StringLiteral) {
nss = env.importLib(((TemplateScalarModel) nss).getAsString(), null);
} else if (namespaces instanceof ListLiteral) {
nss = ((ListLiteral) namespaces).evaluateStringsToNamespaces(env);
}
if (nss != null) {
if (nss instanceof TemplateHashModel) {
SimpleSequence ss = new SimpleSequence(1);
ss.add(nss);
nss = ss;
} else if (!(nss instanceof TemplateSequenceModel)) {
if (namespaces != null) {
throw new NonSequenceException(namespaces, nss, env);
} else {
// Should not occur
throw new _MiscTemplateException(env, "Expecting a sequence of namespaces after \"using\"");
}
}
}
env.recurse((TemplateNodeModel) node, (TemplateSequenceModel) nss);
return null;
}
use of freemarker.template.SimpleSequence in project freemarker by apache.
the class BeanModel method values.
public TemplateCollectionModel values() throws TemplateModelException {
List<Object> values = new ArrayList<Object>(size());
TemplateModelIterator it = keys().iterator();
while (it.hasNext()) {
String key = ((TemplateScalarModel) it.next()).getAsString();
values.add(get(key));
}
return new CollectionAndSequence(new SimpleSequence(values, wrapper));
}
use of freemarker.template.SimpleSequence in project entando-core by entando.
the class PagerTag method doStartTag.
@Override
public int doStartTag() throws JspException {
ServletRequest request = this.pageContext.getRequest();
try {
Object object = this.pageContext.getAttribute(this.getListName());
Collection collection = (null != object && object instanceof SimpleSequence) ? ((SimpleSequence) object).toList() : (Collection) object;
if (collection == null) {
_logger.error("There is no list in the request");
} else {
PagerTagHelper helper = new PagerTagHelper();
IPagerVO pagerVo = helper.getPagerVO(collection, this.getPagerId(), this.isPagerIdFromFrame(), this.getMax(), this.isAdvanced(), this.getOffset(), request);
this.pageContext.setAttribute(this.getObjectName(), pagerVo);
}
} catch (Throwable t) {
_logger.error("Error detected during tag initialization", t);
// ApsSystemUtils.logThrowable(e, this, "doStartTag");
throw new JspException("Error detected during tag initialization", t);
}
return EVAL_BODY_INCLUDE;
}
Aggregations