Java Code Examples for org.jivesoftware.smackx.pubsub.packet.PubSub#getExtension()

The following examples show how to use org.jivesoftware.smackx.pubsub.packet.PubSub#getExtension() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Node.java    From Smack with Apache License 2.0 6 votes vote down vote up
private List<Subscription> getSubscriptions(SubscriptionsNamespace subscriptionsNamespace, List<ExtensionElement> additionalExtensions,
                Collection<ExtensionElement> returnedExtensions)
                throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSubElementType pubSubElementType = subscriptionsNamespace.type;

    PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(pubSubElementType, getId()));
    if (additionalExtensions != null) {
        for (ExtensionElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    SubscriptionsExtension subElem = reply.getExtension(pubSubElementType);
    return subElem.getSubscriptions();
}
 
Example 2
Source File: Node.java    From Smack with Apache License 2.0 6 votes vote down vote up
private List<Affiliation> getAffiliations(AffiliationNamespace affiliationsNamespace, List<ExtensionElement> additionalExtensions,
                Collection<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException,
                NotConnectedException, InterruptedException {
    PubSubElementType pubSubElementType = affiliationsNamespace.type;

    PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(pubSubElementType, getId()));
    if (additionalExtensions != null) {
        for (ExtensionElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    AffiliationsExtension affilElem = reply.getExtension(pubSubElementType);
    return affilElem.getAffiliations();
}
 
Example 3
Source File: PubSubManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instant node, if supported.
 *
 * @return The node that was created
 * @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 LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null);
    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);

    return newNode;
}
 
Example 4
Source File: LeafNode.java    From Smack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends Item> List<T> getItems(PubSub request,
                List<ExtensionElement> returnedExtensions) throws NoResponseException,
                XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub result = pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
    ItemsExtension itemsElem = result.getExtension(PubSubElementType.ITEMS);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(result.getExtensions());
    }
    return (List<T>) itemsElem.getItems();
}
 
Example 5
Source File: PubSubNodeTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@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("[email protected]"), Subscription.State.subscribed),
        new Subscription(JidCreate.from("[email protected]"), 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("[email protected]", sub1.getJid().toString());
    assertEquals(Subscription.State.subscribed, sub1.getState());

    Subscription sub2 = subscriptions.get(1);
    assertEquals("[email protected]", sub2.getJid().toString());
    assertEquals(Subscription.State.none, sub2.getState());
}
 
Example 6
Source File: PubSubProviderTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Test
public void subscriptionsOwnerResultTest() throws Exception {
    // @formatter:off
    final String resultStanza =
      "<iq from='pubsub.example.org' to='[email protected]/Smack' id='HaT4m-13' type='result'>" +
        "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" +
          "<subscriptions node='test'>" +
            "<subscription jid='[email protected]/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" +
            "<subscription jid='[email protected]/Smack' subscription='subscribed' subid='58C18F8917321'/>" +
          "</subscriptions>" +
        "</pubsub>" +
      "</iq>";
    // @formatter:on
    XmlPullParser parser = TestUtils.getIQParser(resultStanza);
    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);
    assertThat("[email protected]/Smack", equalsCharSequence(sub1.getJid()));
    assertEquals(Subscription.State.subscribed, sub1.getState());
    assertEquals("58C1A6F99F2A7", sub1.getId());

    Subscription sub2 = subscriptions.get(1);
    assertThat("[email protected]/Smack", equalsCharSequence(sub2.getJid()));
    assertEquals(Subscription.State.subscribed, sub2.getState());
    assertEquals("58C18F8917321", sub2.getId());
}
 
Example 7
Source File: Node.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * 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 jid The jid to subscribe as.
 * @param subForm TODO javadoc me please
 *
 * @return The subscription
 * @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 Subscription subscribe(Jid jid, FillableSubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DataForm submitForm = subForm.getDataFormToSubmit();
    PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
    request.addExtension(new FormNode(FormNodeType.OPTIONS, submitForm));
    PubSub reply = sendPubsubPacket(request);
    return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
 
Example 8
Source File: PubSubManager.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * 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(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null);
    AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS);
    return listElem.getAffiliations();
}
 
Example 9
Source File: Node.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * 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 jid The jid to subscribe as.
 * @return The subscription
 * @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 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);
}
 
Example 10
Source File: Node.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Get the options for configuring the specified subscription.
 *
 * @param jid JID the subscription is registered under
 * @param subscriptionId The subscription id
 *
 * @return The subscription option form
 * @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 SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub packet = sendPubsubPacket(createPubsubPacket(Type.get, new OptionsExtension(jid, getId(), subscriptionId)));
    FormNode ext = packet.getExtension(PubSubElementType.OPTIONS);
    return new SubscribeForm(ext.getForm());
}