1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 12:37:58 +01:00

Use Jid in pubsub.Subscription

This commit is contained in:
Florian Schmaus 2018-03-21 14:47:22 +01:00
parent ffaca31178
commit 5a29be4c67
3 changed files with 16 additions and 10 deletions

View file

@ -18,6 +18,8 @@ package org.jivesoftware.smackx.pubsub;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.jid.Jid;
/**
* Represents a subscription to node for both requests and replies.
*
@ -25,7 +27,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*/
public class Subscription extends NodeExtension
{
protected String jid;
protected Jid jid;
protected String id;
protected State state;
protected boolean configRequired = false;
@ -41,7 +43,7 @@ public class Subscription extends NodeExtension
*
* @param subscriptionJid The subscriber JID
*/
public Subscription(String subscriptionJid)
public Subscription(Jid subscriptionJid)
{
this(subscriptionJid, null, null, null);
}
@ -53,7 +55,7 @@ public class Subscription extends NodeExtension
* @param subscriptionJid The subscriber JID
* @param nodeId The node id
*/
public Subscription(String subscriptionJid, String nodeId)
public Subscription(Jid subscriptionJid, String nodeId)
{
this(subscriptionJid, nodeId, null, null);
}
@ -67,7 +69,7 @@ public class Subscription extends NodeExtension
* @param subscriptionId The id of this subscription
* @param state The current state of the subscription
*/
public Subscription(String jid, String nodeId, String subscriptionId, State state)
public Subscription(Jid jid, String nodeId, String subscriptionId, State state)
{
super(PubSubElementType.SUBSCRIPTION, nodeId);
this.jid = jid;
@ -86,7 +88,7 @@ public class Subscription extends NodeExtension
* @param state The current state of the subscription
* @param configRequired Is configuration required to complete the subscription
*/
public Subscription(String jid, String nodeId, String subscriptionId, State state, boolean configRequired)
public Subscription(Jid jid, String nodeId, String subscriptionId, State state, boolean configRequired)
{
super(PubSubElementType.SUBSCRIPTION, nodeId);
this.jid = jid;
@ -100,7 +102,7 @@ public class Subscription extends NodeExtension
*
* @return The JID
*/
public String getJid()
public Jid getJid()
{
return jid;
}

View file

@ -19,9 +19,11 @@ package org.jivesoftware.smackx.pubsub.provider;
import java.io.IOException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.pubsub.Subscription;
import org.jxmpp.jid.Jid;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -36,7 +38,7 @@ public class SubscriptionProvider extends ExtensionElementProvider<Subscription>
@Override
public Subscription parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
String jid = parser.getAttributeValue(null, "jid");
Jid jid = ParserUtils.getJidAttribute(parser);
String nodeId = parser.getAttributeValue(null, "node");
String subId = parser.getAttributeValue(null, "subid");
String state = parser.getAttributeValue(null, "subscription");

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2014 Florian Schmaus
* Copyright 2014-2018 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,7 +16,9 @@
*/
package org.jivesoftware.smackx.pubsub.provider;
import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.util.List;
@ -53,12 +55,12 @@ public class PubSubProviderTest {
assertEquals(2, subscriptions.size());
Subscription sub1 = subscriptions.get(0);
assertEquals("foo@example.org/Smack", sub1.getJid());
assertThat("foo@example.org/Smack", equalsCharSequence(sub1.getJid()));
assertEquals(Subscription.State.subscribed, sub1.getState());
assertEquals("58C1A6F99F2A7", sub1.getId());
Subscription sub2 = subscriptions.get(1);
assertEquals("julia@example.org/Smack", sub2.getJid());
assertThat("julia@example.org/Smack", equalsCharSequence(sub2.getJid()));
assertEquals(Subscription.State.subscribed, sub2.getState());
assertEquals("58C18F8917321", sub2.getId());
}