1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

[xdata] Do not require FORM_TYPE field in FilledForm

The FillableForm API is the most convenient way of filling out a
form. Currently only forms with a FORM_TYPE can be filled, due to a
restriction in FillableForm. This makes filling out untyped forms very
cumbersome.

This commit removes the required FORM_TYPE when using FilledForm (and
therefor FillableForm). Some subclasses of FilledForm already check
that the correct FORM_TYPE is set using FilledForm#ensureFormType().
This commit is contained in:
Frank Matheron 2021-02-23 14:25:31 +01:00 committed by Florian Schmaus
parent bca3821343
commit d4d2a7a6d8
2 changed files with 10 additions and 10 deletions

View file

@ -256,11 +256,16 @@ public class FillableForm extends FilledForm {
if (!missingRequiredFields.isEmpty()) {
throw new IllegalStateException("Not all required fields filled. Missing: " + missingRequiredFields);
}
DataForm dataFormToSend = DataForm.builder()
.addField(formTypeFormField)
.addFields(filledFields.values())
.build();
return dataFormToSend;
DataForm.Builder builder = DataForm.builder();
// the submit form has the same FORM_TYPE as the form.
if (formTypeFormField != null) {
builder.addField(formTypeFormField);
}
builder.addFields(filledFields.values());
return builder.build();
}
}

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.xdata.form;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.TextSingleFormField;
@ -32,10 +31,6 @@ public abstract class FilledForm implements FormReader {
public FilledForm(DataForm dataForm) {
this.dataForm = Objects.requireNonNull(dataForm);
String formType = dataForm.getFormType();
if (StringUtils.isNullOrEmpty(formType)) {
throw new IllegalArgumentException("The provided data form has no hidden FROM_TYPE field.");
}
if (dataForm.getType() == Type.cancel) {
throw new IllegalArgumentException("Forms of type 'cancel' are not filled nor fillable");
}