From 07da9ffb4810a3518fe3e38e3c619eac32298413 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 5 Apr 2020 22:10:05 +0200 Subject: [PATCH] Do not have Stanza.getExtension(String, String) return a generic type Returning a generic would allow for List 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 type of the ExtensionElement. * @return the extension, or null if it doesn't exist. */ - @SuppressWarnings("unchecked") - public final 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 getExtension(QName qname) { + public final ExtensionElement getExtension(QName qname) { synchronized (extensionElements) { - return (E) extensionElements.getFirst(qname); + return extensionElements.getFirst(qname); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java index cff077e29..a279b8036 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaBuilder.java @@ -211,10 +211,9 @@ public abstract class StanzaBuilder> implements Stanz return stanzaError; } - @SuppressWarnings("unchecked") @Override - public final E getExtension(QName qname) { - return (E) extensionElements.getFirst(qname); + public final ExtensionElement getExtension(QName qname) { + return extensionElements.getFirst(qname); } @Override diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaView.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaView.java index 9ba4febcf..981898965 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaView.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/StanzaView.java @@ -61,7 +61,7 @@ public interface StanzaView extends XmlLangElement { */ StanzaError getError(); - E getExtension(QName qname); + ExtensionElement getExtension(QName qname); default boolean hasExtension(QName qname) { return getExtension(qname) != null; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/packet/CarbonExtension.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/packet/CarbonExtension.java index 4ab1400af..6fb49ce39 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/packet/CarbonExtension.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/carbons/packet/CarbonExtension.java @@ -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; } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/ChatMarkersElements.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/ChatMarkersElements.java index cf6a21d49..97762fd4d 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/ChatMarkersElements.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/chat_markers/element/ChatMarkersElements.java @@ -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); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/eme/element/ExplicitMessageEncryptionElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/eme/element/ExplicitMessageEncryptionElement.java index 4c6cf0015..632a4611a 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/eme/element/ExplicitMessageEncryptionElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/eme/element/ExplicitMessageEncryptionElement.java @@ -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); } /** diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/gcm/packet/GcmPacketExtension.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/gcm/packet/GcmPacketExtension.java index 36fcd1201..f732a26f4 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/gcm/packet/GcmPacketExtension.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/gcm/packet/GcmPacketExtension.java @@ -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); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoCopyHint.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoCopyHint.java index 5cf5f33bc..393fe55fe 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoCopyHint.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoCopyHint.java @@ -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) { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoPermanentStoreHint.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoPermanentStoreHint.java index bbe68b9bc..63aea7699 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoPermanentStoreHint.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoPermanentStoreHint.java @@ -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) { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoStoreHint.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoStoreHint.java index a3bbd96cb..72bc4ff44 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoStoreHint.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoStoreHint.java @@ -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) { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/StoreHint.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/StoreHint.java index a7f6e052a..f1e6a7983 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/StoreHint.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/StoreHint.java @@ -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) { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/element/IoTFieldsExtension.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/element/IoTFieldsExtension.java index 9831e392c..cb280745f 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/element/IoTFieldsExtension.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/data/element/IoTFieldsExtension.java @@ -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); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/element/Friend.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/element/Friend.java index 30ccea94b..d4699d1e3 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/element/Friend.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/element/Friend.java @@ -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); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/element/Unfriend.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/element/Unfriend.java index da73304dc..badba93f1 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/element/Unfriend.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/element/Unfriend.java @@ -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); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/json/packet/JsonPacketExtension.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/json/packet/JsonPacketExtension.java index 606544da6..0ee9c946f 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/json/packet/JsonPacketExtension.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/json/packet/JsonPacketExtension.java @@ -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); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/element/MUCLightElements.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/element/MUCLightElements.java index 2828bebfb..ba14e5f62 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/element/MUCLightElements.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/muclight/element/MUCLightElements.java @@ -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 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); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/element/PushNotificationsElements.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/element/PushNotificationsElements.java index b258a2253..426f44b37 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/element/PushNotificationsElements.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/element/PushNotificationsElements.java @@ -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); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/sid/element/OriginIdElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/sid/element/OriginIdElement.java index 10531c4e3..10282b70b 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/sid/element/OriginIdElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/sid/element/OriginIdElement.java @@ -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 diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/sid/element/StanzaIdElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/sid/element/StanzaIdElement.java index 77b594c86..ccd1fa146 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/sid/element/StanzaIdElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/sid/element/StanzaIdElement.java @@ -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() { diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/spoiler/SpoilerTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/spoiler/SpoilerTest.java index 585d73a06..33104f575 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/spoiler/SpoilerTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/spoiler/SpoilerTest.java @@ -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()); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java index 6406cbcd4..eb1d611de 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java @@ -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); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java index 4e3f76f15..d4a81fea3 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java @@ -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, diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bob/element/BoBExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bob/element/BoBExtension.java index bd13c6513..a0ee8af9e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bob/element/BoBExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bob/element/BoBExtension.java @@ -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); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java index ea2948f86..c629ab4d0 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java @@ -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; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtension.java index e7d274739..e885c9013 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtension.java @@ -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; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/packet/CapsExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/packet/CapsExtension.java index 7ebaea5be..a3b547548 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/packet/CapsExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/packet/CapsExtension.java @@ -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); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/DelayInformationManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/DelayInformationManager.java index 88b74bbb7..ef582238b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/DelayInformationManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/DelayInformationManager.java @@ -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 null */ public static DelayInformation getLegacyDelayInformation(Stanza packet) { - return packet.getExtension(LEGACY_DELAYED_DELIVERY_ELEMENT, LEGACY_DELAYED_DELIVERY_NAMESPACE); + return packet.getExtension(DelayInformation.class); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/packet/DelayInformation.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/packet/DelayInformation.java index d022900ee..8e9f5d7ba 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/packet/DelayInformation.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/packet/DelayInformation.java @@ -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); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/forward/packet/Forwarded.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/forward/packet/Forwarded.java index e8c886692..4d55a7c69 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/forward/packet/Forwarded.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/forward/packet/Forwarded.java @@ -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); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/packet/GeoLocation.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/packet/GeoLocation.java index caa25b1fe..0b7b823fa 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/packet/GeoLocation.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/packet/GeoLocation.java @@ -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) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/JivePropertiesManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/JivePropertiesManager.java index b58970f23..f02f56c8e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/JivePropertiesManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/JivePropertiesManager.java @@ -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); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/packet/JivePropertiesExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/packet/JivePropertiesExtension.java index 5ca0a7087..4c6b3a685 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/packet/JivePropertiesExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jiveproperties/packet/JivePropertiesExtension.java @@ -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); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/IdleElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/IdleElement.java index 713115abd..2799c1224 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/IdleElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/IdleElement.java @@ -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); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/MessageCorrectExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/MessageCorrectExtension.java index 03f0c603f..f25f46a5a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/MessageCorrectExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/MessageCorrectExtension.java @@ -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); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/element/MoodElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/element/MoodElement.java index ef606387e..39b3c22bf 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/element/MoodElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/element/MoodElement.java @@ -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); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitation.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitation.java index f1244870e..3453f9c61 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitation.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/GroupChatInvitation.java @@ -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 { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCInitialPresence.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCInitialPresence.java index e47450932..8ef57edb3 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCInitialPresence.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCInitialPresence.java @@ -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); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCUser.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCUser.java index 600799d56..87cd64ace 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCUser.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCUser.java @@ -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 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); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java index 367e7811a..bcbba9411 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java @@ -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()); } }); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java index 70e0750ba..7a70c4f5d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java @@ -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; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.XmlStringBuilder; @@ -44,6 +46,8 @@ public class EventElement implements EmbeddedPacketExtension { */ public static final String NAMESPACE = PubSubNamespace.event.getXmlns(); + public static final QName QNAME = new QName(NAMESPACE, ELEMENT); + private final EventElementType type; private final NodeExtension ext; @@ -85,6 +89,6 @@ public class EventElement implements EmbeddedPacketExtension { } public static EventElement from(Stanza stanza) { - return stanza.getExtension(ELEMENT, NAMESPACE); + return stanza.getExtension(EventElement.class); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java index 815a05bd2..2a43636b2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java @@ -656,7 +656,7 @@ public abstract class Node { private static List getSubscriptionIds(Stanza packet) { - HeadersExtension headers = packet.getExtension("headers", "http://jabber.org/protocol/shim"); + HeadersExtension headers = packet.getExtension(HeadersExtension.class); List values = null; if (headers != null) { @@ -686,7 +686,7 @@ public abstract class Node { @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void processStanza(Stanza packet) { - EventElement event = packet.getExtension("event", PubSubNamespace.event.getXmlns()); + EventElement event = (EventElement) packet.getExtension("event", PubSubNamespace.event.getXmlns()); ItemsExtension itemsElem = (ItemsExtension) event.getEvent(); ItemPublishEvent eventItems = new ItemPublishEvent(itemsElem.getNode(), itemsElem.getItems(), getSubscriptionIds(packet), DelayInformationManager.getDelayTimestamp(packet)); // TODO: Use AsyncButOrdered (with Node as Key?) @@ -710,7 +710,7 @@ public abstract class Node { @Override public void processStanza(Stanza packet) { // CHECKSTYLE:OFF - EventElement event = packet.getExtension("event", PubSubNamespace.event.getXmlns()); + EventElement event = (EventElement) packet.getExtension("event", PubSubNamespace.event.getXmlns()); List extList = event.getExtensions(); @@ -749,7 +749,7 @@ public abstract class Node { @Override public void processStanza(Stanza packet) { - EventElement event = packet.getExtension("event", PubSubNamespace.event.getXmlns()); + EventElement event = (EventElement) packet.getExtension("event", PubSubNamespace.event.getXmlns()); ConfigurationEvent config = (ConfigurationEvent) event.getEvent(); // TODO: Use AsyncButOrdered (with Node as Key?) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java index 89dd1c761..420c36f5a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java @@ -25,6 +25,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; +import javax.xml.namespace.QName; + import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; @@ -213,7 +215,8 @@ public final class PubSubManager extends Manager { */ public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null); - NodeExtension elem = reply.getExtension("create", PubSubNamespace.basic.getXmlns()); + QName qname = new QName(PubSubNamespace.basic.getXmlns(), "create"); + NodeExtension elem = (NodeExtension) reply.getExtension(qname); LeafNode newNode = new LeafNode(this, elem.getNode()); nodeMap.put(newNode.getId(), newNode); @@ -500,7 +503,7 @@ public final class PubSubManager extends Manager { */ public List getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Stanza reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null); - SubscriptionsExtension subElem = reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns()); + SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns()); return subElem.getSubscriptions(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java index b505b364b..7b0d7e7f8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java @@ -37,7 +37,7 @@ public class NodeUtils { * @return The configuration form */ public static ConfigureForm getFormFromPacket(Stanza packet, PubSubElementType elem) { - FormNode config = packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns()); + FormNode config = (FormNode) packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns()); Form formReply = config.getForm(); return new ConfigureForm(formReply); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceipt.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceipt.java index 6ad2425b8..9df9575b7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceipt.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceipt.java @@ -19,6 +19,8 @@ package org.jivesoftware.smackx.receipts; import java.util.List; import java.util.Map; +import javax.xml.namespace.QName; + import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.provider.EmbeddedExtensionProvider; @@ -33,6 +35,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder; public class DeliveryReceipt implements ExtensionElement { public static final String NAMESPACE = "urn:xmpp:receipts"; public static final String ELEMENT = "received"; + public static final QName QNAME = new QName(NAMESPACE, ELEMENT); /** * original ID of the delivered message @@ -89,7 +92,7 @@ public class DeliveryReceipt implements ExtensionElement { * @return the {@link DeliveryReceipt} extension or {@code null} */ public static DeliveryReceipt from(Message message) { - return message.getExtension(ELEMENT, NAMESPACE); + return message.getExtension(DeliveryReceipt.class); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptRequest.java index 7473d7a5f..0fc5f2864 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptRequest.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptRequest.java @@ -18,6 +18,8 @@ package org.jivesoftware.smackx.receipts; import java.io.IOException; +import javax.xml.namespace.QName; + import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.MessageBuilder; @@ -35,6 +37,8 @@ import org.jivesoftware.smack.xml.XmlPullParserException; */ public class DeliveryReceiptRequest implements ExtensionElement { public static final String ELEMENT = "request"; + public static final String NAMESPACE = DeliveryReceipt.NAMESPACE; + public static final QName QNAME = new QName(NAMESPACE, ELEMENT); @Override public String getElementName() { @@ -70,7 +74,7 @@ public class DeliveryReceiptRequest implements ExtensionElement { * @return the {@link DeliveryReceiptRequest} extension or {@code null} */ public static DeliveryReceiptRequest from(Stanza packet) { - return packet.getExtension(ELEMENT, DeliveryReceipt.NAMESPACE); + return packet.getExtension(DeliveryReceiptRequest.class); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/rsm/packet/RSMSet.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/rsm/packet/RSMSet.java index 40301863d..e96f74bea 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/rsm/packet/RSMSet.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/rsm/packet/RSMSet.java @@ -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.rsm.packet; +import javax.xml.namespace.QName; + import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.XmlStringBuilder; @@ -24,6 +26,7 @@ public class RSMSet implements ExtensionElement { public static final String ELEMENT = "set"; public static final String NAMESPACE = "http://jabber.org/protocol/rsm"; + public static final QName QNAME = new QName(NAMESPACE, ELEMENT); private final String after; private final String before; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java index 2b734f61d..16167b293 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java @@ -204,7 +204,7 @@ public class UserSearch extends SimpleIQ { done = true; } } - if (search.getExtension("x", "jabber:x:data") == null) { + if (search.getExtension(DataForm.class) == null) { search.addExtension(dataForm); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/shim/packet/HeadersExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/shim/packet/HeadersExtension.java index 914f6dfa5..7b6120d6d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/shim/packet/HeadersExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/shim/packet/HeadersExtension.java @@ -19,6 +19,8 @@ package org.jivesoftware.smackx.shim.packet; import java.util.Collections; import java.util.List; +import javax.xml.namespace.QName; + import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.XmlStringBuilder; @@ -33,6 +35,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder; public class HeadersExtension implements ExtensionElement { public static final String ELEMENT = "headers"; public static final String NAMESPACE = "http://jabber.org/protocol/shim"; + public static final QName QNAME = new QName(NAMESPACE, ELEMENT); private final List
headers; @@ -74,6 +77,6 @@ public class HeadersExtension implements ExtensionElement { * @return the headers extension or null. */ public static HeadersExtension from(Stanza packet) { - return packet.getExtension(ELEMENT, NAMESPACE); + return packet.getExtension(HeadersExtension.class); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/element/UserTuneElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/element/UserTuneElement.java index 47a7bfd40..3208557bb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/element/UserTuneElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/element/UserTuneElement.java @@ -18,6 +18,8 @@ package org.jivesoftware.smackx.usertune.element; import java.net.URI; +import javax.xml.namespace.QName; + import org.jivesoftware.smack.datatypes.UInt16; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Message; @@ -35,6 +37,7 @@ public final class UserTuneElement implements ExtensionElement { public static final String NAMESPACE = "http://jabber.org/protocol/tune"; public static final String ELEMENT = "tune"; + public static final QName QNAME = new QName(NAMESPACE, ELEMENT); private final String artist; private final UInt16 length; @@ -116,11 +119,11 @@ public final class UserTuneElement implements ExtensionElement { } public static boolean hasUserTuneElement(Message message) { - return message.hasExtension(ELEMENT, NAMESPACE); + return message.hasExtension(UserTuneElement.class); } public static UserTuneElement from(Message message) { - return message.getExtension(ELEMENT, NAMESPACE); + return message.getExtension(UserTuneElement.class); } @Override diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java index 12d3bcab8..cbe796492 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java @@ -361,7 +361,7 @@ public class DataForm implements ExtensionElement { * @return the DataForm or null */ public static DataForm from(StanzaView stanzaView) { - return (DataForm) stanzaView.getExtension(QNAME); + return stanzaView.getExtension(DataForm.class); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/packet/XHTMLExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/packet/XHTMLExtension.java index 39713f951..75ebd5bdf 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/packet/XHTMLExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/packet/XHTMLExtension.java @@ -130,6 +130,6 @@ public class XHTMLExtension implements ExtensionElement { } public static XHTMLExtension from(MessageView message) { - return message.getExtension(QNAME); + return message.getExtension(XHTMLExtension.class); } } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java index 443cb24de..42b5a794c 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java @@ -101,7 +101,7 @@ public class InBandBytestreamSessionMessageTest extends InitExtensions { @Override public void verify(Message request, IQ response) { DataPacketExtension dpe = request.getExtension( - DataPacketExtension.ELEMENT, DataPacketExtension.NAMESPACE); + DataPacketExtension.class); assertEquals(lastSeq++, dpe.getSeq()); } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/geoloc/packet/GeoLocationTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/geoloc/packet/GeoLocationTest.java index d6114ebdc..2a1a45692 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/geoloc/packet/GeoLocationTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/geoloc/packet/GeoLocationTest.java @@ -117,8 +117,7 @@ public class GeoLocationTest extends InitExtensions { Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationMessageString); assertNotNull(messageWithGeoLocation); - GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.ELEMENT, - GeoLocation.NAMESPACE); + GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class); assertNotNull(geoLocation); assertNotNull(geoLocation.toXML()); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/geoloc/provider/GeoLocationProviderTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/geoloc/provider/GeoLocationProviderTest.java index 4cf5b5f6a..22fca1bac 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/geoloc/provider/GeoLocationProviderTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/geoloc/provider/GeoLocationProviderTest.java @@ -69,8 +69,7 @@ public class GeoLocationProviderTest extends InitExtensions { Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString); assertNotNull(messageWithGeoLocation); - GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.ELEMENT, - GeoLocation.NAMESPACE); + GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class); assertNotNull(geoLocation); assertEquals((Double) 23d, geoLocation.getAccuracy()); @@ -138,8 +137,7 @@ public class GeoLocationProviderTest extends InitExtensions { Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString); assertNotNull(messageWithGeoLocation); - GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.ELEMENT, - GeoLocation.NAMESPACE); + GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class); assertNotNull(geoLocation); assertEquals((Double) 23d, geoLocation.getAccuracy()); @@ -183,8 +181,7 @@ public class GeoLocationProviderTest extends InitExtensions { Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString); - GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.ELEMENT, - GeoLocation.NAMESPACE); + GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class); assertEquals((Double) 90d, geoLocation.getError()); } @@ -203,8 +200,7 @@ public class GeoLocationProviderTest extends InitExtensions { Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString); - GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.ELEMENT, - GeoLocation.NAMESPACE); + GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class); assertEquals((Double) 90d, geoLocation.getAccuracy()); } @@ -224,8 +220,7 @@ public class GeoLocationProviderTest extends InitExtensions { Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString); - GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.ELEMENT, - GeoLocation.NAMESPACE); + GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class); assertEquals((Double) 90d, geoLocation.getAccuracy()); assertNull(geoLocation.getError()); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java index 91374b43d..9e551003f 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java @@ -62,7 +62,7 @@ public class DeliveryReceiptTest extends InitExtensions { parser = PacketParserUtils.getParserFor(control); Message p = PacketParserUtils.parseMessage(parser); - DeliveryReceiptRequest drr = p.getExtension(DeliveryReceiptRequest.ELEMENT, DeliveryReceipt.NAMESPACE); + DeliveryReceiptRequest drr = p.getExtension(DeliveryReceiptRequest.class); assertNotNull(drr); assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(p)); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/rsm/provider/RSMSetProviderTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/rsm/provider/RSMSetProviderTest.java index 7a99a6af9..49622397b 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/rsm/provider/RSMSetProviderTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/rsm/provider/RSMSetProviderTest.java @@ -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. @@ -49,7 +49,7 @@ public class RSMSetProviderTest extends InitExtensions { // @formatter:on IQ iqWithRsm = PacketParserUtils.parseStanza(rsmset); - RSMSet rsm = iqWithRsm.getExtension(RSMSet.ELEMENT, RSMSet.NAMESPACE); + RSMSet rsm = iqWithRsm.getExtension(RSMSet.class); assertNotNull(rsm); assertEquals("aftervalue", rsm.getAfter()); assertEquals("beforevalue", rsm.getBefore()); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentRoster.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentRoster.java index 35e32eba6..ab7187b2e 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentRoster.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentRoster.java @@ -317,7 +317,7 @@ public class AgentRoster { // for a particular user a map with the presence packets saved for each resource. if (presence.getType() == Presence.Type.available) { // Ignore the presence packet unless it has an agent status extension. - AgentStatus agentStatus = presence.getExtension( + AgentStatus agentStatus = (AgentStatus) presence.getExtension( AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE); if (agentStatus == null) { return; diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java index a141b50c0..0b8022dfc 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java @@ -784,7 +784,7 @@ public class AgentSession { } // QueueOverview packet extensions contain basic information about a queue. - QueueOverview queueOverview = presence.getExtension(QueueOverview.ELEMENT_NAME, QueueOverview.NAMESPACE); + QueueOverview queueOverview = (QueueOverview) presence.getExtension(QueueOverview.ELEMENT_NAME, QueueOverview.NAMESPACE); if (queueOverview != null) { if (queueOverview.getStatus() == null) { queue.setStatus(WorkgroupQueue.Status.CLOSED); @@ -803,7 +803,7 @@ public class AgentSession { // QueueDetails packet extensions contain information about the users in // a queue. - QueueDetails queueDetails = packet.getExtension(QueueDetails.ELEMENT_NAME, QueueDetails.NAMESPACE); + QueueDetails queueDetails = (QueueDetails) packet.getExtension(QueueDetails.ELEMENT_NAME, QueueDetails.NAMESPACE); if (queueDetails != null) { queue.setUsers(queueDetails.getUsers()); // Fire event. @@ -812,7 +812,7 @@ public class AgentSession { } // Notify agent packets gives an overview of agent activity in a queue. - StandardExtensionElement notifyAgents = presence.getExtension("notify-agents", "http://jabber.org/protocol/workgroup"); + StandardExtensionElement notifyAgents = (StandardExtensionElement) presence.getExtension("notify-agents", "http://jabber.org/protocol/workgroup"); if (notifyAgents != null) { int currentChats = Integer.parseInt(notifyAgents.getFirstElement("current-chats", "http://jabber.org/protocol/workgroup").getText()); int maxChats = Integer.parseInt(notifyAgents.getFirstElement("max-chats", "http://jabber.org/protocol/workgroup").getText()); @@ -827,20 +827,19 @@ public class AgentSession { Message message = (Message) packet; // Check if a room invitation was sent and if the sender is the workgroup - MUCUser mucUser = message.getExtension("x", - "http://jabber.org/protocol/muc#user"); + MUCUser mucUser = MUCUser.from(message); MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null; if (invite != null && workgroupJID.equals(invite.getFrom())) { String sessionID = null; Map> metaData = null; - SessionID sessionIDExt = message.getExtension(SessionID.ELEMENT_NAME, + SessionID sessionIDExt = (SessionID) message.getExtension(SessionID.ELEMENT_NAME, SessionID.NAMESPACE); if (sessionIDExt != null) { sessionID = sessionIDExt.getSessionID(); } - MetaData metaDataExt = message.getExtension(MetaData.ELEMENT_NAME, + MetaData metaDataExt = (MetaData) message.getExtension(MetaData.ELEMENT_NAME, MetaData.NAMESPACE); if (metaDataExt != null) { metaData = metaDataExt.getMetaData(); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java index 8f1319173..cf6da6015 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java @@ -533,7 +533,7 @@ public class Workgroup { else { // Check if a room invitation was sent and if the sender is the workgroup - MUCUser mucUser = msg.getExtension("x", "http://jabber.org/protocol/muc#user"); + MUCUser mucUser = MUCUser.from(msg); MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null; if (invite != null && workgroupJID.equals(invite.getFrom())) { String sessionID = null; diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java index 23b048ec0..267c5e39a 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java @@ -82,7 +82,7 @@ public final class MessageEventManager extends Manager { @Override public void processStanza(Stanza packet) { Message message = (Message) packet; - MessageEvent messageEvent = message.getExtension("x", "jabber:x:event"); + MessageEvent messageEvent = (MessageEvent) message.getExtension("x", "jabber:x:event"); if (messageEvent.isMessageEventRequest()) { // Fire event for requests of message events for (String eventType : messageEvent.getEventTypes()) diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java index 6af000028..eabcd40ad 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java @@ -84,7 +84,7 @@ public class RosterExchangeManager { @Override public void processStanza(Stanza packet) { Message message = (Message) packet; - RosterExchange rosterExchange = message.getExtension(ELEMENT, NAMESPACE); + RosterExchange rosterExchange = (RosterExchange) message.getExtension(ELEMENT, NAMESPACE); // Fire event for roster exchange listeners fireRosterExchangeListeners(message.getFrom(), rosterExchange.getRosterEntries()); } diff --git a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoService.java b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoService.java index 1527e1498..372579b61 100644 --- a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoService.java +++ b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoService.java @@ -1051,7 +1051,7 @@ public abstract class OmemoService discard return; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpElement.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpElement.java index 69d39ba6d..b94e537da 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpElement.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpElement.java @@ -1,6 +1,6 @@ /** * - * Copyright 2017 Florian Schmaus, 2018 Paul Schaub. + * Copyright 2017-2020 Florian Schmaus, 2018 Paul Schaub. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ package org.jivesoftware.smackx.ox.element; import java.io.ByteArrayInputStream; import java.io.InputStream; +import javax.xml.namespace.QName; + import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.StringUtils; @@ -38,6 +40,7 @@ public class OpenPgpElement implements ExtensionElement { public static final String ELEMENT = "openpgp"; public static final String NAMESPACE = "urn:xmpp:openpgp:0"; + public static final QName QNAME = new QName(NAMESPACE, ELEMENT); // Represents the OpenPGP message, but encoded using base64. private final String base64EncodedOpenPgpMessage; @@ -70,6 +73,11 @@ public class OpenPgpElement implements ExtensionElement { return NAMESPACE; } + @Override + public QName getQName() { + return QNAME; + } + @Override public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(this); @@ -78,6 +86,6 @@ public class OpenPgpElement implements ExtensionElement { } public static OpenPgpElement fromStanza(Stanza stanza) { - return stanza.getExtension(ELEMENT, NAMESPACE); + return stanza.getExtension(OpenPgpElement.class); } }