Search in sources :

Example 31 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.

the class AncestorAxis method iterate.

/**
 * Get the ancestors of the context node.
 *
 * @param node
 *            is the type of node.
 */
// XXX unify this with descendants axis ?
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
    if (limitNode != null && limitNode.isSameNode(node.node_value()))
        return;
    int before = copyInto.size();
    // get the parent
    super.iterate(node, copyInto, limitNode);
    // no parent
    if (copyInto.size() == before)
        return;
    NodeType parent = (NodeType) copyInto.item(before);
    // get ancestors of parent
    iterate(parent, copyInto, limitNode);
}
Also used : NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)

Example 32 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType 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 33 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType 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 34 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType in project webtools.sourceediting by eclipse.

the class DefaultStaticContext method derives_from.

/**
 * Checks if an XML node derives from a specified type definition.
 *
 * @param at
 *            node actual type.
 * @param et
 *            type definition of expected type.
 * @return true if a derivation exists.
 */
public boolean derives_from(NodeType at, TypeDefinition et) {
    TypeDefinition td = _model.getType(at.node_value());
    short method = 0;
    return td.derivedFromType(et, method);
}
Also used : TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Example 35 with NodeType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType 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)

Aggregations

NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)39 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)23 Iterator (java.util.Iterator)21 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)15 Collection (java.util.Collection)12 Node (org.w3c.dom.Node)12 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)11 ListIterator (java.util.ListIterator)10 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)9 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)9 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)7 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)6 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)5 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 ArrayList (java.util.ArrayList)4 Attr (org.w3c.dom.Attr)4 ForwardAxis (org.eclipse.wst.xml.xpath2.processor.internal.ForwardAxis)3 ParentAxis (org.eclipse.wst.xml.xpath2.processor.internal.ParentAxis)3 ReverseAxis (org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis)3 AttrType (org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType)3