diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java
index cbe796492..3415041e4 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java
@@ -20,6 +20,7 @@ package org.jivesoftware.smackx.xdata.packet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@@ -303,6 +304,20 @@ public class DataForm implements ExtensionElement {
return Collections.unmodifiableList(extensionElements);
}
+ /**
+ * Return the form type from the hidden form type field.
+ *
+ * @return the form type or null
if this form has none set.
+ * @since 4.4.0
+ */
+ public String getFormType() {
+ FormField formTypeField = getHiddenFormTypeField();
+ if (formTypeField == null) {
+ return null;
+ }
+ return formTypeField.getFirstValue();
+ }
+
/**
* Returns the hidden FORM_TYPE field or null if this data form has none.
*
@@ -364,6 +379,56 @@ public class DataForm implements ExtensionElement {
return stanzaView.getExtension(DataForm.class);
}
+ /**
+ * Get the data form with the given form type from a stanza view.
+ *
+ * @param stanzaView the stanza view to retrieve the data form from
+ * @param formType the form type
+ * @return the retrieved data form or null
if there is no matching one
+ * @since 4.4.0
+ */
+ public static DataForm from(StanzaView stanzaView, String formType) {
+ List dataForms = stanzaView.getExtensions(DataForm.class);
+ return from(dataForms, formType);
+ }
+
+ /**
+ * Return the first matching data form with the given form type from the given collection of data forms.
+ *
+ * @param dataForms the collection of data forms
+ * @param formType the form type to match for
+ * @return the first matching data form or null
if there is none
+ * @since 4.4.0
+ */
+ public static DataForm from(Collection dataForms, String formType) {
+ for (DataForm dataForm : dataForms) {
+ if (formType.equals(dataForm.getFormType())) {
+ return dataForm;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Remove the first matching data form with the given form type from the given collection.
+ *
+ * @param dataForms the collection of data forms
+ * @param formType the form type to match for
+ * @return the removed data form or null
if there was none removed
+ * @since 4.4.0
+ */
+ public static DataForm remove(Collection dataForms, String formType) {
+ Iterator it = dataForms.iterator();
+ while (it.hasNext()) {
+ DataForm dataForm = it.next();
+ if (formType.equals(dataForm.getFormType())) {
+ it.remove();
+ return dataForm;
+ }
+ }
+ return null;
+ }
+
/**
*
* Represents the fields that will be returned from a search. This information is useful when