Search in sources :

Example 6 with SimpleSequence

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;
}
Also used : TemplateSequenceModel(freemarker.template.TemplateSequenceModel) TemplateNodeModel(freemarker.template.TemplateNodeModel) TemplateScalarModel(freemarker.template.TemplateScalarModel) TemplateModel(freemarker.template.TemplateModel) SimpleSequence(freemarker.template.SimpleSequence)

Example 7 with SimpleSequence

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;
}
Also used : Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) TemplateModel(freemarker.template.TemplateModel) SimpleSequence(freemarker.template.SimpleSequence)

Example 8 with SimpleSequence

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;
}
Also used : TemplateSequenceModel(freemarker.template.TemplateSequenceModel) TemplateHashModel(freemarker.template.TemplateHashModel) TemplateNodeModel(freemarker.template.TemplateNodeModel) TemplateScalarModel(freemarker.template.TemplateScalarModel) TemplateModel(freemarker.template.TemplateModel) SimpleSequence(freemarker.template.SimpleSequence)

Example 9 with SimpleSequence

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));
}
Also used : TemplateModelIterator(freemarker.template.TemplateModelIterator) CollectionAndSequence(freemarker.core.CollectionAndSequence) ArrayList(java.util.ArrayList) TemplateScalarModel(freemarker.template.TemplateScalarModel) SimpleSequence(freemarker.template.SimpleSequence)

Example 10 with SimpleSequence

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;
}
Also used : ServletRequest(javax.servlet.ServletRequest) PagerTagHelper(com.agiletec.aps.tags.util.PagerTagHelper) JspException(javax.servlet.jsp.JspException) Collection(java.util.Collection) IPagerVO(com.agiletec.aps.tags.util.IPagerVO) SimpleSequence(freemarker.template.SimpleSequence)

Aggregations

SimpleSequence (freemarker.template.SimpleSequence)12 TemplateModel (freemarker.template.TemplateModel)7 TemplateSequenceModel (freemarker.template.TemplateSequenceModel)6 TemplateScalarModel (freemarker.template.TemplateScalarModel)5 TemplateNodeModel (freemarker.template.TemplateNodeModel)4 TemplateModelIterator (freemarker.template.TemplateModelIterator)3 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 SimpleHash (freemarker.template.SimpleHash)2 SimpleScalar (freemarker.template.SimpleScalar)2 TemplateTransformModel (freemarker.template.TemplateTransformModel)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IPagerVO (com.agiletec.aps.tags.util.IPagerVO)1 PagerTagHelper (com.agiletec.aps.tags.util.PagerTagHelper)1 CollectionAndSequence (freemarker.core.CollectionAndSequence)1 ObjectWrapper (freemarker.template.ObjectWrapper)1 TemplateException (freemarker.template.TemplateException)1 TemplateHashModel (freemarker.template.TemplateHashModel)1 IOException (java.io.IOException)1