Search in sources :

Example 46 with PubSub

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

the class LeafNode method getItems.

/**
 * Get the current items stored in the node.
 *
 * @return List of {@link Item} in the node
 *
 * @throws XMPPException
 */
public <T extends Item> List<T> getItems() throws XMPPException {
    PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId()));
    PubSub result = (PubSub) SyncPacketSend.getReply(con, request);
    ItemsExtension itemsElem = (ItemsExtension) result.getExtension(PubSubElementType.ITEMS);
    return (List<T>) itemsElem.getItems();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) List(java.util.List) ArrayList(java.util.ArrayList)

Example 47 with PubSub

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

the class Node method getSubscriptions.

/**
 * Get the subscriptions currently associated with this node.
 *
 * @return List of {@link Subscription}
 *
 * @throws XMPPException
 */
public List<Subscription> getSubscriptions() throws XMPPException {
    PubSub reply = (PubSub) sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId()));
    SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtension(PubSubElementType.SUBSCRIPTIONS);
    return subElem.getSubscriptions();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 48 with PubSub

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

the class Node method sendConfigurationForm.

/**
 * Update the configuration with the contents of the new {@link Form}
 *
 * @param submitForm
 */
public void sendConfigurationForm(Form submitForm) throws XMPPException {
    PubSub packet = createPubsubPacket(Type.SET, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER);
    SyncPacketSend.getReply(con, packet);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 49 with PubSub

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

the class PubSubManager method createNode.

/**
 * Creates an instant node, if supported.
 *
 * @return The node that was created
 * @exception XMPPException
 */
public LeafNode createNode() throws XMPPException {
    PubSub reply = (PubSub) sendPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.CREATE));
    NodeExtension elem = (NodeExtension) reply.getExtension("create", PubSubNamespace.BASIC.getXmlns());
    LeafNode newNode = new LeafNode(con, elem.getNode());
    newNode.setTo(to);
    nodeMap.put(newNode.getId(), newNode);
    return newNode;
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 50 with PubSub

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

the class PubSubManager method createNode.

/**
 * Creates a node with specified configuration.
 *
 * Note: This is the only way to create a collection node.
 *
 * @param name The name of the node, which must be unique within the
 * pubsub service
 * @param config The configuration for the node
 * @return The node that was created
 * @exception XMPPException
 */
public Node createNode(String name, Form config) throws XMPPException {
    PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name));
    boolean isLeafNode = true;
    if (config != null) {
        request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
        FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
        if (nodeTypeField != null)
            isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString());
    }
    // Errors will cause exceptions in getReply, so it only returns
    // on success.
    sendPubsubPacket(con, to, Type.SET, request);
    Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
    newNode.setTo(to);
    nodeMap.put(newNode.getId(), newNode);
    return newNode;
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) FormField(org.jivesoftware.smackx.FormField)

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