org.apache.james.mime4j.message
Class Entity

java.lang.Object
  extended by org.apache.james.mime4j.message.Entity
All Implemented Interfaces:
Disposable
Direct Known Subclasses:
BodyPart, Message

public abstract class Entity
extends java.lang.Object
implements Disposable

MIME entity. An entity has a header and a body (see RFC 2045).


Constructor Summary
protected Entity()
          Creates a new Entity.
protected Entity(Entity other)
          Creates a new Entity from the specified Entity.
 
Method Summary
 void dispose()
          Disposes of the body of this entity.
 Body getBody()
          Gets the body of this entity.
 java.lang.String getCharset()
          Determines the MIME character set encoding of this Entity.
 java.lang.String getContentTransferEncoding()
          Determines the transfer encoding of this Entity.
 java.lang.String getDispositionType()
          Return the disposition type of the content disposition of this Entity.
 java.lang.String getFilename()
          Returns the filename parameter of the content disposition of this Entity.
 Header getHeader()
          Gets the entity header.
 java.lang.String getMimeType()
          Determines the MIME type of this Entity.
 Entity getParent()
          Gets the parent entity of this entity.
 boolean isMimeType(java.lang.String type)
          Determines if the MIME type of this Entity matches the given one.
 boolean isMultipart()
          Determines if the MIME type of this Entity is multipart/*.
 Body removeBody()
          Removes and returns the body of this entity.
 void setBody(Body body)
          Sets the body of this entity.
 void setBody(Body body, java.lang.String mimeType)
          Sets the body of this entity and sets the content-type to the specified value.
 void setBody(Body body, java.lang.String mimeType, java.util.Map<java.lang.String,java.lang.String> parameters)
          Sets the body of this entity and sets the content-type to the specified value.
 void setContentDisposition(java.lang.String dispositionType)
          Sets the content disposition of this Entity to the specified disposition type.
 void setContentDisposition(java.lang.String dispositionType, java.lang.String filename)
          Sets the content disposition of this Entity to the specified disposition type and filename.
 void setContentDisposition(java.lang.String dispositionType, java.lang.String filename, long size)
          Sets the content disposition of this Entity to the specified values.
 void setContentDisposition(java.lang.String dispositionType, java.lang.String filename, long size, java.util.Date creationDate, java.util.Date modificationDate, java.util.Date readDate)
          Sets the content disposition of this Entity to the specified values.
 void setContentTransferEncoding(java.lang.String contentTransferEncoding)
          Sets the transfer encoding of this Entity to the specified value.
 void setFilename(java.lang.String filename)
          Sets the filename parameter of the content disposition of this Entity to the specified value.
 void setHeader(Header header)
          Sets the entity header.
 void setMessage(Message message)
          Sets the specified message as body of this entity and the content type to "message/rfc822".
 void setMultipart(Multipart multipart)
          Sets the specified multipart as body of this entity.
 void setMultipart(Multipart multipart, java.util.Map<java.lang.String,java.lang.String> parameters)
          Sets the specified multipart as body of this entity.
 void setParent(Entity parent)
          Sets the parent entity of this entity.
 void setText(TextBody textBody)
          Sets the specified TextBody as body of this entity and the content type to "text/plain".
 void setText(TextBody textBody, java.lang.String subtype)
          Sets the specified TextBody as body of this entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Entity

protected Entity()
Creates a new Entity. Typically invoked implicitly by a subclass constructor.


Entity

protected Entity(Entity other)
Creates a new Entity from the specified Entity. The Entity instance is initialized with copies of header and body of the specified Entity. The parent entity of the new entity is null.

Parameters:
other - entity to copy.
Throws:
java.lang.UnsupportedOperationException - if other contains a SingleBody that does not support the copy() operation.
java.lang.IllegalArgumentException - if other contains a Body that is neither a Message, Multipart or SingleBody.
Method Detail

getParent

public Entity getParent()
Gets the parent entity of this entity. Returns null if this is the root entity.

Returns:
the parent or null.

setParent

public void setParent(Entity parent)
Sets the parent entity of this entity.

Parameters:
parent - the parent entity or null if this will be the root entity.

getHeader

public Header getHeader()
Gets the entity header.

Returns:
the header.

setHeader

public void setHeader(Header header)
Sets the entity header.

Parameters:
header - the header.

getBody

public Body getBody()
Gets the body of this entity.

Returns:
the body,

setBody

public void setBody(Body body)
Sets the body of this entity.

Parameters:
body - the body.
Throws:
java.lang.IllegalStateException - if the body has already been set.

removeBody

public Body removeBody()
Removes and returns the body of this entity. The removed body may be attached to another entity. If it is no longer needed it should be disposed of.

Returns:
the removed body or null if no body was set.

setMessage

public void setMessage(Message message)
Sets the specified message as body of this entity and the content type to "message/rfc822". A Header is created if this entity does not already have one.

Parameters:
message - the message to set as body.

setMultipart

public void setMultipart(Multipart multipart)
Sets the specified multipart as body of this entity. Also sets the content type accordingly and creates a message boundary string. A Header is created if this entity does not already have one.

Parameters:
multipart - the multipart to set as body.

setMultipart

public void setMultipart(Multipart multipart,
                         java.util.Map<java.lang.String,java.lang.String> parameters)
Sets the specified multipart as body of this entity. Also sets the content type accordingly and creates a message boundary string. A Header is created if this entity does not already have one.

Parameters:
multipart - the multipart to set as body.
parameters - additional parameters for the Content-Type header field.

setText

public void setText(TextBody textBody)
Sets the specified TextBody as body of this entity and the content type to "text/plain". A Header is created if this entity does not already have one.

Parameters:
textBody - the TextBody to set as body.
See Also:
BodyFactory.textBody(String)

setText

public void setText(TextBody textBody,
                    java.lang.String subtype)
Sets the specified TextBody as body of this entity. Also sets the content type according to the specified sub-type. A Header is created if this entity does not already have one.

Parameters:
textBody - the TextBody to set as body.
subtype - the text subtype (e.g. "plain", "html" or "xml").
See Also:
BodyFactory.textBody(String)

setBody

public void setBody(Body body,
                    java.lang.String mimeType)
Sets the body of this entity and sets the content-type to the specified value. A Header is created if this entity does not already have one.

Parameters:
body - the body.
mimeType - the MIME media type of the specified body ("type/subtype").

setBody

public void setBody(Body body,
                    java.lang.String mimeType,
                    java.util.Map<java.lang.String,java.lang.String> parameters)
Sets the body of this entity and sets the content-type to the specified value. A Header is created if this entity does not already have one.

Parameters:
body - the body.
mimeType - the MIME media type of the specified body ("type/subtype").
parameters - additional parameters for the Content-Type header field.

getMimeType

public java.lang.String getMimeType()
Determines the MIME type of this Entity. The MIME type is derived by looking at the parent's Content-Type field if no Content-Type field is set for this Entity.

Returns:
the MIME type.

getCharset

public java.lang.String getCharset()
Determines the MIME character set encoding of this Entity.

Returns:
the MIME character set encoding.

getContentTransferEncoding

public java.lang.String getContentTransferEncoding()
Determines the transfer encoding of this Entity.

Returns:
the transfer encoding.

setContentTransferEncoding

public void setContentTransferEncoding(java.lang.String contentTransferEncoding)
Sets the transfer encoding of this Entity to the specified value.

Parameters:
contentTransferEncoding - transfer encoding to use.

getDispositionType

public java.lang.String getDispositionType()
Return the disposition type of the content disposition of this Entity.

Returns:
the disposition type or null if no disposition type has been set.

setContentDisposition

public void setContentDisposition(java.lang.String dispositionType)
Sets the content disposition of this Entity to the specified disposition type. No filename, size or date parameters are included in the content disposition.

Parameters:
dispositionType - disposition type value (usually inline or attachment).

setContentDisposition

public void setContentDisposition(java.lang.String dispositionType,
                                  java.lang.String filename)
Sets the content disposition of this Entity to the specified disposition type and filename. No size or date parameters are included in the content disposition.

Parameters:
dispositionType - disposition type value (usually inline or attachment).
filename - filename parameter value or null if the parameter should not be included.

setContentDisposition

public void setContentDisposition(java.lang.String dispositionType,
                                  java.lang.String filename,
                                  long size)
Sets the content disposition of this Entity to the specified values. No date parameters are included in the content disposition.

Parameters:
dispositionType - disposition type value (usually inline or attachment).
filename - filename parameter value or null if the parameter should not be included.
size - size parameter value or -1 if the parameter should not be included.

setContentDisposition

public void setContentDisposition(java.lang.String dispositionType,
                                  java.lang.String filename,
                                  long size,
                                  java.util.Date creationDate,
                                  java.util.Date modificationDate,
                                  java.util.Date readDate)
Sets the content disposition of this Entity to the specified values.

Parameters:
dispositionType - disposition type value (usually inline or attachment).
filename - filename parameter value or null if the parameter should not be included.
size - size parameter value or -1 if the parameter should not be included.
creationDate - creation-date parameter value or null if the parameter should not be included.
modificationDate - modification-date parameter value or null if the parameter should not be included.
readDate - read-date parameter value or null if the parameter should not be included.

getFilename

public java.lang.String getFilename()
Returns the filename parameter of the content disposition of this Entity.

Returns:
the filename parameter of the content disposition or null if the filename has not been set.

setFilename

public void setFilename(java.lang.String filename)
Sets the filename parameter of the content disposition of this Entity to the specified value. If this entity does not have a content disposition header field a new one with disposition type attachment is created.

Parameters:
filename - filename parameter value or null if the parameter should be removed.

isMimeType

public boolean isMimeType(java.lang.String type)
Determines if the MIME type of this Entity matches the given one. MIME types are case-insensitive.

Parameters:
type - the MIME type to match against.
Returns:
true on match, false otherwise.

isMultipart

public boolean isMultipart()
Determines if the MIME type of this Entity is multipart/*. Since multipart-entities must have a boundary parameter in the Content-Type field this method returns false if no boundary exists.

Returns:
true on match, false otherwise.

dispose

public void dispose()
Disposes of the body of this entity. Note that the dispose call does not get forwarded to the parent entity of this Entity. Subclasses that need to free resources should override this method and invoke super.dispose().

Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.