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 AbstractEntityBuilderaddField(Field field)Adds a field to the end of the list of fields.AbstractEntityBuilderclearFields()Clears all fields.booleancontainsField(java.lang.String name)Returnstrueif there is at least one explicitly set field with the given name.BodygetBody()Returns message body.java.lang.StringgetCharset()Returns MIME character set encoding of this message.java.lang.StringgetContentTransferEncoding()Returns transfer encoding of this message.java.util.DategetCreationDate()Returns creation date of the content disposition of this message.java.lang.StringgetDispositionType()Return disposition type of this message.FieldgetField(java.lang.String name)Gets aFieldgiven a field name.<F extends Field>
FgetField(java.lang.String name, java.lang.Class<F> clazz)Gets aFieldgiven 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 allFields having the specified field name.<F extends Field>
java.util.List<F>getFields(java.lang.String name, java.lang.Class<F> clazz)Gets allFields having the specified field name and of the given type.java.lang.StringgetFilename()Returns filename of the content disposition of this message.java.lang.StringgetMimeType()Returns MIME type of this message.java.util.DategetModificationDate()Returns modification date of the content disposition of this message.java.util.DategetReadDate()Returns read date of the content disposition of this message.longgetSize()Returns size of the content disposition of this message.<F extends ParsedField>
FobtainField(java.lang.String fieldName)AbstractEntityBuilderremoveFields(java.lang.String name)Removes allFields having the specified field name.AbstractEntityBuildersetBody(BinaryBody binaryBody)Sets binaryBody of this message.AbstractEntityBuildersetBody(Body body)Sets body of this message.AbstractEntityBuildersetBody(Message message)Sets body of this message.AbstractEntityBuildersetBody(Message.Builder message)AbstractEntityBuildersetBody(Multipart multipart)Sets body of this message.AbstractEntityBuildersetBody(TextBody textBody)Sets body of this message.AbstractEntityBuildersetBody(MultipartBuilder multipart)AbstractEntityBuildersetBody(SingleBodyBuilder body)AbstractEntityBuildersetContentDisposition(java.lang.String dispositionType)Sets content disposition of this message to the specified disposition type.AbstractEntityBuildersetContentDisposition(java.lang.String dispositionType, java.lang.String filename)Sets content disposition of this message to the specified disposition type and filename.AbstractEntityBuildersetContentDisposition(java.lang.String dispositionType, java.lang.String filename, long size)Sets content disposition of this message to the specified values.AbstractEntityBuildersetContentDisposition(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.AbstractEntityBuildersetContentTransferEncoding(java.lang.String contentTransferEncoding)Sets transfer encoding of this message.AbstractEntityBuildersetContentType(java.lang.String mimeType, NameValuePair... parameters)Sets transfer encoding of this message.AbstractEntityBuildersetField(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
Fieldobjects.
-
getField
public Field getField(java.lang.String name)
Gets aFieldgiven 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
nullif none found.
-
getField
public <F extends Field> F getField(java.lang.String name, java.lang.Class<F> clazz)
Gets aFieldgiven 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
nullif none found.
-
containsField
public boolean containsField(java.lang.String name)
Returnstrueif there is at least one explicitly set field with the given name.- Parameters:
name- the field name (e.g. From, Subject).- Returns:
trueif there is at least one explicitly set field with the given name,falseotherwise.
-
getFields
public java.util.List<Field> getFields(java.lang.String name)
Gets allFields 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 allFields 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 allFields 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
nullif 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
nullif 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
nullif 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 (usuallyinlineorattachment).
-
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 (usuallyinlineorattachment).filename- filename parameter value ornullif 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 (usuallyinlineorattachment).filename- filename parameter value ornullif the parameter should not be included.size- size parameter value or-1if 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 (usuallyinlineorattachment).filename- filename parameter value ornullif the parameter should not be included.size- size parameter value or-1if the parameter should not be included.creationDate- creation-date parameter value ornullif the parameter should not be included.modificationDate- modification-date parameter value ornullif the parameter should not be included.readDate- read-date parameter value ornullif 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
nullif 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
-1if 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
nullif 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
nullif 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
nullif 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.
-
-