Search in sources :

Example 1 with DocType

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

the class FnCollection method getCollection.

private static ResultSequence getCollection(String uri, EvaluationContext ec) {
    ResultBuffer rs = new ResultBuffer();
    Map /*<String, List<Document>>*/
    collectionMap = ec.getDynamicContext().getCollections();
    List /*<Document>*/
    docList = (List) collectionMap.get(uri);
    for (int i = 0; i < docList.size(); i++) {
        Document doc = (Document) docList.get(i);
        rs.add(new DocType(doc, ec.getStaticContext().getTypeModel()));
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.w3c.dom.Document) Map(java.util.Map) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 2 with DocType

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

the class DefaultDynamicContext method get_doc.

/**
 * get document
 *
 * @return a ResultSequence from ResultSequenceFactory.create_new()
 * @since 1.1
 */
public ResultSequence get_doc(URI resolved) {
    Document doc = null;
    if (_loaded_documents.containsKey(resolved)) {
        // tried before
        doc = (Document) _loaded_documents.get(resolved);
    } else {
        doc = retrieve_doc(resolved);
        _loaded_documents.put(resolved, doc);
    }
    if (doc == null)
        return null;
    return ResultSequenceFactory.create_new(new DocType(doc, getTypeModel(doc)));
}
Also used : Document(org.w3c.dom.Document) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 3 with DocType

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

the class AbstractPsychoPathWTPTest method setupVariables.

protected DynamicContext setupVariables(DynamicContext dc) {
    dc.add_variable(new QName("x"));
    dc.add_variable(new QName("var"));
    if (domDoc != null) {
        AnyType docType = new DocType(domDoc, dc.getTypeModel(domDoc));
        dc.set_variable(new QName("input-context1"), docType);
        dc.set_variable(new QName("input-context"), docType);
        if (domDoc2 == null) {
            dc.set_variable(new QName("input-context2"), docType);
        } else {
            dc.set_variable(new QName("input-context2"), (AnyType) new DocType(domDoc2, dc.getTypeModel(domDoc2)));
        }
    }
    return dc;
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 4 with DocType

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

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

DocType (org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)8 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)3 Document (org.w3c.dom.Document)3 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)2 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)2 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 DynamicContext (org.eclipse.wst.xml.xpath2.api.DynamicContext)1 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)1 TypeModel (org.eclipse.wst.xml.xpath2.api.typesystem.TypeModel)1 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)1 XPathNode (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathNode)1