Search in sources :

Example 16 with ResultBuffer

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

the class FnTokenize method tokenize.

/**
 * Tokenize operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:tokenize operation.
 */
public static ResultSequence tokenize(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    String str1 = "";
    if (!arg1.empty()) {
        str1 = ((XSString) arg1.first()).value();
    }
    ResultSequence arg2 = (ResultSequence) argiter.next();
    String pattern = ((XSString) arg2.first()).value();
    String flags = null;
    if (argiter.hasNext()) {
        ResultSequence flagRS = null;
        flagRS = (ResultSequence) argiter.next();
        flags = flagRS.first().getStringValue();
        if (validflags.indexOf(flags) == -1 && flags.length() > 0) {
            throw DynamicError.regex_flags_error(null);
        }
    }
    try {
        ArrayList ret = tokenize(pattern, flags, str1);
        for (Iterator retIter = ret.iterator(); retIter.hasNext(); ) {
            rs.add(new XSString((String) retIter.next()));
        }
    } catch (PatternSyntaxException err) {
        throw DynamicError.regex_error(null);
    }
    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) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 17 with ResultBuffer

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

the class OpExcept method op_except.

/**
 * Op-Except operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of operation.
 */
public static ResultSequence op_except(Collection args) throws DynamicError {
    ResultBuffer rs = new ResultBuffer();
    // convert arguments
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arguments
    Iterator iter = cargs.iterator();
    ResultSequence one = (ResultSequence) iter.next();
    ResultSequence two = (ResultSequence) iter.next();
    // XXX lame
    for (Iterator i = one.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        boolean found = false;
        // death
        for (Iterator j = two.iterator(); j.hasNext(); ) {
            NodeType node2 = (NodeType) j.next();
            if (node.node_value() == node2.node_value()) {
                found = true;
                break;
            }
        }
        if (!found)
            rs.add(node);
    }
    rs = NodeType.linarize(rs);
    return rs.getSequence();
}
Also used : 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) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 18 with ResultBuffer

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

the class OpUnion method op_union.

/**
 * Op-Union operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of operation.
 */
public static ResultSequence op_union(Collection args) throws DynamicError {
    ResultBuffer rs = new ResultBuffer();
    // convert arguments
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arguments
    Iterator iter = cargs.iterator();
    ResultSequence one = (ResultSequence) iter.next();
    ResultSequence two = (ResultSequence) iter.next();
    // XXX i don't fink u've ever seen anything lamer than this
    rs.concat(one);
    rs.concat(two);
    rs = NodeType.linarize(rs);
    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) Collection(java.util.Collection)

Example 19 with ResultBuffer

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

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

the class DefaultEvaluator method visit.

/**
 * visit decimal literal.
 *
 * @param e
 *            is the decimal literal.
 * @return a result sequence
 */
public Object visit(DecimalLiteral e) {
    ResultBuffer rs = new ResultBuffer();
    rs.add(e.value());
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer)

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