Search in sources :

Example 1 with Element

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;
}
Also used : ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Element(org.jivesoftware.smack.packet.Element) XmlStringBuilder(org.jivesoftware.smack.util.XmlStringBuilder) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 2 with Element

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

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);
}
Also used : RangeValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement) ValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement) RangeValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement) 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) FormField(org.jivesoftware.smackx.xdata.FormField) Test(org.junit.Test)

Aggregations

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