com.arsdigita.messaging
Class Message

java.lang.Object
  extended bycom.arsdigita.domain.DomainObject
      extended bycom.arsdigita.domain.ObservableDomainObject
          extended bycom.arsdigita.kernel.ACSObject
              extended bycom.arsdigita.messaging.Message
All Implemented Interfaces:
MessageType, MessageType
Direct Known Subclasses:
ThreadedMessage

public class Message
extends ACSObject
implements MessageType

A plain text message with optional attachments. The message body should have a MIME type of text/plain or text/html. Each attachment to the message can have an arbitrary MIME type and format. Messages can also refer to another object on the system, and in this way be attached to ContentItems, bboard forums, etc.

Version:
$Id: //core-platform/dev/src/com/arsdigita/messaging/Message.java#13 $
Author:
Ron Henderson, David Dao

Field Summary
static String BASE_DATA_OBJECT_TYPE
          Base DataObject type
static String BODY
           
static String INREPLYTO
           
static String MESSAGE_ID
           
static String MESSAGE_PART
           
static String OBJECT_ID
           
static String REPLY_TO
           
static String SENDER
          Keys for persistent data.
static String SENT
           
static String SUBJECT
           
static String TYPE
           
 
Fields inherited from class com.arsdigita.kernel.ACSObject
CONTAINER, DEFAULT_DOMAIN_CLASS, DISPLAY_NAME, ID, OBJECT_TYPE, versionId
 
Fields inherited from interface com.arsdigita.util.MessageType
TEXT_HTML, TEXT_PLAIN, TEXT_PREFORMATTED, TEXT_SMART
 
Constructor Summary
Message()
          Creates a new message with the sentDate initialized to the current time, but leaves all other parameters null.
Message(BigDecimal id)
          Creates a message by retrieving it from the database using its id.
Message(DataObject dataObject)
          Creates a message from its underlying data object.
Message(OID oid)
          Creates a message by retrieving it from the database using its OID.
Message(Party f, String s)
          Creates a message from a party with a given subject.
Message(Party f, String s, String b)
          Creates a message from a party with a given subject and body.
Message(String type)
          Creates a new message of the specified data object type.
 
Method Summary
protected  void afterSave()
           
 void attach(MessagePart part)
          Attaches a MessagePart to this message.
 void attach(String text, String name)
          Adds a text/plain attachment to a message with a given name and a disposition of MessagePart.ATTACHMENT.
 void attach(String text, String name, String description)
          Adds a text/plain attachment with the given name and description to a message, with a disposition of MessagePart.ATTACHMENT.
 void attach(String text, String name, String description, String disposition)
          Adds a text/plain attachment with the given name, description and disposition to a message.
 void doWriteCheck()
          Allow writes if user has read on the parent (forum).
static String generateHTMLText(String text, String formatType)
          Deprecated. Use com.arsdigita.util.HtmlToText.generateHTMLText.
 int getAttachmentCount()
          Returns the number of items attached to this message.
 ListIterator getAttachments()
          Returns an iterator over the attachments for this message.
 String getBody()
          Returns the content of the message as a String.
 String getBodyAsHTML()
          This returns the body in a form that can be displayed directly as HTML.
 String getBodyType()
          Returns the MIME type of the message body.
 ACSObject getContainer()
          Returns the Container for this Message.
 String getDisplayName()
          Returns the name of the message
 Party getFrom()
          Gets the sender of the message.
 BigDecimal getMessageID()
          Deprecated. Use getID in place of getMessageID
 BigDecimal getRefersTo()
          Returns the ID of an ACSObject which this message refers to.
protected  void getReplyInfo(Message msg)
          Copies the necessary reply information from a parent message to this one.
 String getReplyTo()
          Gets the return email address of the message.
 String getRFCMessageID()
          Return the RFC 822 Message-ID header for this message.
 Date getSentDate()
          Returns the date this message was sent.
 String getSubject()
          Gets the subject of the message.
 boolean isContainerModified()
          Returns true if this object has been moved to a new container, or null if the container has not changed.
 boolean isMimeType(String mimeType)
          Returns true if this message is of the specified MIME type.
 Message reply()
          Gets a new message that is suitable for a reply to this message.
 void setBody(String body, String type)
          Sets the body of the message to the given string with the specified MIME type.
 void setFrom(Party f)
          Sets the sender of the message.
 void setRefersTo(ACSObject obj)
          Sets the ACSObject which this message refers to.
 void setRefersTo(BigDecimal id)
          Sets the ID of an ACSObject which this message refers to.
 void setReplyTo(String addr)
          Sets the return email address of the message.
 void setRFCMessageID(String messageID)
          Set RFC 822 Message-ID header for this message.
 void setSentDate(Date sentDate)
          Sets the sent date of a message.
 void setSubject(String s)
          Sets the subject of the message.
 void setText(String text)
          A convenience method that sets the body of the message to a string with a MIME type of "text/plain".
 
Methods inherited from class com.arsdigita.kernel.ACSObject
assertPrivilege, beforeSave, checkPrivilege, doCreateCheck, getBaseDataObjectType, getDefaultDomainClass, getID, getSpecificObjectType, getSpecificOID, gimmeContainer, initialize, setID, setID
 
Methods inherited from class com.arsdigita.domain.ObservableDomainObject
addObserver, getObservers
 
Methods inherited from class com.arsdigita.domain.DomainObject
add, add, addToAssociation, afterDelete, beforeDelete, clear, delete, disconnect, equals, get, getObjectType, getOID, getSession, hashCode, isDeleted, isDisconnected, isModified, isNew, isPropertyModified, isValid, remove, remove, remove, removeFromAssociation, save, set, setAssociation, setAssociation, specializeDataObject, specializeDataObject, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BASE_DATA_OBJECT_TYPE

public static final String BASE_DATA_OBJECT_TYPE
Base DataObject type


SENDER

public static final String SENDER
Keys for persistent data.

See Also:
Constant Field Values

REPLY_TO

public static final String REPLY_TO
See Also:
Constant Field Values

SUBJECT

public static final String SUBJECT
See Also:
Constant Field Values

BODY

public static final String BODY
See Also:
Constant Field Values

TYPE

public static final String TYPE
See Also:
Constant Field Values

SENT

public static final String SENT
See Also:
Constant Field Values

INREPLYTO

public static final String INREPLYTO
See Also:
Constant Field Values

OBJECT_ID

public static final String OBJECT_ID
See Also:
Constant Field Values

MESSAGE_ID

public static final String MESSAGE_ID
See Also:
Constant Field Values

MESSAGE_PART

public static final String MESSAGE_PART
See Also:
Constant Field Values
Constructor Detail

Message

public Message()
Creates a new message with the sentDate initialized to the current time, but leaves all other parameters null.


Message

public Message(String type)
Creates a new message of the specified data object type. Initializes the sentDate to the current time, but leaves all other parameters null.

Parameters:
type - the DataObject type.

Message

public Message(Party f,
               String s)
Creates a message from a party with a given subject.

Parameters:
f - the party sending the message
s - the subject of the message

Message

public Message(Party f,
               String s,
               String b)
Creates a message from a party with a given subject and body.

Parameters:
f - the party sending the message
s - the subject of the message
b - the plain-text body of the message

Message

public Message(DataObject dataObject)
Creates a message from its underlying data object.

Parameters:
dataObject - the DataObject representing this message.

Message

public Message(BigDecimal id)
        throws DataObjectNotFoundException
Creates a message by retrieving it from the database using its id.

Parameters:
id - the id of the message

Message

public Message(OID oid)
        throws DataObjectNotFoundException
Creates a message by retrieving it from the database using its OID.

Parameters:
oid - the OID of the message
Method Detail

getReplyInfo

protected void getReplyInfo(Message msg)
Copies the necessary reply information from a parent message to this one. This includes:

Parameters:
msg - the message to generate reply information from

getDisplayName

public String getDisplayName()
Returns the name of the message

Overrides:
getDisplayName in class ACSObject
Returns:
the displayable name for this object.

reply

public Message reply()
              throws MessagingException
Gets a new message that is suitable for a reply to this message.

Throws:
MessagingException

getSubject

public String getSubject()
Gets the subject of the message.

Returns:
the subject of the message.

setSubject

public void setSubject(String s)
Sets the subject of the message.

Parameters:
s - the subject

setFrom

public void setFrom(Party f)
Sets the sender of the message.

Parameters:
f - the party sending the message

getFrom

public Party getFrom()
Gets the sender of the message.

Returns:
the sender.

setReplyTo

public void setReplyTo(String addr)
Sets the return email address of the message. Sets this field if you want return address differs than sender.

Parameters:
addr - reply address.

getReplyTo

public String getReplyTo()
Gets the return email address of the message.

Returns:
the return email address.

getBody

public String getBody()
Returns the content of the message as a String. Message bodies can always be represented as text. If you need to check on the MIME type of the body, use the getBodyType method and process the body accordingly.

Returns:
the content of the message.

getBodyAsHTML

public String getBodyAsHTML()
This returns the body in a form that can be displayed directly as HTML. Basically, this conditionally modifies the body depending on the result of getBodyType();


setBody

public void setBody(String body,
                    String type)
Sets the body of the message to the given string with the specified MIME type. Use one of the standard types defined in the MessageType interface:

Parameters:
body - the body of the message
type - the MIME type

setText

public void setText(String text)
A convenience method that sets the body of the message to a string with a MIME type of "text/plain".


getBodyType

public String getBodyType()
Returns the MIME type of the message body. This should normally have a primary type of text and secondary type of plain or html.

Returns:
the MIME type of the message body.

isMimeType

public boolean isMimeType(String mimeType)
Returns true if this message is of the specified MIME type. Only compares the primary type and subtype, and ignore any additional qualifiers.

Returns:
true if this message is of the specified MIME type; false otherwise.

getSentDate

public Date getSentDate()
Returns the date this message was sent.

Returns:
the date this message was sent.

setSentDate

public void setSentDate(Date sentDate)
Sets the sent date of a message.

Parameters:
sentDate - the date the message was sent

getRefersTo

public BigDecimal getRefersTo()
Returns the ID of an ACSObject which this message refers to. Applications should implement their own methods for retrieving the underlying object from the database.

Returns:
the ID of an ACSObject which this message refers to.

setRefersTo

public void setRefersTo(BigDecimal id)
Sets the ID of an ACSObject which this message refers to.

Parameters:
id - the ID of the ACSObject this message refers to.

setRefersTo

public void setRefersTo(ACSObject obj)
Sets the ACSObject which this message refers to.

Parameters:
obj - the ACSObject this message refers to.

getRFCMessageID

public String getRFCMessageID()
Return the RFC 822 Message-ID header for this message.

Returns:
RFC 822 Message-ID

setRFCMessageID

public void setRFCMessageID(String messageID)
Set RFC 822 Message-ID header for this message. Message-ID header needs to be in internet address format (e.g. xxx@hostname)


attach

public void attach(String text,
                   String name)
Adds a text/plain attachment to a message with a given name and a disposition of MessagePart.ATTACHMENT.

Parameters:
text - the content of the attachment
name - the name of the attachment

attach

public void attach(String text,
                   String name,
                   String description)
Adds a text/plain attachment with the given name and description to a message, with a disposition of MessagePart.ATTACHMENT.

Parameters:
text - the content of the attachment
name - the name of the attachment
description - a description of the attachment

attach

public void attach(String text,
                   String name,
                   String description,
                   String disposition)
Adds a text/plain attachment with the given name, description and disposition to a message.

Parameters:
text - the content of the attachment
name - the name of the attachment
description - a description of the attachment

attach

public void attach(MessagePart part)
Attaches a MessagePart to this message. This method is used by all of the other attach methods.

Parameters:
part - the MessagePart to attach

getAttachmentCount

public int getAttachmentCount()
Returns the number of items attached to this message.

Returns:
the number of items attached to this message.

getAttachments

public ListIterator getAttachments()
Returns an iterator over the attachments for this message.

Returns:
an iterator over the attachments for this message.

getMessageID

public BigDecimal getMessageID()
Deprecated. Use getID in place of getMessageID

Returns the MessageID of this instance as a BigDecimal.

Returns:
the MessageID of this instance.

getContainer

public ACSObject getContainer()
Returns the Container for this Message. This is implemented by instantiating the object the message refers to, which may or may not be null.

Overrides:
getContainer in class ACSObject
Returns:
the ACSObject that contains this message.

doWriteCheck

public void doWriteCheck()
Allow writes if user has read on the parent (forum).

Overrides:
doWriteCheck in class ACSObject

isContainerModified

public boolean isContainerModified()
Description copied from class: ACSObject
Returns true if this object has been moved to a new container, or null if the container has not changed. This methods is used by ACSObject.save() to determine when to denormalize the result of getContainer(). While this method is not abstract, the default implementation "guesses" the container based on metadata about the object. If this object's data object type has a composite role property (required, visible property where com.arsdigita.persistence.metadata.Property.isComposite()==true), then we check whether the composite role property has been modified. If no composite role is found, then the return value is false. Subclasses should provide their own implementations if the metadata driven default implementation is inadequate. See the example mentioned in getContainer().

Overrides:
isContainerModified in class ACSObject
Returns:
true if the container for this Message has changed.
See Also:
ACSObject.getContainer()

generateHTMLText

public static String generateHTMLText(String text,
                                      String formatType)
Deprecated. Use com.arsdigita.util.HtmlToText.generateHTMLText.


afterSave

protected void afterSave()
Overrides:
afterSave in class DomainObject


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC