use of org.activityinfo.io.xform.xpath.XPathBuilderException in project activityinfo by bedatadriven.
the class XPathBuilderTest method relevanceConditions.
@Test
public void relevanceConditions() throws IOException {
URL resource = Resources.getResource(SimpleConditionList.class, "formulas.txt");
List<String> formulas = Resources.readLines(resource, Charsets.UTF_8);
fieldList = new ArrayList<>();
exprList = new ArrayList<>();
for (String formula : formulas) {
FormulaNode node = FormulaParser.parse(formula);
exprList.add(node);
List<ResourceId> fieldIds = getFieldIds(node);
addToFieldList(fieldIds);
}
TestSymbolHandler symbolHandler = new TestSymbolHandler(fieldList);
XPathBuilder xPathBuilder = new XPathBuilder(symbolHandler);
StringBuilder stringBuilder = new StringBuilder();
try {
String xpath;
Iterator<FormulaNode> it = exprList.listIterator();
while (it.hasNext()) {
FormulaNode node = it.next();
xpath = xPathBuilder.build(node);
stringBuilder.append(node.asExpression() + "\t" + xpath + System.lineSeparator());
}
} catch (XPathBuilderException e) {
throw new AssertionError("Unable to construct XPath for relevance condition: " + e.getMessage());
} finally {
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("xpath.txt")))) {
writer.write(stringBuilder.toString());
writer.close();
}
}
}
Aggregations