summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Robbings <tim.robbings@isode.com>2014-10-22 09:06:10 (GMT)
committerSwift Review <review@swift.im>2014-10-28 10:00:39 (GMT)
commit47cad5fd7883b8c7273ea11073643aa585b485c6 (patch)
tree1d7bc39fc1c847e0bbe88716257a9a0710ac8745 /src/com/isode/stroke/elements/Form.java
parent244aff320257d178bbe35d87b0e09d939bd2f893 (diff)
downloadstroke-47cad5fd7883b8c7273ea11073643aa585b485c6.zip
stroke-47cad5fd7883b8c7273ea11073643aa585b485c6.tar.bz2
Stroke FormField refactoring
Changes to catch up with Swiften changes to FormField in commit 00284e5, also adds <reported/> and <item/> elements, added to Swiften in commit 83afa3d. Changes include refactoring of the FormField class, changes to Form parser and serializer classes and updates to JUnit tests. Test-information: Tested using updated JUnit tests, all tests complete successfully. Change-Id: Ic91ad4a11a335fb3d2b2a2c4a1865f836e2af70b Reviewer: Alex Clayton <alex.clayton@isode.com> Reviewer: Gurmeen Bindra <gurmeen.bindra@isode.com>
Diffstat (limited to 'src/com/isode/stroke/elements/Form.java')
-rw-r--r--src/com/isode/stroke/elements/Form.java82
1 files changed, 65 insertions, 17 deletions
diff --git a/src/com/isode/stroke/elements/Form.java b/src/com/isode/stroke/elements/Form.java
index 362408a..8068f28 100644
--- a/src/com/isode/stroke/elements/Form.java
+++ b/src/com/isode/stroke/elements/Form.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012 Isode Limited, London, England.
+ * Copyright (c) 2012-2014 Isode Limited, London, England.
* All rights reserved.
*/
/*
@@ -12,7 +12,6 @@ package com.isode.stroke.elements;
import java.util.ArrayList;
import java.util.List;
-import com.isode.stroke.elements.FormField.HiddenFormField;
/**
* XEP-0004 Data form. For the relevant Fields, the parsers and serialisers
@@ -34,6 +33,16 @@ public class Form extends Payload {
* Element "instructions"
*/
public static final String FORM_ELEMENT_INSTRUCTIONS = "instructions";
+
+ /**
+ * Element "reported"
+ */
+ public static final String FORM_ELEMENT_REPORTED = "reported";
+
+ /**
+ * Element "item"
+ */
+ public static final String FORM_ELEMENT_ITEM = "item";
/**
* Element "field"
@@ -97,13 +106,15 @@ public class Form extends Payload {
public String getStringForm() {
return stringForm_;
}
- };
+ }
private List<FormField> fields_ = new ArrayList<FormField>();
- private String title_ = "";
+ private List<FormField> reportedFields_ = new ArrayList<FormField>();
+ private List<FormItem> items_ = new ArrayList<FormItem>();
private String instructions_ = "";
+ private String title_ = "";
private Type type_;
-
+
/**
* Create a form of the given type.
*
@@ -130,7 +141,6 @@ public class Form extends Payload {
if (field == null) {
throw new NullPointerException("'field' must not be null");
}
-
fields_.add(field);
}
@@ -143,6 +153,52 @@ public class Form extends Payload {
public List<FormField> getFields() {
return new ArrayList<FormField>(fields_);
}
+
+ /**
+ * Add a reported element to this Form.
+ * @param reportedField should not be null
+ */
+ public void addReportedField(FormField reportedField) {
+ if (reportedField == null) {
+ throw new NullPointerException("'reportedField' should not be null");
+ }
+ reportedFields_.add(reportedField);
+ }
+
+ /**
+ * Return the list of reported fields for this Form.
+ * @return reportedFields_, never null
+ */
+ public List<FormField> getReportedFields() {
+ return reportedFields_;
+ }
+
+ /**
+ * Add a list of item elements to the Form.
+ * @param item List<FormField>, should not be null
+ */
+ public void addItem(FormItem item) {
+ if (item == null) {
+ throw new NullPointerException("'item' should not be null");
+ }
+ items_.add(item);
+ }
+
+ /**
+ * Get the list of FormItem elements for the form.
+ * @return itemsCopy ArrayList<List<FormItem>>, list of items for the Form,
+ * a copy is made
+ */
+ public List<FormItem> getItems() {
+ return new ArrayList<FormItem>(items_);
+ }
+
+ /**
+ * Remove all reported fields from this Form.
+ */
+ public void clearReportedFields() {
+ reportedFields_.clear();
+ }
/**
* Set title of the form.
@@ -209,19 +265,11 @@ public class Form extends Payload {
* the form, an empty string otherwise, will never be null
*/
public String getFormType() {
- String value = null;
-
FormField field = getField("FORM_TYPE");
- try {
- HiddenFormField f = (HiddenFormField) field;
- if (f != null) {
- value = f.getValue();
- }
- } catch (ClassCastException e) {
- // value remains null
+ if (field != null && field.getType() == FormField.Type.HIDDEN_TYPE) {
+ return field.getValues().isEmpty() ? "" : field.getValues().get(0);
}
-
- return ((value != null) ? value : "");
+ return "";
}
/**