aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/pubsub/PubSubPacket.java
blob: 31186191fa41f3978df2a68be3380d8756b93a0a (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package de.thedevstack.conversationsplus.xmpp.pubsub;

import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;

/**
 * Representation of a PubSub IQ packet as defined in XEP-0060.
 * <br>One example:
 * <pre>
 *   <iq type='get'
 *       from='romeo@montague.lit'
 *       to='pubsub.shakespeare.lit'
 *       id='items1'>
 *      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
 *          <items node='urn:xmpp:pubsub:subscription'/>
 *      </pubsub>
 *   </iq>
 * </pre>
 * @see <a href="http://xmpp.org/extensions/xep-0330.html">http://xmpp.org/extensions/xep-0060.html</a>
 */
public class PubSubPacket extends IqPacket {
    /**
     * The namespace of pubsub.
     */
    public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";
    /**
     * The name of the root element.
     */
    public static final String ELEMENT_NAME = "pubsub";
    /**
     * The PubSub element - everything which is added to this packet is a child of this element.
     */
    private Element pubSubElement;

    /**
     * Instantiate the PubSubPacket for the given type.
     * @param type the IqPacket.TYPE
     */
    public PubSubPacket(IqPacket.TYPE type) {
        super(type);
        this.pubSubElement = super.addChild(PubSubPacket.ELEMENT_NAME, PubSubPacket.NAMESPACE);
    }

    /**
     * Adds an element to the PubSub element instead of the IqPacket.
     * @param child the children to be added
     * @return the added children
     */
    @Override
    public Element addChild(Element child) {
        return this.pubSubElement.addChild(child);
    }

    /**
     * Adds an element to the PubSub element instead of the IqPacket.
     * @param name name of the children to be added
     * @return the added children
     */
    @Override
    public Element addChild(String name) {
        return this.pubSubElement.addChild(name);
    }

    /**
     * Adds an element to the PubSub element instead of the IqPacket.
     * @param name name of the children to be added
     * @param xmlns namespace of the children to be added
     * @return the added children
     */
    @Override
    public Element addChild(String name, String xmlns) {
        return this.pubSubElement.addChild(name, xmlns);
    }
}