From 1d88c857b5c200062dfe16cad9e15c93259c0e96 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 6 Apr 2018 13:24:54 +0200 Subject: [PATCH] Change FormField value(s) type from String to CharSequence --- .../httpfileupload/HttpFileUploadManager.java | 6 +-- .../smackx/caps/EntityCapsManager.java | 6 +-- .../filetransfer/FileTransferNegotiator.java | 2 +- .../smackx/muc/MucConfigFormManager.java | 2 +- .../org/jivesoftware/smackx/muc/RoomInfo.java | 33 +++++++------- .../smackx/offline/OfflineMessageManager.java | 2 +- .../smackx/pubsub/ConfigureForm.java | 6 +-- .../smackx/pubsub/SubscribeForm.java | 4 +- .../smackx/search/ReportedData.java | 10 ++--- .../smackx/search/SimpleUserSearch.java | 2 +- .../org/jivesoftware/smackx/xdata/Form.java | 6 +-- .../jivesoftware/smackx/xdata/FormField.java | 44 ++++++++++++++++--- 12 files changed, 79 insertions(+), 44 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java index 9bf90c443..3b13bed28 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java @@ -157,13 +157,13 @@ public final class HttpFileUploadManager extends Manager { return new UploadService(address, version); } - List values = field.getValues(); - if (values.isEmpty()) { + String maxFileSizeValue = field.getFirstValue(); + if (maxFileSizeValue == null) { return new UploadService(address, version); } - Long maxFileSize = Long.valueOf(values.get(0)); + Long maxFileSize = Long.valueOf(maxFileSizeValue); return new UploadService(address, version, maxFileSize); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java index ced47c452..920329835 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java @@ -723,10 +723,10 @@ public final class EntityCapsManager extends Manager { return new CapsVersionAndHash(version, hash); } - private static void formFieldValuesToCaps(List i, StringBuilder sb) { - SortedSet fvs = new TreeSet<>(); + private static void formFieldValuesToCaps(List i, StringBuilder sb) { + SortedSet fvs = new TreeSet<>(); fvs.addAll(i); - for (String fv : fvs) { + for (CharSequence fv : fvs) { sb.append(fv); sb.append('<'); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java index 39a424618..3f618776d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java @@ -341,7 +341,7 @@ public final class FileTransferNegotiator extends Manager { private StreamNegotiator getOutgoingNegotiator(final FormField field) throws NoAcceptableTransferMechanisms { boolean isByteStream = false; boolean isIBB = false; - for (String variable : field.getValues()) { + for (CharSequence variable : field.getValues()) { if (variable.equals(Bytestream.NAMESPACE) && !IBB_ONLY) { isByteStream = true; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucConfigFormManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucConfigFormManager.java index 26c1c4efa..b97b49e1e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucConfigFormManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucConfigFormManager.java @@ -107,7 +107,7 @@ public class MucConfigFormManager { // Set the local variables according to the fields found in the answer form if (answerForm.hasField(MUC_ROOMCONFIG_ROOMOWNERS)) { // Set 'owners' to the currently configured owners - List ownerStrings = answerForm.getField(MUC_ROOMCONFIG_ROOMOWNERS).getValues(); + List ownerStrings = answerForm.getField(MUC_ROOMCONFIG_ROOMOWNERS).getValues(); owners = new ArrayList<>(ownerStrings.size()); JidUtil.jidsFrom(ownerStrings, owners, null); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java index 99fc30832..e0b283ec9 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java @@ -19,6 +19,7 @@ package org.jivesoftware.smackx.muc; import java.net.MalformedURLException; import java.net.URL; +import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -29,6 +30,7 @@ import org.jivesoftware.smackx.xdata.FormField; import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.Jid; +import org.jxmpp.jid.util.JidUtil; /** * Represents the room information that was discovered using Service Discovery. It's possible to @@ -97,7 +99,7 @@ public class RoomInfo { /** * Contact Address */ - private final List contactJid; + private final List contactJid; /** * Natural Language for Room Discussions @@ -157,7 +159,7 @@ public class RoomInfo { int occupantsCount = -1; String description = ""; int maxhistoryfetch = -1; - List contactJid = null; + List contactJid = null; String lang = null; String ldapgroup = null; Boolean subjectmod = null; @@ -169,49 +171,48 @@ public class RoomInfo { FormField descField = form.getField("muc#roominfo_description"); if (descField != null && !descField.getValues().isEmpty()) { // Prefer the extended result description - description = descField.getValues().get(0); + description = descField.getFirstValue(); } FormField subjField = form.getField("muc#roominfo_subject"); if (subjField != null && !subjField.getValues().isEmpty()) { - subject = subjField.getValues().get(0); + subject = subjField.getFirstValue(); } FormField occCountField = form.getField("muc#roominfo_occupants"); if (occCountField != null && !occCountField.getValues().isEmpty()) { - occupantsCount = Integer.parseInt(occCountField.getValues().get( - 0)); + occupantsCount = Integer.parseInt(occCountField.getFirstValue()); } FormField maxhistoryfetchField = form.getField("muc#maxhistoryfetch"); if (maxhistoryfetchField != null && !maxhistoryfetchField.getValues().isEmpty()) { - maxhistoryfetch = Integer.parseInt(maxhistoryfetchField.getValues().get( - 0)); + maxhistoryfetch = Integer.parseInt(maxhistoryfetchField.getFirstValue()); } FormField contactJidField = form.getField("muc#roominfo_contactjid"); if (contactJidField != null && !contactJidField.getValues().isEmpty()) { - contactJid = contactJidField.getValues(); + List contactJidValues = contactJidField.getValues(); + contactJid = JidUtil.filterEntityBareJidList(JidUtil.jidSetFrom(contactJidValues)); } FormField langField = form.getField("muc#roominfo_lang"); if (langField != null && !langField.getValues().isEmpty()) { - lang = langField.getValues().get(0); + lang = langField.getFirstValue(); } FormField ldapgroupField = form.getField("muc#roominfo_ldapgroup"); if (ldapgroupField != null && !ldapgroupField.getValues().isEmpty()) { - ldapgroup = ldapgroupField.getValues().get(0); + ldapgroup = ldapgroupField.getFirstValue(); } FormField subjectmodField = form.getField("muc#roominfo_subjectmod"); if (subjectmodField != null && !subjectmodField.getValues().isEmpty()) { - subjectmod = Boolean.valueOf(subjectmodField.getValues().get(0)); + subjectmod = Boolean.valueOf(subjectmodField.getFirstValue()); } FormField urlField = form.getField("muc#roominfo_logs"); if (urlField != null && !urlField.getValues().isEmpty()) { - String urlString = urlField.getValues().get(0); + String urlString = urlField.getFirstValue(); try { logs = new URL(urlString); } catch (MalformedURLException e) { @@ -221,7 +222,7 @@ public class RoomInfo { FormField pubsubField = form.getField("muc#roominfo_pubsub"); if (pubsubField != null && !pubsubField.getValues().isEmpty()) { - pubsub = pubsubField.getValues().get(0); + pubsub = pubsubField.getFirstValue(); } } this.description = description; @@ -354,8 +355,8 @@ public class RoomInfo { * * @return a list of contact addresses for this room. */ - public List getContactJids() { - return contactJid; + public List getContactJids() { + return Collections.unmodifiableList(contactJid); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java index d6298b386..08ff858d1 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java @@ -103,7 +103,7 @@ public class OfflineMessageManager { namespace); Form extendedInfo = Form.getFormFrom(info); if (extendedInfo != null) { - String value = extendedInfo.getField("number_of_messages").getValues().get(0); + String value = extendedInfo.getField("number_of_messages").getFirstValue(); return Integer.parseInt(value); } return 0; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java index a0555e6b8..3ff1cebd5 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java @@ -606,7 +606,7 @@ public class ConfigureForm extends Form { StringBuilder valuesBuilder = new StringBuilder(); - for (String value : formField.getValues()) { + for (CharSequence value : formField.getValues()) { if (valuesBuilder.length() > 0) result.append(','); valuesBuilder.append(value); @@ -628,13 +628,13 @@ public class ConfigureForm extends Form { private String getFieldValue(ConfigureNodeFields field) { FormField formField = getField(field.getFieldName()); - return (formField.getValues().isEmpty()) ? null : formField.getValues().get(0); + return formField.getFirstValue(); } private List getFieldValues(ConfigureNodeFields field) { FormField formField = getField(field.getFieldName()); - return formField.getValues(); + return formField.getValuesAsString(); } private void addField(ConfigureNodeFields nodeField, FormField.Type type) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java index fbfab6af1..31628a7f5 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java @@ -196,13 +196,13 @@ public class SubscribeForm extends Form { private String getFieldValue(SubscribeOptionFields field) { FormField formField = getField(field.getFieldName()); - return formField.getValues().get(0); + return formField.getFirstValue(); } private List getFieldValues(SubscribeOptionFields field) { FormField formField = getField(field.getFieldName()); - return formField.getValues(); + return formField.getValuesAsString(); } private void addField(SubscribeOptionFields nodeField, FormField.Type type) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/ReportedData.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/ReportedData.java index 7d8bb0e0f..90926b317 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/ReportedData.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/ReportedData.java @@ -74,7 +74,7 @@ public class ReportedData { List fieldList = new ArrayList<>(columns.size()); for (FormField field : item.getFields()) { // The field is created with all the values of the data form's field - List values = new ArrayList<>(); + List values = new ArrayList<>(); values.addAll(field.getValues()); fieldList.add(new Field(field.getVariable(), values)); } @@ -205,7 +205,7 @@ public class ReportedData { * @param variable the variable to match. * @return the values of the field whose variable matches the requested variable. */ - public List getValues(String variable) { + public List getValues(String variable) { for (Field field : getFields()) { if (variable.equalsIgnoreCase(field.getVariable())) { return field.getValues(); @@ -226,9 +226,9 @@ public class ReportedData { public static class Field { private final String variable; - private final List values; + private final List values; - public Field(String variable, List values) { + public Field(String variable, List values) { this.variable = variable; this.values = values; } @@ -247,7 +247,7 @@ public class ReportedData { * * @return the returned values of the search. */ - public List getValues() { + public List getValues() { return Collections.unmodifiableList(values); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/SimpleUserSearch.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/SimpleUserSearch.java index 56a121ea8..90879e415 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/SimpleUserSearch.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/SimpleUserSearch.java @@ -85,7 +85,7 @@ class SimpleUserSearch extends IQ { } private static String getSingleValue(FormField formField) { - List values = formField.getValues(); + List values = formField.getValuesAsString(); if (values.isEmpty()) { return ""; } else { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/Form.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/Form.java index d9f202803..670840808 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/Form.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/Form.java @@ -277,7 +277,7 @@ public class Form { * @throws IllegalStateException if the form is not of type "submit". * @throws IllegalArgumentException if the form does not include the specified variable. */ - public void setAnswer(String variable, List values) { + public void setAnswer(String variable, List values) { if (!isSubmitType()) { throw new IllegalStateException("Cannot set an answer if the form is not of type " + "\"submit\""); @@ -324,7 +324,7 @@ public class Form { // Clear the old values field.resetValues(); // Set the default value - for (String value : field.getValues()) { + for (CharSequence value : field.getValues()) { field.addValue(value); } } @@ -504,7 +504,7 @@ public class Form { if (field.getType() == FormField.Type.hidden) { // Since a hidden field could have many values we need to collect them // in a list - List values = new ArrayList<>(); + List values = new ArrayList<>(); values.addAll(field.getValues()); form.setAnswer(field.getVariable(), values); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/FormField.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/FormField.java index c01ad2088..c14a0c1a5 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/FormField.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/FormField.java @@ -142,7 +142,7 @@ public class FormField implements NamedElement { private String label; private Type type; private final List