mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 11:38:00 +01:00
Change SubscribeExtension's jid field type from String to Jid
and make it final.
This commit is contained in:
parent
89b64fbf0c
commit
9c0da3ed07
2 changed files with 81 additions and 6 deletions
|
@ -46,6 +46,10 @@ import org.jivesoftware.smackx.shim.packet.Header;
|
|||
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
|
||||
import org.jivesoftware.smackx.xdata.Form;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
public abstract class Node {
|
||||
protected final PubSubManager pubSubManager;
|
||||
protected final String id;
|
||||
|
@ -386,12 +390,45 @@ public abstract class Node {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public Subscription subscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public Subscription subscribe(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
PubSub pubSub = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
|
||||
PubSub reply = sendPubsubPacket(pubSub);
|
||||
return reply.getExtension(PubSubElementType.SUBSCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user subscribes to the node using the supplied jid. The
|
||||
* bare jid portion of this one must match the jid for the connection.
|
||||
*
|
||||
* Please note that the {@link Subscription.State} should be checked
|
||||
* on return since more actions may be required by the caller.
|
||||
* {@link Subscription.State#pending} - The owner must approve the subscription
|
||||
* request before messages will be received.
|
||||
* {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
|
||||
* the caller must configure the subscription before messages will be received. If it is false
|
||||
* the caller can configure it but is not required to do so.
|
||||
*
|
||||
* @param jidString The jid to subscribe as.
|
||||
* @return The subscription
|
||||
* @throws XMPPErrorException
|
||||
* @throws NoResponseException
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if the provided string is not a valid JID.
|
||||
* @deprecated use {@link #subscribe(Jid)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: Remove in Smack 4.5.
|
||||
public Subscription subscribe(String jidString) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
Jid jid;
|
||||
try {
|
||||
jid = JidCreate.from(jidString);
|
||||
} catch (XmppStringprepException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
return subscribe(jid);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user subscribes to the node using the supplied jid and subscription
|
||||
* options. The bare jid portion of this one must match the jid for the
|
||||
|
@ -414,13 +451,49 @@ public abstract class Node {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public Subscription subscribe(String jid, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public Subscription subscribe(Jid jid, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
|
||||
request.addExtension(new FormNode(FormNodeType.OPTIONS, subForm));
|
||||
PubSub reply = sendPubsubPacket(request);
|
||||
return reply.getExtension(PubSubElementType.SUBSCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user subscribes to the node using the supplied jid and subscription
|
||||
* options. The bare jid portion of this one must match the jid for the
|
||||
* connection.
|
||||
*
|
||||
* Please note that the {@link Subscription.State} should be checked
|
||||
* on return since more actions may be required by the caller.
|
||||
* {@link Subscription.State#pending} - The owner must approve the subscription
|
||||
* request before messages will be received.
|
||||
* {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
|
||||
* the caller must configure the subscription before messages will be received. If it is false
|
||||
* the caller can configure it but is not required to do so.
|
||||
*
|
||||
* @param jidString The jid to subscribe as.
|
||||
* @param subForm
|
||||
*
|
||||
* @return The subscription
|
||||
* @throws XMPPErrorException
|
||||
* @throws NoResponseException
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
* @throws IllegalArgumentException if the provided string is not a valid JID.
|
||||
* @deprecated use {@link #subscribe(Jid, SubscribeForm)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: Remove in Smack 4.5.
|
||||
public Subscription subscribe(String jidString, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
Jid jid;
|
||||
try {
|
||||
jid = JidCreate.from(jidString);
|
||||
} catch (XmppStringprepException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
return subscribe(jid, subForm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the subscription related to the specified JID. This will only
|
||||
* work if there is only 1 subscription. If there are multiple subscriptions,
|
||||
|
|
|
@ -16,25 +16,27 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* Represents a request to subscribe to a node.
|
||||
*
|
||||
* @author Robin Collier
|
||||
*/
|
||||
public class SubscribeExtension extends NodeExtension {
|
||||
protected String jid;
|
||||
protected final Jid jid;
|
||||
|
||||
public SubscribeExtension(String subscribeJid) {
|
||||
public SubscribeExtension(Jid subscribeJid) {
|
||||
super(PubSubElementType.SUBSCRIBE);
|
||||
jid = subscribeJid;
|
||||
}
|
||||
|
||||
public SubscribeExtension(String subscribeJid, String nodeId) {
|
||||
public SubscribeExtension(Jid subscribeJid, String nodeId) {
|
||||
super(PubSubElementType.SUBSCRIBE, nodeId);
|
||||
jid = subscribeJid;
|
||||
}
|
||||
|
||||
public String getJid() {
|
||||
public Jid getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue