Package org.apache.james.mime4j.internal
Class AbstractEntityBuilder
- java.lang.Object
-
- org.apache.james.mime4j.internal.AbstractEntityBuilder
-
- Direct Known Subclasses:
BodyPartBuilder
,Message.Builder
public abstract class AbstractEntityBuilder extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description AbstractEntityBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractEntityBuilder
addField(Field field)
Adds a field to the end of the list of fields.AbstractEntityBuilder
clearFields()
Clears all fields.boolean
containsField(java.lang.String name)
Returnstrue
if there is at least one explicitly set field with the given name.Body
getBody()
Returns message body.java.lang.String
getCharset()
Returns MIME character set encoding of this message.java.lang.String
getContentTransferEncoding()
Returns transfer encoding of this message.java.util.Date
getCreationDate()
Returns creation date of the content disposition of this message.java.lang.String
getDispositionType()
Return disposition type of this message.Field
getField(java.lang.String name)
Gets aField
given a field name.<F extends Field>
FgetField(java.lang.String name, java.lang.Class<F> clazz)
Gets aField
given a field name and of the given type.java.util.List<Field>
getFields()
Gets the fields of this header.java.util.List<Field>
getFields(java.lang.String name)
Gets allField
s having the specified field name.<F extends Field>
java.util.List<F>getFields(java.lang.String name, java.lang.Class<F> clazz)
Gets allField
s having the specified field name and of the given type.java.lang.String
getFilename()
Returns filename of the content disposition of this message.java.lang.String
getMimeType()
Returns MIME type of this message.java.util.Date
getModificationDate()
Returns modification date of the content disposition of this message.java.util.Date
getReadDate()
Returns read date of the content disposition of this message.long
getSize()
Returns size of the content disposition of this message.<F extends ParsedField>
FobtainField(java.lang.String fieldName)
AbstractEntityBuilder
removeFields(java.lang.String name)
Removes allField
s having the specified field name.AbstractEntityBuilder
setBody(BinaryBody binaryBody)
Sets binaryBody of this message.AbstractEntityBuilder
setBody(Body body)
Sets body of this message.AbstractEntityBuilder
setBody(Message message)
Sets body of this message.AbstractEntityBuilder
setBody(Message.Builder message)
AbstractEntityBuilder
setBody(Multipart multipart)
Sets body of this message.AbstractEntityBuilder
setBody(TextBody textBody)
Sets body of this message.AbstractEntityBuilder
setBody(MultipartBuilder multipart)
AbstractEntityBuilder
setBody(SingleBodyBuilder body)
AbstractEntityBuilder
setContentDisposition(java.lang.String dispositionType)
Sets content disposition of this message to the specified disposition type.AbstractEntityBuilder
setContentDisposition(java.lang.String dispositionType, java.lang.String filename)
Sets content disposition of this message to the specified disposition type and filename.AbstractEntityBuilder
setContentDisposition(java.lang.String dispositionType, java.lang.String filename, long size)
Sets content disposition of this message to the specified values.AbstractEntityBuilder
setContentDisposition(java.lang.String dispositionType, java.lang.String filename, long size, java.util.Date creationDate, java.util.Date modificationDate, java.util.Date readDate)
Sets content disposition of this message to the specified values.AbstractEntityBuilder
setContentTransferEncoding(java.lang.String contentTransferEncoding)
Sets transfer encoding of this message.AbstractEntityBuilder
setContentType(java.lang.String mimeType, NameValuePair... parameters)
Sets transfer encoding of this message.AbstractEntityBuilder
setField(Field field)
Sets or replaces a field.
-
-
-
Method Detail
-
addField
public AbstractEntityBuilder addField(Field field)
Adds a field to the end of the list of fields.- Parameters:
field
- the field to add.
-
getFields
public java.util.List<Field> getFields()
Gets the fields of this header. The returned list will not be modifiable.- Returns:
- the list of
Field
objects.
-
getField
public Field getField(java.lang.String name)
Gets aField
given a field name. If there are multiple such fields defined in this header the first one will be returned.- Parameters:
name
- the field name (e.g. From, Subject).- Returns:
- the field or
null
if none found.
-
getField
public <F extends Field> F getField(java.lang.String name, java.lang.Class<F> clazz)
Gets aField
given a field name and of the given type. If there are multiple such fields defined in this header the first one will be returned.- Parameters:
name
- the field name (e.g. From, Subject).clazz
- the field class.- Returns:
- the field or
null
if none found.
-
containsField
public boolean containsField(java.lang.String name)
Returnstrue
if there is at least one explicitly set field with the given name.- Parameters:
name
- the field name (e.g. From, Subject).- Returns:
true
if there is at least one explicitly set field with the given name,false
otherwise.
-
getFields
public java.util.List<Field> getFields(java.lang.String name)
Gets allField
s having the specified field name.- Parameters:
name
- the field name (e.g. From, Subject).- Returns:
- the list of fields.
-
getFields
public <F extends Field> java.util.List<F> getFields(java.lang.String name, java.lang.Class<F> clazz)
Gets allField
s having the specified field name and of the given type.- Parameters:
name
- the field name (e.g. From, Subject).clazz
- the field class.- Returns:
- the list of fields.
-
removeFields
public AbstractEntityBuilder removeFields(java.lang.String name)
Removes allField
s having the specified field name.- Parameters:
name
- the field name (e.g. From, Subject).
-
setField
public AbstractEntityBuilder setField(Field field)
Sets or replaces a field. This method is useful for header fields such as Subject or Message-ID that should not occur more than once in a message. If this builder does not already contain a header field of the same name as the given field then it is added to the end of the list of fields (same behavior asaddField(org.apache.james.mime4j.stream.Field)
). Otherwise the first occurrence of a field with the same name is replaced by the given field and all further occurrences are removed.- Parameters:
field
- the field to set.
-
clearFields
public AbstractEntityBuilder clearFields()
Clears all fields.
-
obtainField
public <F extends ParsedField> F obtainField(java.lang.String fieldName)
-
getMimeType
public java.lang.String getMimeType()
Returns MIME type of this message.- Returns:
- the MIME type or
null
if no MIME type has been set.
-
getCharset
public java.lang.String getCharset()
Returns MIME character set encoding of this message.- Returns:
- the MIME character set encoding or
null
if no charset type has been set.
-
setContentType
public AbstractEntityBuilder setContentType(java.lang.String mimeType, NameValuePair... parameters)
Sets transfer encoding of this message.- Parameters:
mimeType
- MIME type of this message the MIME type to use.parameters
- content type parameters to use.
-
getContentTransferEncoding
public java.lang.String getContentTransferEncoding()
Returns transfer encoding of this message.- Returns:
- the transfer encoding.
-
setContentTransferEncoding
public AbstractEntityBuilder setContentTransferEncoding(java.lang.String contentTransferEncoding)
Sets transfer encoding of this message.- Parameters:
contentTransferEncoding
- transfer encoding to use.
-
getDispositionType
public java.lang.String getDispositionType()
Return disposition type of this message.- Returns:
- the disposition type or
null
if no disposition type has been set.
-
setContentDisposition
public AbstractEntityBuilder setContentDisposition(java.lang.String dispositionType)
Sets content disposition of this message to the specified disposition type. No filename, size or date parameters are included in the content disposition.- Parameters:
dispositionType
- disposition type value (usuallyinline
orattachment
).
-
setContentDisposition
public AbstractEntityBuilder setContentDisposition(java.lang.String dispositionType, java.lang.String filename)
Sets content disposition of this message to the specified disposition type and filename. No size or date parameters are included in the content disposition.- Parameters:
dispositionType
- disposition type value (usuallyinline
orattachment
).filename
- filename parameter value ornull
if the parameter should not be included.
-
setContentDisposition
public AbstractEntityBuilder setContentDisposition(java.lang.String dispositionType, java.lang.String filename, long size)
Sets content disposition of this message to the specified values. No date parameters are included in the content disposition.- Parameters:
dispositionType
- disposition type value (usuallyinline
orattachment
).filename
- filename parameter value ornull
if the parameter should not be included.size
- size parameter value or-1
if the parameter should not be included.
-
setContentDisposition
public AbstractEntityBuilder setContentDisposition(java.lang.String dispositionType, java.lang.String filename, long size, java.util.Date creationDate, java.util.Date modificationDate, java.util.Date readDate)
Sets content disposition of this message to the specified values.- Parameters:
dispositionType
- disposition type value (usuallyinline
orattachment
).filename
- filename parameter value ornull
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 ornull
if the parameter should not be included.modificationDate
- modification-date parameter value ornull
if the parameter should not be included.readDate
- read-date parameter value ornull
if the parameter should not be included.
-
getFilename
public java.lang.String getFilename()
Returns filename of the content disposition of this message.- Returns:
- the filename parameter of the content disposition or
null
if the filename has not been set.
-
getSize
public long getSize()
Returns size of the content disposition of this message.- Returns:
- the size parameter of the content disposition or
-1
if the filename has not been set.
-
getCreationDate
public java.util.Date getCreationDate()
Returns creation date of the content disposition of this message.- Returns:
- the creation date parameter of the content disposition or
null
if the filename has not been set.
-
getModificationDate
public java.util.Date getModificationDate()
Returns modification date of the content disposition of this message.- Returns:
- the modification date parameter of the content disposition or
null
if the filename has not been set.
-
getReadDate
public java.util.Date getReadDate()
Returns read date of the content disposition of this message.- Returns:
- the read date parameter of the content disposition or
null
if the filename has not been set.
-
setBody
public AbstractEntityBuilder setBody(Body body)
Sets body of this message. Also sets the content type based on properties of the givenBody
.- Parameters:
body
- the body.
-
setBody
public AbstractEntityBuilder setBody(SingleBodyBuilder body) throws java.io.IOException
- Throws:
java.io.IOException
-
setBody
public AbstractEntityBuilder setBody(TextBody textBody)
Sets body of this message. Also sets the content type based on properties of the givenBody
.- Parameters:
textBody
- the body.
-
setBody
public AbstractEntityBuilder setBody(BinaryBody binaryBody)
Sets binaryBody of this message. Also sets the content type based on properties of the givenBody
.- Parameters:
binaryBody
- the binaryBody.
-
setBody
public AbstractEntityBuilder setBody(Message message)
Sets body of this message. Also sets the content type based on properties of the givenMessage
.- Parameters:
message
- the body.
-
setBody
public AbstractEntityBuilder setBody(Message.Builder message)
-
setBody
public AbstractEntityBuilder setBody(Multipart multipart)
Sets body of this message. Also sets the content type based on properties of the givenMultipart
.- Parameters:
multipart
- the body.
-
setBody
public AbstractEntityBuilder setBody(MultipartBuilder multipart)
-
getBody
public Body getBody()
Returns message body.- Returns:
- the message body.
-
-