1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-17 09:42:05 +01:00

Do not have Stanza.getExtension(String, String) return a generic type

Returning a generic would allow for

List<ExtensionElement> list = stanza.getExtension("foo", "bar");

to compile (Note the we are calling getExtension(), not
getExtension*s*()).

Users are encouraged to use the type safe getExtension(Class<? extends
ExtensionElement) variant instead.

Fixes SMACK-825.
This commit is contained in:
Florian Schmaus 2020-04-05 22:10:05 +02:00
parent 62916b8490
commit 07da9ffb48
65 changed files with 207 additions and 121 deletions

View file

@ -26,7 +26,6 @@ import java.util.Set;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.Message.Thread;
import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.Objects;

View file

@ -356,11 +356,9 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
*
* @param elementName the XML element name of the extension. (May be null)
* @param namespace the XML element namespace of the extension.
* @param <PE> type of the ExtensionElement.
* @return the extension, or <code>null</code> if it doesn't exist.
*/
@SuppressWarnings("unchecked")
public final <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
public final ExtensionElement getExtension(String elementName, String namespace) {
if (namespace == null) {
return null;
}
@ -369,14 +367,13 @@ public abstract class Stanza implements StanzaView, TopLevelStreamElement {
if (packetExtension == null) {
return null;
}
return (PE) packetExtension;
return packetExtension;
}
@SuppressWarnings("unchecked")
@Override
public final <E extends ExtensionElement> E getExtension(QName qname) {
public final ExtensionElement getExtension(QName qname) {
synchronized (extensionElements) {
return (E) extensionElements.getFirst(qname);
return extensionElements.getFirst(qname);
}
}

View file

@ -211,10 +211,9 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
return stanzaError;
}
@SuppressWarnings("unchecked")
@Override
public final <E extends ExtensionElement> E getExtension(QName qname) {
return (E) extensionElements.getFirst(qname);
public final ExtensionElement getExtension(QName qname) {
return extensionElements.getFirst(qname);
}
@Override

View file

@ -61,7 +61,7 @@ public interface StanzaView extends XmlLangElement {
*/
StanzaError getError();
<E extends ExtensionElement> E getExtension(QName qname);
ExtensionElement getExtension(QName qname);
default boolean hasExtension(QName qname) {
return getExtension(qname) != null;

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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);
}
/**

View file

@ -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);
}
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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

View file

@ -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() {

View file

@ -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());

View file

@ -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);
}

View file

@ -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,

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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);
}
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@ package org.jivesoftware.smackx.delay;
import java.util.Date;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
@ -34,6 +36,7 @@ public class DelayInformationManager {
public static final String LEGACY_DELAYED_DELIVERY_NAMESPACE = "jabber:x:delay";
public static final String LEGACY_DELAYED_DELIVERY_ELEMENT = "x";
public static final QName QNAME = new QName(LEGACY_DELAYED_DELIVERY_NAMESPACE, LEGACY_DELAYED_DELIVERY_ELEMENT);
/**
@ -57,7 +60,7 @@ public class DelayInformationManager {
* @return the Delayed Delivery information or <code>null</code>
*/
public static DelayInformation getLegacyDelayInformation(Stanza packet) {
return packet.getExtension(LEGACY_DELAYED_DELIVERY_ELEMENT, LEGACY_DELAYED_DELIVERY_NAMESPACE);
return packet.getExtension(DelayInformation.class);
}
/**

View file

@ -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);
}
}

View file

@ -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);
}
/**

View file

@ -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) {

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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);
}
/**

View file

@ -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);
}
}

View file

@ -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);
}
/**

View file

@ -19,6 +19,8 @@ package org.jivesoftware.smackx.muc.packet;
import java.io.IOException;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XmlEnvironment;
@ -68,6 +70,8 @@ public class GroupChatInvitation implements ExtensionElement {
*/
public static final String NAMESPACE = "jabber:x:conference";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final String roomAddress;
/**
@ -128,7 +132,7 @@ public class GroupChatInvitation implements ExtensionElement {
* @return the GroupChatInvitation or null
*/
public static GroupChatInvitation from(Stanza packet) {
return packet.getExtension(ELEMENT, NAMESPACE);
return packet.getExtension(GroupChatInvitation.class);
}
public static class Provider extends ExtensionElementProvider<GroupChatInvitation> {

View file

@ -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);
}
/**

View file

@ -22,6 +22,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.Stanza;
@ -41,6 +43,7 @@ public class MUCUser implements ExtensionElement {
public static final String ELEMENT = "x";
public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#user";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final Set<Status> statusCodes = new HashSet<>(4);
@ -236,7 +239,7 @@ public class MUCUser implements ExtensionElement {
* @return the MUCUser PacketExtension or {@code null}
*/
public static MUCUser from(Stanza packet) {
return packet.getExtension(ELEMENT, NAMESPACE);
return packet.getExtension(MUCUser.class);
}
/**

View file

@ -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());
}
});

View file

@ -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);
}
}

View file

@ -656,7 +656,7 @@ public abstract class Node {
private static List<String> getSubscriptionIds(Stanza packet) {
HeadersExtension headers = packet.getExtension("headers", "http://jabber.org/protocol/shim");
HeadersExtension headers = packet.getExtension(HeadersExtension.class);
List<String> 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<ExtensionElement> 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?)

View file

@ -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<Subscription> 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();
}

View file

@ -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);
}

View file

@ -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);
}
/**

View file

@ -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);
}
/**

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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<Header> 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);
}
}

View file

@ -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

View file

@ -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);
}
/**

View file

@ -130,6 +130,6 @@ public class XHTMLExtension implements ExtensionElement {
}
public static XHTMLExtension from(MessageView message) {
return message.getExtension(QNAME);
return message.getExtension(XHTMLExtension.class);
}
}

View file

@ -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());
}

View file

@ -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());

View file

@ -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());

View file

@ -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));

View file

@ -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());

View file

@ -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;

View file

@ -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<String, List<String>> 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();

View file

@ -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;

View file

@ -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())

View file

@ -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());
}

View file

@ -1051,7 +1051,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
for (Message message : mamQuery.getMessages()) {
if (OmemoManager.stanzaContainsOmemoElement(message)) {
OmemoElement element =
message.getExtension(OmemoElement.NAME_ENCRYPTED, OmemoConstants.OMEMO_NAMESPACE_V_AXOLOTL);
(OmemoElement) message.getExtension(OmemoElement.NAME_ENCRYPTED, OmemoConstants.OMEMO_NAMESPACE_V_AXOLOTL);
// Decrypt OMEMO messages
try {
OmemoMessage.Received omemoMessage = decryptMessage(managerGuard, message.getFrom().asBareJid(), element);
@ -1080,7 +1080,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
// Avoid the ratchet being manipulated and the bundle being published multiple times simultaneously
synchronized (manager) {
OmemoDevice userDevice = manager.getOwnDevice();
OmemoElement element = carbonCopy.getExtension(OmemoElement.NAME_ENCRYPTED, OmemoElement_VAxolotl.NAMESPACE);
OmemoElement element = (OmemoElement) carbonCopy.getExtension(OmemoElement.NAME_ENCRYPTED, OmemoElement_VAxolotl.NAMESPACE);
if (element == null) {
return;
}
@ -1137,7 +1137,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
// Avoid the ratchet being manipulated and the bundle being published multiple times simultaneously
synchronized (manager) {
OmemoDevice userDevice = manager.getOwnDevice();
OmemoElement element = stanza.getExtension(OmemoElement.NAME_ENCRYPTED, OmemoElement_VAxolotl.NAMESPACE);
OmemoElement element = (OmemoElement) stanza.getExtension(OmemoElement.NAME_ENCRYPTED, OmemoElement_VAxolotl.NAMESPACE);
if (element == null) {
return;
}
@ -1228,7 +1228,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
// Avoid the ratchet being manipulated and the bundle being published multiple times simultaneously
synchronized (manager) {
OmemoDevice userDevice = manager.getOwnDevice();
OmemoElement element = stanza.getExtension(OmemoElement.NAME_ENCRYPTED, OmemoElement_VAxolotl.NAMESPACE);
OmemoElement element = (OmemoElement) stanza.getExtension(OmemoElement.NAME_ENCRYPTED, OmemoElement_VAxolotl.NAMESPACE);
if (element == null) {
return null;
}

View file

@ -555,7 +555,7 @@ public final class OpenPgpManager extends Manager {
Async.go(new Runnable() {
@Override
public void run() {
OpenPgpElement element = message.getExtension(OpenPgpElement.ELEMENT, OpenPgpElement.NAMESPACE);
OpenPgpElement element = message.getExtension(OpenPgpElement.class);
if (element == null) {
// Message does not contain an OpenPgpElement -> discard
return;

View file

@ -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);
}
}