blob: 1a1bb74bffec09647bed9827b9b5a7eb378ec515 (
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
|
/*
* Copyright (c) 2012, Isode Limited, London, England.
* All rights reserved.
*/
/*
* Copyright (c) 2011, Kevin Smith
* All rights reserved.
*/
package com.isode.stroke.parser.payloadparsers;
import com.isode.stroke.elements.MUCItem;
import com.isode.stroke.elements.MUCOccupant.Affiliation;
import com.isode.stroke.elements.MUCOccupant.Role;
import com.isode.stroke.jid.JID;
import com.isode.stroke.parser.tree.ParserElement;
/**
* Class containing parser functions for MUC Item
*
*/
public class MUCItemParser {
/**
* Get the MUC Item from the node
* @param root XML node element
* @return MUC Item, not null
*/
public static MUCItem itemFromTree(ParserElement root) {
MUCItem item = new MUCItem();
String affiliation = root.getAttributes().getAttribute("affiliation");
String role = root.getAttributes().getAttribute("role");
String nick = root.getAttributes().getAttribute("nick");
String jid = root.getAttributes().getAttribute("jid");
item.affiliation = parseAffiliation(affiliation);
item.role = parseRole(role);
if (!jid.isEmpty()) {
item.realJID = new JID(jid);
}
if (!nick.isEmpty()) {
item.nick = nick;
}
String xmlns = root.getNamespace();
String reason = root.getChild("reason", xmlns).getText();
String actor = root.getChild("actor", xmlns).getAttributes().getAttribute("jid");
if (!reason.isEmpty()) {
item.reason = reason;
}
if (!actor.isEmpty()) {
item.actor = new JID(actor);
}
return item;
}
private static Role parseRole(String val) {
for(Role role : Role.values()) {
if(role.nodeName.equals(val)) {
return role;
}
}
return null;
}
private static Affiliation parseAffiliation(String val) {
for(Affiliation aff : Affiliation.values()) {
if(aff.nodeName.equals(val)) {
return aff;
}
}
return null;
}
}
|