use of org.activityinfo.io.xform.xpath.XPathBuilder in project activityinfo by bedatadriven.
the class XlsFormBuilder method build.
public void build(ResourceId formClassId) {
FormClass formClass = formClassProvider.getFormClass(formClassId);
symbolHandler = new XlsSymbolHandler(formClass.getFields());
xPathBuilder = new XPathBuilder(symbolHandler);
writeFields(formClass);
}
use of org.activityinfo.io.xform.xpath.XPathBuilder in project activityinfo by bedatadriven.
the class XFormBuilder method build.
public XForm build(FormClass formClass) {
this.formClass = formClass;
startDateFieldId = field(formClass.getId(), START_DATE_FIELD);
endDateFieldId = field(formClass.getId(), END_DATE_FIELD);
dateFields = Sets.newHashSet(startDateFieldId, endDateFieldId);
locationNameFieldId = field(formClass.getId(), LOCATION_NAME_FIELD);
gpsFieldId = field(formClass.getId(), GPS_FIELD);
fields = createFieldBuilders(formClass);
odkSymbolHandler = new OdkSymbolHandler(fields);
xPathBuilder = new XPathBuilder(odkSymbolHandler);
xform = new XForm();
xform.getHead().setTitle(formClass.getLabel());
xform.getHead().setModel(createModel());
xform.setBody(createBody());
return xform;
}
use of org.activityinfo.io.xform.xpath.XPathBuilder 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