Package org.apache.james.mime4j.dom
Interface Header
-
- All Known Implementing Classes:
AbstractHeader,HeaderImpl
public interface Header extends Iterable<Field>
A header of an MIME entity (as defined in RFC 2045).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddField(Field field)Adds a field to the end of the list of fields.FieldgetField(String name)Gets aFieldgiven a field name.<F extends Field>
FgetField(String name, Class<F> clazz)Gets aFieldgiven a field name and of the given type.List<Field>getFields()Gets the fields of this header.List<Field>getFields(String name)Gets allFields having the specified field name.<F extends Field>
List<F>getFields(String name, Class<F> clazz)Gets allFields having the specified field name and of the given type.Map<String,List<Field>>getFieldsAsMap()Gets the fields of this header.Iterator<Field>iterator()Returns an iterator over the list of fields of this header.intremoveFields(String name)Removes allFields having the specified field name.voidsetField(Field field)Sets or replaces a field.-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
addField
void addField(Field field)
Adds a field to the end of the list of fields.- Parameters:
field- the field to add.
-
getFields
List<Field> getFields()
Gets the fields of this header. The returned list will not be modifiable.- Returns:
- the list of
Fieldobjects.
-
getFieldsAsMap
Map<String,List<Field>> getFieldsAsMap()
Gets the fields of this header. The returned map will not be modifiable. For each header name, values are ordered by which they appear in the underlying entity.- Returns:
- the map of
Fieldobjects indexed by names.
-
getField
Field getField(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
<F extends Field> F getField(String name, 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.
-
getFields
List<Field> getFields(String name)
Gets allFields having the specified field name.- Parameters:
name- the field name (e.g. From, Subject).- Returns:
- the list of fields.
-
getFields
<F extends Field> List<F> getFields(String name, 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
int removeFields(String name)
Removes allFields having the specified field name.- Parameters:
name- the field name (e.g. From, Subject).- Returns:
- number of fields removed.
-
setField
void 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 thisHeaderdoes 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(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.
-
-