use of org.jivesoftware.smack.packet.Element in project Smack by igniterealtime.
the class DataForm method toXML.
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder buf = new XmlStringBuilder(this);
buf.attribute("type", getType());
buf.rightAngleBracket();
buf.optElement("title", getTitle());
for (String instruction : getInstructions()) {
buf.element("instructions", instruction);
}
// Append the list of fields returned from a search
if (getReportedData() != null) {
buf.append(getReportedData().toXML());
}
// Loop through all the items returned from a search and append them to the string buffer
for (Item item : getItems()) {
buf.append(item.toXML());
}
// Loop through all the form fields and append them to the string buffer
for (FormField field : getFields()) {
buf.append(field.toXML());
}
for (Element element : extensionElements) {
buf.append(element.toXML());
}
buf.closeElement(this);
return buf;
}
use of org.jivesoftware.smack.packet.Element 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.smack.packet.Element in project Smack by igniterealtime.
the class DataFormTest method testValidation.
@Test
public void testValidation() 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);
ValidateElement dv = new RangeValidateElement("xs:integer", "1111", "9999");
field.setValidateElement(dv);
assertNotNull(df.toXML());
String output = df.toXML().toString();
assertEquals(TEST_OUTPUT_3, output);
XmlPullParser parser = PacketParserUtils.getParserFor(output);
df = pr.parse(parser);
assertNotNull(df);
assertNotNull(df.getFields());
assertEquals(1, df.getFields().size());
Element element = df.getFields().get(0).getValidateElement();
assertNotNull(element);
dv = (ValidateElement) element;
assertEquals("xs:integer", dv.getDatatype());
assertNotNull(df.toXML());
output = df.toXML().toString();
assertEquals(TEST_OUTPUT_3, output);
}
Aggregations