Search in sources :

Example 31 with ResultBuffer

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

the class DefaultEvaluator method visit.

/**
 * visit context item expression.
 *
 * @param e
 *            is the context item expression.
 * @return a result sequence
 */
public Object visit(CntxItemExpr e) {
    ResultBuffer rs = new ResultBuffer();
    AnyType contextItem = focus().context_item();
    if (contextItem == null) {
        report_error(DynamicError.contextUndefined());
    }
    rs.add(contextItem);
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 32 with ResultBuffer

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

the class DefaultEvaluator method root_self_node.

private ResultSequence root_self_node() {
    Axis axis = new SelfAxis();
    ResultBuffer buffer = new ResultBuffer();
    // XXX the cast!!!
    axis.iterate((NodeType) focus().context_item(), buffer, _dc.getLimitNode());
    ResultSequence rs = kind_test(buffer.getSequence(), NodeType.class);
    List records = new ArrayList();
    records.add(rs);
    rs = FnRoot.fn_root(records, _ec);
    return rs;
}
Also used : SelfAxis(org.eclipse.wst.xml.xpath2.processor.internal.SelfAxis) DescendantOrSelfAxis(org.eclipse.wst.xml.xpath2.processor.internal.DescendantOrSelfAxis) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) ParentAxis(org.eclipse.wst.xml.xpath2.processor.internal.ParentAxis) SelfAxis(org.eclipse.wst.xml.xpath2.processor.internal.SelfAxis) ReverseAxis(org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis) DescendantOrSelfAxis(org.eclipse.wst.xml.xpath2.processor.internal.DescendantOrSelfAxis) ForwardAxis(org.eclipse.wst.xml.xpath2.processor.internal.ForwardAxis) Axis(org.eclipse.wst.xml.xpath2.processor.internal.Axis)

Example 33 with ResultBuffer

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

the class DefaultEvaluator method visit.

/**
 * visit variable reference
 *
 * @param e
 *            is the variable reference.
 * @return a result sequence
 */
public Object visit(VarRef e) {
    ResultBuffer rs = new ResultBuffer();
    Object var = getVariable(e.name());
    assert var != null;
    if (var instanceof AnyType) {
        rs.add((AnyType) var);
    } else if (var instanceof ResultSequence) {
        rs.concat((ResultSequence) var);
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 34 with ResultBuffer

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

the class DefaultEvaluator method do_predicate.

// do the predicate for all items in focus
private ResultSequence do_predicate(Collection exprs) {
    ResultBuffer rs = new ResultBuffer();
    Focus focus = focus();
    int original_cp = focus.position();
    // check if predicate is single numeric constant
    if (exprs.size() == 1) {
        Expr expr = (Expr) exprs.iterator().next();
        if (expr instanceof XPathExpr) {
            XPathExpr xpe = (XPathExpr) expr;
            if (xpe.next() == null && xpe.slashes() == 0 && xpe.expr() instanceof FilterExpr) {
                FilterExpr fex = (FilterExpr) xpe.expr();
                if (fex.primary() instanceof IntegerLiteral) {
                    int pos = (((IntegerLiteral) fex.primary()).value().int_value()).intValue();
                    if (pos <= focus.last() && pos > 0) {
                        focus.set_position(pos);
                        rs.add(focus.context_item());
                    }
                    focus.set_position(original_cp);
                    return rs.getSequence();
                }
            }
        }
    }
    // go through all elements
    while (true) {
        // do the predicate
        // XXX saxon doesn't allow for predicates to have
        // commas... but XPath 2.0 spec seems to do
        ResultSequence res = do_expr(exprs.iterator());
        // in the sequence
        if (predicate_truth(res))
            rs.add(focus().context_item());
        if (!focus.advance_cp())
            break;
    }
    // restore
    focus.set_position(original_cp);
    return rs.getSequence();
}
Also used : QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) IfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr) OrExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr) TreatAsExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.TreatAsExpr) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) ParExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr) DivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr) SubExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.SubExpr) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr) RangeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.RangeExpr) InstOfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr) IntersectExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr) IDivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr) AddExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr) CmpExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr) PipeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PipeExpr) BinExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr) MulExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr) Expr(org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr) MinusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) CastableExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr) PlusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PlusExpr) AndExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) CntxItemExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr) ExceptExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr) UnionExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnionExpr) ModExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) IntegerLiteral(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntegerLiteral) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 35 with ResultBuffer

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

the class AncestorAxis method iterate.

/**
 * Get the ancestors of the context node.
 *
 * @param node
 *            is the type of node.
 */
// XXX unify this with descendants axis ?
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
    if (limitNode != null && limitNode.isSameNode(node.node_value()))
        return;
    int before = copyInto.size();
    // get the parent
    super.iterate(node, copyInto, limitNode);
    // no parent
    if (copyInto.size() == before)
        return;
    NodeType parent = (NodeType) copyInto.item(before);
    // get ancestors of parent
    iterate(parent, copyInto, limitNode);
}
Also used : NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)

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