use of org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section in project Smack by igniterealtime.
the class DataLayoutProvider method parseSection.
private static Section parseSection(XmlPullParser parser) throws XmlPullParserException, IOException {
Section layout = new Section(parser.getAttributeValue("", "label"));
parseLayout(layout.getSectionLayout(), parser);
return layout;
}
use of org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section 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);
}
use of org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section 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);
}
use of org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section 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);
}
use of org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section 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);
}
Aggregations