aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/pubsub/PubSubPacketGenerator.java
blob: 1eb44b5e509a7c1a257e0dfd8b7120b2001fde40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package de.thedevstack.conversationsplus.xmpp.pubsub;

import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;

/**
 * Created by tzur on 15.01.2016.
 */
public final class PubSubPacketGenerator {

    public static PubSubPacket generatePubSubPublishPacket(String nodeName, Element item) {
        final PubSubPacket pubsub = new PubSubPacket(IqPacket.TYPE.SET);
        final Element publish = pubsub.addChild("publish");
        publish.setAttribute("node", nodeName);
        publish.addChild(item);
        return pubsub;
    }

    public static PubSubPacket generatePubSubRetrievePacket(String nodeName, Element item) {
        final PubSubPacket pubsub = new PubSubPacket(IqPacket.TYPE.GET);
        final Element items = pubsub.addChild("items");
        items.setAttribute("node", nodeName);
        if (item != null) {
            items.addChild(item);
        }
        return pubsub;
    }

    private PubSubPacketGenerator() {
        // Avoid instantiation
    }
}