org.apache.james.mime4j.message
Class AbstractEntity

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

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

Abstract MIME entity.


Constructor Summary
protected AbstractEntity()
          Creates a new Entity.
 
Method Summary
protected abstract  java.lang.String calcCharset(ContentTypeField contentType)
           
protected abstract  java.lang.String calcMimeType(ContentTypeField child, ContentTypeField parent)
           
protected abstract  java.lang.String calcTransferEncoding(ContentTransferEncodingField f)
           
 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/*.
protected abstract  ContentDispositionField newContentDisposition(java.lang.String dispositionType, java.util.Map<java.lang.String,java.lang.String> parameters)
           
protected abstract  ContentDispositionField newContentDisposition(java.lang.String dispositionType, java.lang.String filename, long size, java.util.Date creationDate, java.util.Date modificationDate, java.util.Date readDate)
           
protected abstract  ContentTransferEncodingField newContentTransferEncoding(java.lang.String contentTransferEncoding)
           
protected abstract  ContentTypeField newContentType(java.lang.String mimeType, java.util.Map<java.lang.String,java.lang.String> parameters)
           
protected abstract  java.lang.String newUniqueBoundary()
           
 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

AbstractEntity

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

Method Detail

getParent

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

Specified by:
getParent in interface Entity
Returns:
the parent or null.

setParent

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

Specified by:
setParent in interface Entity
Parameters:
parent - the parent entity or null if this will be the root entity.

getHeader

public Header getHeader()
Gets the entity header.

Specified by:
getHeader in interface Entity
Returns:
the header.

setHeader

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

Specified by:
setHeader in interface Entity
Parameters:
header - the header.

getBody

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

Specified by:
getBody in interface Entity
Returns:
the body,

setBody

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

Specified by:
setBody in interface 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.

Specified by:
removeBody in interface Entity
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(java.io.InputStream, 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").

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.

Specified by:
getMimeType in interface Entity
Returns:
the MIME type.

getCharset

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

Specified by:
getCharset in interface Entity
Returns:
the MIME character set encoding.

getContentTransferEncoding

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

Specified by:
getContentTransferEncoding in interface 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.

Specified by:
getDispositionType in interface 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.

Specified by:
getFilename in interface 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.

Specified by:
isMultipart in interface Entity
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()

newUniqueBoundary

protected abstract java.lang.String newUniqueBoundary()

newContentDisposition

protected abstract ContentDispositionField newContentDisposition(java.lang.String dispositionType,
                                                                 java.lang.String filename,
                                                                 long size,
                                                                 java.util.Date creationDate,
                                                                 java.util.Date modificationDate,
                                                                 java.util.Date readDate)

newContentDisposition

protected abstract ContentDispositionField newContentDisposition(java.lang.String dispositionType,
                                                                 java.util.Map<java.lang.String,java.lang.String> parameters)

newContentType

protected abstract ContentTypeField newContentType(java.lang.String mimeType,
                                                   java.util.Map<java.lang.String,java.lang.String> parameters)

newContentTransferEncoding

protected abstract ContentTransferEncodingField newContentTransferEncoding(java.lang.String contentTransferEncoding)

calcMimeType

protected abstract java.lang.String calcMimeType(ContentTypeField child,
                                                 ContentTypeField parent)

calcTransferEncoding

protected abstract java.lang.String calcTransferEncoding(ContentTransferEncodingField f)

calcCharset

protected abstract java.lang.String calcCharset(ContentTypeField contentType)


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