Search in sources :

Example 6 with ResultBuffer

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

the class FnDistinctValues method distinct_values.

/**
 * Distinct-values operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:distinct-values operation.
 */
public static ResultSequence distinct_values(Collection args, DynamicContext context) throws DynamicError {
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = ResultBuffer.EMPTY;
    if (citer.hasNext()) {
        arg2 = (ResultSequence) citer.next();
    }
    String collationURI = context.getCollationProvider().getDefaultCollation();
    if (!arg2.empty()) {
        XSString collation = (XSString) arg2.item(0);
        collationURI = collation.getStringValue();
    }
    for (Iterator iter = arg1.iterator(); iter.hasNext(); ) {
        AnyAtomicType atomizedItem = (AnyAtomicType) FnData.atomize((Item) iter.next());
        if (!contains(rs, atomizedItem, context, collationURI))
            rs.add(atomizedItem);
    }
    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) Iterator(java.util.Iterator) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 7 with ResultBuffer

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

the class FnID method processChildNodes.

private static void processChildNodes(Node node, List idrefs, ResultBuffer rs, EvaluationContext context) {
    if (!node.hasChildNodes()) {
        return;
    }
    NodeList nodeList = node.getChildNodes();
    for (int nodecnt = 0; nodecnt < nodeList.getLength(); nodecnt++) {
        Node childNode = nodeList.item(nodecnt);
        if (childNode.getNodeType() == Node.ELEMENT_NODE && !isDuplicate(childNode, rs)) {
            ElementType element = new ElementType((Element) childNode, context.getStaticContext().getTypeModel());
            if (element.isID()) {
                if (hasIDREF(idrefs, childNode)) {
                    rs.add(element);
                }
            }
            processAttributes(childNode, idrefs, rs, context);
            processChildNodes(childNode, idrefs, rs, context);
        }
    }
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 8 with ResultBuffer

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

the class FnID method id.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence id(Collection args, EvaluationContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argIt = cargs.iterator();
    ResultSequence idrefRS = (ResultSequence) argIt.next();
    String[] idrefst = idrefRS.first().getStringValue().split(" ");
    ArrayList idrefs = createIDRefs(idrefst);
    ResultSequence nodeArg = null;
    NodeType nodeType = null;
    if (argIt.hasNext()) {
        nodeArg = (ResultSequence) argIt.next();
        nodeType = (NodeType) nodeArg.first();
    } else {
        if (context.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        if (!(context.getContextItem() instanceof NodeType)) {
            throw new DynamicError(TypeError.invalid_type(null));
        }
        nodeType = (NodeType) context.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
        throw DynamicError.contextUndefined();
    // throw DynamicError.noContextDoc();
    }
    if (hasIDREF(idrefs, node)) {
        ElementType element = new ElementType((Element) node, context.getStaticContext().getTypeModel());
        rs.add(element);
    }
    processAttributes(node, idrefs, rs, context);
    processChildNodes(node, idrefs, rs, context);
    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 9 with ResultBuffer

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

the class FnIndexOf method index_of.

/**
 * Index-Of operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dynamicContext
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:index-of operation.
 */
public static ResultSequence index_of(Collection args, DynamicContext dc) {
    Function.convert_arguments(args, expected_args());
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    String collationUri = dc.getCollationProvider().getDefaultCollation();
    if (citer.hasNext()) {
        ResultSequence arg3 = (ResultSequence) citer.next();
        if (!arg3.empty()) {
            XSString collation = (XSString) arg3.first();
            collationUri = collation.getStringValue();
        }
    }
    ResultBuffer rb = new ResultBuffer();
    AnyAtomicType at = (AnyAtomicType) arg2.first();
    get_comparable(at);
    int index = 1;
    for (Iterator i = arg1.iterator(); i.hasNext(); ) {
        AnyType cmptype = (AnyType) i.next();
        get_comparable(cmptype);
        if (!(at instanceof CmpEq))
            continue;
        if (isBoolean(cmptype, at)) {
            XSBoolean boolat = (XSBoolean) cmptype;
            if (boolat.eq(at, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (isNumeric(cmptype, at)) {
            NumericType numericat = (NumericType) at;
            if (numericat.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (isDuration(cmptype, at)) {
            XSDuration durat = (XSDuration) at;
            if (durat.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (at instanceof QName && cmptype instanceof QName) {
            QName qname = (QName) at;
            if (qname.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (needsStringComparison(cmptype, at)) {
            XSString xstr1 = new XSString(cmptype.getStringValue());
            XSString itemStr = new XSString(at.getStringValue());
            if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).equals(BigInteger.ZERO)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        }
        index++;
    }
    return rb.getSequence();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) 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) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 10 with ResultBuffer

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

the class FnStringToCodepoints method string_to_codepoints.

/**
 * Base-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:base-uri operation.
 */
public static ResultSequence string_to_codepoints(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    XSString xstr = (XSString) arg1.first();
    CodePointIterator cpi = new StringCodePointIterator(xstr.value());
    ResultBuffer rs = new ResultBuffer();
    for (int codePoint = cpi.current(); codePoint != CodePointIterator.DONE; codePoint = cpi.next()) {
        rs.add(new XSInteger(BigInteger.valueOf(codePoint)));
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) CodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.CodePointIterator) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator)

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