Search in sources :

Example 11 with PubSub

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

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 XMPPErrorException
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    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));
    pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) ArrayList(java.util.ArrayList)

Example 12 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 13 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 14 with PubSub

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

the class Node method getSubscriptionOptions.

/**
     * 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 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * 
     */
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());
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 15 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project camel by apache.

the class XmppBinding method extractHeadersFromXmpp.

public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
    Map<String, Object> answer = new HashMap<String, Object>();
    PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe != null && jpe instanceof JivePropertiesExtension) {
        extractHeadersFrom((JivePropertiesExtension) jpe, exchange, answer);
    }
    if (jpe != null && jpe instanceof DefaultPacketExtension) {
        extractHeadersFrom((DefaultPacketExtension) jpe, exchange, answer);
    }
    if (xmppPacket instanceof Message) {
        Message xmppMessage = (Message) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
        answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
        answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
    } else if (xmppPacket instanceof PubSub) {
        PubSub pubsubPacket = (PubSub) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
    }
    answer.put(XmppConstants.FROM, xmppPacket.getFrom());
    answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
    answer.put(XmppConstants.TO, xmppPacket.getTo());
    return answer;
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) Message(org.jivesoftware.smack.packet.Message) HashMap(java.util.HashMap) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Aggregations

PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)25 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)2 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)2 HashMap (java.util.HashMap)1 List (java.util.List)1 RuntimeExchangeException (org.apache.camel.RuntimeExchangeException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 DefaultPacketExtension (org.jivesoftware.smack.packet.DefaultPacketExtension)1 Message (org.jivesoftware.smack.packet.Message)1 PacketExtension (org.jivesoftware.smack.packet.PacketExtension)1 Stanza (org.jivesoftware.smack.packet.Stanza)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)1 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)1 JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)1 Subscription (org.jivesoftware.smackx.pubsub.Subscription)1 SubscriptionsExtension (org.jivesoftware.smackx.pubsub.SubscriptionsExtension)1