org.apache.james.mime4j.message
Class Multipart

java.lang.Object
  extended by org.apache.james.mime4j.message.Multipart
All Implemented Interfaces:
Body, Disposable

public class Multipart
extends java.lang.Object
implements Body

Represents a MIME multipart body (see RFC 2045).A multipart body has a ordered list of body parts. The multipart body also has a preamble and epilogue. The preamble consists of whatever characters appear before the first body part while the epilogue consists of whatever characters come after the last body part.


Constructor Summary
Multipart(Multipart other)
          Creates a new Multipart from the specified Multipart.
Multipart(java.lang.String subType)
          Creates a new empty Multipart instance.
 
Method Summary
 void addBodyPart(BodyPart bodyPart)
          Adds a body part to the end of the list of body parts.
 void addBodyPart(BodyPart bodyPart, int index)
          Inserts a body part at the specified position in the list of body parts.
 void dispose()
          Disposes of the BodyParts of this Multipart.
 java.util.List<BodyPart> getBodyParts()
          Gets the list of body parts.
 int getCount()
          Returns the number of body parts.
 java.lang.String getEpilogue()
          Gets the epilogue.
 Entity getParent()
          Gets the parent of this body.
 java.lang.String getPreamble()
          Gets the preamble.
 java.lang.String getSubType()
          Gets the multipart sub-type.
 BodyPart removeBodyPart(int index)
          Removes the body part at the specified position in the list of body parts.
 BodyPart replaceBodyPart(BodyPart bodyPart, int index)
          Replaces the body part at the specified position in the list of body parts with the specified body part.
 void setBodyParts(java.util.List<BodyPart> bodyParts)
          Sets the list of body parts.
 void setEpilogue(java.lang.String epilogue)
          Sets the epilogue.
 void setParent(Entity parent)
          Sets the parent of this body.
 void setPreamble(java.lang.String preamble)
          Sets the preamble.
 void setSubType(java.lang.String subType)
          Sets the multipart sub-type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Multipart

public Multipart(java.lang.String subType)
Creates a new empty Multipart instance.


Multipart

public Multipart(Multipart other)
Creates a new Multipart from the specified Multipart. The Multipart instance is initialized with copies of preamble, epilogue, sub type and the list of body parts of the specified Multipart. The parent entity of the new multipart is null.

Parameters:
other - multipart to copy.
Throws:
java.lang.UnsupportedOperationException - if other contains a SingleBody that does not support the copy() operation.
java.lang.IllegalArgumentException - if other contains a Body that is neither a Message, Multipart or SingleBody.
Method Detail

getSubType

public java.lang.String getSubType()
Gets the multipart sub-type. E.g. alternative (the default) or parallel. See RFC 2045 for common sub-types and their meaning.

Returns:
the multipart sub-type.

setSubType

public void setSubType(java.lang.String subType)
Sets the multipart sub-type. E.g. alternative or parallel. See RFC 2045 for common sub-types and their meaning.

Parameters:
subType - the sub-type.

getParent

public Entity getParent()
Description copied from interface: Body
Gets the parent of this body.

Specified by:
getParent in interface Body
Returns:
the parent.
See Also:
Body.getParent()

setParent

public void setParent(Entity parent)
Description copied from interface: Body
Sets the parent of this body.

Specified by:
setParent in interface Body
Parameters:
parent - the parent.
See Also:
Body.setParent(org.apache.james.mime4j.message.Entity)

getCount

public int getCount()
Returns the number of body parts.

Returns:
number of BodyPart objects.

getBodyParts

public java.util.List<BodyPart> getBodyParts()
Gets the list of body parts. The list is immutable.

Returns:
the list of BodyPart objects.

setBodyParts

public void setBodyParts(java.util.List<BodyPart> bodyParts)
Sets the list of body parts.

Parameters:
bodyParts - the new list of BodyPart objects.

addBodyPart

public void addBodyPart(BodyPart bodyPart)
Adds a body part to the end of the list of body parts.

Parameters:
bodyPart - the body part.

addBodyPart

public void addBodyPart(BodyPart bodyPart,
                        int index)
Inserts a body part at the specified position in the list of body parts.

Parameters:
bodyPart - the body part.
index - index at which the specified body part is to be inserted.
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > getCount()).

removeBodyPart

public BodyPart removeBodyPart(int index)
Removes the body part at the specified position in the list of body parts.

Parameters:
index - index of the body part to be removed.
Returns:
the removed body part.
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getCount()).

replaceBodyPart

public BodyPart replaceBodyPart(BodyPart bodyPart,
                                int index)
Replaces the body part at the specified position in the list of body parts with the specified body part.

Parameters:
bodyPart - body part to be stored at the specified position.
index - index of body part to replace.
Returns:
the replaced body part.
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getCount()).

getPreamble

public java.lang.String getPreamble()
Gets the preamble.

Returns:
the preamble.

setPreamble

public void setPreamble(java.lang.String preamble)
Sets the preamble.

Parameters:
preamble - the preamble.

getEpilogue

public java.lang.String getEpilogue()
Gets the epilogue.

Returns:
the epilogue.

setEpilogue

public void setEpilogue(java.lang.String epilogue)
Sets the epilogue.

Parameters:
epilogue - the epilogue.

dispose

public void dispose()
Disposes of the BodyParts of this Multipart. Note that the dispose call does not get forwarded to the parent entity of this Multipart.

Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()


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