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