mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-01-22 17:46:24 +01:00
Do not have Stanza.getExtension(String, String) return a generic type
Returning a generic would allow for List<ExtensionElement> list = stanza.getExtension("foo", "bar"); to compile (Note the we are calling getExtension(), not getExtension*s*()). Users are encouraged to use the type safe getExtension(Class<? extends ExtensionElement) variant instead. Fixes SMACK-825.
This commit is contained in:
parent
62916b8490
commit
07da9ffb48
65 changed files with 207 additions and 121 deletions
|
@ -26,7 +26,6 @@ import java.util.Set;
|
|||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message.Thread;
|
||||
import org.jivesoftware.smack.util.EqualsUtil;
|
||||
import org.jivesoftware.smack.util.HashCode;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
|
|
@ -356,11 +356,9 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
|
|||
*
|
||||
* @param elementName the XML element name of the extension. (May be null)
|
||||
* @param namespace the XML element namespace of the extension.
|
||||
* @param <PE> type of the ExtensionElement.
|
||||
* @return the extension, or <code>null</code> if it doesn't exist.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
|
||||
public final ExtensionElement getExtension(String elementName, String namespace) {
|
||||
if (namespace == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -369,14 +367,13 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
|
|||
if (packetExtension == null) {
|
||||
return null;
|
||||
}
|
||||
return (PE) packetExtension;
|
||||
return packetExtension;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public final <E extends ExtensionElement> E getExtension(QName qname) {
|
||||
public final ExtensionElement getExtension(QName qname) {
|
||||
synchronized (extensionElements) {
|
||||
return (E) extensionElements.getFirst(qname);
|
||||
return extensionElements.getFirst(qname);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,10 +211,9 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
|
|||
return stanzaError;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public final <E extends ExtensionElement> E getExtension(QName qname) {
|
||||
return (E) extensionElements.getFirst(qname);
|
||||
public final ExtensionElement getExtension(QName qname) {
|
||||
return extensionElements.getFirst(qname);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -61,7 +61,7 @@ public interface StanzaView extends XmlLangElement {
|
|||
*/
|
||||
StanzaError getError();
|
||||
|
||||
<E extends ExtensionElement> E getExtension(QName qname);
|
||||
ExtensionElement getExtension(QName qname);
|
||||
|
||||
default boolean hasExtension(QName qname) {
|
||||
return getExtension(qname) != null;
|
||||
|
|
|
@ -114,9 +114,9 @@ public class CarbonExtension implements ExtensionElement {
|
|||
* @return a Carbon if available, null otherwise.
|
||||
*/
|
||||
public static CarbonExtension from(Message msg) {
|
||||
CarbonExtension cc = msg.getExtension(Direction.received.name(), NAMESPACE);
|
||||
CarbonExtension cc = (CarbonExtension) msg.getExtension(Direction.received.name(), NAMESPACE);
|
||||
if (cc == null)
|
||||
cc = msg.getExtension(Direction.sent.name(), NAMESPACE);
|
||||
cc = (CarbonExtension) msg.getExtension(Direction.sent.name(), NAMESPACE);
|
||||
return cc;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Fernando Ramirez, 2018 Florian Schmaus
|
||||
* Copyright © 2016 Fernando Ramirez, 2018-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.
|
||||
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.chat_markers.element;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
@ -46,11 +48,11 @@ public class ChatMarkersElements {
|
|||
public static final class MarkableExtension implements ExtensionElement {
|
||||
|
||||
public static final MarkableExtension INSTANCE = new MarkableExtension();
|
||||
|
||||
/**
|
||||
* markable element.
|
||||
*/
|
||||
public static final String ELEMENT = ChatMarkersState.markable.toString();
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private MarkableExtension() {
|
||||
}
|
||||
|
@ -73,7 +75,7 @@ public class ChatMarkersElements {
|
|||
}
|
||||
|
||||
public static MarkableExtension from(Message message) {
|
||||
return (MarkableExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(MarkableExtension.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,6 +118,7 @@ public class ChatMarkersElements {
|
|||
* received element.
|
||||
*/
|
||||
public static final String ELEMENT = ChatMarkersState.received.toString();
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
public ReceivedExtension(String id) {
|
||||
super(id);
|
||||
|
@ -132,7 +135,7 @@ public class ChatMarkersElements {
|
|||
}
|
||||
|
||||
public static ReceivedExtension from(Message message) {
|
||||
return (ReceivedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(ReceivedExtension.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,6 +153,7 @@ public class ChatMarkersElements {
|
|||
* displayed element.
|
||||
*/
|
||||
public static final String ELEMENT = ChatMarkersState.displayed.toString();
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
public DisplayedExtension(String id) {
|
||||
super(id);
|
||||
|
@ -166,7 +170,7 @@ public class ChatMarkersElements {
|
|||
}
|
||||
|
||||
public static DisplayedExtension from(Message message) {
|
||||
return (DisplayedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(DisplayedExtension.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,6 +188,7 @@ public class ChatMarkersElements {
|
|||
* acknowledged element.
|
||||
*/
|
||||
public static final String ELEMENT = ChatMarkersState.acknowledged.toString();
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
public AcknowledgedExtension(String id) {
|
||||
super(id);
|
||||
|
@ -200,7 +205,7 @@ public class ChatMarkersElements {
|
|||
}
|
||||
|
||||
public static AcknowledgedExtension from(Message message) {
|
||||
return (AcknowledgedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(AcknowledgedExtension.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ public class ExplicitMessageEncryptionElement implements ExtensionElement {
|
|||
}
|
||||
|
||||
public static ExplicitMessageEncryptionElement from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(ExplicitMessageEncryptionElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014 Florian Schmaus
|
||||
* Copyright © 2014-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.
|
||||
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.gcm.packet;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;
|
||||
|
@ -33,6 +35,7 @@ public class GcmPacketExtension extends AbstractJsonPacketExtension {
|
|||
|
||||
public static final String ELEMENT = "gcm";
|
||||
public static final String NAMESPACE = "google:mobile:data";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
public GcmPacketExtension(String json) {
|
||||
super(json);
|
||||
|
@ -55,6 +58,6 @@ public class GcmPacketExtension extends AbstractJsonPacketExtension {
|
|||
* @return the GCM stanza extension or null.
|
||||
*/
|
||||
public static GcmPacketExtension from(Stanza packet) {
|
||||
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||
return packet.getExtension(GcmPacketExtension.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-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.
|
||||
|
@ -48,7 +48,7 @@ public final class NoCopyHint extends MessageProcessingHint {
|
|||
}
|
||||
|
||||
public static NoCopyHint from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return (NoCopyHint) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
||||
public static boolean hasHint(Message message) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-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.
|
||||
|
@ -48,7 +48,7 @@ public final class NoPermanentStoreHint extends MessageProcessingHint {
|
|||
}
|
||||
|
||||
public static NoPermanentStoreHint from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return (NoPermanentStoreHint) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
||||
public static boolean hasHint(Message message) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-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.
|
||||
|
@ -48,7 +48,7 @@ public final class NoStoreHint extends MessageProcessingHint {
|
|||
}
|
||||
|
||||
public static NoStoreHint from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return (NoStoreHint) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
||||
public static boolean hasHint(Message message) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017-2019 Florian Schmaus
|
||||
* Copyright 2017-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.
|
||||
|
@ -53,7 +53,7 @@ public final class StoreHint extends MessageProcessingHint {
|
|||
}
|
||||
|
||||
public static StoreHint from(MessageView message) {
|
||||
return message.getExtension(QNAME);
|
||||
return message.getExtension(StoreHint.class);
|
||||
}
|
||||
|
||||
public static boolean hasHint(MessageView message) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Florian Schmaus
|
||||
* Copyright © 2016-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.
|
||||
|
@ -20,6 +20,8 @@ import java.util.Collections;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
@ -30,6 +32,7 @@ public class IoTFieldsExtension implements ExtensionElement {
|
|||
|
||||
public static final String ELEMENT = "fields";
|
||||
public static final String NAMESPACE = Constants.IOT_SENSORDATA_NAMESPACE;
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final int seqNr;
|
||||
private final boolean done;
|
||||
|
@ -88,6 +91,6 @@ public class IoTFieldsExtension implements ExtensionElement {
|
|||
}
|
||||
|
||||
public static IoTFieldsExtension from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(IoTFieldsExtension.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Florian Schmaus
|
||||
* Copyright © 2016-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.
|
||||
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.iot.provisioning.element;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
@ -27,6 +29,7 @@ public class Friend implements ExtensionElement {
|
|||
|
||||
public static final String ELEMENT = "friend";
|
||||
public static final String NAMESPACE = Constants.IOT_PROVISIONING_NAMESPACE;
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final BareJid friend;
|
||||
|
||||
|
@ -57,6 +60,6 @@ public class Friend implements ExtensionElement {
|
|||
}
|
||||
|
||||
public static Friend from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(Friend.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Florian Schmaus
|
||||
* Copyright © 2016-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.
|
||||
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.iot.provisioning.element;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
@ -25,6 +27,7 @@ import org.jxmpp.jid.BareJid;
|
|||
public class Unfriend implements ExtensionElement {
|
||||
public static final String ELEMENT = "UNFRIEND";
|
||||
public static final String NAMESPACE = Constants.IOT_PROVISIONING_NAMESPACE;
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final BareJid jid;
|
||||
|
||||
|
@ -55,6 +58,6 @@ public class Unfriend implements ExtensionElement {
|
|||
}
|
||||
|
||||
public static Unfriend from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(Unfriend.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014 Florian Schmaus
|
||||
* Copyright © 2014-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.
|
||||
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.json.packet;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +29,7 @@ public class JsonPacketExtension extends AbstractJsonPacketExtension {
|
|||
|
||||
public static final String ELEMENT = "json";
|
||||
public static final String NAMESPACE = "urn:xmpp:json:0";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
public JsonPacketExtension(String json) {
|
||||
super(json);
|
||||
|
@ -49,6 +52,6 @@ public class JsonPacketExtension extends AbstractJsonPacketExtension {
|
|||
* @return the JSON stanza extension or null.
|
||||
*/
|
||||
public static JsonPacketExtension from(Stanza packet) {
|
||||
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||
return packet.getExtension(JsonPacketExtension.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.Element;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
@ -44,6 +46,7 @@ public abstract class MUCLightElements {
|
|||
|
||||
public static final String ELEMENT = DataForm.ELEMENT;
|
||||
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final HashMap<Jid, MUCLightAffiliation> affiliations;
|
||||
private final String prevVersion;
|
||||
|
@ -112,7 +115,7 @@ public abstract class MUCLightElements {
|
|||
}
|
||||
|
||||
public static AffiliationsChangeExtension from(Message message) {
|
||||
return message.getExtension(AffiliationsChangeExtension.ELEMENT, AffiliationsChangeExtension.NAMESPACE);
|
||||
return message.getExtension(AffiliationsChangeExtension.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -230,7 +233,7 @@ public abstract class MUCLightElements {
|
|||
}
|
||||
|
||||
public static ConfigurationsChangeExtension from(Message message) {
|
||||
return message.getExtension(ConfigurationsChangeExtension.ELEMENT, ConfigurationsChangeExtension.NAMESPACE);
|
||||
return (ConfigurationsChangeExtension) message.getExtension(ConfigurationsChangeExtension.ELEMENT, ConfigurationsChangeExtension.NAMESPACE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.push_notifications.element;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
@ -40,6 +42,7 @@ public class PushNotificationsElements {
|
|||
|
||||
public static final String NAMESPACE = PubSub.NAMESPACE;
|
||||
public static final String ELEMENT = PubSub.ELEMENT;
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final String node;
|
||||
private final Jid userJid;
|
||||
|
@ -94,7 +97,7 @@ public class PushNotificationsElements {
|
|||
}
|
||||
|
||||
public static RemoteDisablingExtension from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(RemoteDisablingExtension.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class OriginIdElement extends StableAndUniqueIdElement {
|
|||
* @return origin-id element
|
||||
*/
|
||||
public static OriginIdElement getOriginId(Message message) {
|
||||
return message.getExtension(OriginIdElement.ELEMENT, StableUniqueStanzaIdManager.NAMESPACE);
|
||||
return (OriginIdElement) message.getExtension(OriginIdElement.ELEMENT, StableUniqueStanzaIdManager.NAMESPACE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.sid.element;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
@ -24,6 +26,8 @@ import org.jivesoftware.smackx.sid.StableUniqueStanzaIdManager;
|
|||
public class StanzaIdElement extends StableAndUniqueIdElement {
|
||||
|
||||
public static final String ELEMENT = "stanza-id";
|
||||
public static final String NAMESPACE = StableUniqueStanzaIdManager.NAMESPACE;
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
public static final String ATTR_BY = "by";
|
||||
|
||||
private final String by;
|
||||
|
@ -55,7 +59,7 @@ public class StanzaIdElement extends StableAndUniqueIdElement {
|
|||
* @return stanza-id element of a jid, or null if absent.
|
||||
*/
|
||||
public static StanzaIdElement getStanzaId(Message message) {
|
||||
return message.getExtension(StanzaIdElement.ELEMENT, StableUniqueStanzaIdManager.NAMESPACE);
|
||||
return message.getExtension(StanzaIdElement.class);
|
||||
}
|
||||
|
||||
public String getBy() {
|
||||
|
|
|
@ -44,7 +44,7 @@ public class SpoilerTest extends SmackTestSuite {
|
|||
Message message = StanzaBuilder.buildMessage().build();
|
||||
SpoilerElement.addSpoiler(message);
|
||||
|
||||
SpoilerElement empty = message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
SpoilerElement empty = (SpoilerElement) message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
|
||||
assertNull(empty.getHint());
|
||||
assertNull(empty.getLanguage());
|
||||
|
@ -63,7 +63,7 @@ public class SpoilerTest extends SmackTestSuite {
|
|||
Message message = StanzaBuilder.buildMessage().build();
|
||||
SpoilerElement.addSpoiler(message, "Love story end");
|
||||
|
||||
SpoilerElement withHint = message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
SpoilerElement withHint = (SpoilerElement) message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
|
||||
assertEquals("Love story end", withHint.getHint());
|
||||
assertNull(withHint.getLanguage());
|
||||
|
@ -83,7 +83,7 @@ public class SpoilerTest extends SmackTestSuite {
|
|||
Message message = StanzaBuilder.buildMessage().build();
|
||||
SpoilerElement.addSpoiler(message, "de", "Der Kuchen ist eine Lüge!");
|
||||
|
||||
SpoilerElement i18nHint = message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
SpoilerElement i18nHint = (SpoilerElement) message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
|
||||
assertEquals("Der Kuchen ist eine Lüge!", i18nHint.getHint());
|
||||
assertEquals("de", i18nHint.getLanguage());
|
||||
|
|
|
@ -203,7 +203,7 @@ public class MultipleRecipientManager {
|
|||
* if none was found.
|
||||
*/
|
||||
public static MultipleRecipientInfo getMultipleRecipientInfo(Stanza packet) {
|
||||
MultipleAddresses extension = packet.getExtension(MultipleAddresses.ELEMENT, MultipleAddresses.NAMESPACE);
|
||||
MultipleAddresses extension = packet.getExtension(MultipleAddresses.class);
|
||||
return extension == null ? null : new MultipleRecipientInfo(extension);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.jivesoftware.smackx.address.packet;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
@ -34,6 +36,7 @@ public class MultipleAddresses implements ExtensionElement {
|
|||
|
||||
public static final String NAMESPACE = "http://jabber.org/protocol/address";
|
||||
public static final String ELEMENT = "addresses";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
public enum Type {
|
||||
bcc,
|
||||
|
|
|
@ -91,7 +91,7 @@ public class BoBExtension extends XHTMLExtension {
|
|||
}
|
||||
|
||||
public static BoBExtension from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return (BoBExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -535,8 +535,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
public void processStanza(Stanza packet) {
|
||||
// get data packet extension
|
||||
DataPacketExtension data = packet.getExtension(
|
||||
DataPacketExtension.ELEMENT,
|
||||
DataPacketExtension.NAMESPACE);
|
||||
DataPacketExtension.class);
|
||||
|
||||
// check if encoded data is valid
|
||||
if (data.getDecodedData() == null) {
|
||||
|
@ -590,8 +589,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
|||
} else {
|
||||
// stanza contains data packet extension
|
||||
data = packet.getExtension(
|
||||
DataPacketExtension.ELEMENT,
|
||||
DataPacketExtension.NAMESPACE);
|
||||
DataPacketExtension.class);
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.IQ.IQChildElementXmlStringBuilder;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
@ -39,6 +41,8 @@ public class DataPacketExtension implements ExtensionElement {
|
|||
*/
|
||||
public static final String NAMESPACE = "http://jabber.org/protocol/ibb";
|
||||
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
/* unique session ID identifying this In-Band Bytestream */
|
||||
private final String sessionID;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2009 Jonas Ådahl, 2011-2014 Florian Schmaus
|
||||
* Copyright © 2009 Jonas Ådahl, 2011-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.
|
||||
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.caps.packet;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
@ -26,6 +28,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
|||
public class CapsExtension implements ExtensionElement {
|
||||
public static final String NAMESPACE = "http://jabber.org/protocol/caps";
|
||||
public static final String ELEMENT = "c";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final String node, ver, hash;
|
||||
|
||||
|
@ -77,6 +80,6 @@ public class CapsExtension implements ExtensionElement {
|
|||
}
|
||||
|
||||
public static CapsExtension from(Stanza stanza) {
|
||||
return stanza.getExtension(ELEMENT, NAMESPACE);
|
||||
return stanza.getExtension(CapsExtension.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014 Florian Schmaus
|
||||
* Copyright © 2014-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.
|
||||
|
@ -18,6 +18,8 @@ package org.jivesoftware.smackx.delay;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
|
@ -34,6 +36,7 @@ public class DelayInformationManager {
|
|||
|
||||
public static final String LEGACY_DELAYED_DELIVERY_NAMESPACE = "jabber:x:delay";
|
||||
public static final String LEGACY_DELAYED_DELIVERY_ELEMENT = "x";
|
||||
public static final QName QNAME = new QName(LEGACY_DELAYED_DELIVERY_NAMESPACE, LEGACY_DELAYED_DELIVERY_ELEMENT);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -57,7 +60,7 @@ public class DelayInformationManager {
|
|||
* @return the Delayed Delivery information or <code>null</code>
|
||||
*/
|
||||
public static DelayInformation getLegacyDelayInformation(Stanza packet) {
|
||||
return packet.getExtension(LEGACY_DELAYED_DELIVERY_ELEMENT, LEGACY_DELAYED_DELIVERY_NAMESPACE);
|
||||
return packet.getExtension(DelayInformation.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.jivesoftware.smackx.delay.packet;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
@ -39,6 +41,7 @@ import org.jxmpp.util.XmppDateTime;
|
|||
public class DelayInformation implements ExtensionElement {
|
||||
public static final String ELEMENT = "delay";
|
||||
public static final String NAMESPACE = "urn:xmpp:delay";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final Date stamp;
|
||||
private final String from;
|
||||
|
@ -129,6 +132,6 @@ public class DelayInformation implements ExtensionElement {
|
|||
* @return the DelayInformation or null
|
||||
*/
|
||||
public static DelayInformation from(Stanza packet) {
|
||||
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||
return packet.getExtension(DelayInformation.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
@ -36,6 +38,7 @@ import org.jivesoftware.smackx.delay.packet.DelayInformation;
|
|||
public class Forwarded implements ExtensionElement {
|
||||
public static final String NAMESPACE = "urn:xmpp:forward:0";
|
||||
public static final String ELEMENT = "forwarded";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final DelayInformation delay;
|
||||
private final Stanza forwardedPacket;
|
||||
|
@ -115,7 +118,7 @@ public class Forwarded implements ExtensionElement {
|
|||
* @return the Forwarded extension or null
|
||||
*/
|
||||
public static Forwarded from(Stanza packet) {
|
||||
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||
return packet.getExtension(Forwarded.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -274,7 +274,7 @@ public final class GeoLocation implements Serializable, ExtensionElement, FormFi
|
|||
}
|
||||
|
||||
public static GeoLocation from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(GeoLocation.class);
|
||||
}
|
||||
|
||||
public static GeoLocation from(FormField formField) {
|
||||
|
|
|
@ -95,7 +95,7 @@ public class JivePropertiesManager {
|
|||
*/
|
||||
public static Object getProperty(StanzaView packet, String name) {
|
||||
Object res = null;
|
||||
JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.QNAME);
|
||||
JivePropertiesExtension jpe = packet.getExtension(JivePropertiesExtension.class);
|
||||
if (jpe != null) {
|
||||
res = jpe.getProperty(name);
|
||||
}
|
||||
|
|
|
@ -213,6 +213,6 @@ public class JivePropertiesExtension implements ExtensionElement {
|
|||
* @since 4.2
|
||||
*/
|
||||
public static JivePropertiesExtension from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(JivePropertiesExtension.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.jivesoftware.smackx.last_interaction.element;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
@ -27,6 +29,7 @@ public class IdleElement implements ExtensionElement {
|
|||
|
||||
public static final String NAMESPACE = "urn:xmpp:idle:1";
|
||||
public static final String ELEMENT = "idle";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
public static final String ATTR_SINCE = "since";
|
||||
|
||||
private final Date since;
|
||||
|
@ -70,7 +73,7 @@ public class IdleElement implements ExtensionElement {
|
|||
* @return idleElement from presence or null
|
||||
*/
|
||||
public static IdleElement fromPresence(Presence presence) {
|
||||
return presence.getExtension(ELEMENT, NAMESPACE);
|
||||
return presence.getExtension(IdleElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.message_correct.element;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
@ -44,6 +46,8 @@ public class MessageCorrectExtension implements ExtensionElement {
|
|||
*/
|
||||
public static final String NAMESPACE = "urn:xmpp:message-correct:0";
|
||||
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
/**
|
||||
* The id tag of a 'message correct' extension.
|
||||
*/
|
||||
|
@ -81,7 +85,7 @@ public class MessageCorrectExtension implements ExtensionElement {
|
|||
}
|
||||
|
||||
public static MessageCorrectExtension from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(MessageCorrectExtension.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.mood.element;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.FullyQualifiedElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
@ -36,6 +38,8 @@ public class MoodElement implements ExtensionElement {
|
|||
|
||||
public static final String NAMESPACE = "http://jabber.org/protocol/mood";
|
||||
public static final String ELEMENT = "mood";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
public static final String ELEM_TEXT = "text";
|
||||
|
||||
private final MoodSubjectElement mood;
|
||||
|
@ -136,7 +140,7 @@ public class MoodElement implements ExtensionElement {
|
|||
* @return {@link MoodElement} or null.
|
||||
*/
|
||||
public static MoodElement fromMessage(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
return message.getExtension(MoodElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.jivesoftware.smackx.muc.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
|
@ -68,6 +70,8 @@ public class GroupChatInvitation implements ExtensionElement {
|
|||
*/
|
||||
public static final String NAMESPACE = "jabber:x:conference";
|
||||
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final String roomAddress;
|
||||
|
||||
/**
|
||||
|
@ -128,7 +132,7 @@ public class GroupChatInvitation implements ExtensionElement {
|
|||
* @return the GroupChatInvitation or null
|
||||
*/
|
||||
public static GroupChatInvitation from(Stanza packet) {
|
||||
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||
return packet.getExtension(GroupChatInvitation.class);
|
||||
}
|
||||
|
||||
public static class Provider extends ExtensionElementProvider<GroupChatInvitation> {
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.jivesoftware.smackx.muc.packet;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
@ -42,6 +44,7 @@ public class MUCInitialPresence implements ExtensionElement {
|
|||
|
||||
public static final String ELEMENT = "x";
|
||||
public static final String NAMESPACE = "http://jabber.org/protocol/muc";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
// TODO make those fields final once deprecated setter methods have been removed.
|
||||
private String password;
|
||||
|
@ -156,7 +159,7 @@ public class MUCInitialPresence implements ExtensionElement {
|
|||
* @return the MUCInitialPresence PacketExtension or {@code null}
|
||||
*/
|
||||
public static MUCInitialPresence from(Stanza packet) {
|
||||
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||
return packet.getExtension(MUCInitialPresence.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,8 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
@ -41,6 +43,7 @@ public class MUCUser implements ExtensionElement {
|
|||
|
||||
public static final String ELEMENT = "x";
|
||||
public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#user";
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private final Set<Status> statusCodes = new HashSet<>(4);
|
||||
|
||||
|
@ -236,7 +239,7 @@ public class MUCUser implements ExtensionElement {
|
|||
* @return the MUCUser PacketExtension or {@code null}
|
||||
*/
|
||||
public static MUCUser from(Stanza packet) {
|
||||
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||
return packet.getExtension(MUCUser.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -159,8 +159,7 @@ public class OfflineMessageManager {
|
|||
StanzaFilter messageFilter = new AndFilter(PACKET_FILTER, new StanzaFilter() {
|
||||
@Override
|
||||
public boolean accept(Stanza packet) {
|
||||
OfflineMessageInfo info = packet.getExtension("offline",
|
||||
namespace);
|
||||
OfflineMessageInfo info = packet.getExtension(OfflineMessageInfo.class);
|
||||
return nodes.contains(info.getNode());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.jivesoftware.smackx.pubsub;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||