Conversations/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java

67 lines
1.4 KiB
Java
Raw Normal View History

2014-03-10 19:22:13 +01:00
package eu.siacs.conversations.xmpp.stanzas;
2014-02-28 18:46:01 +01:00
import eu.siacs.conversations.xml.Element;
2014-03-10 19:22:13 +01:00
public class MessagePacket extends AbstractStanza {
public static final int TYPE_CHAT = 0;
2014-03-15 04:59:18 +01:00
public static final int TYPE_NORMAL = 2;
public static final int TYPE_GROUPCHAT = 3;
public static final int TYPE_ERROR = 4;
2014-08-05 01:36:17 +02:00
public static final int TYPE_HEADLINE = 5;
2014-08-31 16:28:21 +02:00
public MessagePacket() {
super("message");
}
2014-08-31 16:28:21 +02:00
2014-02-01 15:07:20 +01:00
public String getBody() {
2014-02-02 17:53:34 +01:00
Element body = this.findChild("body");
2014-08-31 16:28:21 +02:00
if (body != null) {
2014-02-02 17:53:34 +01:00
return body.getContent();
} else {
return null;
}
2014-02-01 15:07:20 +01:00
}
2014-08-31 16:28:21 +02:00
public void setBody(String text) {
2014-02-13 23:40:08 +01:00
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:
2014-08-31 16:28:21 +02:00
this.setAttribute("type", "chat");
break;
case TYPE_GROUPCHAT:
this.setAttribute("type", "groupchat");
break;
case TYPE_NORMAL:
break;
default:
2014-08-31 16:28:21 +02:00
this.setAttribute("type", "chat");
break;
}
}
2014-08-31 16:28:21 +02:00
2014-02-02 17:53:34 +01:00
public int getType() {
String type = getAttribute("type");
2014-08-31 16:28:21 +02:00
if (type == null) {
2014-03-15 04:59:18 +01:00
return TYPE_NORMAL;
} else if (type.equals("normal")) {
return TYPE_NORMAL;
} else if (type.equals("chat")) {
2014-02-02 17:53:34 +01:00
return TYPE_CHAT;
} else if (type.equals("groupchat")) {
return TYPE_GROUPCHAT;
} else if (type.equals("error")) {
return TYPE_ERROR;
2014-08-05 01:36:17 +02:00
} else if (type.equals("headline")) {
return TYPE_HEADLINE;
2014-02-02 17:53:34 +01:00
} else {
return TYPE_NORMAL;
2014-02-02 17:53:34 +01:00
}
}
}