Search in sources :

Example 36 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class AttributeAxis method iterate.

/**
 * Retrieves the context node's attributes.
 *
 * @param node
 *            is the type of node.
 */
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
    // only elements have attributes
    if (!(node instanceof ElementType))
        return;
    // get attributes
    ElementType elem = (ElementType) node;
    NamedNodeMap attrs = elem.value().getAttributes();
    // add attributes
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        copyInto.add(NodeType.dom_to_xpath(attr, node.getTypeModel()));
    }
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NamedNodeMap(org.w3c.dom.NamedNodeMap) Attr(org.w3c.dom.Attr)

Example 37 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class ChildAxis method addChildren.

protected void addChildren(NodeType node, ResultBuffer copyInto, boolean recurse) {
    NodeList nl = null;
    // only document and element nodes have children
    if (node instanceof DocType) {
        nl = ((DocType) node).value().getChildNodes();
    }
    if (node instanceof ElementType)
        nl = ((ElementType) node).value().getChildNodes();
    // add the children to the result
    if (nl != null) {
        for (int i = 0; i < nl.getLength(); i++) {
            Node dnode = nl.item(i);
            NodeType n = NodeType.dom_to_xpath(dnode, node.getTypeModel());
            if (n != null) {
                copyInto.add(n);
                if (recurse)
                    addChildren(n, copyInto, recurse);
            }
        }
    }
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 38 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class FollowingAxis method iterate.

/**
 * Return the result of FollowingAxis expression
 *
 * @param node
 *            is the type of node.
 */
public void iterate(NodeType node, ResultBuffer result, Node limitNode) {
    if (limitNode != null && limitNode.isSameNode(node.node_value())) {
        // no further, we have reached the limit node
        return;
    }
    // get the parent
    NodeType parent = null;
    ResultBuffer parentBuffer = new ResultBuffer();
    new ParentAxis().iterate(node, parentBuffer, limitNode);
    if (parentBuffer.size() == 1)
        parent = (NodeType) parentBuffer.item(0);
    // get the following siblings of this node, and add them
    FollowingSiblingAxis fsa = new FollowingSiblingAxis();
    ResultBuffer siblingBuffer = new ResultBuffer();
    fsa.iterate(node, siblingBuffer, limitNode);
    // for each sibling, get all its descendants
    DescendantAxis da = new DescendantAxis();
    for (Iterator i = siblingBuffer.iterator(); i.hasNext(); ) {
        result.add((NodeType) i);
        da.iterate((NodeType) i.next(), result, null);
    }
    // and add the results
    if (parent != null) {
        iterate(parent, result, limitNode);
    }
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Iterator(java.util.Iterator)

Example 39 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class ParentAxis method iterate.

/**
 * returns parent accessors of the context node
 *
 * @param node
 *            is the node type.
 * @throws dc
 *             is the Dynamic context.
 */
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
    Node n = node.node_value();
    if (limitNode != null && limitNode.isSameNode(n)) {
        // no further, we have reached the limit node
        return;
    }
    Node parent = findParent(n);
    // if a parent exists... add it
    if (parent != null) {
        NodeType nodeType = NodeType.dom_to_xpath(parent, node.getTypeModel());
        if (nodeType != null) {
            copyInto.add(nodeType);
        }
    }
}
Also used : Node(org.w3c.dom.Node) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)

Example 40 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.

the class FnSubsequence method subsequence.

/**
 * Subsequence operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:subsequence operation.
 */
public static ResultSequence subsequence(Collection args) throws DynamicError {
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence seq = (ResultSequence) citer.next();
    if (seq.empty())
        return ResultBuffer.EMPTY;
    ResultSequence startLoc = (ResultSequence) citer.next();
    ResultSequence length = null;
    if (citer.hasNext()) {
        length = (ResultSequence) citer.next();
    }
    Item at = startLoc.first();
    if (!(at instanceof NumericType)) {
        DynamicError.throw_type_error();
    }
    at = new XSDouble(at.getStringValue());
    int start = (int) ((XSDouble) at).double_value();
    // no of items beyond index >= 1 that are added to the result
    int effectiveNoItems = 0;
    if (length != null) {
        // the 3rd argument is present
        if (length.size() != 1)
            DynamicError.throw_type_error();
        at = length.first();
        if (!(at instanceof NumericType)) {
            DynamicError.throw_type_error();
        }
        at = new XSDouble(at.getStringValue());
        int len = (int) ((XSDouble) at).double_value();
        if (len < 0) {
            DynamicError.throw_type_error();
        }
        if (start <= 0) {
            effectiveNoItems = start + len - 1;
            start = 1;
        } else {
            effectiveNoItems = len;
        }
    } else {
        // 3rd argument is absent
        if (start <= 0) {
            start = 1;
            effectiveNoItems = seq.size();
        } else {
            effectiveNoItems = seq.size() - start + 1;
        }
    }
    // index running parallel to the iterator
    int pos = 1;
    int addedItems = 0;
    if (effectiveNoItems > 0) {
        for (Iterator seqIter = seq.iterator(); seqIter.hasNext(); ) {
            at = (AnyType) seqIter.next();
            if (start <= pos && addedItems < effectiveNoItems) {
                rs.add(at);
                addedItems++;
            }
            pos++;
        }
    }
    return rs.getSequence();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator)

Aggregations

ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)40 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)31 Iterator (java.util.Iterator)26 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)20 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)12 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)11 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)10 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 Item (org.eclipse.wst.xml.xpath2.api.Item)8 Node (org.w3c.dom.Node)8 ListIterator (java.util.ListIterator)7 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)6 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)5 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)5 NodeList (org.w3c.dom.NodeList)5 List (java.util.List)4 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)4 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)4 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)4