Search in sources :

Example 1 with XPathBuilder

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);
}
Also used : FormClass(org.activityinfo.model.form.FormClass) XPathBuilder(org.activityinfo.io.xform.xpath.XPathBuilder)

Example 2 with XPathBuilder

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;
}
Also used : OdkSymbolHandler(org.activityinfo.server.endpoint.odk.OdkSymbolHandler) XPathBuilder(org.activityinfo.io.xform.xpath.XPathBuilder)

Example 3 with XPathBuilder

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();
        }
    }
}
Also used : XPathBuilder(org.activityinfo.io.xform.xpath.XPathBuilder) URL(java.net.URL) ResourceId(org.activityinfo.model.resource.ResourceId) XPathBuilderException(org.activityinfo.io.xform.xpath.XPathBuilderException) Test(org.junit.Test)

Aggregations

XPathBuilder (org.activityinfo.io.xform.xpath.XPathBuilder)3 URL (java.net.URL)1 XPathBuilderException (org.activityinfo.io.xform.xpath.XPathBuilderException)1 FormClass (org.activityinfo.model.form.FormClass)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 OdkSymbolHandler (org.activityinfo.server.endpoint.odk.OdkSymbolHandler)1 Test (org.junit.Test)1