Examples of TemplateSequenceModel


Examples of freemarker.template.TemplateSequenceModel

                return true;
            }
        });

        // TemplateSequenceModel
        params.put("property8", new TemplateSequenceModel() {
            public TemplateModel get(int arg0) throws TemplateModelException {
                return null;
            }

            public int size() throws TemplateModelException {
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

                return true;
            }
        });

        // TemplateSequenceModel
        params.put("property8", new TemplateSequenceModel() {
            public TemplateModel get(int arg0) throws TemplateModelException {
                return null;
            }

            public int size() throws TemplateModelException {
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

        }
        if(model instanceof TemplateBooleanModel) {
            return Boolean.valueOf(((TemplateBooleanModel)model).getAsBoolean());
        }
        if(model instanceof TemplateSequenceModel) {
            TemplateSequenceModel seq = (TemplateSequenceModel)model;
            ArrayList list = new ArrayList(seq.size());
            for(int i = 0; i < seq.size(); ++i) {
                list.add(unwrap(seq.get(i), nullModel, permissive));
            }
            return list;
        }
        if(model instanceof TemplateCollectionModel) {
            TemplateCollectionModel coll = (TemplateCollectionModel)model;
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

     * The special key "/" returns the root document node associated with this element.
     */
    public TemplateModel get(String key) throws TemplateModelException {
        if (key.equals("*")) {
            NodeListModel ns = new NodeListModel(this);
            TemplateSequenceModel children = getChildNodes();
            for (int i=0;i < children.size();i++) {
                NodeModel child = (NodeModel) children.get(i);
                if (child.node.getNodeType() == Node.ELEMENT_NODE) {
                    ns.add(child);
                }
            }
            return ns;
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

        {
            NodeListModel result = new NodeListModel(contextNode);
            for (int i=0; i<size(); i++) {
                NodeModel nm = (NodeModel) get(i);
                if (nm instanceof ElementModel) {
                    TemplateSequenceModel tsm = (TemplateSequenceModel) ((ElementModel) nm).get(key);
                    int size = tsm == null ? 0 : tsm.size();
                    for (int j=0; j < size; j++) {
                        result.add(tsm.get(j));
                    }
                }
            }
            if (result.size() == 1) {
                return result.get(0);
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

    }
   
    public DebugModel[] get(int fromIndex, int toIndex) throws TemplateModelException, RemoteException
    {
        DebugModel[] dm = new DebugModel[toIndex - fromIndex];
        TemplateSequenceModel s = (TemplateSequenceModel)model;
        for (int i = fromIndex; i < toIndex; i++)
        {
            dm[i - fromIndex] = getDebugModel(s.get(i));
        }
        return dm;
    }
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

                                               int index,
                                               Environment env)
        throws TemplateException
    {
        if (targetModel instanceof TemplateSequenceModel) {
            TemplateSequenceModel tsm = (TemplateSequenceModel) targetModel;
            int size;
            try {
                size = tsm.size();
            } catch (Exception e) {
                size = Integer.MAX_VALUE;
            }
            return index < size ? tsm.get(index) : null;
        }
       
        try
        {
            String s = target.evalAndCoerceToString(env);
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

        throw new NonHashException(target, targetModel, env);
    }

    private TemplateModel dealWithRangeKey(TemplateModel targetModel, RangeModel range, Environment env)
    throws UnexpectedTypeException, InvalidReferenceException, TemplateException {
        final TemplateSequenceModel targetSeq;
        final String targetStr;
        if (targetModel instanceof TemplateSequenceModel) {
            targetSeq = (TemplateSequenceModel) targetModel;
            targetStr = null;
        } else {
            targetSeq = null;
            try {
                targetStr = target.evalAndCoerceToString(env);
            } catch(NonStringException e) {
                throw new UnexpectedTypeException(
                        target, target.eval(env),
                        "sequence or " + NonStringException.STRING_COERCABLE_TYPES_DESC,
                        NUMERICAL_KEY_LHO_EXPECTED_TYPES, env);
            }
        }
       
        final int size = range.size();
        final boolean rightUnbounded = range.isRightUnbounded();
        final boolean rightAdaptive = range.isRightAdaptive();
       
        // Right bounded empty ranges are accepted even if the begin index is out of bounds. That's because a such range
        // produces an empty sequence, which thus doesn't contain any illegal indexes.
        if (!rightUnbounded && size == 0) {
            return emptyResult(targetSeq != null);
        }

        final int firstIdx = range.getBegining();
        if (firstIdx < 0) {
            throw new _MiscTemplateException(keyExpression, new Object[] {
                    "Negative range start index (", new Integer(firstIdx),
                    ") isn't allowed for a range used for slicing." });
        }
       
        final int targetSize = targetStr != null ? targetStr.length() : targetSeq.size();
        final int step = range.getStep();
       
        // Right-adaptive increasing ranges can start 1 after the last element of the target, because they are like
        // ranges with exclusive end index of at most targetSize. Thence a such range is just an empty list of indexes,
        // and thus it isn't out-of-bounds.
        // Right-adaptive decreasing ranges has exclusive end -1, so it can't help on a  to high firstIndex.
        // Right-bounded ranges at this point aren't empty, so the right index surely can't reach targetSize.
        if (rightAdaptive && step == 1 ? firstIdx > targetSize : firstIdx >= targetSize) {
            throw new _MiscTemplateException(keyExpression, new Object[] {
                    "Range start index ", new Integer(firstIdx), " is out of bounds, because the sliced ",
                    (targetStr != null ? "string" : "sequence"),
                    " has only ", new Integer(targetSize), " ", (targetStr != null ? "character(s)" : "element(s)"),
                    ". ", "(Note that indices are 0-based)." });
        }
       
        final int resultSize;
        if (!rightUnbounded) {
            final int lastIdx = firstIdx + (size - 1) * step;
            if (lastIdx < 0) {
                if (!rightAdaptive) {
                    throw new _MiscTemplateException(keyExpression, new Object[] {
                            "Negative range end index (", new Integer(lastIdx),
                            ") isn't allowed for a range used for slicing." });
                } else {
                    resultSize = firstIdx + 1;
                }
            } else if (lastIdx >= targetSize) {
                if (!rightAdaptive) {
                    throw new _MiscTemplateException(keyExpression, new Object[] {
                            "Range end index ", new Integer(lastIdx), " is out of bounds, because the sliced ",
                            (targetStr != null ? "string" : "sequence"),
                            " has only ", new Integer(targetSize), " ", (targetStr != null ? "character(s)" : "element(s)"),
                            ". (Note that indices are 0-based)." });
                } else {
                    resultSize = Math.abs(targetSize - firstIdx);
                }
            } else {
                resultSize = size;
            }
        } else {
            resultSize = targetSize - firstIdx;
        }
       
        if (resultSize == 0) {
            return emptyResult(targetSeq != null);
        }
        if (targetSeq != null) {
            ArrayList/*<TemplateModel>*/ list = new ArrayList(resultSize);
            int srcIdx = firstIdx;
            for (int i = 0; i < resultSize; i++) {
                list.add(targetSeq.get(srcIdx));
                srcIdx += step;
            }
            // List items are already wrapped, so the wrapper will be null:
            return new SimpleSequence(list, null);
        } else {
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

                String[] subvars;
                Object obj = args.get(0);
                if (obj instanceof TemplateScalarModel) {
                    subvars = new String[]{((TemplateScalarModel) obj).getAsString()};
                } else if (obj instanceof TemplateSequenceModel) {
                    TemplateSequenceModel seq = (TemplateSequenceModel) obj;
                    int ln = seq.size();
                    subvars = new String[ln];
                    for (int i = 0; i < ln; i++) {
                        Object item = seq.get(i);
                        try {
                            subvars[i] = ((TemplateScalarModel) item)
                                    .getAsString();
                        } catch (ClassCastException e) {
                            if (!(item instanceof TemplateScalarModel)) {
View Full Code Here

Examples of freemarker.template.TemplateSequenceModel

            nodeNamespaces = ss;
        }
        int prevNodeNamespaceIndex = this.nodeNamespaceIndex;
        String prevNodeName = this.currentNodeName;
        String prevNodeNS = this.currentNodeNS;
        TemplateSequenceModel prevNodeNamespaces = nodeNamespaces;
        TemplateNodeModel prevVisitorNode = currentVisitorNode;
        currentVisitorNode = node;
        if (namespaces != null) {
            this.nodeNamespaces = namespaces;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.