Java Code Examples for org.jivesoftware.smackx.xdata.packet.DataForm#getType()

The following examples show how to use org.jivesoftware.smackx.xdata.packet.DataForm#getType() . 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: FormFieldRegistry.java    From Smack with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ReferenceEquality")
public static synchronized void register(DataForm dataForm) {
    // TODO: Also allow forms of type 'result'?
    if (dataForm.getType() != DataForm.Type.form) {
        throw new IllegalArgumentException();
    }

    String formType = null;
    TextSingleFormField hiddenFormTypeField = dataForm.getHiddenFormTypeField();
    if (hiddenFormTypeField != null) {
        formType = hiddenFormTypeField.getValue();
    }

    for (FormField formField : dataForm.getFields()) {
        // Note that we can compare here by reference equality to skip the hidden form type field.
        if (formField == hiddenFormTypeField) {
            continue;
        }

        String fieldName = formField.getFieldName();
        FormField.Type type = formField.getType();
        register(formType, fieldName, type);
    }
}
 
Example 2
Source File: FillableForm.java    From Smack with Apache License 2.0 6 votes vote down vote up
public FillableForm(DataForm dataForm) {
    super(dataForm);
    if (dataForm.getType() != DataForm.Type.form) {
        throw new IllegalArgumentException();
    }

    Set<String> requiredFields = new HashSet<>();
    for (FormField formField : dataForm.getFields()) {
        if (formField.isRequired()) {
            String fieldName = formField.getFieldName();
            requiredFields.add(fieldName);
            missingRequiredFields.add(fieldName);
        }
    }
    this.requiredFields = Collections.unmodifiableSet(requiredFields);
}
 
Example 3
Source File: Form.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static Form from(StanzaView stanzaView) {
    DataForm dataForm = DataForm.from(stanzaView);
    if (dataForm == null || dataForm.getType() != Type.form) {
        return null;
    }
    return new Form(dataForm);
}
 
Example 4
Source File: FilledForm.java    From Smack with Apache License 2.0 5 votes vote down vote up
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");
    }
    formTypeFormField = dataForm.getHiddenFormTypeField();
}
 
Example 5
Source File: Form.java    From Smack with Apache License 2.0 4 votes vote down vote up
public Form(DataForm dataForm) {
    super(dataForm);
    if (dataForm.getType() != Type.form) {
        throw new IllegalArgumentException();
    }
}