Search in sources :

Example 11 with ResultBuffer

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

the class FnRemove method remove.

/**
 * Remove operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:remove operation.
 */
public static ResultSequence remove(Collection args) throws DynamicError {
    assert args.size() == 2;
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence target = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg2.first();
    if (!(at instanceof XSInteger))
        DynamicError.throw_type_error();
    int position = ((XSInteger) at).int_value().intValue();
    if (position < 1)
        return target;
    if (position > target.size())
        return target;
    if (target.empty())
        return rs.getSequence();
    int curpos = 1;
    for (Iterator i = target.iterator(); i.hasNext(); ) {
        at = (AnyType) i.next();
        if (curpos != position)
            rs.add(at);
        curpos++;
    }
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator)

Example 12 with ResultBuffer

use of org.eclipse.wst.xml.xpath2.api.ResultBuffer 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 13 with ResultBuffer

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

the class PrecedingAxis method iterate.

// XXX DOCUMENT ORDER.... dunno
/**
 * returns preceding nodes of the context node
 *
 * @param node
 *            is the node type.
 * @throws dc
 *             is the Dynamic context.
 */
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);
        // if we got a parent, we gotta repeat the story for the parent
        // and add the results
        iterate(parent, result, limitNode);
    }
    // get the following siblings of this node, and add them
    PrecedingSiblingAxis psa = new PrecedingSiblingAxis();
    ResultBuffer siblingBuffer = new ResultBuffer();
    psa.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);
    }
}
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 14 with ResultBuffer

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

the class PrecedingSiblingAxis method iterate.

// XXX again, unify with following
/**
 * returns preceding nodes 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) {
    // XXX check for attribute / namespace node... if so return
    // empty sequence
    int pos = copyInto.size();
    Node iterNode = node.node_value();
    // get the children of the parent [siblings]
    do {
        iterNode = iterNode.getPreviousSibling();
        if (iterNode != null) {
            NodeType nodeType = NodeType.dom_to_xpath(iterNode, node.getTypeModel());
            if (nodeType != null) {
                copyInto.addAt(pos, nodeType);
            }
        }
    } while (iterNode != null);
}
Also used : Node(org.w3c.dom.Node) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)

Example 15 with ResultBuffer

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

the class FnString method string.

/**
 * String operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:string operation.
 */
public static ResultSequence string(Collection args, EvaluationContext ec) throws DynamicError {
    assert (args.size() == 0 || args.size() == 1);
    ResultSequence arg1 = null;
    if (args.isEmpty()) {
        // support for arity = 0
        return getResultSetForArityZero(ec);
    } else {
        arg1 = (ResultSequence) args.iterator().next();
    }
    // sanity check args
    if (arg1.size() > 1)
        throw new DynamicError(TypeError.invalid_type(null));
    ResultBuffer rs = new ResultBuffer();
    if (arg1.empty()) {
        rs.add(new XSString(""));
    } else {
        Item at = arg1.first();
        rs.add(new XSString(at.getStringValue()));
    }
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

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