aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/xmpp/MessagePacket.java
blob: de486a5da3f109fc314c3714ddb5e4a51e262f10 (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
package de.gultsch.chat.xmpp;

import de.gultsch.chat.xml.Element;

public class MessagePacket extends Element {
	public static final int TYPE_CHAT = 0;

	private MessagePacket(String name) {
		super(name);
	}
	
	public MessagePacket() {
		super("message");
	}
	
	public String getTo() {
		return getAttribute("to");
	}

	public String getFrom() {
		return getAttribute("from");
	}
	
	public String getBody() {
		return this.findChild("body").getContent();
	}
	
	public void setTo(String to) {
		setAttribute("to", to);
	}
	
	public void setFrom(String from) {
		setAttribute("from",from);
	}
	
	public void setBody(String text) {
		Element body = new Element("body");
		body.setContent(text);
		this.children.add(body);
	}

	public void setType(int type) {
		switch (type) {
		case TYPE_CHAT:
			this.setAttribute("type","chat");
			break;

		default:
			this.setAttribute("type","chat");
			break;
		}
	}
}