com.echomine.jabber
Class JabberChatMessage

java.lang.Object
  extended by com.echomine.jabber.JabberMessage
      extended by com.echomine.jabber.JabberJDOMMessage
          extended by com.echomine.jabber.AbstractJabberMessage
              extended by com.echomine.jabber.JabberChatMessage
All Implemented Interfaces:
JabberCode, JabberMessageParsable

public class JabberChatMessage
extends AbstractJabberMessage
implements JabberCode

This is the base message for working with private IM messages, group chats, and anything that is sent through the tag.

The message body may come in different formats. For instance, it can come in as XHTML for better style support. This is an extension and is NOT considered to be an X Message. Thus, it is retrieved through this class' getHTML(). To display XHTML data in Java is rather easy. You can simply use a JTextPane or JEditorPane, set the Content MIME Type to text/html, and then just set the Text Pane's text to getHTML().

Processing of X Messages are supported as always, but it is up to the developer to implement capabilities to work with the X Message types.

Thread IDs is easy to work with. Normally, if you initiate a chat for the first time with a JID, you should set the Thread ID to a new ID (you can obtain a new ID from the generateThreadID() method, which will return a GUID 32-byte hex string). However, if you are replying to a message, you should set your reply message's Thread ID to the ID of the message that you're replying to. ie. reply.setThreadID(origMsg.getThreadID()). The developer is responsible for setting the Thread IDs for reply messages. However, if this message is a new message, the API will automatically set the Thread ID to a new GUID for you so you don't need to worry about that part. But that's only for new messages.


Field Summary
static java.lang.String TYPE_CHAT
           
static java.lang.String TYPE_GROUPCHAT
           
static java.lang.String TYPE_HEADLINE
           
static java.lang.String TYPE_NORMAL
           
 
Fields inherited from class com.echomine.jabber.AbstractJabberMessage
TYPE_ERROR
 
Fields inherited from class com.echomine.jabber.JabberMessage
messageID
 
Fields inherited from interface com.echomine.jabber.JabberCode
MSG_CHAT, MSG_INIT, MSG_IQ, MSG_IQ_AGENTS, MSG_IQ_AUTH, MSG_IQ_BROWSE, MSG_IQ_DISCO_INFO, MSG_IQ_DISCO_ITEMS, MSG_IQ_GATEWAY, MSG_IQ_LAST, MSG_IQ_OOB, MSG_IQ_PRIVATE, MSG_IQ_REGISTER, MSG_IQ_ROSTER, MSG_IQ_SEARCH, MSG_IQ_TIME, MSG_IQ_VACATION, MSG_IQ_VCARD, MSG_IQ_VERSION, MSG_IQ_XMLRPC, MSG_PRESENCE, MSG_UNKNOWN, MSG_X_DATA, MSG_X_DELAY, MSG_X_EVENT, MSG_X_EXPIRE, MSG_X_OOB, MSG_X_PGP_ENCRYPTED, MSG_X_PGP_SIGNED, MSG_X_ROSTER, PARSER_CHAT, PARSER_IQ, PARSER_IQ_AGENTS, PARSER_IQ_AUTH, PARSER_IQ_BROWSE, PARSER_IQ_DISCO_INFO, PARSER_IQ_DISCO_ITEMS, PARSER_IQ_GATEWAY, PARSER_IQ_LAST, PARSER_IQ_OOB, PARSER_IQ_PRIVATE, PARSER_IQ_REGISTER, PARSER_IQ_ROSTER, PARSER_IQ_SEARCH, PARSER_IQ_TIME, PARSER_IQ_VACATION, PARSER_IQ_VCARD, PARSER_IQ_VERSION, PARSER_IQ_XMLRPC, PARSER_PRESENCE, PARSER_X_DATA, PARSER_X_DELAY, PARSER_X_EVENT, PARSER_X_EXPIRE, PARSER_X_OOB, PARSER_X_PGP_ENCRYPTED, PARSER_X_PGP_SIGNED, PARSER_X_ROSTER, XMLNS_CHAT, XMLNS_ERROR_STANZA, XMLNS_ERROR_STREAM, XMLNS_IQ, XMLNS_IQ_AGENTS, XMLNS_IQ_AUTH, XMLNS_IQ_BROWSE, XMLNS_IQ_DISCO_INFO, XMLNS_IQ_DISCO_ITEMS, XMLNS_IQ_GATEWAY, XMLNS_IQ_LAST, XMLNS_IQ_OOB, XMLNS_IQ_PRIVATE, XMLNS_IQ_REGISTER, XMLNS_IQ_ROSTER, XMLNS_IQ_SEARCH, XMLNS_IQ_TIME, XMLNS_IQ_VACATION, XMLNS_IQ_VCARD, XMLNS_IQ_VERSION, XMLNS_IQ_XMLRPC, XMLNS_PRESENCE, XMLNS_STREAM, XMLNS_X_DATA, XMLNS_X_DELAY, XMLNS_X_EVENT, XMLNS_X_EXPIRE, XMLNS_X_OOB, XMLNS_X_PGP_ENCRYPTED, XMLNS_X_PGP_SIGNED, XMLNS_X_ROSTER
 
Constructor Summary
JabberChatMessage()
          defaults the message type to a normal type
JabberChatMessage(java.lang.String type)
          Normally used for creating an outgoing message
 
Method Summary
static java.lang.String generateThreadID()
          the method will generate a unique ID for use.
 java.lang.String getBody()
          retrieves the message body
 DelayXMessage getDelayMessage()
          convenience method to retrieve the Delay X Message (you can get the message by calling getXMessage() as well)
 EventXMessage getEventMessage()
          retrieves the event message if there is one associated with it
 java.lang.String getHTMLBody()
          retrieves the body that is encoded with XHTML.
 int getMessageType()
          the default message type is unknown.
 PGPEncryptedXMessage getPGPMessage()
          a convenience method to retrieve the PGP encrypted data if there is one attached to this message
 java.util.List getRosterList()
          retrieves a list of RosterItem's contained in this message if there are any.
 java.lang.String getSubject()
          retrieves the message subject
 java.lang.String getThreadID()
          retrieve the thread id associated with this message.
 boolean isRosterMessage()
          checks to see if this message contains a jabber:x:roster message.
 JabberMessage parse(JabberMessageParser parser, Element msgTree)
          parses the message.
 void setBody(java.lang.String body)
          sets the outgoing message body
 void setHTMLBody(java.lang.String html)
          this sets the HTML text.
 void setSubject(java.lang.String subject)
          sets the message subject.
 void setThreadID(java.lang.String threadID)
          sets the thread id.
 
Methods inherited from class com.echomine.jabber.AbstractJabberMessage
getErrorMessage, getFrom, getTo, getType, isError, setErrorMessage, setFrom, setTo, setType
 
Methods inherited from class com.echomine.jabber.JabberJDOMMessage
encode, getDOM, getXMLOutputter, setMessageID, toString
 
Methods inherited from class com.echomine.jabber.JabberMessage
getMessageID, getReplyMessage, getTimeout, getXMessage, getXMessages, interrupt, isReplyRequired, isSendXMessages, isSynchronized, replyReceived, setReplyRequired, setSendXMessages, setSynchronized, setTimeout, setXMessage, setXMessages
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_NORMAL

public static final java.lang.String TYPE_NORMAL
See Also:
Constant Field Values

TYPE_CHAT

public static final java.lang.String TYPE_CHAT
See Also:
Constant Field Values

TYPE_GROUPCHAT

public static final java.lang.String TYPE_GROUPCHAT
See Also:
Constant Field Values

TYPE_HEADLINE

public static final java.lang.String TYPE_HEADLINE
See Also:
Constant Field Values
Constructor Detail

JabberChatMessage

public JabberChatMessage(java.lang.String type)
Normally used for creating an outgoing message


JabberChatMessage

public JabberChatMessage()
defaults the message type to a normal type

Method Detail

parse

public JabberMessage parse(JabberMessageParser parser,
                           Element msgTree)
                    throws ParseException
Description copied from class: AbstractJabberMessage
parses the message. The parser is really not used

Specified by:
parse in interface JabberMessageParsable
Overrides:
parse in class AbstractJabberMessage
Throws:
ParseException

getBody

public java.lang.String getBody()
retrieves the message body


setBody

public void setBody(java.lang.String body)
sets the outgoing message body


getHTMLBody

public java.lang.String getHTMLBody()
retrieves the body that is encoded with XHTML. If there isn't a XHTML body, this method will return null. Normally the body is the same as the getBody() but with additional formatting tags (using XHTML Basic).


setHTMLBody

public void setHTMLBody(java.lang.String html)
                 throws ParseException
this sets the HTML text. You must make sure that the text is XHTML Basic compliant. Otherwise, the server will report an error. Set to null to remove the HTML from being sent. The html tag should be the following format:

Throws:
ParseException

getSubject

public java.lang.String getSubject()
retrieves the message subject


setSubject

public void setSubject(java.lang.String subject)
sets the message subject. Normally this can be null since not all clients may use or display the subject. The message will be added straight into the dom tree. Set to null to remove an existing subject.


getThreadID

public java.lang.String getThreadID()
retrieve the thread id associated with this message. It's used to associate different messages so you know which message is going with which conversation. Since the Thread ID is already parsed in the parse() method, we have no need to retrieve the data again from the DOM.


setThreadID

public void setThreadID(java.lang.String threadID)
sets the thread id. Set to null to remove the thread ID from getting sent with the message


isRosterMessage

public boolean isRosterMessage()
checks to see if this message contains a jabber:x:roster message. If it does, then this message is marked as a message that is sending a list of roster contacts over to someone (either someone sending contacts to you or you sending contacts to someone else).

Returns:
true if this message contains roster contacts, false otherwise.

getRosterList

public java.util.List getRosterList()
retrieves a list of RosterItem's contained in this message if there are any. If not, then the method returns null.

Returns:
List of RosterItem objects, null if there is no list

getEventMessage

public EventXMessage getEventMessage()
retrieves the event message if there is one associated with it

Returns:
the event message, null if none exists

getDelayMessage

public DelayXMessage getDelayMessage()
convenience method to retrieve the Delay X Message (you can get the message by calling getXMessage() as well)

Returns:
the delay message, null if none exists

getPGPMessage

public PGPEncryptedXMessage getPGPMessage()
a convenience method to retrieve the PGP encrypted data if there is one attached to this message

Returns:
the PGP Encrypted X Message or null if there isn't one attached to this message

generateThreadID

public static java.lang.String generateThreadID()
the method will generate a unique ID for use. Currently this implementation will use the MessageID generator and leech some id's from there instead.


getMessageType

public int getMessageType()
Description copied from class: JabberJDOMMessage
the default message type is unknown. It doesn't mean that there is no type. It just means that there is no known message parser for this particular object.

Overrides:
getMessageType in class JabberJDOMMessage
Returns:
a message code that is unique to the message
See Also:
JabberCode


Copyright © 2001-2005 Echomine. All Rights Reserved.