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;
}
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);
}
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);
}
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);
}
Aggregations