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	
12	public MessagePacket() {
13		super("message");
14	}
15	
16	public String getBody() {
17		Element body = this.findChild("body");
18		if (body!=null) {
19			return body.getContent();
20		} else {
21			return null;
22		}
23	}
24	
25	public void setBody(String text) {
26		this.children.remove(findChild("body"));
27		Element body = new Element("body");
28		body.setContent(text);
29		this.children.add(body);
30	}
31
32	public void setType(int type) {
33		switch (type) {
34		case TYPE_CHAT:
35			this.setAttribute("type","chat");
36			break;
37		case TYPE_GROUPCHAT:
38			this.setAttribute("type", "groupchat");
39			break;
40		case TYPE_UNKNOWN:
41			break;
42		case TYPE_NORMAL:
43			break;
44		default:
45			this.setAttribute("type","chat");
46			break;
47		}
48	}
49	
50	public int getType() {
51		String type = getAttribute("type");
52		if (type==null) {
53			return TYPE_NORMAL;
54		} else if (type.equals("normal")) {
55			return TYPE_NORMAL;
56		} else if (type.equals("chat")) {
57			return TYPE_CHAT;
58		} else if (type.equals("groupchat")) {
59			return TYPE_GROUPCHAT;
60		} else if (type.equals("error")) {
61			return TYPE_ERROR;
62		} else {
63			return TYPE_UNKNOWN;
64		}
65	}
66}