mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02: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
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue