Java Code Examples for org.jivesoftware.smackx.xdata.FormField#buildHiddenFormType()

The following examples show how to use org.jivesoftware.smackx.xdata.FormField#buildHiddenFormType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoftwareInfoFormTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
public static SoftwareInfoForm createSoftwareInfoFormUsingDataForm() throws URISyntaxException {
    DataForm.Builder dataFormBuilder = DataForm.builder(Type.result);
    TextSingleFormField formField = FormField.buildHiddenFormType(SoftwareInfoForm.FORM_TYPE);
    dataFormBuilder.addField(formField);

    dataFormBuilder.addField(FormField.builder("icon")
                   .addFormFieldChildElement(createMediaElement())
                   .build());
    dataFormBuilder.addField(FormField.builder("os")
                   .setValue("Windows")
                   .build());
    dataFormBuilder.addField(FormField.builder("os_version")
                   .setValue("XP")
                   .build());
    dataFormBuilder.addField(FormField.builder("software")
                   .setValue("Exodus")
                   .build());
    dataFormBuilder.addField(FormField.builder("software_version")
                   .setValue("0.9.1")
                   .build());

    SoftwareInfoForm softwareInfoForm = SoftwareInfoForm.getBuilder().setDataForm(dataFormBuilder.build()).build();
    return softwareInfoForm;
}
 
Example 2
Source File: EnablePushNotificationsIQ.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
    xml.attribute("jid", jid);
    xml.attribute("node", node);
    xml.rightAngleBracket();

    if (publishOptions != null) {
        DataForm.Builder dataForm = DataForm.builder();

        // TODO: Shouldn't this use some potentially existing PubSub API? Also FORM_TYPE fields are usually of type
        // 'hidden', but the examples in XEP-0357 do also not set the value to hidden and FORM_TYPE itself appears
        // to be more convention than specification.
        FormField formTypeField = FormField.buildHiddenFormType(PubSub.NAMESPACE + "#publish-options");
        dataForm.addField(formTypeField);

        Iterator<Map.Entry<String, String>> publishOptionsIterator = publishOptions.entrySet().iterator();
        while (publishOptionsIterator.hasNext()) {
            Map.Entry<String, String> pairVariableValue = publishOptionsIterator.next();
            TextSingleFormField.Builder field = FormField.builder(pairVariableValue.getKey());
            field.setValue(pairVariableValue.getValue());
            dataForm.addField(field.build());
        }

        xml.append(dataForm.build());
    }

    return xml;
}
 
Example 3
Source File: SoftwareInfoFormTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Test
public void faultySoftwareInfoFormsTest() {
    DataForm.Builder dataFormbuilder = DataForm.builder(Type.result);
    TextSingleFormField formField = FormField.buildHiddenFormType("faulty_formtype");
    dataFormbuilder.addField(formField);
    assertThrows(IllegalArgumentException.class, () -> {
        SoftwareInfoForm.getBuilder().setDataForm(dataFormbuilder.build()).build();
    });

    DataForm.Builder builderWithoutFormType = DataForm.builder(Type.result);
    assertThrows(IllegalArgumentException.class, () -> {
        SoftwareInfoForm.getBuilder().setDataForm(builderWithoutFormType.build()).build();
    });
}
 
Example 4
Source File: MamManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private static DataForm.Builder getNewMamForm() {
    FormField field = FormField.buildHiddenFormType(MamElements.NAMESPACE);
    DataForm.Builder form = DataForm.builder();
    form.addField(field);
    return form;
}
 
Example 5
Source File: SoftwareInfoForm.java    From Smack with Apache License 2.0 4 votes vote down vote up
private Builder() {
    dataFormBuilder = DataForm.builder(Type.result);
    TextSingleFormField formField = FormField.buildHiddenFormType(FORM_TYPE);
    dataFormBuilder.addField(formField);
}
 
Example 6
Source File: DataForm.java    From Smack with Apache License 2.0 4 votes vote down vote up
public Builder setFormType(String formType) {
    FormField formField = FormField.buildHiddenFormType(formType);
    return addField(formField);
}