Search in sources :

Example 21 with GroupDef

use of org.javarosa.core.model.GroupDef in project javarosa by opendatakit.

the class XFormParserTest method parseGroupWithNodesetAttrForm.

@Test
public void parseGroupWithNodesetAttrForm() throws IOException {
    // Given & When
    ParseResult parseResult = parse(r("group-with-nodeset-attr.xml"));
    // Then
    assertEquals(parseResult.formDef.getTitle(), "group with nodeset attribute");
    assertEquals("Number of error messages", 0, parseResult.errorMessages.size());
    final TreeReference expectedTreeReference = new TreeReference();
    // absolute reference
    expectedTreeReference.setRefLevel(-1);
    // the instance root
    expectedTreeReference.add("data", -1);
    // the outer repeat
    expectedTreeReference.add("R1", -1);
    // the inner group
    expectedTreeReference.add("G2", -1);
    final IDataReference expectedXPathReference = new XPathReference(expectedTreeReference);
    IFormElement groupElement = parseResult.formDef.getChild(0).getChild(0);
    assertThat(groupElement, instanceOf(GroupDef.class));
    assertThat(((GroupDef) groupElement).getRepeat(), is(false));
    assertThat(groupElement.getBind(), is(expectedXPathReference));
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) ParseResult(org.javarosa.xform.parse.FormParserHelper.ParseResult) TreeReference(org.javarosa.core.model.instance.TreeReference) IDataReference(org.javarosa.core.model.IDataReference) XPathReference(org.javarosa.model.xform.XPathReference) GroupDef(org.javarosa.core.model.GroupDef) Test(org.junit.Test)

Example 22 with GroupDef

use of org.javarosa.core.model.GroupDef in project javarosa by opendatakit.

the class FormParseInit method printStuff.

/*
     * Makes an 'extremely basic' print out of the xform model.
     */
public String printStuff() {
    String stuff = "";
    // go to the beginning of the form
    fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
    do {
        FormEntryCaption fep = femodel.getCaptionPrompt();
        boolean choiceFlag = false;
        if (fep.getFormElement() instanceof QuestionDef) {
            stuff += "\t[Type:QuestionDef, ";
            List<SelectChoice> s = ((QuestionDef) fep.getFormElement()).getChoices();
            stuff += "ContainsChoices: " + ((s != null && s.size() > 0) ? "true " : "false") + ", ";
            if (s != null && s.size() > 0)
                choiceFlag = true;
        } else if (fep.getFormElement() instanceof FormDef) {
            stuff += "\t[Type:FormDef, ";
        } else if (fep.getFormElement() instanceof GroupDef) {
            stuff += "\t[Type:GroupDef, ";
        } else {
            stuff += "\t[Type:Unknown]\n";
            continue;
        }
        stuff += "ID:" + fep.getFormElement().getID() + ", TextID:" + fep.getFormElement().getTextID() + ",InnerText:" + fep.getFormElement().getLabelInnerText();
        if (choiceFlag) {
            stuff += "] \n\t\t---Choices:" + ((QuestionDef) fep.getFormElement()).getChoices().toString() + "\n";
        } else {
            stuff += "]\n";
        }
    } while (fec.stepToNextEvent() != fec.EVENT_END_OF_FORM);
    return stuff;
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) FormDef(org.javarosa.core.model.FormDef) FormEntryCaption(org.javarosa.form.api.FormEntryCaption) QuestionDef(org.javarosa.core.model.QuestionDef) GroupDef(org.javarosa.core.model.GroupDef)

Aggregations

GroupDef (org.javarosa.core.model.GroupDef)22 IFormElement (org.javarosa.core.model.IFormElement)15 ArrayList (java.util.ArrayList)6 FormIndex (org.javarosa.core.model.FormIndex)6 QuestionDef (org.javarosa.core.model.QuestionDef)5 TreeReference (org.javarosa.core.model.instance.TreeReference)5 TreeElement (org.javarosa.core.model.instance.TreeElement)4 IDataReference (org.javarosa.core.model.IDataReference)3 FormEntryCaption (org.javarosa.form.api.FormEntryCaption)3 HashMap (java.util.HashMap)2 FormDef (org.javarosa.core.model.FormDef)2 Constraint (org.javarosa.core.model.condition.Constraint)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 XPathReference (org.javarosa.model.xform.XPathReference)2 DataBinding (org.javarosa.core.model.DataBinding)1 SelectChoice (org.javarosa.core.model.SelectChoice)1 EvaluationContext (org.javarosa.core.model.condition.EvaluationContext)1 IAnswerData (org.javarosa.core.model.data.IAnswerData)1 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)1 InvalidReferenceException (org.javarosa.core.model.instance.InvalidReferenceException)1