Search in sources :

Example 1 with PubSub

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

the class Node method getSubscriptions.

private List<Subscription> getSubscriptions(List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions, PubSubNamespace pubSubNamespace) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId()), pubSubNamespace);
    if (additionalExtensions != null) {
        for (ExtensionElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtension(PubSubElementType.SUBSCRIPTIONS);
    return subElem.getSubscriptions();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 2 with PubSub

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

the class LeafNode method send.

/**
     * Publishes multiple events to the node.  Same rules apply as in {@link #send(Item)}.
     * 
     * In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input
     * list will get stored on the node, assuming it stores the last sent item.
     *  
     * This is a synchronous call which will throw an exception 
     * on failure.
     * 
     * For asynchronous calls, use {@link #publish(Collection) publish(Collection))}.
     * 
     * @param items - The collection of {@link Item} objects being sent
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * 
     */
public <T extends Item> void send(Collection<T> items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub packet = createPubsubPacket(Type.set, new PublishItem<T>(getId(), items));
    pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 3 with PubSub

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

the class Node method subscribe.

/**
     * 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.
     * @return The subscription
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public Subscription subscribe(String 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);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 4 with PubSub

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

the class Node method getAffiliations.

private List<Affiliation> getAffiliations(PubSubNamespace namespace, List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS, getId()), namespace);
    if (additionalExtensions != null) {
        for (ExtensionElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    AffiliationsExtension affilElem = (AffiliationsExtension) reply.getExtension(PubSubElementType.AFFILIATIONS);
    return affilElem.getAffiliations();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 5 with PubSub

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

the class LeafNode method deleteItem.

/**
 * Delete the items with the specified id's from the node.
 *
 * @param itemIds The list of id's of items to delete
 *
 * @throws XMPPException
 */
public void deleteItem(Collection<String> itemIds) throws XMPPException {
    List<Item> items = new ArrayList<Item>(itemIds.size());
    for (String id : itemIds) {
        items.add(new Item(id));
    }
    PubSub request = createPubsubPacket(Type.SET, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
    SyncPacketSend.getReply(con, request);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) ArrayList(java.util.ArrayList)

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