Search in sources :

Example 41 with ResultBuffer

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

the class FnUnordered method unordered.

/**
 * Unordered operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:unordered operation.
 */
public static ResultSequence unordered(Collection args) throws DynamicError {
    assert args.size() == 1;
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg = (ResultSequence) citer.next();
    if (arg.empty())
        return ResultBuffer.EMPTY;
    // XXX lame
    ArrayList tmp = new ArrayList();
    for (Iterator i = arg.iterator(); i.hasNext(); ) tmp.add(i.next());
    Collections.shuffle(tmp);
    ResultBuffer rb = new ResultBuffer();
    for (Iterator i = tmp.iterator(); i.hasNext(); ) rb.add((AnyType) i.next());
    return rb.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 42 with ResultBuffer

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

the class FnInScopePrefixes method createPrefixResultSet.

private static void createPrefixResultSet(ResultBuffer rs, List prefixList) {
    for (int i = 0; i < prefixList.size(); i++) {
        String prefix = (String) prefixList.get(i);
        rs.add(new XSString(prefix));
    }
}
Also used : XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 43 with ResultBuffer

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

the class FnIDREF method idref.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence idref(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argIt = cargs.iterator();
    ResultSequence idrefRS = (ResultSequence) argIt.next();
    String[] idst = idrefRS.first().getStringValue().split(" ");
    ArrayList ids = createIDs(idst);
    ResultSequence nodeArg = null;
    NodeType nodeType = null;
    if (argIt.hasNext()) {
        nodeArg = (ResultSequence) argIt.next();
        nodeType = (NodeType) nodeArg.first();
    } else {
        if (ec.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        if (!(ec.getContextItem() instanceof NodeType)) {
            throw new DynamicError(TypeError.invalid_type(null));
        }
        nodeType = (NodeType) ec.getContextItem();
        if (nodeType.node_value().getOwnerDocument() == null) {
            throw DynamicError.contextUndefined();
        }
    }
    Node node = nodeType.node_value();
    if (node.getOwnerDocument() == null) {
        // W3C test suite seems to want XPDY0002 here
        throw DynamicError.contextUndefined();
    // throw DynamicError.noContextDoc();
    }
    if (hasID(ids, node)) {
        ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
        rs.add(element);
    }
    rs = processAttributes(node, ids, rs, ec);
    rs = processChildNodes(node, ids, rs, ec);
    return rs.getSequence();
}
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) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 44 with ResultBuffer

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

the class FnIDREF method processAttributes.

private static ResultBuffer processAttributes(Node node, List idrefs, ResultBuffer rs, EvaluationContext ec) {
    if (!node.hasAttributes()) {
        return rs;
    }
    NamedNodeMap attributeList = node.getAttributes();
    for (int atsub = 0; atsub < attributeList.getLength(); atsub++) {
        Attr atNode = (Attr) attributeList.item(atsub);
        NodeType atType = new AttrType(atNode, ec.getStaticContext().getTypeModel());
        if (atType.isID()) {
            if (hasID(idrefs, atNode)) {
                if (!isDuplicate(node, rs)) {
                    ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
                    rs.add(element);
                }
            }
        }
    }
    return rs;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NamedNodeMap(org.w3c.dom.NamedNodeMap) AttrType(org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Attr(org.w3c.dom.Attr)

Example 45 with ResultBuffer

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

the class FnReverse method reverse.

/**
 * Reverse the arguments.
 *
 * @param args
 *            are reversed.
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the reversal of the arguments.
 */
public static ResultSequence reverse(Collection args) throws DynamicError {
    assert args.size() == 1;
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg = (ResultSequence) citer.next();
    if (arg.size() <= 1)
        return arg;
    ResultBuffer rs = new ResultBuffer();
    for (int i = arg.size() - 1; i >= 0; --i) rs.add(arg.item(i));
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) 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