Search in sources :

Example 1 with Text

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

the class DataLayoutTest method testLayoutFromFile.

@Test
public void testLayoutFromFile() throws Exception {
    DataFormProvider pr = new DataFormProvider();
    XmlPullParser parser = PacketParserUtils.newXmppParser();
    parser.setInput(new InputStreamReader(this.getClass().getResourceAsStream(TEST_INPUT_1), "UTF-8"));
    parser.next();
    DataForm form = pr.parse(parser);
    assertNotNull(form);
    assertEquals(1, form.getExtensionElements().size());
    DataLayout layout = (DataLayout) form.getExtensionElements().get(0);
    assertEquals(5, layout.getPageLayout().size());
    assertEquals("Label - & é á ", layout.getLabel());
    Section 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());
    String output = layout.toXML().toString();
    assertEquals(TEST_OUTPUT_SPECIAL, output);
}
Also used : InputStreamReader(java.io.InputStreamReader) DataFormProvider(org.jivesoftware.smackx.xdata.provider.DataFormProvider) XmlPullParser(org.xmlpull.v1.XmlPullParser) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Text(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Text) Section(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section) Test(org.junit.Test)

Example 2 with Text

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

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

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

Section (org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section)4 Text (org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Text)4 Test (org.junit.Test)4 XmlPullParser (org.xmlpull.v1.XmlPullParser)4 Fieldref (org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Fieldref)3 InputStreamReader (java.io.InputStreamReader)1 Element (org.jivesoftware.smack.packet.Element)1 FormField (org.jivesoftware.smackx.xdata.FormField)1 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)1 DataFormProvider (org.jivesoftware.smackx.xdata.provider.DataFormProvider)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