Search in sources :

Example 51 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project ecf by eclipse.

the class PubSubManager method createPubsubPacket.

static PubSub createPubsubPacket(String to, Type type, PacketExtension ext, PubSubNamespace ns) {
    PubSub request = new PubSub();
    request.setTo(to);
    request.setType(type);
    if (ns != null) {
        request.setPubSubNamespace(ns);
    }
    request.addExtension(ext);
    return request;
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 52 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class PubSubProvider method parse.

@Override
public PubSub parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    String namespace = parser.getNamespace();
    PubSubNamespace pubSubNamespace = PubSubNamespace.valueOfFromXmlns(namespace);
    PubSub pubsub = new PubSub(pubSubNamespace);
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch(eventType) {
            case START_ELEMENT:
                PacketParserUtils.addExtensionElement(pubsub, parser, xmlEnvironment);
                break;
            case END_ELEMENT:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
            default:
                // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
                break;
        }
    }
    return pubsub;
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) PubSubNamespace(org.jivesoftware.smackx.pubsub.packet.PubSubNamespace)

Example 53 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class PubSubManager method getAffiliations.

/**
 * Gets the affiliations on the root node.
 *
 * @return List of affiliations
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub reply = sendPubsubPacket(IQ.Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null);
    AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS);
    return listElem.getAffiliations();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 54 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class PubSubNodeTest method getAffiliationsAsOwnerTest.

@Test
public void getAffiliationsAsOwnerTest() throws InterruptedException, SmackException, IOException, XMPPException, Exception {
    Protocol protocol = new Protocol();
    XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, JidTestUtil.FULL_JID_1_RESOURCE_1);
    PubSubManager mgr = new PubSubManager(connection, JidTestUtil.PUBSUB_EXAMPLE_ORG);
    Node testNode = new LeafNode(mgr, "princely_musings");
    List<Affiliation> affiliations = Arrays.asList(new Affiliation(JidTestUtil.BARE_JID_1, Affiliation.Type.member), new Affiliation(JidTestUtil.BARE_JID_2, Affiliation.Type.publisher));
    AffiliationsExtension affiliationsExtension = new AffiliationsExtension(AffiliationNamespace.owner, affiliations);
    PubSub response = new PubSub(JidTestUtil.PUBSUB_EXAMPLE_ORG, IQ.Type.result, PubSubNamespace.owner);
    response.addExtension(affiliationsExtension);
    protocol.addResponse(response);
    List<Affiliation> returnedAffiliations = testNode.getAffiliationsAsOwner();
    PubSub request = (PubSub) protocol.getRequests().get(0);
    assertEquals("http://jabber.org/protocol/pubsub#owner", request.getChildElementNamespace());
    assertEquals("pubsub", request.getChildElementName());
    Affiliation affiliationOne = returnedAffiliations.get(0);
    assertEquals(affiliationOne.getJid(), JidTestUtil.BARE_JID_1);
    assertEquals(affiliationOne.getAffiliation(), Affiliation.Type.member);
    Affiliation affiliationTwo = returnedAffiliations.get(1);
    assertEquals(affiliationTwo.getJid(), JidTestUtil.BARE_JID_2);
    assertEquals(affiliationTwo.getAffiliation(), Affiliation.Type.publisher);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Protocol(org.jivesoftware.util.Protocol) Test(org.junit.jupiter.api.Test)

Example 55 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class PubSubNodeTest method modifySubscriptionsAsOwnerTest.

@Test
public void modifySubscriptionsAsOwnerTest() throws InterruptedException, SmackException, IOException, XMPPException, Exception {
    ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
    PubSubManager mgr = new PubSubManager(con, JidTestUtil.PUBSUB_EXAMPLE_ORG);
    Node testNode = new LeafNode(mgr, "princely_musings");
    List<Subscription> ChangeSubs = Arrays.asList(new Subscription(JidCreate.from("romeo@montague.org"), Subscription.State.subscribed), new Subscription(JidCreate.from("juliet@capulet.org"), Subscription.State.none));
    testNode.modifySubscriptionsAsOwner(ChangeSubs);
    PubSub request = con.getSentPacket();
    assertEquals("http://jabber.org/protocol/pubsub#owner", request.getChildElementNamespace());
    assertEquals("pubsub", request.getChildElementName());
    XmlPullParser parser = TestUtils.getIQParser(request.toXML().toString());
    PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser);
    SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER);
    List<Subscription> subscriptions = subElem.getSubscriptions();
    assertEquals(2, subscriptions.size());
    Subscription sub1 = subscriptions.get(0);
    assertEquals("romeo@montague.org", sub1.getJid().toString());
    assertEquals(Subscription.State.subscribed, sub1.getState());
    Subscription sub2 = subscriptions.get(1);
    assertEquals("juliet@capulet.org", sub2.getJid().toString());
    assertEquals(Subscription.State.none, sub2.getState());
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Test(org.junit.jupiter.api.Test)

Aggregations

PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)57 ArrayList (java.util.ArrayList)10 List (java.util.List)7 Test (org.junit.jupiter.api.Test)5 ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)4 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)2 PacketExtension (org.jivesoftware.smack.packet.PacketExtension)2 XmlElement (org.jivesoftware.smack.packet.XmlElement)2 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)2 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)2 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)2 PubSubNamespace (org.jivesoftware.smackx.pubsub.packet.PubSubNamespace)2 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)2 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 RuntimeExchangeException (org.apache.camel.RuntimeExchangeException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 DefaultPacketExtension (org.jivesoftware.smack.packet.DefaultPacketExtension)1