MessagePacket.java

 1package eu.siacs.conversations.xmpp.stanzas;
 2
 3import eu.siacs.conversations.xml.Element;
 4
 5public class MessagePacket extends AbstractStanza {
 6	public static final int TYPE_CHAT = 0;
 7	public static final int TYPE_UNKNOWN = 1;
 8	public static final int TYPE_NORMAL = 2;
 9	public static final int TYPE_GROUPCHAT = 3;
10	public static final int TYPE_ERROR = 4;
11	public static final int TYPE_HEADLINE = 5;
12	
13	public MessagePacket() {
14		super("message");
15	}
16	
17	public String getBody() {
18		Element body = this.findChild("body");
19		if (body!=null) {
20			return body.getContent();
21		} else {
22			return null;
23		}
24	}
25	
26	public void setBody(String text) {
27		this.children.remove(findChild("body"));
28		Element body = new Element("body");
29		body.setContent(text);
30		this.children.add(body);
31	}
32
33	public void setType(int type) {
34		switch (type) {
35		case TYPE_CHAT:
36			this.setAttribute("type","chat");
37			break;
38		case TYPE_GROUPCHAT:
39			this.setAttribute("type", "groupchat");
40			break;
41		case TYPE_UNKNOWN:
42			break;
43		case TYPE_NORMAL:
44			break;
45		default:
46			this.setAttribute("type","chat");
47			break;
48		}
49	}
50	
51	public int getType() {
52		String type = getAttribute("type");
53		if (type==null) {
54			return TYPE_NORMAL;
55		} else if (type.equals("normal")) {
56			return TYPE_NORMAL;
57		} else if (type.equals("chat")) {
58			return TYPE_CHAT;
59		} else if (type.equals("groupchat")) {
60			return TYPE_GROUPCHAT;
61		} else if (type.equals("error")) {
62			return TYPE_ERROR;
63		} else if (type.equals("headline")) {
64			return TYPE_HEADLINE;
65		} else {
66			return TYPE_UNKNOWN;
67		}
68	}
69}