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_NORMAL = 2;
8 public static final int TYPE_GROUPCHAT = 3;
9 public static final int TYPE_ERROR = 4;
10 public static final int TYPE_HEADLINE = 5;
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(0, 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_NORMAL:
41 break;
42 default:
43 this.setAttribute("type", "chat");
44 break;
45 }
46 }
47
48 public int getType() {
49 String type = getAttribute("type");
50 if (type == null) {
51 return TYPE_NORMAL;
52 } else if (type.equals("normal")) {
53 return TYPE_NORMAL;
54 } else if (type.equals("chat")) {
55 return TYPE_CHAT;
56 } else if (type.equals("groupchat")) {
57 return TYPE_GROUPCHAT;
58 } else if (type.equals("error")) {
59 return TYPE_ERROR;
60 } else if (type.equals("headline")) {
61 return TYPE_HEADLINE;
62 } else {
63 return TYPE_NORMAL;
64 }
65 }
66}