summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Robbings <tim.robbings@isode.com>2014-11-27 17:22:23 (GMT)
committerSwift Review <review@swift.im>2014-12-14 15:02:38 (GMT)
commite327b17aa54430284e67af3accf90f45430f74d6 (patch)
tree552ada79ce95c85e020d2c7437e29e772500814a /src/com/isode/stroke/elements
parent62faa5c8f718399e7e947be04ee04bc942251ea3 (diff)
downloadstroke-e327b17aa54430284e67af3accf90f45430f74d6.zip
stroke-e327b17aa54430284e67af3accf90f45430f74d6.tar.bz2
Changes to improve handling of unknown field types
Change to mirror Swiften code. This change removes some unnecessary code from the FormSerializer class. It also includes changes to the FormField class to improve the handling of 'unknown' form fields. Test-information: Tested using updatedJUnit tests, all tests complete successfully. Change-Id: Ie28ed40be976704170525f7be20b8e08661536b6
Diffstat (limited to 'src/com/isode/stroke/elements')
-rw-r--r--src/com/isode/stroke/elements/FormField.java36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/com/isode/stroke/elements/FormField.java b/src/com/isode/stroke/elements/FormField.java
index 2ec0e4b..84b6af1 100644
--- a/src/com/isode/stroke/elements/FormField.java
+++ b/src/com/isode/stroke/elements/FormField.java
@@ -47,7 +47,7 @@ public class FormField {
private Type type_;
public enum Type {
- UNKNOWN_TYPE("unknown"),
+ UNKNOWN_TYPE(""),
BOOLEAN_TYPE("boolean"),
FIXED_TYPE("fixed"),
HIDDEN_TYPE("hidden"),
@@ -76,6 +76,15 @@ public class FormField {
}
}
+ public FormField() {
+ this(Type.UNKNOWN_TYPE);
+ }
+
+ public FormField(Type type, String value) {
+ this(type);
+ addValue(value);
+ }
+
public FormField(Type type) {
type_ = type;
required_ = false;
@@ -84,12 +93,6 @@ public class FormField {
}
}
- public FormField(Type type, String value) {
- addValue(value);
- type_ = type;
- required_ = false;
- }
-
/**
* This class defines the option element that can be used in
* ListSingleFormField and ListMultiFormField. This class is
@@ -293,12 +296,13 @@ public class FormField {
* @return value boolean, will return false if FormField has no values
*/
public boolean getBoolValue() {
- if (type_ != Type.BOOLEAN_TYPE) {
+ if (type_ != Type.BOOLEAN_TYPE && type_ != Type.UNKNOWN_TYPE) {
throw new IllegalArgumentException(ILLEGAL_ARG_EX_STR + type_);
}
return values_.isEmpty() ? false : values_.get(0).equals("true") || values_.get(0).equals("1");
}
+
/**
* Sets the value of a FormField with type boolean to a boolean value.
* @param bool boolean
@@ -313,7 +317,7 @@ public class FormField {
* @return JID value, or empty JID is FormField has no values
*/
public JID getJIDSingleValue() {
- if (type_ != Type.JID_SINGLE_TYPE) {
+ if (type_ != Type.JID_SINGLE_TYPE && type_ != Type.UNKNOWN_TYPE) {
throw new IllegalArgumentException(ILLEGAL_ARG_EX_STR + type_);
}
return values_.isEmpty() ? new JID() : JID.fromString(values_.get(0));
@@ -325,7 +329,7 @@ public class FormField {
* @return JID value, or empty JID is FormField has no values
*/
public JID getJIDMultiValue(int index) {
- if (type_ != Type.JID_MULTI_TYPE) {
+ if (type_ != Type.JID_MULTI_TYPE && type_ != Type.UNKNOWN_TYPE) {
throw new IllegalArgumentException(ILLEGAL_ARG_EX_STR + type_);
}
return values_.isEmpty() ? new JID() : JID.fromString(values_.get(index));
@@ -336,7 +340,7 @@ public class FormField {
* @return value String, empty String if FormField has no values
*/
public String getTextPrivateValue() {
- if (type_ != Type.TEXT_PRIVATE_TYPE) {
+ if (type_ != Type.TEXT_PRIVATE_TYPE && type_ != Type.UNKNOWN_TYPE) {
throw new IllegalArgumentException(ILLEGAL_ARG_EX_STR + type_);
}
return values_.isEmpty() ? "" : values_.get(0);
@@ -347,7 +351,7 @@ public class FormField {
* @return value String, or empty String if invalid FormField type
*/
public String getFixedValue() {
- if (type_ != Type.FIXED_TYPE) {
+ if (type_ != Type.FIXED_TYPE && type_ != Type.UNKNOWN_TYPE) {
throw new IllegalArgumentException(ILLEGAL_ARG_EX_STR + type_);
}
return values_.isEmpty() ? "" : values_.get(0);
@@ -370,7 +374,7 @@ public class FormField {
* @return value String
*/
public String getTextMultiValue() {
- if (type_ != Type.TEXT_MULTI_TYPE) {
+ if (type_ != Type.TEXT_MULTI_TYPE && type_ != Type.UNKNOWN_TYPE) {
throw new IllegalArgumentException(ILLEGAL_ARG_EX_STR + type_);
}
StringBuilder val = new StringBuilder();
@@ -389,16 +393,16 @@ public class FormField {
* @param val String value to set, must not be null
*/
public void setTextMultiValue(String val) {
- if (type_ != Type.TEXT_MULTI_TYPE) {
+ if (type_ != Type.TEXT_MULTI_TYPE && type_ != Type.UNKNOWN_TYPE) {
throw new IllegalArgumentException(ILLEGAL_ARG_EX_STR + type_);
}
values_.clear();
- if (val.contains("\r\n")){
+ if (val.indexOf("\r\n") != -1) {
for (String s : val.split("\r\n")) {
values_.add(s);
}
}
- else if (val.contains("\n")){
+ else if (val.indexOf("\n") != -1){
for (String s : val.split("\n")) {
values_.add(s);
}