Search in sources :

Example 1 with DataLayout

use of org.jivesoftware.smackx.xdatalayout.packet.DataLayout in project Smack by igniterealtime.

the class DataFormTest method testLayout.

@Test
public void testLayout() throws Exception {
    //Build a Form
    DataForm df = new DataForm(DataForm.Type.submit);
    String instruction = "InstructionTest1";
    df.addInstruction(instruction);
    FormField field = new FormField("testField1");
    df.addField(field);
    DataLayout layout = new DataLayout("Label");
    Fieldref reffield = new Fieldref("testField1");
    layout.getPageLayout().add(reffield);
    Section section = new Section("section Label");
    section.getSectionLayout().add(new Text("SectionText"));
    layout.getPageLayout().add(section);
    layout.getPageLayout().add(new Text("PageText"));
    df.addExtensionElement(layout);
    assertNotNull(df.toXML());
    String output = df.toXML().toString();
    assertEquals(TEST_OUTPUT_2, output);
    XmlPullParser parser = PacketParserUtils.getParserFor(output);
    df = pr.parse(parser);
    assertNotNull(df);
    assertNotNull(df.getExtensionElements());
    assertEquals(1, df.getExtensionElements().size());
    Element element = df.getExtensionElements().get(0);
    assertNotNull(element);
    layout = (DataLayout) element;
    assertEquals(3, layout.getPageLayout().size());
    assertNotNull(df.toXML());
    output = df.toXML().toString();
    assertEquals(TEST_OUTPUT_2, output);
}
Also used : DataLayout(org.jivesoftware.smackx.xdatalayout.packet.DataLayout) Fieldref(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref) Element(org.jivesoftware.smack.packet.Element) ValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement) RangeValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement) XmlPullParser(org.xmlpull.v1.XmlPullParser) Text(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Text) FormField(org.jivesoftware.smackx.xdata.FormField) Section(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section) Test(org.junit.Test)

Example 2 with DataLayout

use of org.jivesoftware.smackx.xdatalayout.packet.DataLayout in project Smack by igniterealtime.

the class DataLayoutProvider method parse.

public static DataLayout parse(XmlPullParser parser) throws XmlPullParserException, IOException {
    DataLayout dataLayout = new DataLayout(parser.getAttributeValue("", "label"));
    parseLayout(dataLayout.getPageLayout(), parser);
    return dataLayout;
}
Also used : DataLayout(org.jivesoftware.smackx.xdatalayout.packet.DataLayout)

Aggregations

DataLayout (org.jivesoftware.smackx.xdatalayout.packet.DataLayout)2 Element (org.jivesoftware.smack.packet.Element)1 FormField (org.jivesoftware.smackx.xdata.FormField)1 Fieldref (org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref)1 Section (org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section)1 Text (org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Text)1 ValidateElement (org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement)1 RangeValidateElement (org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement)1 Test (org.junit.Test)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1