mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 10:19:41 +02:00
Re-work data form API
Apply builder pattern to form fields and replace getVariable() with getFieldName(). Refer to the field name as "field name" instead of "variable" everyone, just as XEP-0004 does. Improve the high-level form API: introduce FilledForm and FillableForm which perform stronger validation and consistency checks. Also add FormFieldRegistry to enable processing of 'submit' forms where the form field types are omitted. Smack also now does omit the form field type declaration on 'submit' type forms, as it is allowed by XEP-0004.
This commit is contained in:
parent
3270c113c5
commit
77e26fc575
97 changed files with 3809 additions and 2427 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Florian Schmaus
|
||||
* Copyright 2019-2020 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -30,6 +30,10 @@ public class SmackParsingException extends Exception {
|
|||
super(exception);
|
||||
}
|
||||
|
||||
public SmackParsingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public static class SmackTextParseException extends SmackParsingException {
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -18,9 +18,12 @@ package org.jivesoftware.smack.util;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CollectionUtil {
|
||||
|
@ -59,6 +62,20 @@ public class CollectionUtil {
|
|||
return new ArrayList<>(collection);
|
||||
}
|
||||
|
||||
public static <T> List<T> cloneAndSeal(Collection<? extends T> collection) {
|
||||
if (collection == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
ArrayList<T> clone = newListWith(collection);
|
||||
return Collections.unmodifiableList(clone);
|
||||
}
|
||||
|
||||
public static <K, V> Map<K, V> cloneAndSeal(Map<K, V> map) {
|
||||
Map<K, V> clone = new HashMap<>(map);
|
||||
return Collections.unmodifiableMap(clone);
|
||||
}
|
||||
|
||||
public static <T> Set<T> newSetWith(Collection<? extends T> collection) {
|
||||
if (collection == null) {
|
||||
return null;
|
||||
|
|
|
@ -20,8 +20,10 @@ package org.jivesoftware.smack.util;
|
|||
import java.io.IOException;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -591,4 +593,11 @@ public class StringUtils {
|
|||
}
|
||||
return appendable.append('\n');
|
||||
}
|
||||
|
||||
public static final String PORTABLE_NEWLINE_REGEX = "\\r?\\n";
|
||||
|
||||
public static List<String> splitLinesPortable(String input) {
|
||||
String[] lines = input.split(PORTABLE_NEWLINE_REGEX);
|
||||
return Arrays.asList(lines);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,10 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
|||
.build();
|
||||
}
|
||||
|
||||
public XmlEnvironment getXmlEnvironment() {
|
||||
return effectiveXmlEnvironment;
|
||||
}
|
||||
|
||||
public XmlStringBuilder escapedElement(String name, String escapedContent) {
|
||||
assert escapedContent != null;
|
||||
openElement(name);
|
||||
|
@ -493,6 +497,13 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
|||
return this;
|
||||
}
|
||||
|
||||
public XmlStringBuilder optAppend(Collection<? extends Element> elements) {
|
||||
if (elements != null) {
|
||||
append(elements);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public XmlStringBuilder optTextChild(CharSequence sqc, NamedElement parentElement) {
|
||||
if (sqc == null) {
|
||||
return closeEmptyElement();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue