Author: mwiederkehr
Date: Sat Jan 3 14:42:26 2009
New Revision: 731117
URL: http://svn.apache.org/viewvc?rev=731117&view=rev
Log:
Convenience methods for manipulating the list of body parts (MIME4J-95)
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java?rev=731117&r1=731116&r2=731117&view=diff
==============================================================================
---
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java
(original)
+++
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java
Sat Jan 3 14:42:26 2009
@@ -147,6 +147,15 @@
}
/**
+ * Returns the number of body parts.
+ *
+ * @return number of <code>BodyPart</code> objects.
+ */
+ public int getCount() {
+ return bodyParts.size();
+ }
+
+ /**
* Gets the list of body parts. The list is immutable.
*
* @return the list of <code>BodyPart</code> objects.
@@ -173,11 +182,77 @@
* @param bodyPart the body part.
*/
public void addBodyPart(BodyPart bodyPart) {
+ if (bodyPart == null)
+ throw new IllegalArgumentException();
+
bodyParts.add(bodyPart);
bodyPart.setParent(parent);
}
/**
+ * Inserts a body part at the specified position in the list of body parts.
+ *
+ * @param bodyPart
+ * the body part.
+ * @param index
+ * index at which the specified body part is to be inserted.
+ * @throws IndexOutOfBoundsException
+ * if the index is out of range (index < 0 || index >
+ * getCount()).
+ */
+ public void addBodyPart(BodyPart bodyPart, int index) {
+ if (bodyPart == null)
+ throw new IllegalArgumentException();
+
+ bodyParts.add(index, bodyPart);
+ bodyPart.setParent(parent);
+ }
+
+ /**
+ * Removes the body part at the specified position in the list of body
+ * parts.
+ *
+ * @param index
+ * index of the body part to be removed.
+ * @return the removed body part.
+ * @throws IndexOutOfBoundsException
+ * if the index is out of range (index < 0 || index >=
+ * getCount()).
+ */
+ public BodyPart removeBodyPart(int index) {
+ BodyPart bodyPart = bodyParts.remove(index);
+ bodyPart.setParent(null);
+ return bodyPart;
+ }
+
+ /**
+ * Replaces the body part at the specified position in the list of body
+ * parts with the specified body part.
+ *
+ * @param bodyPart
+ * body part to be stored at the specified position.
+ * @param index
+ * index of body part to replace.
+ * @return the replaced body part.
+ * @throws IndexOutOfBoundsException
+ * if the index is out of range (index < 0 || index >=
+ * getCount()).
+ */
+ public BodyPart replaceBodyPart(BodyPart bodyPart, int index) {
+ if (bodyPart == null)
+ throw new IllegalArgumentException();
+
+ BodyPart replacedBodyPart = bodyParts.set(index, bodyPart);
+ if (bodyPart == replacedBodyPart)
+ throw new IllegalArgumentException("Cannot replace body part with
itself");
+
+ bodyPart.setParent(parent);
+ replacedBodyPart.setParent(null);
+
+ return replacedBodyPart;
+ }
+
+ /**
* Gets the preamble.
*
* @return the preamble.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]