james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r894868 - in /james/mime4j/branches/cycleclean: core/src/main/java/org/apache/james/mime4j/message/ core/src/main/java/org/apache/james/mime4j/message/impl/ core/src/test/java/org/apache/james/mime4j/message/ examples/src/main/java/org/apac...
Date Thu, 31 Dec 2009 15:36:27 GMT
Author: bago
Date: Thu Dec 31 15:36:26 2009
New Revision: 894868

URL: http://svn.apache.org/viewvc?rev=894868&view=rev
Log:
Moved more non-api (non-dom) classes from the message package (BodyCopier, BodyPart). Separated
abstract code from Multipart and moved implementation specifci MultipartImpl to impl package.
BodyPart is simply an implementation of Entity. No need to create another level, moved BodyPart
to the impl package and changed Multipart abstract class to deal with Entity instead of BodyPart
(this is also a bugfix because Message should be "addable" to a Multipart) (MIME4J-156)

Added:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyCopier.java
  (contents, props changed)
      - copied, changed from r894746, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java
  (contents, props changed)
      - copied, changed from r894746, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MultipartImpl.java
  (with props)
Removed:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java
Modified:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageBuilder.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/CopyConstructorTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/EntityTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
    james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
Thu Dec 31 15:36:26 2009
@@ -48,34 +48,6 @@
     }
 
     /**
-     * Creates a new <code>Entity</code> from the specified
-     * <code>Entity</code>. The <code>Entity</code> instance is initialized
-     * with copies of header and body of the specified <code>Entity</code>.
-     * The parent entity of the new entity is <code>null</code>.
-     * 
-     * @param other
-     *            entity to copy.
-     * @throws UnsupportedOperationException
-     *             if <code>other</code> contains a {@link SingleBody} that
-     *             does not support the {@link SingleBody#copy() copy()}
-     *             operation.
-     * @throws IllegalArgumentException
-     *             if <code>other</code> contains a <code>Body</code>
that
-     *             is neither a {@link Message}, {@link Multipart} or
-     *             {@link SingleBody}.
-     */
-    protected Entity(Entity other) {
-        if (other.header != null) {
-            header = new Header(other.header);
-        }
-
-        if (other.body != null) {
-            Body bodyCopy = BodyCopier.copy(other.body);
-            setBody(bodyCopy);
-        }
-    }
-
-    /**
      * Gets the parent entity of this entity.
      * Returns <code>null</code> if this is the root entity.
      * 

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
Thu Dec 31 15:36:26 2009
@@ -42,6 +42,7 @@
 import org.apache.james.mime4j.field.address.AddressList;
 import org.apache.james.mime4j.field.address.Mailbox;
 import org.apache.james.mime4j.field.address.MailboxList;
+import org.apache.james.mime4j.message.impl.BodyCopier;
 import org.apache.james.mime4j.message.impl.MessageBuilder;
 import org.apache.james.mime4j.parser.MimeEntityConfig;
 import org.apache.james.mime4j.parser.MimeStreamParser;
@@ -83,7 +84,14 @@
      *             {@link SingleBody}.
      */
     public Message(Message other) {
-        super(other);
+        if (other.getHeader() != null) {
+            setHeader(new Header(other.getHeader()));
+        }
+
+        if (other.getBody() != null) {
+            Body bodyCopy = BodyCopier.copy(other.getBody());
+            setBody(bodyCopy);
+        }
     }
 
     /**

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java
Thu Dec 31 15:36:26 2009
@@ -131,7 +131,7 @@
         writeBytes(multipart.getPreambleRaw(), out);
         out.write(CRLF);
 
-        for (BodyPart bodyPart : multipart.getBodyParts()) {
+        for (Entity bodyPart : multipart.getBodyParts()) {
             out.write(DASHES);
             writeBytes(boundary, out);
             out.write(CRLF);

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Multipart.java
Thu Dec 31 15:36:26 2009
@@ -24,7 +24,6 @@
 import java.util.List;
 
 import org.apache.james.mime4j.util.ByteSequence;
-import org.apache.james.mime4j.util.ContentUtil;
 
 /**
  * Represents a MIME multipart body (see RFC 2045).A multipart body has a
@@ -33,63 +32,21 @@
  * first body part while the epilogue consists of whatever characters come after
  * the last body part.
  */
-public class Multipart implements Body {
+public abstract class Multipart implements Body {
 
-    private List<BodyPart> bodyParts = new LinkedList<BodyPart>();
+    protected List<Entity> bodyParts = new LinkedList<Entity>();
     private Entity parent = null;
 
-    private ByteSequence preamble;
-    private transient String preambleStrCache;
-    private ByteSequence epilogue;
-    private transient String epilogueStrCache;
-
     private String subType;
 
     /**
      * Creates a new empty <code>Multipart</code> instance.
      */
     public Multipart(String subType) {
-        preamble = ByteSequence.EMPTY;
-        preambleStrCache = "";
-        epilogue = ByteSequence.EMPTY;
-        epilogueStrCache = "";
-
         this.subType = subType;
     }
 
     /**
-     * Creates a new <code>Multipart</code> from the specified
-     * <code>Multipart</code>. The <code>Multipart</code> instance
is
-     * initialized with copies of preamble, epilogue, sub type and the list of
-     * body parts of the specified <code>Multipart</code>. The parent entity
-     * of the new multipart is <code>null</code>.
-     * 
-     * @param other
-     *            multipart to copy.
-     * @throws UnsupportedOperationException
-     *             if <code>other</code> contains a {@link SingleBody} that
-     *             does not support the {@link SingleBody#copy() copy()}
-     *             operation.
-     * @throws IllegalArgumentException
-     *             if <code>other</code> contains a <code>Body</code>
that
-     *             is neither a {@link Message}, {@link Multipart} or
-     *             {@link SingleBody}.
-     */
-    public Multipart(Multipart other) {
-        preamble = other.preamble;
-        preambleStrCache = other.preambleStrCache;
-        epilogue = other.epilogue;
-        epilogueStrCache = other.epilogueStrCache;
-
-        for (BodyPart otherBodyPart : other.bodyParts) {
-            BodyPart bodyPartCopy = new BodyPart(otherBodyPart);
-            addBodyPart(bodyPartCopy);
-        }
-
-        subType = other.subType;
-    }
-
-    /**
      * Gets the multipart sub-type. E.g. <code>alternative</code> (the
      * default) or <code>parallel</code>. See RFC 2045 for common sub-types
      * and their meaning.
@@ -124,7 +81,7 @@
      */
     public void setParent(Entity parent) {
         this.parent = parent;
-        for (BodyPart bodyPart : bodyParts) {
+        for (Entity bodyPart : bodyParts) {
             bodyPart.setParent(parent);
         }
     }
@@ -132,7 +89,7 @@
     /**
      * Returns the number of body parts.
      * 
-     * @return number of <code>BodyPart</code> objects.
+     * @return number of <code>Entity</code> objects.
      */
     public int getCount() {
         return bodyParts.size();
@@ -141,9 +98,9 @@
     /**
      * Gets the list of body parts. The list is immutable.
      * 
-     * @return the list of <code>BodyPart</code> objects.
+     * @return the list of <code>Entity</code> objects.
      */
-    public List<BodyPart> getBodyParts() {
+    public List<Entity> getBodyParts() {
         return Collections.unmodifiableList(bodyParts);
     }
 
@@ -151,11 +108,11 @@
      * Sets the list of body parts.
      * 
      * @param bodyParts
-     *            the new list of <code>BodyPart</code> objects.
+     *            the new list of <code>Entity</code> objects.
      */
-    public void setBodyParts(List<BodyPart> bodyParts) {
+    public void setBodyParts(List<Entity> bodyParts) {
         this.bodyParts = bodyParts;
-        for (BodyPart bodyPart : bodyParts) {
+        for (Entity bodyPart : bodyParts) {
             bodyPart.setParent(parent);
         }
     }
@@ -166,7 +123,7 @@
      * @param bodyPart
      *            the body part.
      */
-    public void addBodyPart(BodyPart bodyPart) {
+    public void addBodyPart(Entity bodyPart) {
         if (bodyPart == null)
             throw new IllegalArgumentException();
 
@@ -185,7 +142,7 @@
      *             if the index is out of range (index &lt; 0 || index &gt;
      *             getCount()).
      */
-    public void addBodyPart(BodyPart bodyPart, int index) {
+    public void addBodyPart(Entity bodyPart, int index) {
         if (bodyPart == null)
             throw new IllegalArgumentException();
 
@@ -204,8 +161,8 @@
      *             if the index is out of range (index &lt; 0 || index &gt;=
      *             getCount()).
      */
-    public BodyPart removeBodyPart(int index) {
-        BodyPart bodyPart = bodyParts.remove(index);
+    public Entity removeBodyPart(int index) {
+        Entity bodyPart = bodyParts.remove(index);
         bodyPart.setParent(null);
         return bodyPart;
     }
@@ -223,29 +180,19 @@
      *             if the index is out of range (index &lt; 0 || index &gt;=
      *             getCount()).
      */
-    public BodyPart replaceBodyPart(BodyPart bodyPart, int index) {
+    public Entity replaceBodyPart(Entity bodyPart, int index) {
         if (bodyPart == null)
             throw new IllegalArgumentException();
 
-        BodyPart replacedBodyPart = bodyParts.set(index, bodyPart);
-        if (bodyPart == replacedBodyPart)
+        Entity replacedEntity = bodyParts.set(index, bodyPart);
+        if (bodyPart == replacedEntity)
             throw new IllegalArgumentException(
                     "Cannot replace body part with itself");
 
         bodyPart.setParent(parent);
-        replacedBodyPart.setParent(null);
+        replacedEntity.setParent(null);
 
-        return replacedBodyPart;
-    }
-
-    // package private for now; might become public someday
-    ByteSequence getPreambleRaw() {
-        return preamble;
-    }
-
-    public void setPreambleRaw(ByteSequence preamble) {
-        this.preamble = preamble;
-        this.preambleStrCache = null;
+        return replacedEntity;
     }
 
     /**
@@ -253,12 +200,10 @@
      * 
      * @return the preamble.
      */
-    public String getPreamble() {
-        if (preambleStrCache == null) {
-            preambleStrCache = ContentUtil.decode(preamble);
-        }
-        return preambleStrCache;
-    }
+    public abstract String getPreamble();
+
+    // package private for now; might become public someday
+    public abstract ByteSequence getPreambleRaw();
 
     /**
      * Sets the preamble.
@@ -266,32 +211,17 @@
      * @param preamble
      *            the preamble.
      */
-    public void setPreamble(String preamble) {
-        this.preamble = ContentUtil.encode(preamble);
-        this.preambleStrCache = preamble;
-    }
-
-    // package private for now; might become public someday
-    ByteSequence getEpilogueRaw() {
-        return epilogue;
-    }
-
-    public void setEpilogueRaw(ByteSequence epilogue) {
-        this.epilogue = epilogue;
-        this.epilogueStrCache = null;
-    }
+    public abstract void setPreamble(String preamble);
 
     /**
      * Gets the epilogue.
      * 
      * @return the epilogue.
      */
-    public String getEpilogue() {
-        if (epilogueStrCache == null) {
-            epilogueStrCache = ContentUtil.decode(epilogue);
-        }
-        return epilogueStrCache;
-    }
+    public abstract String getEpilogue();
+
+    // package private for now; might become public someday
+    public abstract ByteSequence getEpilogueRaw();
 
     /**
      * Sets the epilogue.
@@ -299,10 +229,7 @@
      * @param epilogue
      *            the epilogue.
      */
-    public void setEpilogue(String epilogue) {
-        this.epilogue = ContentUtil.encode(epilogue);
-        this.epilogueStrCache = epilogue;
-    }
+    public abstract void setEpilogue(String epilogue);
 
     /**
      * Disposes of the BodyParts of this Multipart. Note that the dispose call
@@ -311,7 +238,7 @@
      * @see org.apache.james.mime4j.message.Disposable#dispose()
      */
     public void dispose() {
-        for (BodyPart bodyPart : bodyParts) {
+        for (Entity bodyPart : bodyParts) {
             bodyPart.dispose();
         }
     }

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyCopier.java
(from r894746, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyCopier.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyCopier.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java&r1=894746&r2=894868&rev=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyCopier.java
Thu Dec 31 15:36:26 2009
@@ -17,7 +17,13 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.message.impl;
+
+import org.apache.james.mime4j.message.Body;
+import org.apache.james.mime4j.message.Disposable;
+import org.apache.james.mime4j.message.Message;
+import org.apache.james.mime4j.message.Multipart;
+import org.apache.james.mime4j.message.SingleBody;
 
 /**
  * Utility class for copying message bodies.
@@ -57,7 +63,7 @@
             return new Message((Message) body);
 
         if (body instanceof Multipart)
-            return new Multipart((Multipart) body);
+            return new MultipartImpl((Multipart) body);
 
         if (body instanceof SingleBody)
             return ((SingleBody) body).copy();

Propchange: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyCopier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java
(from r894746, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java&r1=894746&r2=894868&rev=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java
Thu Dec 31 15:36:26 2009
@@ -17,7 +17,14 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j.message.impl;
+
+import org.apache.james.mime4j.message.Body;
+import org.apache.james.mime4j.message.Entity;
+import org.apache.james.mime4j.message.Header;
+import org.apache.james.mime4j.message.Message;
+import org.apache.james.mime4j.message.Multipart;
+import org.apache.james.mime4j.message.SingleBody;
 
 /**
  * Represents a MIME body part  (see RFC 2045).
@@ -47,8 +54,15 @@
      *             is neither a {@link Message}, {@link Multipart} or
      *             {@link SingleBody}.
      */
-    public BodyPart(BodyPart other) {
-        super(other);
+    public BodyPart(Entity other) {
+        if (other.getHeader() != null) {
+            setHeader(new Header(other.getHeader()));
+        }
+
+        if (other.getBody() != null) {
+            Body bodyCopy = BodyCopier.copy(other.getBody());
+            setBody(bodyCopy);
+        }
     }
 
 }

Propchange: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageBuilder.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageBuilder.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageBuilder.java
Thu Dec 31 15:36:26 2009
@@ -28,7 +28,6 @@
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.message.Body;
-import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.Entity;
 import org.apache.james.mime4j.message.Header;
 import org.apache.james.mime4j.message.Message;
@@ -124,7 +123,7 @@
         
         final Entity e = (Entity) stack.peek();
         final String subType = bd.getSubType();
-        final Multipart multiPart = new Multipart(subType);
+        final Multipart multiPart = new MultipartImpl(subType);
         e.setBody(multiPart);
         stack.push(multiPart);
     }
@@ -194,18 +193,18 @@
      * @see org.apache.james.mime4j.parser.ContentHandler#epilogue(java.io.InputStream)
      */
     public void epilogue(InputStream is) throws MimeException, IOException {
-        expect(Multipart.class);
+        expect(MultipartImpl.class);
         ByteSequence bytes = loadStream(is);
-        ((Multipart) stack.peek()).setEpilogueRaw(bytes);
+        ((MultipartImpl) stack.peek()).setEpilogueRaw(bytes);
     }
     
     /**
      * @see org.apache.james.mime4j.parser.ContentHandler#preamble(java.io.InputStream)
      */
     public void preamble(InputStream is) throws MimeException, IOException {
-        expect(Multipart.class);
+        expect(MultipartImpl.class);
         ByteSequence bytes = loadStream(is);
-        ((Multipart) stack.peek()).setPreambleRaw(bytes);
+        ((MultipartImpl) stack.peek()).setPreambleRaw(bytes);
     }
     
     /**

Added: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MultipartImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MultipartImpl.java?rev=894868&view=auto
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MultipartImpl.java
(added)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MultipartImpl.java
Thu Dec 31 15:36:26 2009
@@ -0,0 +1,155 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.message.impl;
+
+import org.apache.james.mime4j.message.Entity;
+import org.apache.james.mime4j.message.Multipart;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+
+/**
+ * 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.
+ */
+public class MultipartImpl extends Multipart {
+
+    private ByteSequence preamble;
+    private transient String preambleStrCache;
+    private ByteSequence epilogue;
+    private transient String epilogueStrCache;
+
+    /**
+     * Creates a new empty <code>Multipart</code> instance.
+     */
+    public MultipartImpl(String subType) {
+        super(subType);
+        preamble = ByteSequence.EMPTY;
+        preambleStrCache = "";
+        epilogue = ByteSequence.EMPTY;
+        epilogueStrCache = "";
+    }
+
+    /**
+     * Creates a new <code>Multipart</code> from the specified
+     * <code>Multipart</code>. The <code>Multipart</code> instance
is
+     * initialized with copies of preamble, epilogue, sub type and the list of
+     * body parts of the specified <code>Multipart</code>. The parent entity
+     * of the new multipart is <code>null</code>.
+     * 
+     * @param other
+     *            multipart to copy.
+     * @throws UnsupportedOperationException
+     *             if <code>other</code> contains a {@link SingleBody} that
+     *             does not support the {@link SingleBody#copy() copy()}
+     *             operation.
+     * @throws IllegalArgumentException
+     *             if <code>other</code> contains a <code>Body</code>
that
+     *             is neither a {@link Message}, {@link MultipartImpl} or
+     *             {@link SingleBody}.
+     */
+    public MultipartImpl(Multipart other) {
+    	super(other.getSubType());
+
+    	for (Entity otherBodyPart : other.getBodyParts()) {
+    		Entity bodyPartCopy = new BodyPart(otherBodyPart);
+            addBodyPart(bodyPartCopy);
+        }
+
+    	if (other instanceof MultipartImpl) {
+	        preamble = ((MultipartImpl) other).preamble;
+	        epilogue = ((MultipartImpl) other).epilogue;
+	        preambleStrCache = ((MultipartImpl) other).preambleStrCache;
+	        epilogueStrCache = ((MultipartImpl) other).epilogueStrCache;
+    	} else {
+    		setPreamble(other.getPreamble());
+    		setEpilogue(other.getEpilogue());
+    	}
+    }
+
+    // package private for now; might become public someday
+    public ByteSequence getPreambleRaw() {
+        return preamble;
+    }
+
+    public void setPreambleRaw(ByteSequence preamble) {
+        this.preamble = preamble;
+        this.preambleStrCache = null;
+    }
+
+    /**
+     * Gets the preamble.
+     * 
+     * @return the preamble.
+     */
+    public String getPreamble() {
+        if (preambleStrCache == null) {
+            preambleStrCache = ContentUtil.decode(preamble);
+        }
+        return preambleStrCache;
+    }
+
+    /**
+     * Sets the preamble.
+     * 
+     * @param preamble
+     *            the preamble.
+     */
+    public void setPreamble(String preamble) {
+        this.preamble = ContentUtil.encode(preamble);
+        this.preambleStrCache = preamble;
+    }
+
+    // package private for now; might become public someday
+    public ByteSequence getEpilogueRaw() {
+        return epilogue;
+    }
+
+    public void setEpilogueRaw(ByteSequence epilogue) {
+        this.epilogue = epilogue;
+        this.epilogueStrCache = null;
+    }
+
+    /**
+     * Gets the epilogue.
+     * 
+     * @return the epilogue.
+     */
+    public String getEpilogue() {
+        if (epilogueStrCache == null) {
+            epilogueStrCache = ContentUtil.decode(epilogue);
+        }
+        return epilogueStrCache;
+    }
+
+    /**
+     * Sets the epilogue.
+     * 
+     * @param epilogue
+     *            the epilogue.
+     */
+    public void setEpilogue(String epilogue) {
+        this.epilogue = ContentUtil.encode(epilogue);
+        this.epilogueStrCache = epilogue;
+    }
+
+}

Propchange: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MultipartImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MultipartImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/CopyConstructorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/CopyConstructorTest.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/CopyConstructorTest.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/CopyConstructorTest.java
Thu Dec 31 15:36:26 2009
@@ -25,6 +25,8 @@
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.message.impl.BodyFactory;
+import org.apache.james.mime4j.message.impl.BodyPart;
+import org.apache.james.mime4j.message.impl.MultipartImpl;
 
 import junit.framework.TestCase;
 
@@ -97,9 +99,9 @@
     }
 
     public void testCopyEmptyMultipart() throws Exception {
-        Multipart original = new Multipart("mixed");
+        Multipart original = new MultipartImpl("mixed");
 
-        Multipart copy = new Multipart(original);
+        Multipart copy = new MultipartImpl(original);
 
         assertSame(original.getPreamble(), copy.getPreamble());
         assertSame(original.getEpilogue(), copy.getEpilogue());
@@ -112,13 +114,13 @@
         Message parent = new Message();
         BodyPart bodyPart = new BodyPart();
 
-        Multipart original = new Multipart("mixed");
+        Multipart original = new MultipartImpl("mixed");
         original.setPreamble("preamble");
         original.setEpilogue("epilogue");
         original.setParent(parent);
         original.addBodyPart(bodyPart);
 
-        Multipart copy = new Multipart(original);
+        Multipart copy = new MultipartImpl(original);
 
         assertSame(original.getPreamble(), copy.getPreamble());
         assertSame(original.getEpilogue(), copy.getEpilogue());
@@ -126,7 +128,7 @@
         assertEquals(1, copy.getBodyParts().size());
         assertNull(copy.getParent());
 
-        BodyPart bodyPartCopy = copy.getBodyParts().iterator().next();
+        Entity bodyPartCopy = copy.getBodyParts().iterator().next();
         assertNotSame(bodyPart, bodyPartCopy);
 
         assertSame(parent, bodyPart.getParent());
@@ -137,7 +139,7 @@
         BodyPart bodyPart1 = new BodyPart();
         BodyPart bodyPart2 = new BodyPart();
 
-        Multipart multipart = new Multipart("mixed");
+        Multipart multipart = new MultipartImpl("mixed");
         multipart.addBodyPart(bodyPart1);
         multipart.addBodyPart(bodyPart2);
 
@@ -148,9 +150,9 @@
         Message copy = new Message(original);
 
         Multipart multipartCopy = (Multipart) copy.getBody();
-        List<BodyPart> bodyParts = multipartCopy.getBodyParts();
-        BodyPart bodyPartCopy1 = bodyParts.get(0);
-        BodyPart bodyPartCopy2 = bodyParts.get(1);
+        List<Entity> bodyParts = multipartCopy.getBodyParts();
+        Entity bodyPartCopy1 = bodyParts.get(0);
+        Entity bodyPartCopy2 = bodyParts.get(1);
 
         assertNotSame(bodyPart1, bodyPartCopy1);
         assertEquals(original, bodyPart1.getParent());

Modified: james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/EntityTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/EntityTest.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/EntityTest.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/EntityTest.java
Thu Dec 31 15:36:26 2009
@@ -22,6 +22,7 @@
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.message.Entity;
 import org.apache.james.mime4j.message.impl.BodyFactory;
+import org.apache.james.mime4j.message.impl.BodyPart;
 
 import junit.framework.TestCase;
 

Modified: james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
Thu Dec 31 15:36:26 2009
@@ -162,14 +162,14 @@
             sb.append("<multipart>\r\n");
             
             Multipart multipart =(Multipart) e.getBody(); 
-            List<BodyPart> parts = multipart.getBodyParts();
+            List<Entity> parts = multipart.getBodyParts();
 
             sb.append("<preamble>\r\n");
             sb.append(escape(multipart.getPreamble()));
             sb.append("</preamble>\r\n");
             
             int i = 1;
-            for (BodyPart bodyPart : parts) {
+            for (Entity bodyPart : parts) {
                 sb.append(getStructure(bodyPart, prefix, id + "_" + (i++)));
             }
 

Modified: james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
Thu Dec 31 15:36:26 2009
@@ -36,6 +36,8 @@
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.field.address.Group;
 import org.apache.james.mime4j.field.address.Mailbox;
+import org.apache.james.mime4j.message.impl.BodyPart;
+import org.apache.james.mime4j.message.impl.MultipartImpl;
 
 public class MessageTest extends TestCase {
     private Header headerTextPlain = null;
@@ -448,7 +450,7 @@
         part2.setHeader(headerEmpty);
         part2.setBody(body2);
 
-        Multipart mp = new Multipart("mixed");
+        Multipart mp = new MultipartImpl("mixed");
         mp.addBodyPart(part1);
         mp.addBodyPart(part2);
 

Modified: james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
Thu Dec 31 15:36:26 2009
@@ -25,6 +25,8 @@
 
 import org.apache.james.mime4j.field.DefaultFieldParser;
 import org.apache.james.mime4j.message.impl.BodyFactory;
+import org.apache.james.mime4j.message.impl.BodyPart;
+import org.apache.james.mime4j.message.impl.MultipartImpl;
 
 public class MultipartFormTest extends TestCase {
 
@@ -37,7 +39,7 @@
                 DefaultFieldParser.parse("Content-Type: multipart/form-data; boundary=foo"));
         message.setHeader(header);
         
-        Multipart multipart = new Multipart("alternative");
+        Multipart multipart = new MultipartImpl("alternative");
         multipart.setParent(message);
         BodyPart p1 = new BodyPart();
         Header h1 = new Header();

Modified: james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
(original)
+++ james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
Thu Dec 31 15:36:26 2009
@@ -31,11 +31,12 @@
 
 import org.apache.james.mime4j.field.address.Mailbox;
 import org.apache.james.mime4j.message.BinaryBody;
-import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.Message;
 import org.apache.james.mime4j.message.Multipart;
 import org.apache.james.mime4j.message.TextBody;
 import org.apache.james.mime4j.message.impl.BodyFactory;
+import org.apache.james.mime4j.message.impl.BodyPart;
+import org.apache.james.mime4j.message.impl.MultipartImpl;
 import org.apache.james.mime4j.storage.Storage;
 import org.apache.james.mime4j.storage.StorageOutputStream;
 import org.apache.james.mime4j.storage.StorageProvider;
@@ -67,7 +68,7 @@
 
         // 3) set a multipart body
 
-        Multipart multipart = new Multipart("mixed");
+        Multipart multipart = new MultipartImpl("mixed");
 
         // a multipart may have a preamble
         multipart.setPreamble("This is a multi-part message in MIME format.");

Modified: james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
(original)
+++ james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
Thu Dec 31 15:36:26 2009
@@ -26,11 +26,13 @@
 
 import org.apache.james.mime4j.field.address.Mailbox;
 import org.apache.james.mime4j.message.Body;
-import org.apache.james.mime4j.message.BodyPart;
+import org.apache.james.mime4j.message.Entity;
 import org.apache.james.mime4j.message.Message;
 import org.apache.james.mime4j.message.Multipart;
 import org.apache.james.mime4j.message.TextBody;
 import org.apache.james.mime4j.message.impl.BodyFactory;
+import org.apache.james.mime4j.message.impl.BodyPart;
+import org.apache.james.mime4j.message.impl.MultipartImpl;
 import org.apache.james.mime4j.storage.DefaultStorageProvider;
 import org.apache.james.mime4j.storage.StorageProvider;
 import org.apache.james.mime4j.storage.TempFileStorageProvider;
@@ -102,7 +104,7 @@
 
         // For no particular reason remove the second binary body part (now
         // at index four).
-        BodyPart removed = multipart.removeBodyPart(4);
+        Entity removed = multipart.removeBodyPart(4);
 
         // The removed body part no longer has a parent entity it belongs to so
         // it should be disposed of.
@@ -122,7 +124,7 @@
      * two binary).
      */
     private static Message createTemplate() throws IOException {
-        Multipart multipart = new Multipart("mixed");
+        Multipart multipart = new MultipartImpl("mixed");
 
         BodyPart part1 = createTextPart("This is the first part of the template..");
         multipart.addBodyPart(part1);

Modified: james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java?rev=894868&r1=894867&r2=894868&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
(original)
+++ james/mime4j/branches/cycleclean/examples/src/main/java/org/apache/james/mime4j/samples/tree/MessageTree.java
Thu Dec 31 15:36:26 2009
@@ -49,12 +49,12 @@
 import org.apache.james.mime4j.field.address.MailboxList;
 import org.apache.james.mime4j.message.BinaryBody;
 import org.apache.james.mime4j.message.Body;
-import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.Entity;
 import org.apache.james.mime4j.message.Header;
 import org.apache.james.mime4j.message.Message;
 import org.apache.james.mime4j.message.Multipart;
 import org.apache.james.mime4j.message.TextBody;
+import org.apache.james.mime4j.message.impl.BodyPart;
 
 /**
  * Displays a parsed Message in a window. The window will be divided into
@@ -167,7 +167,7 @@
 
         node.add(new DefaultMutableTreeNode(
                        new ObjectWrapper("Preamble", multipart.getPreamble())));
-        for (BodyPart part : multipart.getBodyParts()) {
+        for (Entity part : multipart.getBodyParts()) {
             node.add(createNode(part));
         }
         node.add(new DefaultMutableTreeNode(



Mime
View raw message