Item.java

 1package im.conversations.android.xmpp.model.muc.user;
 2
 3import android.util.Log;
 4
 5import com.google.common.base.Strings;
 6
 7import eu.siacs.conversations.Config;
 8import eu.siacs.conversations.xmpp.Jid;
 9
10import im.conversations.android.annotation.XmlElement;
11import im.conversations.android.xmpp.model.Extension;
12import im.conversations.android.xmpp.model.muc.Affiliation;
13import im.conversations.android.xmpp.model.muc.Role;
14
15import java.util.Locale;
16
17@XmlElement
18public class Item extends Extension {
19
20
21    public Item() {
22        super(Item.class);
23    }
24
25    public Affiliation getAffiliation() {
26        final var affiliation = this.getAttribute("affiliation");
27        if (Strings.isNullOrEmpty(affiliation)) {
28            return Affiliation.NONE;
29        }
30        try {
31            return Affiliation.valueOf(affiliation.toUpperCase(Locale.ROOT));
32        } catch (final IllegalArgumentException e) {
33            Log.d(Config.LOGTAG,"could not parse affiliation "+affiliation);
34            return Affiliation.NONE;
35        }
36    }
37
38    public Role getRole() {
39        final var role = this.getAttribute("role");
40        if (Strings.isNullOrEmpty(role)) {
41            return Role.NONE;
42        }
43        try {
44            return Role.valueOf(role.toUpperCase(Locale.ROOT));
45        } catch (final IllegalArgumentException e) {
46            Log.d(Config.LOGTAG,"could not parse role "+ role);
47            return Role.NONE;
48        }
49    }
50
51    public String getNick() {
52        return this.getAttribute("nick");
53    }
54
55    public Jid getJid() {
56        return this.getAttributeAsJid("jid");
57    }
58}