Search in sources :

Example 1 with XPathStep

use of org.javarosa.xpath.expr.XPathStep in project javarosa by opendatakit.

the class ASTNodeLocPath method build.

public XPathExpression build() throws XPathSyntaxException {
    Vector<XPathStep> steps = new Vector<XPathStep>();
    XPathExpression filtExpr = null;
    int offset = isAbsolute() ? 1 : 0;
    for (int i = 0; i < clauses.size() + offset; i++) {
        if (offset == 0 || i > 0) {
            if (clauses.elementAt(i - offset) instanceof ASTNodePathStep) {
                steps.addElement(((ASTNodePathStep) clauses.elementAt(i - offset)).getStep());
            } else {
                filtExpr = clauses.elementAt(i - offset).build();
            }
        }
        if (i < separators.size()) {
            if (Parser.vectInt(separators, i) == Token.DBL_SLASH) {
                steps.addElement(XPathStep.ABBR_DESCENDANTS());
            }
        }
    }
    XPathStep[] stepArr = new XPathStep[steps.size()];
    for (int i = 0; i < stepArr.length; i++) stepArr[i] = steps.elementAt(i);
    if (filtExpr == null) {
        return new XPathPathExpr(isAbsolute() ? XPathPathExpr.INIT_CONTEXT_ROOT : XPathPathExpr.INIT_CONTEXT_RELATIVE, stepArr);
    } else {
        if (filtExpr instanceof XPathFilterExpr) {
            return new XPathPathExpr((XPathFilterExpr) filtExpr, stepArr);
        } else {
            return new XPathPathExpr(new XPathFilterExpr(filtExpr, new XPathExpression[0]), stepArr);
        }
    }
}
Also used : XPathExpression(org.javarosa.xpath.expr.XPathExpression) XPathPathExpr(org.javarosa.xpath.expr.XPathPathExpr) XPathStep(org.javarosa.xpath.expr.XPathStep) XPathFilterExpr(org.javarosa.xpath.expr.XPathFilterExpr) Vector(java.util.Vector)

Aggregations

Vector (java.util.Vector)1 XPathExpression (org.javarosa.xpath.expr.XPathExpression)1 XPathFilterExpr (org.javarosa.xpath.expr.XPathFilterExpr)1 XPathPathExpr (org.javarosa.xpath.expr.XPathPathExpr)1 XPathStep (org.javarosa.xpath.expr.XPathStep)1