Browse Source

Make ExtensionElement marker interface wrt. QNAME field

ExtensionElement is now a marker interface that requires all
implementation non-abstract classes to carry a static final QNAME
field (of type QName). This is verified by a new unit test.

Also FullyQualifiedElement is renamed to simply XmlElement. XmlElement
is used over ExtensionElement when implementing classes do not
statically know the qualified name of the XML elements they
represent. In general, XmlElement should be used sparingly, and every
XML element should be modeled by its own Java class (implementing
ExtensionElement).
master
Florian Schmaus 1 year ago
parent
commit
3d4e7938a7
  1. 1
      build.gradle
  2. 10
      smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
  3. 8
      smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
  4. 5
      smack-core/src/main/java/org/jivesoftware/smack/filter/ExtensionElementFilter.java
  5. 16
      smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java
  6. 21
      smack-core/src/main/java/org/jivesoftware/smack/packet/ExtensionElement.java
  7. 2
      smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java
  8. 2
      smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
  9. 6
      smack-core/src/main/java/org/jivesoftware/smack/packet/MessageView.java
  10. 2
      smack-core/src/main/java/org/jivesoftware/smack/packet/NamedElement.java
  11. 4
      smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java
  12. 4
      smack-core/src/main/java/org/jivesoftware/smack/packet/StandardExtensionElement.java
  13. 45
      smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java
  14. 20
      smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java
  15. 2
      smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaError.java
  16. 12
      smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaView.java
  17. 2
      smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java
  18. 2
      smack-core/src/main/java/org/jivesoftware/smack/packet/TopLevelStreamElement.java
  19. 20
      smack-core/src/main/java/org/jivesoftware/smack/packet/XmlElement.java
  20. 8
      smack-core/src/main/java/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java
  21. 4
      smack-core/src/main/java/org/jivesoftware/smack/provider/ExtensionElementProvider.java
  22. 21
      smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
  23. 8
      smack-core/src/main/java/org/jivesoftware/smack/util/PacketUtil.java
  24. 8
      smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java
  25. 16
      smack-core/src/main/java/org/jivesoftware/smack/util/XmppElementUtil.java
  26. 2
      smack-core/src/test/java/org/jivesoftware/smack/packet/StreamErrorTest.java
  27. 8
      smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/packet/CarbonExtension.java
  28. 4
      smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/filter/EligibleForChatMarkerFilter.java
  29. 17
      smack-experimental/src/main/java/org/jivesoftware/smackx/csi/packet/ClientStateIndication.java
  30. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/fallback_indication/FallbackIndicationListener.java
  31. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/fallback_indication/FallbackIndicationManager.java
  32. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/fallback_indication/provider/FallbackIndicationElementProvider.java
  33. 8
      smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/packet/AbstractHttpOverXmpp.java
  34. 2
      smack-experimental/src/main/java/org/jivesoftware/smackx/httpfileupload/HttpFileUploadManager.java
  35. 6
      smack-experimental/src/main/java/org/jivesoftware/smackx/iot/control/element/SetData.java
  36. 6
      smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/element/IoTDataExtensionElement.java
  37. 8
      smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/element/Checksum.java
  38. 7
      smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/element/JingleFileTransfer.java
  39. 4
      smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/element/Range.java
  40. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java
  41. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_fastening/MessageFasteningManager.java
  42. 16
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_fastening/element/FasteningElement.java
  43. 5
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_fastening/provider/FasteningElementProvider.java
  44. 2
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_markup/element/BlockQuoteElement.java
  45. 3
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_markup/element/CodeBlockElement.java
  46. 14
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_markup/element/ListElement.java
  47. 2
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_markup/element/MarkupElement.java
  48. 5
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_markup/element/SpanElement.java
  49. 2
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_markup/provider/MarkupElementProvider.java
  50. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_retraction/MessageRetractionManager.java
  51. 8
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_retraction/element/RetractedElement.java
  52. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_retraction/provider/RetractElementProvider.java
  53. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/message_retraction/provider/RetractedElementProvider.java
  54. 20
      smack-experimental/src/main/java/org/jivesoftware/smackx/reference/element/ReferenceElement.java
  55. 4
      smack-experimental/src/main/java/org/jivesoftware/smackx/reference/provider/ReferenceProvider.java
  56. 8
      smack-experimental/src/main/java/org/jivesoftware/smackx/spoiler/element/SpoilerElement.java
  57. 9
      smack-experimental/src/main/java/org/jivesoftware/smackx/stanza_content_encryption/element/ContentElement.java
  58. 8
      smack-experimental/src/main/java/org/jivesoftware/smackx/stanza_content_encryption/element/PayloadElement.java
  59. 1
      smack-experimental/src/main/java/org/jivesoftware/smackx/stanza_content_encryption/provider/AffixExtensionElementProvider.java
  60. 5
      smack-experimental/src/main/java/org/jivesoftware/smackx/stanza_content_encryption/provider/ContentElementProvider.java
  61. 4
      smack-experimental/src/test/java/org/jivesoftware/smackx/eme/ExplicitMessageEncryptionElementTest.java
  62. 1
      smack-experimental/src/test/java/org/jivesoftware/smackx/message_fastening/MessageFasteningElementsTest.java
  63. 1
      smack-experimental/src/test/java/org/jivesoftware/smackx/message_retraction/element/RetractElementTest.java
  64. 1
      smack-experimental/src/test/java/org/jivesoftware/smackx/message_retraction/element/RetractedElementTest.java
  65. 1
      smack-experimental/src/test/java/org/jivesoftware/smackx/stanza_content_encryption/element/ContentElementTest.java
  66. 1
      smack-experimental/src/test/java/org/jivesoftware/smackx/stanza_content_encryption/provider/ContentElementProviderTest.java
  67. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java
  68. 8
      smack-extensions/src/main/java/org/jivesoftware/smackx/attention/packet/AttentionExtension.java
  69. 1
      smack-extensions/src/main/java/org/jivesoftware/smackx/bob/element/BoBDataExtension.java
  70. 1
      smack-extensions/src/main/java/org/jivesoftware/smackx/bob/provider/BoBDataExtensionProvider.java
  71. 1
      smack-extensions/src/main/java/org/jivesoftware/smackx/bob/provider/BoBProviderUtil.java
  72. 17
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java
  73. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java
  74. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java
  75. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/packet/ChatStateExtension.java
  76. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java
  77. 1
      smack-extensions/src/main/java/org/jivesoftware/smackx/formtypes/FormFieldRegistry.java
  78. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/provider/RegistrationProvider.java
  79. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContent.java
  80. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescription.java
  81. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescriptionChildElement.java
  82. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentTransport.java
  83. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentTransportCandidate.java
  84. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentTransportInfo.java
  85. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleError.java
  86. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleReason.java
  87. 9
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_ibb/element/JingleIBBTransport.java
  88. 9
      smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/elements/JingleS5BTransport.java
  89. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/mediaelement/element/MediaElement.java
  90. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/mood/element/MoodElement.java
  91. 1
      smack-extensions/src/main/java/org/jivesoftware/smackx/offline/packet/OfflineMessageInfo.java
  92. 1
      smack-extensions/src/main/java/org/jivesoftware/smackx/offline/packet/OfflineMessageRequest.java
  93. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java
  94. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigurationEvent.java
  95. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EmbeddedPacketExtension.java
  96. 11
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java
  97. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java
  98. 10
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java
  99. 28
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
  100. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeExtension.java
  101. Some files were not shown because too many files have changed in this diff Show More

1
build.gradle

@ -153,6 +153,7 @@ allprojects {
bouncyCastleVersion = '1.68'
guavaVersion = '30.1-jre'
mockitoVersion = '3.7.7'
orgReflectionsVersion = '0.9.11'
if (project.hasProperty("useSonatype")) {
useSonatype = project.getProperty("useSonatype").toBoolean()

10
smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java

@ -74,7 +74,6 @@ import org.jivesoftware.smack.packet.AbstractStreamOpen;
import org.jivesoftware.smack.packet.Bind;
import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Mechanisms;
import org.jivesoftware.smack.packet.Message;
@ -92,6 +91,7 @@ import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.packet.TopLevelStreamElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.packet.id.StanzaIdSource;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
@ -239,7 +239,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected final Lock connectionLock = new ReentrantLock();
protected final Map<QName, FullyQualifiedElement> streamFeatures = new HashMap<>();
protected final Map<QName, XmlElement> streamFeatures = new HashMap<>();
/**
* The full JID of the authenticated user, as returned by the resource binding response of the server.
@ -1859,7 +1859,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getDepth() == initialDepth + 1) {
FullyQualifiedElement streamFeature = null;
XmlElement streamFeature = null;
String name = parser.getName();
String namespace = parser.getNamespace();
switch (name) {
@ -1928,7 +1928,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@SuppressWarnings("unchecked")
@Override
public <F extends FullyQualifiedElement> F getFeature(QName qname) {
public <F extends XmlElement> F getFeature(QName qname) {
return (F) streamFeatures.get(qname);
}
@ -1937,7 +1937,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return streamFeatures.containsKey(qname);
}
protected void addStreamFeature(FullyQualifiedElement feature) {
protected void addStreamFeature(XmlElement feature) {
QName key = feature.getQName();
streamFeatures.put(key, feature);
}

8
smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java

@ -27,7 +27,6 @@ import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.MessageBuilder;
@ -36,6 +35,7 @@ import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.PresenceBuilder;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StanzaFactory;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.util.Consumer;
import org.jivesoftware.smack.util.Predicate;
import org.jivesoftware.smack.util.XmppElementUtil;
@ -583,7 +583,7 @@ public interface XMPPConnection {
*/
// TODO: Remove in Smack 4.5.
@Deprecated
default <F extends FullyQualifiedElement> F getFeature(String element, String namespace) {
default <F extends XmlElement> F getFeature(String element, String namespace) {
QName qname = new QName(namespace, element);
return getFeature(qname);
}
@ -597,7 +597,7 @@ public interface XMPPConnection {
* @return a stanza extensions of the feature or <code>null</code>
* @since 4.4
*/
<F extends FullyQualifiedElement> F getFeature(QName qname);
<F extends XmlElement> F getFeature(QName qname);
/**
* Get the feature stanza extensions for a given stream feature of the
@ -608,7 +608,7 @@ public interface XMPPConnection {
* @return a stanza extensions of the feature or <code>null</code>
* @since 4.4
*/
default <F extends FullyQualifiedElement> F getFeature(Class<F> featureClass) {
default <F extends XmlElement> F getFeature(Class<F> featureClass) {
QName qname = XmppElementUtil.getQNameFor(featureClass);
return getFeature(qname);
}

5
smack-core/src/main/java/org/jivesoftware/smack/filter/ExtensionElementFilter.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2020 Florian Schmaus
* Copyright 2020-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@ import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.util.XmppElementUtil;
public class ExtensionElementFilter<E extends ExtensionElement> implements StanzaFilter {
@ -34,7 +35,7 @@ public class ExtensionElementFilter<E extends ExtensionElement> implements Stanz
@Override
public final boolean accept(Stanza stanza) {
ExtensionElement extensionElement = stanza.getExtension(extensionElementQName);
XmlElement extensionElement = stanza.getExtension(extensionElementQName);
if (extensionElement == null) {
return false;
}

16
smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2014-2015 Florian Schmaus
* Copyright 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,18 +32,18 @@ public class AbstractError {
protected final String textNamespace;
protected final Map<String, String> descriptiveTexts;
protected final List<ExtensionElement> extensions;
protected final List<XmlElement> extensions;
protected AbstractError(Map<String, String> descriptiveTexts) {
this(descriptiveTexts, null);
}
protected AbstractError(Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
protected AbstractError(Map<String, String> descriptiveTexts, List<XmlElement> extensions) {
this(descriptiveTexts, null, extensions);
}
protected AbstractError(Map<String, String> descriptiveTexts, String textNamespace, List<ExtensionElement> extensions) {
protected AbstractError(Map<String, String> descriptiveTexts, String textNamespace, List<XmlElement> extensions) {
if (descriptiveTexts != null) {
this.descriptiveTexts = descriptiveTexts;
} else {
@ -108,7 +108,7 @@ public class AbstractError {
* @param <PE> type of the ExtensionElement.
* @return the extension, or <code>null</code> if it doesn't exist.
*/
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
public <PE extends XmlElement> PE getExtension(String elementName, String namespace) {
return PacketUtil.extensionElementFrom(extensions, elementName, namespace);
}
@ -128,7 +128,7 @@ public class AbstractError {
public abstract static class Builder<B extends Builder<B>> {
protected String textNamespace;
protected Map<String, String> descriptiveTexts;
protected List<ExtensionElement> extensions;
protected List<XmlElement> extensions;
public B setDescriptiveTexts(Map<String, String> descriptiveTexts) {
if (descriptiveTexts == null) {
@ -173,7 +173,7 @@ public class AbstractError {
return getThis();
}
public B setExtensions(List<ExtensionElement> extensions) {
public B setExtensions(List<XmlElement> extensions) {
if (this.extensions == null) {
this.extensions = extensions;
}
@ -183,7 +183,7 @@ public class AbstractError {
return getThis();
}
public B addExtension(ExtensionElement extension) {
public B addExtension(XmlElement extension) {
if (extensions == null) {
extensions = new ArrayList<>();
}

21
smack-core/src/main/java/org/jivesoftware/smack/packet/ExtensionElement.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2018 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2018-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,21 +17,16 @@
package org.jivesoftware.smack.packet;
/**
* Interface to represent extension elements.
* Interface to represent XMPP extension elements. Unlike {@link XmlElement}, every non-abstract class that implements
* {@link ExtensionElement} must have a static final QNAME member of the type {@link javax.xml.namespace.QName}. This
* allows type-safe functions like {@link StanzaView#getExtension(Class)}. Hence this is a marker interface.
* <p>
* An extension element is an XML subdocument
* with a root element name and namespace. Extension elements are used to provide
* extended functionality beyond what is in the base XMPP specification. Examples of
* extensions elements include message events, message properties, and extra presence data.
* IQ stanzas have limited support for extension elements.
* <p>
* This class is used primarily for extended content in XMPP Stanzas, to act as so called "extension elements". For more
* information see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>.
* Use this class when implementing new extension elements when possible. This means that every instance of your
* implemented class must represent an XML element of the same qualified name.
* </p>
*
* @see org.jivesoftware.smack.provider.ExtensionElementProvider
* @author Matt Tucker
* @see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>
*/
public interface ExtensionElement extends FullyQualifiedElement {
public interface ExtensionElement extends XmlElement {
}

2
smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java

@ -211,7 +211,7 @@ public abstract class IQ extends Stanza implements IqView {
xml.append(iqChildElement);
List<ExtensionElement> extensionsXml = getExtensions();
List<XmlElement> extensionsXml = getExtensions();
if (iqChildElement.isEmptyElement) {
if (extensionsXml.isEmpty()) {
xml.closeEmptyElement();

2
smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java

@ -344,7 +344,7 @@ public final class Message extends MessageOrPresence<MessageBuilder>
@Deprecated
// TODO: Remove when stanza builder is ready.
public boolean removeBody(Body body) {
ExtensionElement removedElement = removeExtension(body);
XmlElement removedElement = removeExtension(body);
return removedElement != null;
}

6
smack-core/src/main/java/org/jivesoftware/smack/packet/MessageView.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2019-2020 Florian Schmaus
* Copyright 2003-2007 Jive Software, 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -150,9 +150,9 @@ public interface MessageView extends StanzaView {
* @since 3.0.2
*/
default Set<Message.Body> getBodies() {
List<ExtensionElement> bodiesList = getExtensions(Message.Body.QNAME);
List<XmlElement> bodiesList = getExtensions(Message.Body.QNAME);
Set<Message.Body> resultSet = new HashSet<>(bodiesList.size());
for (ExtensionElement extensionElement : bodiesList) {
for (XmlElement extensionElement : bodiesList) {
Message.Body body = (Message.Body) extensionElement;
resultSet.add(body);
}

2
smack-core/src/main/java/org/jivesoftware/smack/packet/NamedElement.java

@ -23,7 +23,7 @@ package org.jivesoftware.smack.packet;
* <p>
* Please note that usage of this interface is <b>discouraged</b>. The reason is that every XML element is fully
* qualified, i.e., it is qualified by a namespace. The namespace may not be explicitly given, but instead, is inherited
* from an outer element. Use {@link FullyQualifiedElement} instead when possible.
* from an outer element. Use {@link XmlElement} instead when possible.
* </p>
*/
public interface NamedElement extends Element {

4
smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2020 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2020-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -319,7 +319,7 @@ public final class Presence extends MessageOrPresence<PresenceBuilder>
buf.attribute("type", type);
}
List<ExtensionElement> extensions = getExtensions();
List<XmlElement> extensions = getExtensions();
if (status == null
&& priority == null
&& (mode == null || mode == Mode.available)

4
smack-core/src/main/java/org/jivesoftware/smack/packet/StandardExtensionElement.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2015-2020 Florian Schmaus.
* Copyright 2015-2021 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
* @since 4.2
* @author Florian Schmaus
*/
public final class StandardExtensionElement implements ExtensionElement {
public final class StandardExtensionElement implements XmlElement {
private final String name;
private final String namespace;

45
smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java

@ -64,7 +64,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
protected static final String DEFAULT_LANGUAGE =
java.util.Locale.getDefault().getLanguage().toLowerCase(Locale.US);
private final MultiMap<QName, ExtensionElement> extensionElements;
private final MultiMap<QName, XmlElement> extensionElements;
// Assume that all stanzas Smack handles are in the client namespace, since Smack is an XMPP client library. We can
// change this behavior later if it is required.
@ -284,18 +284,18 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
}
@Override
public final List<ExtensionElement> getExtensions() {
public final List<XmlElement> getExtensions() {
synchronized (extensionElements) {
// No need to create a new list, values() will already create a new one for us
return extensionElements.values();
}
}
public final MultiMap<QName, ExtensionElement> getExtensionsMap() {
public final MultiMap<QName, XmlElement> getExtensionsMap() {
return cloneExtensionsMap();
}
final MultiMap<QName, ExtensionElement> cloneExtensionsMap() {
final MultiMap<QName, XmlElement> cloneExtensionsMap() {
synchronized (extensionElements) {
return extensionElements.clone();
}
@ -312,7 +312,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @return a set of all matching extensions.
* @since 4.1
*/
public final List<ExtensionElement> getExtensions(String elementName, String namespace) {
public final List<XmlElement> getExtensions(String elementName, String namespace) {
requireNotNullNorEmpty(elementName, "elementName must not be null nor empty");
requireNotNullNorEmpty(namespace, "namespace must not be null nor empty");
QName key = new QName(namespace, elementName);
@ -320,8 +320,8 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
}
@Override
public final List<ExtensionElement> getExtensions(QName qname) {
List<ExtensionElement> res;
public final List<XmlElement> getExtensions(QName qname) {
List<XmlElement> res;
synchronized (extensionElements) {
res = extensionElements.getAll(qname);
}
@ -344,7 +344,8 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @param namespace the namespace of the extension that is desired.
* @return the stanza extension with the given namespace.
*/
public final ExtensionElement getExtension(String namespace) {
// TODO: Mark this method as deprecated in favor of getExtension(QName).
public final XmlElement getExtension(String namespace) {
return PacketUtil.extensionElementFrom(getExtensions(), null, namespace);
}
@ -361,12 +362,12 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @param namespace the XML element namespace of the extension.
* @return the extension, or <code>null</code> if it doesn't exist.
*/
public final ExtensionElement getExtensionElement(String elementName, String namespace) {
public final XmlElement getExtensionElement(String elementName, String namespace) {
if (namespace == null) {
return null;
}
QName key = new QName(namespace, elementName);
ExtensionElement packetExtension = getExtension(key);
XmlElement packetExtension = getExtension(key);
if (packetExtension == null) {
return null;
}
@ -390,7 +391,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
}
@Override
public final ExtensionElement getExtension(QName qname) {
public final XmlElement getExtension(QName qname) {
synchronized (extensionElements) {
return extensionElements.getFirst(qname);
}
@ -400,13 +401,13 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* Adds a stanza extension to the packet. Does nothing if extension is null.
* <p>
* Please note that although this method is not yet marked as deprecated, it is recommended to use
* {@link StanzaBuilder#addExtension(ExtensionElement)} instead.
* {@link StanzaBuilder#addExtension(XmlElement)} instead.
* </p>
*
* @param extension a stanza extension.
*/
// TODO: Mark this as deprecated once StanzaBuilder is ready and all call sites are gone.
public final void addExtension(ExtensionElement extension) {
public final void addExtension(XmlElement extension) {
if (extension == null) return;
QName key = extension.getQName();
synchronized (extensionElements) {
@ -419,7 +420,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* namespace.
* <p>
* Please note that although this method is not yet marked as deprecated, it is recommended to use
* {@link StanzaBuilder#overrideExtension(ExtensionElement)} instead.
* {@link StanzaBuilder#overrideExtension(XmlElement)} instead.
* </p>
*
* @param extension the extension element to add.
@ -427,13 +428,13 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @since 4.1.2
*/
// TODO: Mark this as deprecated once StanzaBuilder is ready and all call sites are gone.
public final ExtensionElement overrideExtension(ExtensionElement extension) {
public final XmlElement overrideExtension(XmlElement extension) {
if (extension == null) return null;
synchronized (extensionElements) {
// Note that we need to use removeExtension(String, String) here. If would use
// removeExtension(ExtensionElement) then we would remove based on the equality of ExtensionElement, which
// is not what we want in this case.
ExtensionElement removedExtension = removeExtension(extension.getElementName(), extension.getNamespace());
XmlElement removedExtension = removeExtension(extension.getElementName(), extension.getNamespace());
addExtension(extension);
return removedExtension;
}
@ -445,9 +446,9 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @param extensions a collection of stanza extensions
*/
// TODO: Mark this as deprecated once StanzaBuilder is ready and all call sites are gone.
public final void addExtensions(Collection<? extends ExtensionElement> extensions) {
public final void addExtensions(Collection<? extends XmlElement> extensions) {
if (extensions == null) return;
for (ExtensionElement packetExtension : extensions) {
for (XmlElement packetExtension : extensions) {
addExtension(packetExtension);
}
}
@ -476,7 +477,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
@Override
public final boolean hasExtension(String namespace) {
synchronized (extensionElements) {
for (ExtensionElement packetExtension : extensionElements.values()) {
for (XmlElement packetExtension : extensionElements.values()) {
if (packetExtension.getNamespace().equals(namespace)) {
return true;
}
@ -493,7 +494,7 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
* @return the removed stanza extension or null.
*/
// TODO: Mark this as deprecated once StanzaBuilder is ready and all call sites are gone.
public final ExtensionElement removeExtension(String elementName, String namespace) {
public final XmlElement removeExtension(String elementName, String namespace) {
QName key = new QName(namespace, elementName);
synchronized (extensionElements) {
return extensionElements.remove(key);
@ -509,10 +510,10 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
*/
@Deprecated
// TODO: Remove in Smack 4.5.
public final ExtensionElement removeExtension(ExtensionElement extension) {
public final XmlElement removeExtension(XmlElement extension) {
QName key = extension.getQName();
synchronized (extensionElements) {
List<ExtensionElement> list = extensionElements.getAll(key);
List<XmlElement> list = extensionElements.getAll(key);
boolean removed = list.remove(extension);
if (removed) {
return extension;

20
smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2019-2020 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
String language;
MultiMap<QName, ExtensionElement> extensionElements = new MultiMap<>();
MultiMap<QName, XmlElement> extensionElements = new MultiMap<>();
protected StanzaBuilder(StanzaBuilder<?> other) {
stanzaIdSource = other.stanzaIdSource;
@ -156,13 +156,13 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
return getThis();
}
public final B addExtension(ExtensionElement extensionElement) {
public final B addExtension(XmlElement extensionElement) {
QName key = extensionElement.getQName();
extensionElements.put(key, extensionElement);
return getThis();
}
public final B addOptExtensions(Collection<? extends ExtensionElement> extensionElements) {
public final B addOptExtensions(Collection<? extends XmlElement> extensionElements) {
if (extensionElements == null) {
return getThis();
}
@ -170,14 +170,14 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
return addExtensions(extensionElements);
}
public final B addExtensions(Collection<? extends ExtensionElement> extensionElements) {
for (ExtensionElement extensionElement : extensionElements) {
public final B addExtensions(Collection<? extends XmlElement> extensionElements) {
for (XmlElement extensionElement : extensionElements) {
addExtension(extensionElement);
}
return getThis();
}
public final B overrideExtension(ExtensionElement extensionElement) {
public final B overrideExtension(XmlElement extensionElement) {
QName key = extensionElement.getQName();
extensionElements.remove(key);
extensionElements.put(key, extensionElement);
@ -214,17 +214,17 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
}
@Override
public final ExtensionElement getExtension(QName qname) {
public final XmlElement getExtension(QName qname) {
return extensionElements.getFirst(qname);
}
@Override
public final List<ExtensionElement> getExtensions() {
public final List<XmlElement> getExtensions() {
return extensionElements.values();
}
@Override
public final List<ExtensionElement> getExtensions(QName qname) {
public final List<XmlElement> getExtensions(QName qname) {
return extensionElements.getAll(qname);
}

2
smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaError.java

@ -125,7 +125,7 @@ public class StanzaError extends AbstractError implements ExtensionElement {
* @param extensions list of stanza extensions
*/
public StanzaError(Condition condition, String conditionText, String errorGenerator, Type type, Map<String, String> descriptiveTexts,
List<ExtensionElement> extensions) {
List<XmlElement> extensions) {
super(descriptiveTexts, ERROR_CONDITION_AND_TEXT_NAMESPACE, extensions);
this.condition = Objects.requireNonNull(condition, "condition must not be null");
// Some implementations may send the condition as non-empty element containing the empty string, that is

12
smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaView.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2019-2020 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ public interface StanzaView extends XmlLangElement {
*/
StanzaError getError();
ExtensionElement getExtension(QName qname);
XmlElement getExtension(QName qname);
default boolean hasExtension(QName qname) {
return getExtension(qname) != null;
@ -78,7 +78,7 @@ public interface StanzaView extends XmlLangElement {
* @return true if a stanza extension exists, false otherwise.
*/
default boolean hasExtension(String namespace) {
for (ExtensionElement packetExtension : getExtensions()) {
for (XmlElement packetExtension : getExtensions()) {
if (packetExtension.getNamespace().equals(namespace)) {
return true;
}
@ -89,7 +89,7 @@ public interface StanzaView extends XmlLangElement {
default <E extends ExtensionElement> E getExtension(Class<E> extensionElementClass) {
QName qname = XmppElementUtil.getQNameFor(extensionElementClass);
ExtensionElement extensionElement = getExtension(qname);
XmlElement extensionElement = getExtension(qname);
if (extensionElement == null) {
return null;
@ -103,9 +103,9 @@ public interface StanzaView extends XmlLangElement {
*
* @return a list of all extension elements of this stanza.
*/
List<ExtensionElement> getExtensions();
List<XmlElement> getExtensions();
List<ExtensionElement> getExtensions(QName qname);
List<XmlElement> getExtensions(QName qname);
/**
* Return all extension elements of the given type. Returns the empty list if there a none.

2
smack-core/src/main/java/org/jivesoftware/smack/packet/StreamError.java

@ -105,7 +105,7 @@ public class StreamError extends AbstractError implements Nonza {
private final Condition condition;
private final String conditionText;
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<XmlElement> extensions) {
super(descriptiveTexts, extensions);
// Some implementations may send the condition as non-empty element containing the empty string, that is
// <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string

2
smack-core/src/main/java/org/jivesoftware/smack/packet/TopLevelStreamElement.java

@ -20,6 +20,6 @@ package org.jivesoftware.smack.packet;
* A XMPP top level stream element. This is either a stanza ({@link Stanza}) or
* just a plain stream element ({@link Nonza}).
*/
public interface TopLevelStreamElement extends FullyQualifiedElement {
public interface TopLevelStreamElement extends XmlElement {
}

20
smack-core/src/main/java/org/jivesoftware/smack/packet/FullyQualifiedElement.java → smack-core/src/main/java/org/jivesoftware/smack/packet/XmlElement.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2018-2019 Florian Schmaus
* Copyright 2018-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,7 +18,23 @@ package org.jivesoftware.smack.packet;
import javax.xml.namespace.QName;
public interface FullyQualifiedElement extends NamedElement, XmlLangElement {
/**
* Interface to represent XML elements. Every XML element in XMPP has a qualified XML name ({@link QName}). This name
* can be obtained via {@link #getQName()}.
* <p>
* XMPP uses "extension elements", i.e. XML elements, to provide extended functionality beyond what is in the base XMPP
* specification. Examples of extensions elements include message events, message properties, and extra presence data.
* IQ stanzas have limited support for extension elements. See {@link ExtensionElement} for more information about XMPP
* extension elements.
* </p>
* <p>
* It is recommend to use {@link ExtensionElement} over this class when creating new extension elements.
* </p>
*
* @see org.jivesoftware.smack.provider.ExtensionElementProvider
* @since 4.5
*/
public interface XmlElement extends NamedElement, XmlLangElement {
/**
* Returns the root element XML namespace.

8
smack-core/src/main/java/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java

@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.util.PacketParserUtils;
@ -82,7 +82,7 @@ import org.jivesoftware.smack.xml.XmlPullParserException;
*
* @author Robin Collier
*/
public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
public abstract class EmbeddedExtensionProvider<PE extends XmlElement> extends ExtensionElementProvider<PE> {
@Override
public final PE parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
@ -95,7 +95,7 @@ public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> ext
attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
}
List<ExtensionElement> extensions = new ArrayList<>();
List<XmlElement> extensions = new ArrayList<>();
XmlPullParser.Event event;
do {
event = parser.next();
@ -109,5 +109,5 @@ public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> ext
}
protected abstract PE createReturnExtension(String currentElement, String currentNamespace,
Map<String, String> attributeMap, List<? extends ExtensionElement> content);
Map<String, String> attributeMap, List<? extends XmlElement> content);
}

4
smack-core/src/main/java/org/jivesoftware/smack/provider/ExtensionElementProvider.java

@ -17,7 +17,7 @@
package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
/**
* An abstract class for parsing custom extensions elements. Each ExtensionElementProvider must
@ -26,6 +26,6 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*
* @author Matt Tucker
*/
public abstract class ExtensionElementProvider<EE extends ExtensionElement> extends Provider<EE> {
public abstract class ExtensionElementProvider<E extends XmlElement> extends Provider<E> {
}

21
smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java

@ -48,6 +48,7 @@ import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.UnparsedIQ;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.StandardExtensionElementProvider;
@ -183,7 +184,7 @@ public class PacketParserUtils {
message.setError(parseError(parser, messageXmlEnvironment));
break;
default:
ExtensionElement extensionElement = parseExtensionElement(elementName, namespace, parser, messageXmlEnvironment);
XmlElement extensionElement = parseExtensionElement(elementName, namespace, parser, messageXmlEnvironment);
message.addExtension(extensionElement);
break;
}
@ -474,7 +475,7 @@ public class PacketParserUtils {
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
// failing completely here. See SMACK-390 for more information.
try {
ExtensionElement extensionElement = parseExtensionElement(elementName, namespace, parser, presenceXmlEnvironment);
XmlElement extensionElement = parseExtensionElement(elementName, namespace, parser, presenceXmlEnvironment);
presence.addExtension(extensionElement);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to parse extension element in Presence stanza: " + presence, e);
@ -701,7 +702,7 @@ public class PacketParserUtils {
*/
public static StreamError parseStreamError(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
final int initialDepth = parser.getDepth();
List<ExtensionElement> extensions = new ArrayList<>();
List<XmlElement> extensions = new ArrayList<>();
Map<String, String> descriptiveTexts = null;
StreamError.Condition condition = null;
String conditionText = null;
@ -765,7 +766,7 @@ public class PacketParserUtils {
final int initialDepth = parser.getDepth();
Map<String, String> descriptiveTexts = null;
XmlEnvironment stanzaErrorXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
List<ExtensionElement> extensions = new ArrayList<>();
List<XmlElement> extensions = new ArrayList<>();
StanzaError.Builder builder = StanzaError.getBuilder();
// Parse the error header
@ -825,7 +826,7 @@ public class PacketParserUtils {
* @throws IOException if an I/O error occurred.
* @throws SmackParsingException if the Smack parser (provider) encountered invalid input.
*/
public static ExtensionElement parseExtensionElement(String elementName, String namespace,
public static XmlElement parseExtensionElement(String elementName, String namespace,
XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
ParserUtils.assertAtStartTag(parser);
// See if a provider is registered to handle the extension.
@ -907,7 +908,7 @@ public class PacketParserUtils {
public static void addExtensionElement(StanzaBuilder<?> stanzaBuilder, XmlPullParser parser, String elementName,
String namespace, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
ExtensionElement extensionElement = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
XmlElement extensionElement = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
stanzaBuilder.addExtension(extensionElement);
}
@ -919,18 +920,18 @@ public class PacketParserUtils {
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
String namespace, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
XmlElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
packet.addExtension(packetExtension);
}
public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser parser, XmlEnvironment outerXmlEnvironment)
public static void addExtensionElement(Collection<XmlElement> collection, XmlPullParser parser, XmlEnvironment outerXmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace(), outerXmlEnvironment);
}
public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser parser,
public static void addExtensionElement(Collection<XmlElement> collection, XmlPullParser parser,
String elementName, String namespace, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
XmlElement packetExtension = parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
collection.add(packetExtension);
}
}

8
smack-core/src/main/java/org/jivesoftware/smack/util/PacketUtil.java

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2020 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,7 +18,7 @@ package org.jivesoftware.smack.util;
import java.util.Collection;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
public class PacketUtil {
@ -33,9 +33,9 @@ public class PacketUtil {
* @return the extension element
*/
@SuppressWarnings("unchecked")
public static <PE extends ExtensionElement> PE extensionElementFrom(Collection<ExtensionElement> collection,
public static <PE extends XmlElement> PE extensionElementFrom(Collection<XmlElement> collection,
String element, String namespace) {
for (ExtensionElement packetExtension : collection) {
for (XmlElement packetExtension : collection) {
if ((element == null || packetExtension.getElementName().equals(
element))
&& packetExtension.getNamespace().equals(namespace)) {

8
smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java

@ -24,8 +24,8 @@ import java.util.Date;
import java.util.List;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jxmpp.util.XmppDateTime;
@ -42,7 +42,7 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
effectiveXmlEnvironment = null;
}
public XmlStringBuilder(FullyQualifiedElement pe) {
public XmlStringBuilder(XmlElement pe) {
this(pe, null);
}
@ -51,7 +51,7 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
halfOpenElement(e.getElementName());
}
public XmlStringBuilder(FullyQualifiedElement element, XmlEnvironment enclosingXmlEnvironment) {
public XmlStringBuilder(XmlElement element, XmlEnvironment enclosingXmlEnvironment) {
sb = new LazyStringBuilder();
halfOpenElement(element);
@ -516,7 +516,7 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
return escape(text.toString());
}
protected XmlStringBuilder prelude(FullyQualifiedElement pe) {
protected XmlStringBuilder prelude(XmlElement pe) {
return prelude(pe.getElementName(), pe.getNamespace());
}

16
smack-core/src/main/java/org/jivesoftware/smack/util/XmppElementUtil.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2018-2020 Florian Schmaus
* Copyright 2018-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,19 +24,19 @@ import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.StandardExtensionElement;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jxmpp.util.cache.LruCache;
public class XmppElementUtil {
private static final LruCache<Class<? extends FullyQualifiedElement>, QName> CLASS_TO_QNAME_CACHE = new LruCache<>(512);
private static final LruCache<Class<? extends XmlElement>, QName> CLASS_TO_QNAME_CACHE = new LruCache<>(512);
public static final Logger LOGGER = Logger.getLogger(XmppElementUtil.class.getName());
public static QName getQNameFor(Class<? extends FullyQualifiedElement> fullyQualifiedElement) {
public static QName getQNameFor(Class<? extends XmlElement> fullyQualifiedElement) {
QName qname = CLASS_TO_QNAME_CACHE.get(fullyQualifiedElement);
if (qname != null) {
return qname;
@ -72,24 +72,24 @@ public class XmppElementUtil {
}
public static <E extends ExtensionElement> List<E> getElementsFrom(
MultiMap<QName, ExtensionElement> elementMap, Class<E> extensionElementClass) {
MultiMap<QName, XmlElement> elementMap, Class<E> extensionElementClass) {
QName qname = XmppElementUtil.getQNameFor(extensionElementClass);
List<ExtensionElement> extensionElements = elementMap.getAll(qname);
List<XmlElement> extensionElements = elementMap.getAll(qname);
if (extensionElements.isEmpty()) {
return Collections.emptyList();
}
List<E> res = new ArrayList<>(extensionElements.size());
for (ExtensionElement extensionElement : extensionElements) {
for (XmlElement extensionElement : extensionElements) {
E e = castOrThrow(extensionElement, extensionElementClass);
res.add(e);
}
return res;
}
public static <E extends ExtensionElement> E castOrThrow(ExtensionElement extensionElement, Class<E> extensionElementClass) {
public static <E extends ExtensionElement> E castOrThrow(XmlElement extensionElement, Class<E> extensionElementClass) {
if (!extensionElementClass.isInstance(extensionElement)) {
final QName qname = getQNameFor(extensionElementClass);

2
smack-core/src/test/java/org/jivesoftware/smack/packet/StreamErrorTest.java

@ -101,7 +101,7 @@ public class StreamErrorTest {
assertNotNull(error);
assertEquals(Condition.conflict, error.getCondition());
assertEquals("Replaced by new connection", error.getDescriptiveText());
ExtensionElement appSpecificElement = error.getExtension("appSpecificElement", "myns");
XmlElement appSpecificElement = error.getExtension("appSpecificElement", "myns");
assertNotNull(appSpecificElement);
}

8
smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/packet/CarbonExtension.java

@ -1,6 +1,6 @@
/**
*
* Copyright 2013-2014 Georg Lukas, 2020 Florian Schmaus
* Copyright 2013-2014 Georg Lukas, 2020-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,9 +16,12 @@
*/
package org.jivesoftware.smackx.carbons.packet;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.forward.packet.Forwarded;
@ -34,7 +37,7 @@ import org.jivesoftware.smackx.forward.packet.Forwarded;
*
* @author Georg Lukas
*/
public class CarbonExtension implements ExtensionElement {
public class CarbonExtension implements XmlElement {
public static final String NAMESPACE = Carbon.NAMESPACE;
private final Direction dir;
@ -136,6 +139,7 @@ public class CarbonExtension implements ExtensionElement {
public static final class Private implements ExtensionElement {
public static final Private INSTANCE = new Private();
public static final String ELEMENT = "private";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private Private() {
}

4
smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/filter/EligibleForChatMarkerFilter.java

@ -17,8 +17,8 @@
package org.jivesoftware.smackx.chat_markers.filter;
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XmlElement;
import org.jivesoftware.smackx.chatstates.ChatState;
import org.jivesoftware.smackx.chatstates.ChatStateManager;
@ -56,7 +56,7 @@ public final class EligibleForChatMarkerFilter extends StanzaExtensionFilter {
}
if (super.accept(message)) {
ExtensionElement extension = message.getExtension(ChatStateManager.NAMESPACE);
XmlElement extension = message.getExtension(ChatStateManager.NAMESPACE);
String chatStateElementName = extension.getElementName();
ChatState state;

17
smack-experimental/src/main/java/org/jivesoftware/smackx/csi/packet/ClientStateIndication.java

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2015 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");