Search in sources :

Example 1 with Fieldref

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

the class DataLayoutProvider method parseFieldref.

private static Fieldref parseFieldref(XmlPullParser parser) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    Fieldref fieldref = new Fieldref(parser.getAttributeValue("", "var"));
    outerloop: while (true) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initialDepth) {
            break outerloop;
        }
    }
    return fieldref;
}
Also used : Fieldref(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref)

Example 2 with Fieldref

use of org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref 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 3 with Fieldref

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

the class DataLayoutTest method testLayoutSpecialCharacters.

@Test
public void testLayoutSpecialCharacters() throws XmlPullParserException, IOException {
    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 - & é á "));
    section = new Section("<html>Number of Persons by<br/> Nationality and Status</html>");
    section.getSectionLayout().add(new Reportedref());
    layout.getPageLayout().add(section);
    layout.getPageLayout().add(new Text("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>"));
    assertNotNull(layout.toXML());
    String output = layout.toXML().toString();
    assertEquals(TEST_OUTPUT_SPECIAL, output);
    XmlPullParser parser = PacketParserUtils.getParserFor(output);
    layout = DataLayoutProvider.parse(parser);
    assertEquals(5, layout.getPageLayout().size());
    assertEquals("Label - & é á ", layout.getLabel());
    section = (Section) layout.getPageLayout().get(1);
    assertEquals("section Label - & é á ", section.getLabel());
    Text text = (Text) layout.getPageLayout().get(2);
    assertEquals("PageText - & é á ", text.getText());
    section = (Section) layout.getPageLayout().get(3);
    assertEquals("<html>Number of Persons by<br/> Nationality and Status</html>", section.getLabel());
    text = (Text) layout.getPageLayout().get(4);
    assertEquals("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>", text.getText());
    assertNotNull(layout.toXML());
    output = layout.toXML().toString();
    assertEquals(TEST_OUTPUT_SPECIAL, output);
}
Also used : Fieldref(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref) Reportedref(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Reportedref) XmlPullParser(org.xmlpull.v1.XmlPullParser) Text(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Text) Section(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section) Test(org.junit.Test)

Example 4 with Fieldref

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

the class DataLayoutTest method testLayout.

@Test
public void testLayout() throws Exception {
    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"));
    assertNotNull(layout.toXML());
    String output = layout.toXML().toString();
    assertEquals(TEST_OUTPUT_2, output);
    XmlPullParser parser = PacketParserUtils.getParserFor(output);
    layout = DataLayoutProvider.parse(parser);
    assertEquals(3, layout.getPageLayout().size());
    assertEquals("Label", layout.getLabel());
    assertNotNull(layout.toXML());
    output = layout.toXML().toString();
    assertEquals(TEST_OUTPUT_2, output);
}
Also used : Fieldref(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref) XmlPullParser(org.xmlpull.v1.XmlPullParser) Text(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Text) Section(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section) Test(org.junit.Test)

Aggregations

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