Package org.apache.james.mime4j.message
Class AbstractEntity
- java.lang.Object
-
- 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
Constructors Modifier Constructor Description protected
AbstractEntity()
Creates a newEntity
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 thisEntity
.java.lang.String
getContentTransferEncoding()
Determines the transfer encoding of thisEntity
.private ContentTypeField
getContentTypeField()
java.lang.String
getDispositionType()
Return the disposition type of the content disposition of thisEntity
.java.lang.String
getFilename()
Returns the filename parameter of the content disposition of thisEntity
.Header
getHeader()
Gets the entity header.java.lang.String
getMimeType()
Determines the MIME type of thisEntity
.Entity
getParent()
Gets the parent entity of this entity.boolean
isMultipart()
Determines if the MIME type of thisEntity
ismultipart/*
.(package private) <F extends ParsedField>
FobtainField(java.lang.String fieldName)
Obtains the header field with the specified name.(package private) Header
obtainHeader()
Obtains the header of this entity.Body
removeBody()
Removes and returns the body of this entity.void
setBody(Body body)
Sets the body of this entity.void
setHeader(Header header)
Sets the entity header.void
setParent(Entity parent)
Sets the parent entity of this entity.
-
-
-
Method Detail
-
getParent
public Entity getParent()
Gets the parent entity of this entity. Returnsnull
if this is the root entity.
-
setParent
public void setParent(Entity parent)
Sets the parent entity of this entity.
-
getHeader
public Header getHeader()
Gets the entity header.
-
setHeader
public void setHeader(Header header)
Sets the entity header.
-
getBody
public Body getBody()
Gets the body of this entity.
-
setBody
public void setBody(Body body)
Sets the body of this entity.
-
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 bedisposed
of.- Specified by:
removeBody
in interfaceEntity
- Returns:
- the removed body or
null
if no body was set.
-
getMimeType
public java.lang.String getMimeType()
Description copied from interface:Entity
Determines the MIME type of thisEntity
. The MIME type is derived by looking at the parent's Content-Type field if no Content-Type field is set for thisEntity
.- Specified by:
getMimeType
in interfaceEntity
- Returns:
- the MIME type.
-
getContentTypeField
private ContentTypeField getContentTypeField()
-
getCharset
public java.lang.String getCharset()
Determines the MIME character set encoding of thisEntity
.- Specified by:
getCharset
in interfaceEntity
- Returns:
- the MIME character set encoding.
-
getContentTransferEncoding
public java.lang.String getContentTransferEncoding()
Determines the transfer encoding of thisEntity
.- Specified by:
getContentTransferEncoding
in interfaceEntity
- Returns:
- the transfer encoding.
-
getDispositionType
public java.lang.String getDispositionType()
Return the disposition type of the content disposition of thisEntity
.- Specified by:
getDispositionType
in interfaceEntity
- Returns:
- the disposition type or
null
if no disposition type has been set.
-
getFilename
public java.lang.String getFilename()
Returns the filename parameter of the content disposition of thisEntity
.- Specified by:
getFilename
in interfaceEntity
- Returns:
- the filename parameter of the content disposition or
null
if the filename has not been set.
-
isMultipart
public boolean isMultipart()
Determines if the MIME type of thisEntity
ismultipart/*
. Since multipart-entities must have a boundary parameter in theContent-Type
field this method returnsfalse
if no boundary exists.- Specified by:
isMultipart
in interfaceEntity
- 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 interfaceDisposable
- See Also:
Disposable.dispose()
-
obtainHeader
Header obtainHeader()
Obtains the header of this entity. Creates and sets a new header if this entity's header is currentlynull
.- Returns:
- the header of this entity; never
null
.
-
obtainField
<F extends ParsedField> F obtainField(java.lang.String fieldName)
Obtains the header field with the specified name.- Type Parameters:
F
- concrete field type.- Parameters:
fieldName
- name of the field to retrieve.- Returns:
- the header field or
null
if this entity has no header or the header contains no such field.
-
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)
-
-