mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 09:09:38 +02:00
Introduce FormFieldChildElement and make FormField immutable
This commit is contained in:
parent
1a99801501
commit
4d36e3b521
36 changed files with 1191 additions and 490 deletions
|
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
@ -295,7 +296,7 @@ public final class MamManager extends Manager {
|
|||
public static final class Builder {
|
||||
private String node;
|
||||
|
||||
private final Map<String, FormField> formFields = new HashMap<>(8);
|
||||
private final Map<String, FormField> formFields = new LinkedHashMap<>(8);
|
||||
|
||||
private int maxResults = -1;
|
||||
|
||||
|
@ -329,8 +330,9 @@ public final class MamManager extends Manager {
|
|||
return this;
|
||||
}
|
||||
|
||||
FormField formField = new FormField(FORM_FIELD_START);
|
||||
formField.addValue(start);
|
||||
FormField formField = FormField.builder(FORM_FIELD_START)
|
||||
.addValue(start)
|
||||
.build();
|
||||
formFields.put(formField.getVariable(), formField);
|
||||
|
||||
FormField endFormField = formFields.get(FORM_FIELD_END);
|
||||
|
@ -356,8 +358,9 @@ public final class MamManager extends Manager {
|
|||
return this;
|
||||
}
|
||||
|
||||
FormField formField = new FormField(FORM_FIELD_END);
|
||||
formField.addValue(end);
|
||||
FormField formField = FormField.builder(FORM_FIELD_END)
|
||||
.addValue(end)
|
||||
.build();
|
||||
formFields.put(formField.getVariable(), formField);
|
||||
|
||||
FormField startFormField = formFields.get(FORM_FIELD_START);
|
||||
|
@ -469,9 +472,9 @@ public final class MamManager extends Manager {
|
|||
}
|
||||
|
||||
private static FormField getWithFormField(Jid withJid) {
|
||||
FormField formField = new FormField(FORM_FIELD_WITH);
|
||||
formField.addValue(withJid.toString());
|
||||
return formField;
|
||||
return FormField.builder(FORM_FIELD_WITH)
|
||||
.addValue(withJid.toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
public MamQuery queryMostRecentPage(Jid jid, int max) throws NoResponseException, XMPPErrorException,
|
||||
|
@ -711,9 +714,7 @@ public final class MamManager extends Manager {
|
|||
}
|
||||
|
||||
private static DataForm getNewMamForm() {
|
||||
FormField field = new FormField(FormField.FORM_TYPE);
|
||||
field.setType(FormField.Type.hidden);
|
||||
field.addValue(MamElements.NAMESPACE);
|
||||
FormField field = FormField.hiddenFormType(MamElements.NAMESPACE);
|
||||
DataForm form = new DataForm(DataForm.Type.submit);
|
||||
form.addField(field);
|
||||
return form;
|
||||
|
|
|
@ -100,16 +100,19 @@ public class EnablePushNotificationsIQ extends IQ {
|
|||
if (publishOptions != null) {
|
||||
DataForm dataForm = new DataForm(DataForm.Type.submit);
|
||||
|
||||
FormField formTypeField = new FormField("FORM_TYPE");
|
||||
// TODO: Shouldn't this use some potentially existing PubSub API? Also FORM_TYPE fields are usually of type
|
||||
// 'hidden', but the examples in XEP-0357 do also not set the value to hidden and FORM_TYPE itself appears
|
||||
// to be more convention than specification.
|
||||
FormField.Builder formTypeField = FormField.builder("FORM_TYPE");
|
||||
formTypeField.addValue(PubSub.NAMESPACE + "#publish-options");
|
||||
dataForm.addField(formTypeField);
|
||||
dataForm.addField(formTypeField.build());
|
||||
|
||||
Iterator<Map.Entry<String, String>> publishOptionsIterator = publishOptions.entrySet().iterator();
|
||||
while (publishOptionsIterator.hasNext()) {
|
||||
Map.Entry<String, String> pairVariableValue = publishOptionsIterator.next();
|
||||
FormField field = new FormField(pairVariableValue.getKey());
|
||||
FormField.Builder field = FormField.builder(pairVariableValue.getKey());
|
||||
field.addValue(pairVariableValue.getValue());
|
||||
dataForm.addField(field);
|
||||
dataForm.addField(field.build());
|
||||
}
|
||||
|
||||
xml.element(dataForm);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Fernando Ramirez, 2018 Florian Schmaus
|
||||
* Copyright 2016 Fernando Ramirez, 2018-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -36,7 +36,7 @@ public class RetrieveFormFieldsTest extends MamTest {
|
|||
|
||||
private static final String additionalFieldsStanza = "<x xmlns='jabber:x:data' type='submit'>" + "<field var='FORM_TYPE' type='hidden'>"
|
||||
+ "<value>" + MamElements.NAMESPACE + "</value>" + "</field>"
|
||||
+ "<field var='urn:example:xmpp:free-text-search' type='text-single'>" + "<value>Hi</value>" + "</field>"
|
||||
+ "<field var='urn:example:xmpp:free-text-search'>" + "<value>Hi</value>" + "</field>"
|
||||
+ "<field var='urn:example:xmpp:stanza-content' type='jid-single'>" + "<value>Hi2</value>" + "</field>"
|
||||
+ "</x>";
|
||||
|
||||
|
@ -50,13 +50,15 @@ public class RetrieveFormFieldsTest extends MamTest {
|
|||
|
||||
@Test
|
||||
public void checkAddAdditionalFieldsStanza() throws Exception {
|
||||
FormField field1 = new FormField("urn:example:xmpp:free-text-search");
|
||||
field1.setType(FormField.Type.text_single);
|
||||
field1.addValue("Hi");
|
||||
FormField field1 = FormField.builder("urn:example:xmpp:free-text-search")
|
||||
.setType(FormField.Type.text_single)
|
||||
.addValue("Hi")
|
||||
.build();
|
||||
|
||||
FormField field2 = new FormField("urn:example:xmpp:stanza-content");
|
||||
field2.setType(FormField.Type.jid_single);
|
||||
field2.addValue("Hi2");
|
||||
FormField field2 = FormField.builder("urn:example:xmpp:stanza-content")
|
||||
.setType(FormField.Type.jid_single)
|
||||
.addValue("Hi2")
|
||||
.build();
|
||||
|
||||
MamQueryArgs mamQueryArgs = MamQueryArgs.builder()
|
||||
.withAdditionalFormField(field1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue