summaryrefslogtreecommitdiffstats
blob: a3bf80c656660234bd74d0c1fcac34e268c649e1 (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
/*
 * Copyright (c) 2012, Isode Limited, London, England.
 * All rights reserved.
 */
/*
 * Copyright (c) 2011, Kevin Smith
 * All rights reserved.
 */
package com.isode.stroke.serializer.payloadserializers;

import com.isode.stroke.elements.MUCItem;
import com.isode.stroke.serializer.xml.XMLElement;
import com.isode.stroke.serializer.xml.XMLTextNode;

/**
 * Class representing a serializer for {@link MUCItem}
 *
 */
public class MUCItemSerializer {

    /**
     * Create an XMLElement from the given MUC Item
     * @param item MUC Item, not null
     * @return XML Element, not null
     */
    public static XMLElement itemToElement(MUCItem item) {
        XMLElement itemElement = new XMLElement("item");
        if (item.affiliation != null) {
            itemElement.setAttribute("affiliation", item.affiliation.nodeName);
        }
        if (item.role != null) {
            itemElement.setAttribute("role", item.role.nodeName);
        }
        if (item.realJID != null) {
            itemElement.setAttribute("jid", item.realJID.toString());
        }
        if (item.nick != null) {
            itemElement.setAttribute("nick", item.nick);
        }
        if (item.actor != null) {
            XMLElement actorElement = new XMLElement("actor");
            actorElement.setAttribute("jid", item.actor.toString());
            itemElement.addNode(actorElement);
        }
        if (item.reason != null) {
            XMLElement reasonElement = new XMLElement("reason");
            reasonElement.addNode(new XMLTextNode(item.reason));
            itemElement.addNode(reasonElement);
        }
        return itemElement;
    }
}