Search in sources :

Example 6 with ElementType

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

the class DefaultEvaluator method visit.

/**
 * visit element test.
 *
 * @param e
 *            is the element test.
 * @return a result sequence
 */
public Object visit(ElementTest e) {
    // filter out all elements
    ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, ElementType.class);
    // match the name if it's not a wild card
    ResultBuffer rb = new ResultBuffer();
    QName nameTest = e.name();
    QName typeTest = e.type();
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        if (nameTest != null && !e.wild()) {
            // skip if there's a name test and the name does not match
            if (!name_test((ElementType) node, nameTest, "element"))
                continue;
        }
        if (typeTest != null) {
            // check if element derives from
            if (!derivesFrom(node, typeTest))
                continue;
            // nilled may be true or false
            if (!e.qmark()) {
                XSBoolean nilled = (XSBoolean) node.nilled().first();
                if (nilled.value())
                    continue;
            }
        }
        rb.add(node);
    }
    ((Pair) _param)._two = rb.getSequence();
    return ((Pair) _param)._two;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 7 with ElementType

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

the class DefaultEvaluator method visit.

/**
 * visit document test.
 *
 * @param e
 *            is the document test.
 * @return result sequence
 */
public Object visit(DocumentTest e) {
    ResultSequence arg = (ResultSequence) ((Pair) _param)._two;
    int type = e.type();
    // filter doc nodes
    ResultSequence rs = kind_test(arg, DocType.class);
    if (type == DocumentTest.NONE)
        return rs;
    // the element test
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        DocType doc = (DocType) i.next();
        int elem_count = 0;
        ElementType elem = null;
        // make sure doc has only 1 element
        NodeList children = doc.node_value().getChildNodes();
        for (int j = 0; j < children.getLength(); j++) {
            Node child = children.item(j);
            // bingo
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                elem_count++;
                if (elem_count > 1)
                    break;
                elem = new ElementType((Element) child, _sc.getTypeModel());
            }
        }
        // this doc is no good... send him to hell
        if (elem_count != 1) {
            i.remove();
            continue;
        }
        assert elem != null;
        // setup parameter for element test
        ResultSequence res = new ResultBuffer.SingleResultSequence(elem);
        _param = new Pair("element", res);
        // do name test
        res = null;
        if (type == DocumentTest.ELEMENT)
            res = (ResultSequence) e.elem_test().accept(this);
        else if (type == DocumentTest.SCHEMA_ELEMENT)
            res = (ResultSequence) e.schema_elem_test().accept(this);
        else
            assert false;
        // check if element survived nametest
        if (res.size() != 1)
            i.remove();
    }
    return rs;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeList(org.w3c.dom.NodeList) XPathNode(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 8 with ElementType

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

the class DefaultEvaluator method visit.

/**
 * visit schema element test.
 *
 * @param e
 *            is the schema element test.
 * @return a result sequence
 */
public Object visit(SchemaElemTest e) {
    // filter out all elements
    ResultSequence rs = kind_test((ResultSequence) ((Pair) _param)._two, ElementType.class);
    // match the name
    // XXX substitution groups
    QName name = e.name();
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        if (!name_test((ElementType) i.next(), name, "element"))
            i.remove();
    }
    // check the type
    TypeDefinition et = _sc.getTypeModel().lookupElementDeclaration(name.namespace(), name.local());
    for (Iterator i = rs.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        if (!derivesFrom(node, et)) {
            i.remove();
            continue;
        }
        XSBoolean nilled = (XSBoolean) node.nilled().first();
        // XXX or, in schema it is nillable
        if (nilled.value())
            i.remove();
    }
    return rs;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair) TypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)

Example 9 with ElementType

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

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

Aggregations

ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)19 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)8 Node (org.w3c.dom.Node)8 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)7 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 NodeList (org.w3c.dom.NodeList)5 Collection (java.util.Collection)4 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)4 Element (org.w3c.dom.Element)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 ListIterator (java.util.ListIterator)3 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)3 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)3 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)3 Attr (org.w3c.dom.Attr)3 List (java.util.List)2 XSModel (org.apache.xerces.xs.XSModel)2 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)2