aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/MessagePacket.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-28 18:46:01 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-28 18:46:01 +0100
commitacf80bddd07d5579cdb20a888b3f9e99e53030a5 (patch)
tree034a8e364488c89c8e1997f56313d919019afa65 /src/eu/siacs/conversations/xmpp/MessagePacket.java
parent03d96266f8bbb76e25610e903d74a0afa7dcd03b (diff)
rebranding
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/MessagePacket.java')
-rw-r--r--src/eu/siacs/conversations/xmpp/MessagePacket.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/xmpp/MessagePacket.java b/src/eu/siacs/conversations/xmpp/MessagePacket.java
new file mode 100644
index 00000000..a014155f
--- /dev/null
+++ b/src/eu/siacs/conversations/xmpp/MessagePacket.java
@@ -0,0 +1,81 @@
+package eu.siacs.conversations.xmpp;
+
+import eu.siacs.conversations.xml.Element;
+
+public class MessagePacket extends Element {
+ public static final int TYPE_CHAT = 0;
+ public static final int TYPE_UNKNOWN = 1;
+ public static final int TYPE_NO = 2;
+ public static final int TYPE_GROUPCHAT = 3;
+ public static final int TYPE_ERROR = 4;
+
+ 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() {
+ Element body = this.findChild("body");
+ if (body!=null) {
+ return body.getContent();
+ } else {
+ return null;
+ }
+ }
+
+ public void setTo(String to) {
+ setAttribute("to", to);
+ }
+
+ public void setFrom(String from) {
+ setAttribute("from",from);
+ }
+
+ public void setBody(String text) {
+ this.children.remove(findChild("body"));
+ 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;
+ case TYPE_GROUPCHAT:
+ this.setAttribute("type", "groupchat");
+ break;
+ default:
+ this.setAttribute("type","chat");
+ break;
+ }
+ }
+
+ public int getType() {
+ String type = getAttribute("type");
+ if (type==null) {
+ return TYPE_NO;
+ }
+ if (type.equals("chat")) {
+ return TYPE_CHAT;
+ } else if (type.equals("groupchat")) {
+ return TYPE_GROUPCHAT;
+ } else if (type.equals("error")) {
+ return TYPE_ERROR;
+ } else {
+ return TYPE_UNKNOWN;
+ }
+ }
+}