james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieu...@apache.org
Subject svn commit: r1457434 - in /james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message: DefaultMessageBuilder.java DefaultMessageImplFactory.java EntityBuilder.java MessageImplFactory.java
Date Sun, 17 Mar 2013 12:20:53 GMT
Author: ieugen
Date: Sun Mar 17 12:20:53 2013
New Revision: 1457434

URL: http://svn.apache.org/r1457434
Log:
Fixes MIME4J-225 and MIME4J-222

* thanks Rustam Gupta for the MIME4J-222 patch
* changed version format to 0.8.0

Added:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageImplFactory.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImplFactory.java
Modified:
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java?rev=1457434&r1=1457433&r2=1457434&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java
Sun Mar 17 12:20:53 2013
@@ -49,6 +49,7 @@ import org.apache.james.mime4j.stream.Mi
 public class DefaultMessageBuilder implements MessageBuilder {
 
     private FieldParser<? extends ParsedField> fieldParser = null;
+    private MessageImplFactory messageImplFactory = null;
     private BodyFactory bodyFactory = null;
     private MimeConfig config = null;
     private BodyDescriptorBuilder bodyDescBuilder = null;
@@ -64,6 +65,10 @@ public class DefaultMessageBuilder imple
         this.fieldParser = fieldParser;
     }
 
+    public void setMessageImplFactory(final MessageImplFactory messageImplFactory) {
+        this.messageImplFactory = messageImplFactory;
+    }
+
     public void setBodyFactory(final BodyFactory bodyFactory) {
         this.bodyFactory = bodyFactory;
     }
@@ -220,7 +225,7 @@ public class DefaultMessageBuilder imple
      *             {@link SingleBody}.
      */
     public Message copy(Message other) {
-        MessageImpl copy = new MessageImpl();
+        MessageImpl copy = newMessageImpl();
         if (other.getHeader() != null) {
             copy.setHeader(copy(other.getHeader()));
         }
@@ -280,7 +285,7 @@ public class DefaultMessageBuilder imple
     }
 
     public Message newMessage() {
-        return new MessageImpl();
+        return newMessageImpl();
     }
 
     public Message newMessage(final Message source) {
@@ -289,7 +294,7 @@ public class DefaultMessageBuilder imple
 
     public Message parseMessage(final InputStream is) throws IOException, MimeIOException
{
         try {
-            MessageImpl message = new MessageImpl();
+            MessageImpl message = newMessageImpl();
             MimeConfig cfg = config != null ? config : new MimeConfig();
             boolean strict = cfg.isStrictParsing();
             DecodeMonitor mon = monitor != null ? monitor :
@@ -315,4 +320,9 @@ public class DefaultMessageBuilder imple
         }
     }
 
+    private MessageImpl newMessageImpl() {
+        MessageImplFactory mif = messageImplFactory != null ? messageImplFactory : new DefaultMessageImplFactory();
+        return mif.messageImpl();
+    }
+
 }

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageImplFactory.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageImplFactory.java?rev=1457434&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageImplFactory.java
(added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageImplFactory.java
Sun Mar 17 12:20:53 2013
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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;
+
+/**
+ * A default MessageImplFactory that returns an unmodified MessageImpl using the default
constructor.
+ */
+public class DefaultMessageImplFactory implements MessageImplFactory {
+
+    @Override
+    public MessageImpl messageImpl() {
+        return new MessageImpl();
+    }
+}

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java?rev=1457434&r1=1457433&r2=1457434&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/EntityBuilder.java
Sun Mar 17 12:20:53 2013
@@ -19,10 +19,6 @@
 
 package org.apache.james.mime4j.message;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Stack;
-
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.dom.Body;
 import org.apache.james.mime4j.dom.Entity;
@@ -32,10 +28,13 @@ import org.apache.james.mime4j.dom.Multi
 import org.apache.james.mime4j.parser.ContentHandler;
 import org.apache.james.mime4j.stream.BodyDescriptor;
 import org.apache.james.mime4j.stream.Field;
-import org.apache.james.mime4j.stream.RawField;
 import org.apache.james.mime4j.util.ByteArrayBuffer;
 import org.apache.james.mime4j.util.ByteSequence;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Stack;
+
 /**
  * A <code>ContentHandler</code> for building an <code>Entity</code>
to be
  * used in conjunction with a {@link org.apache.james.mime4j.parser.MimeStreamParser}.
@@ -43,6 +42,7 @@ import org.apache.james.mime4j.util.Byte
 class EntityBuilder implements ContentHandler {
 
     private final Entity entity;
+    private MessageImplFactory messageImplFactory;
     private final BodyFactory bodyFactory;
     private final Stack<Object> stack;
 
@@ -50,6 +50,17 @@ class EntityBuilder implements ContentHa
             final Entity entity,
             final BodyFactory bodyFactory) {
         this.entity = entity;
+        this.messageImplFactory = new DefaultMessageImplFactory();
+        this.bodyFactory = bodyFactory;
+        this.stack = new Stack<Object>();
+    }
+
+    EntityBuilder(
+            final Entity entity,
+            final MessageImplFactory messageImplFactory,
+            final BodyFactory bodyFactory) {
+        this.entity = entity;
+        this.messageImplFactory = messageImplFactory;
         this.bodyFactory = bodyFactory;
         this.stack = new Stack<Object>();
     }
@@ -62,45 +73,36 @@ class EntityBuilder implements ContentHa
         }
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#startMessage()
-     */
+    @Override
     public void startMessage() throws MimeException {
         if (stack.isEmpty()) {
             stack.push(this.entity);
         } else {
             expect(Entity.class);
-            Message m = new MessageImpl();
+            Message m = messageImplFactory.messageImpl();
             ((Entity) stack.peek()).setBody(m);
             stack.push(m);
         }
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#endMessage()
-     */
+    @Override
     public void endMessage() throws MimeException {
         expect(Message.class);
         stack.pop();
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#startHeader()
-     */
+    @Override
     public void startHeader() throws MimeException {
         stack.push(new HeaderImpl());
     }
 
-    /**
-     */
+    @Override
     public void field(Field field) throws MimeException {
         expect(Header.class);
         ((Header) stack.peek()).addField(field);
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#endHeader()
-     */
+    @Override
     public void endHeader() throws MimeException {
         expect(Header.class);
         Header h = (Header) stack.pop();
@@ -108,9 +110,7 @@ class EntityBuilder implements ContentHa
         ((Entity) stack.peek()).setHeader(h);
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#startMultipart(org.apache.james.mime4j.stream.BodyDescriptor)
-     */
+    @Override
     public void startMultipart(final BodyDescriptor bd) throws MimeException {
         expect(Entity.class);
 
@@ -121,9 +121,7 @@ class EntityBuilder implements ContentHa
         stack.push(multiPart);
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#body(org.apache.james.mime4j.stream.BodyDescriptor,
java.io.InputStream)
-     */
+    @Override
     public void body(BodyDescriptor bd, final InputStream is) throws MimeException, IOException
{
         expect(Entity.class);
 
@@ -156,16 +154,12 @@ class EntityBuilder implements ContentHa
         entity.setBody(body);
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#endMultipart()
-     */
+    @Override
     public void endMultipart() throws MimeException {
         stack.pop();
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#startBodyPart()
-     */
+    @Override
     public void startBodyPart() throws MimeException {
         expect(Multipart.class);
 
@@ -174,26 +168,20 @@ class EntityBuilder implements ContentHa
         stack.push(bodyPart);
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#endBodyPart()
-     */
+    @Override
     public void endBodyPart() throws MimeException {
         expect(BodyPart.class);
         stack.pop();
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#epilogue(java.io.InputStream)
-     */
+    @Override
     public void epilogue(InputStream is) throws MimeException, IOException {
         expect(MultipartImpl.class);
         ByteSequence bytes = loadStream(is);
         ((MultipartImpl) stack.peek()).setEpilogueRaw(bytes);
     }
 
-    /**
-     * @see org.apache.james.mime4j.parser.ContentHandler#preamble(java.io.InputStream)
-     */
+    @Override
     public void preamble(InputStream is) throws MimeException, IOException {
         expect(MultipartImpl.class);
         ByteSequence bytes = loadStream(is);
@@ -202,8 +190,11 @@ class EntityBuilder implements ContentHa
 
     /**
      * Unsupported.
-     * @see org.apache.james.mime4j.parser.ContentHandler#raw(java.io.InputStream)
+     *
+     * @param is the raw contents of the entity.
+     * @throws UnsupportedOperationException
      */
+    @Override
     public void raw(InputStream is) throws MimeException, IOException {
         throw new UnsupportedOperationException("Not supported");
     }

Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImplFactory.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImplFactory.java?rev=1457434&view=auto
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImplFactory.java
(added)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageImplFactory.java
Sun Mar 17 12:20:53 2013
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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;
+
+/**
+ * Factory for creating message implementations.
+ */
+public interface MessageImplFactory {
+
+    MessageImpl messageImpl();
+
+}



Mime
View raw message