use of org.javarosa.xpath.expr.XPathPathExpr 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);
}
}
}
use of org.javarosa.xpath.expr.XPathPathExpr in project javarosa by opendatakit.
the class XFormParserTest method parsesExternalSecondaryInstanceForm.
@Test
public void parsesExternalSecondaryInstanceForm() throws IOException, XPathSyntaxException {
FormDef formDef = parse(EXTERNAL_SECONDARY_INSTANCE_XML).formDef;
assertEquals("Form with external secondary instance", formDef.getTitle());
TreeReference treeReference = ((XPathPathExpr) parseXPath("instance('towns')/data_set")).getReference();
EvaluationContext evaluationContext = formDef.getEvaluationContext();
List<TreeReference> treeReferences = evaluationContext.expandReference(treeReference);
assertEquals(1, treeReferences.size());
DataInstance townInstance = formDef.getNonMainInstance("towns");
AbstractTreeElement tiRoot = townInstance.getRoot();
assertEquals("towndata", tiRoot.getName());
assertEquals(1, tiRoot.getNumChildren());
AbstractTreeElement dataSetChild = tiRoot.getChild("data_set", 0);
assertEquals("us_east", dataSetChild.getValue().getDisplayText());
}
Aggregations