mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +01:00
Message type constants moved to innner class to be consistent with other parts of API.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1922 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
0d156ee0a6
commit
aa9e8f8960
1 changed files with 42 additions and 22 deletions
|
@ -80,13 +80,7 @@ import org.jivesoftware.smack.util.StringUtils;
|
||||||
*/
|
*/
|
||||||
public class Message extends Packet {
|
public class Message extends Packet {
|
||||||
|
|
||||||
public static final Type NORMAL = new Type("normal");
|
private Type type = Type.NORMAL;
|
||||||
public static final Type CHAT = new Type("chat");
|
|
||||||
public static final Type GROUP_CHAT = new Type("groupchat");
|
|
||||||
public static final Type HEADLINE = new Type("headline");
|
|
||||||
public static final Type ERROR = new Type("error");
|
|
||||||
|
|
||||||
private Type type = NORMAL;
|
|
||||||
private String subject = null;
|
private String subject = null;
|
||||||
private String body = null;
|
private String body = null;
|
||||||
private String thread = null;
|
private String thread = null;
|
||||||
|
@ -95,7 +89,6 @@ public class Message extends Packet {
|
||||||
* Creates a new, "normal" message.
|
* Creates a new, "normal" message.
|
||||||
*/
|
*/
|
||||||
public Message() {
|
public Message() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,6 +97,9 @@ public class Message extends Packet {
|
||||||
* @param to the recipient of the message.
|
* @param to the recipient of the message.
|
||||||
*/
|
*/
|
||||||
public Message(String to) {
|
public Message(String to) {
|
||||||
|
if (to == null) {
|
||||||
|
throw new IllegalArgumentException("Parameter cannot be null");
|
||||||
|
}
|
||||||
setTo(to);
|
setTo(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,9 +178,9 @@ public class Message extends Packet {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the thread id of the message, which is a unique identifier for a sequence
|
* Returns the thread id of the message, which is a unique identifier for a sequence
|
||||||
* of "chat" messages.
|
* of "chat" messages. If no thread id is set, <tt>null</tt> will be returned.
|
||||||
*
|
*
|
||||||
* @return the thread id of the message.
|
* @return the thread id of the message, or <tt>null</tt> if it doesn't exist.
|
||||||
*/
|
*/
|
||||||
public String getThread() {
|
public String getThread() {
|
||||||
return thread;
|
return thread;
|
||||||
|
@ -200,11 +196,6 @@ public class Message extends Packet {
|
||||||
this.thread = thread;
|
this.thread = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the message as XML.
|
|
||||||
*
|
|
||||||
* @return the message as XML.
|
|
||||||
*/
|
|
||||||
public String toXML() {
|
public String toXML() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
buf.append("<message");
|
buf.append("<message");
|
||||||
|
@ -215,7 +206,7 @@ public class Message extends Packet {
|
||||||
if (getFrom() != null) {
|
if (getFrom() != null) {
|
||||||
buf.append(" from=\"").append(getFrom()).append("\"");
|
buf.append(" from=\"").append(getFrom()).append("\"");
|
||||||
}
|
}
|
||||||
if (type != NORMAL) {
|
if (type != Type.NORMAL) {
|
||||||
buf.append(" type=\"").append(type).append("\"");
|
buf.append(" type=\"").append(type).append("\"");
|
||||||
}
|
}
|
||||||
buf.append(">");
|
buf.append(">");
|
||||||
|
@ -229,16 +220,14 @@ public class Message extends Packet {
|
||||||
buf.append("<thread>").append(thread).append("</thread>");
|
buf.append("<thread>").append(thread).append("</thread>");
|
||||||
}
|
}
|
||||||
// Append the error subpacket if the message type is an error.
|
// Append the error subpacket if the message type is an error.
|
||||||
if (type == ERROR) {
|
if (type == Type.ERROR) {
|
||||||
XMPPError error = getError();
|
XMPPError error = getError();
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
buf.append(error.toXML());
|
buf.append(error.toXML());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String properties = getPropertiesXML();
|
// Add packet extensions, if any are defined.
|
||||||
if (properties != null) {
|
buf.append(getExtentionsXML());
|
||||||
buf.append(properties);
|
|
||||||
}
|
|
||||||
buf.append("</message>");
|
buf.append("</message>");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
@ -248,6 +237,37 @@ public class Message extends Packet {
|
||||||
*/
|
*/
|
||||||
public static class Type {
|
public static class Type {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Default) a normal text message used in email like interface.
|
||||||
|
*/
|
||||||
|
public static final Type NORMAL = new Type("normal");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Typically short text message used in line-by-line chat interfaces.
|
||||||
|
*/
|
||||||
|
public static final Type CHAT = new Type("chat");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chat message sent to a groupchat server for group chats.
|
||||||
|
*/
|
||||||
|
public static final Type GROUP_CHAT = new Type("groupchat");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text message to be displayed in scrolling marquee displays.
|
||||||
|
*/
|
||||||
|
public static final Type HEADLINE = new Type("headline");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* indicates a messaging error.
|
||||||
|
*/
|
||||||
|
public static final Type ERROR = new Type("error");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a String value into its Type representation.
|
||||||
|
*
|
||||||
|
* @param type the String value.
|
||||||
|
* @return the Type corresponding to the String.
|
||||||
|
*/
|
||||||
public static Type fromString(String type) {
|
public static Type fromString(String type) {
|
||||||
if (CHAT.toString().equals(type)) {
|
if (CHAT.toString().equals(type)) {
|
||||||
return CHAT;
|
return CHAT;
|
||||||
|
|
Loading…
Reference in a new issue