net.kano.joscar.snaccmd.chat
Class ChatMsg

java.lang.Object
  extended byChatMsg
All Implemented Interfaces:
LiveWritable

public class ChatMsg
extends java.lang.Object
implements LiveWritable

Represents a single message sent or received in a chat room.


Field Summary
static java.lang.String CONTENTENCODING_DEFAULT
          A default content encoding always used by the official AIM clients ("binary").
static java.lang.String CONTENTTYPE_DEFAULT
          A default content type for "normal" (non-secure) chat rooms ("text/x-aolrtf").
static java.lang.String CONTENTTYPE_SECURE
          A default content type for secure chat rooms ("application/pkcs7-mime").
 
Constructor Summary
ChatMsg(java.lang.String message)
          Creates a new unencrypted chat message in the JVM's current language.
ChatMsg(java.lang.String message, java.util.Locale locale)
          Creates a new unencrypted chat message in the given language.
ChatMsg(java.lang.String contentType, java.lang.String contentEncoding, java.lang.String charset, ByteBlock messageData, java.util.Locale language)
          Creates a new chat message with the given properties.
 
Method Summary
 java.lang.String getCharset()
          Returns the charset in which the given message is encoded.
 java.lang.String getContentEncoding()
          Returns the content encoding string sent with this message.
 java.lang.String getContentType()
          Returns the content type string sent with this message.
 java.util.Locale getLanguage()
          Returns a Locale object representing the language in which this message was written, or null if no language value was sent.
 java.lang.String getMessage()
          Attempts to extract the actual message body from this chat message object.
 java.lang.String getMessageAsString()
          Decodes the message data block stored in this message using the specified charset.
 ByteBlock getMessageData()
          Returns the binary message data block contained in this message.
static ChatMsg readChatMsg(ByteBlock msgBlock)
          Reads a chat message from the given data block.
 java.lang.String toString()
           
 void write(java.io.OutputStream out)
          Writes a representation of this object to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTENTENCODING_DEFAULT

public static final java.lang.String CONTENTENCODING_DEFAULT
A default content encoding always used by the official AIM clients ("binary").

See Also:
Constant Field Values

CONTENTTYPE_DEFAULT

public static final java.lang.String CONTENTTYPE_DEFAULT
A default content type for "normal" (non-secure) chat rooms ("text/x-aolrtf").

See Also:
Constant Field Values

CONTENTTYPE_SECURE

public static final java.lang.String CONTENTTYPE_SECURE
A default content type for secure chat rooms ("application/pkcs7-mime").

See Also:
Constant Field Values
Constructor Detail

ChatMsg

public ChatMsg(java.lang.String message)
Creates a new unencrypted chat message in the JVM's current language. Calling this method is equivalent to calling new ChatMessage(message, Locale.getDefault()).

Parameters:
message - the text of this chat message

ChatMsg

public ChatMsg(java.lang.String message,
               java.util.Locale locale)
Creates a new unencrypted chat message in the given language.

Parameters:
message - the text of this chat message
locale - a locale object representing the language in which this message is written

ChatMsg

public ChatMsg(java.lang.String contentType,
               java.lang.String contentEncoding,
               java.lang.String charset,
               ByteBlock messageData,
               java.util.Locale language)
Creates a new chat message with the given properties.

Parameters:
contentType - a content type string, like CONTENTTYPE_DEFAULT
contentEncoding - a content encoding string, like CONTENTENCODING_DEFAULT
charset - the charset in which the message is encoded
messageData - the message data, possibly encrypted
language - a Locale object representing the language in which the message was written
Method Detail

readChatMsg

public static ChatMsg readChatMsg(ByteBlock msgBlock)
Reads a chat message from the given data block.

Parameters:
msgBlock - the data block containing chat message TLV's
Returns:
a chat message object read from the given data block

getMessageData

public final ByteBlock getMessageData()
Returns the binary message data block contained in this message. If this is an encrypted message, this will normally be the CMS signed data block; otherwise, this will normally simply be the binary form of the message text. See getMessage() for details on extracting a message from an unencrypted message block.

Returns:
the binary message data block

getContentType

public final java.lang.String getContentType()
Returns the content type string sent with this message. Note that this will normally be CONTENTTYPE_DEFAULT for plaintext messages and CONTENTTYPE_SECURE for secure messages.

Returns:
the content type string sent with this message, or null if none was sent

getContentEncoding

public final java.lang.String getContentEncoding()
Returns the content encoding string sent with this message. This value will normally be CONTENTENCODING_DEFAULT.

Returns:
this message's content encoding string, or null if none was sent

getCharset

public final java.lang.String getCharset()
Returns the charset in which the given message is encoded. Note that this will be null if no charset was sent. For details on decoding plaintext messages, see getMessage().

Returns:
the charset in which the given message is encoded, or null if no charset value was sent

getLanguage

public final java.util.Locale getLanguage()
Returns a Locale object representing the language in which this message was written, or null if no language value was sent.

Returns:
the language in which this message was written, or null if no language value was sent

getMessage

public final java.lang.String getMessage()
Attempts to extract the actual message body from this chat message object. This method will always return null if the content type is non-null and is not equal to CONTENTTYPE_DEFAULT because in such a case the message is probably in a different format than plaintext (such as in encrypted form).

In short, this method should successfully extract a plaintext message, but will return null if it suspects that the message is in a different format. To force reading the message data as a plaintext message (for example, if you know that the message data is in plaintext format and not encrypted), use getMessageAsString().

Returns:
the plaintext message body stored in this object, or null if no plaintext message is present

getMessageAsString

public final java.lang.String getMessageAsString()
Decodes the message data block stored in this message using the specified charset. Note that this method will not decode encrypted messages; rather, it will attempt to convert the encrypted form of the message to a String with the given charset, most likely producing a string of "garbage."

Returns:
the message body contained in this object, converted using the associated charset
See Also:
OscarTools.getString(net.kano.joscar.ByteBlock, java.lang.String)

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Description copied from interface: LiveWritable
Writes a representation of this object to the given stream.

Specified by:
write in interface LiveWritable
Parameters:
out - the stream to which to write
Throws:
java.io.IOException - if an I/O error occurs

toString

public java.lang.String toString()