james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1061321 - in /james/mime4j/branches/dom-api-refactoring: dom/src/main/java/org/apache/james/mime4j/dom/ dom/src/main/java/org/apache/james/mime4j/message/ dom/src/test/java/org/apache/james/mime4j/dom/ examples/src/main/java/org/apache/jam...
Date Thu, 20 Jan 2011 14:45:02 GMT
Author: olegk
Date: Thu Jan 20 14:45:01 2011
New Revision: 1061321

URL: http://svn.apache.org/viewvc?rev=1061321&view=rev
Log:
Removed #writeTo method from the Message interface; added option of using a different MimeWriter
/ MimeBuilder implementations with MessageBuilderImpl

Modified:
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/Message.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
    james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java
    james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
    james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java
    james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
    james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
    james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/Message.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/Message.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/Message.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/Message.java
Thu Jan 20 14:45:01 2011
@@ -19,8 +19,6 @@
 
 package org.apache.james.mime4j.dom;
 
-import java.io.IOException;
-import java.io.OutputStream;
 import java.util.Collection;
 import java.util.Date;
 import java.util.TimeZone;
@@ -33,16 +31,6 @@ import org.apache.james.mime4j.dom.addre
 public interface Message extends Entity, Body {
 
     /**
-     * Write the content to the given output stream.
-     * 
-     * @param out
-     *            the output stream to write to.
-     * @throws IOException
-     *             in case of an I/O error
-     */
-    void writeTo(OutputStream out) throws IOException;
-
-    /**
      * Returns the value of the <i>Message-ID</i> header field of this message
      * or <code>null</code> if it is not present.
      * 

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilder.java
Thu Jan 20 14:45:01 2011
@@ -21,6 +21,7 @@ package org.apache.james.mime4j.dom;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.codec.DecodeMonitor;
@@ -36,6 +37,8 @@ public abstract class MessageBuilder {
 
     public abstract Message parse(InputStream source) throws MimeException, IOException;
 
+    public abstract void writeTo(Message message, OutputStream out) throws IOException;
+
     public abstract void setDecodeMonitor(
             DecodeMonitor decodeMonitor);
 

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderImpl.java
Thu Jan 20 14:45:01 2011
@@ -2,6 +2,7 @@ package org.apache.james.mime4j.message;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.codec.DecodeMonitor;
@@ -17,6 +18,8 @@ import org.apache.james.mime4j.stream.Mu
  */
 public class MessageBuilderImpl extends MessageBuilder {
 
+    private MimeWriter mimeWriter;
+    private MimeBuilder mimeBuilder;
     private StorageProvider storageProvider = null;
     private DecodeMonitor decodeMonitor = null;
     private MimeEntityConfig mimeEntityConfig = null;
@@ -32,14 +35,32 @@ public class MessageBuilderImpl extends 
         return new MessageImpl();
     }
 
+    private MimeBuilder getMimeBuilder() {
+        if (this.mimeBuilder != null) {
+            return this.mimeBuilder;
+        } else {
+            return MimeBuilder.DEFAULT;
+        }
+        
+    }
+    
+    private MimeWriter getMimeWriter() {
+        if (this.mimeWriter != null) {
+            return this.mimeWriter;
+        } else {
+            return MimeWriter.DEFAULT;
+        }
+        
+    }
+    
     @Override
     public Message newMessage(Message source) {
-        return MimeBuilder.DEFAULT.copy(source);
+        return getMimeBuilder().copy(source);
     }
 
     @Override
     public Message parse(InputStream source) throws MimeException, IOException {
-        return MimeBuilder.DEFAULT.parse(source, 
+        return getMimeBuilder().parse(source, 
                 mimeEntityConfig, 
                 storageProvider, 
                 mutableBodyDescriptorFactory, 
@@ -49,6 +70,11 @@ public class MessageBuilderImpl extends 
     }
 
     @Override
+    public void writeTo(Message message, OutputStream out) throws IOException {
+        getMimeWriter().writeMessage(message, out);
+    }
+
+    @Override
     public void setDecodeMonitor(DecodeMonitor decodeMonitor) {
         this.decodeMonitor = decodeMonitor;
     }
@@ -76,4 +102,12 @@ public class MessageBuilderImpl extends 
         this.flatMode = true;
     }
 
+    public void setMimeWriter(MimeWriter mimeWriter) {
+        this.mimeWriter = mimeWriter;
+    }
+
+    public void setMimeBuilder(MimeBuilder mimeBuilder) {
+        this.mimeBuilder = mimeBuilder;
+    }
+
 }

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageImpl.java
Thu Jan 20 14:45:01 2011
@@ -19,8 +19,6 @@
 
 package org.apache.james.mime4j.message;
 
-import java.io.IOException;
-import java.io.OutputStream;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
@@ -53,13 +51,6 @@ public class MessageImpl extends Abstrac
     public MessageImpl() {
     }
 
-    /**
-     * @see org.apache.james.mime4j.dom.Message#writeTo(java.io.OutputStream)
-     */
-    public void writeTo(OutputStream out) throws IOException {
-        MimeWriter.DEFAULT.writeEntity(this, out);
-    }
-
     @Override
     protected String newUniqueBoundary() {
         return MimeUtil.createUniqueBoundary();

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeWriter.java
Thu Jan 20 14:45:01 2011
@@ -119,6 +119,21 @@ public class MimeWriter {
     }
 
     /**
+     * Write the specified <code>Message</code> to the specified
+     * <code>OutputStream</code>.
+     * 
+     * @param entity
+     *            the <code>Message</code> to write.
+     * @param out
+     *            the OutputStream to write to.
+     * @throws IOException
+     *             if an I/O error occurs.
+     */
+    public void writeMessage(Message message, OutputStream out) throws IOException {
+        writeEntity(message, out);
+    }
+    
+    /**
      * Write the specified <code>Multipart</code> to the specified
      * <code>OutputStream</code>.
      * 

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java
Thu Jan 20 14:45:01 2011
@@ -36,6 +36,7 @@ import junit.framework.TestSuite;
 import org.apache.james.mime4j.codec.CodecUtil;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.message.MimeBuilder;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.stream.MimeEntityConfig;
 
 /**
@@ -60,7 +61,7 @@ public class ExampleMessagesRoundtripTes
         config.setMaxLineLen(-1);
         Message inputMessage = MimeBuilder.DEFAULT.parse(url.openStream(), config);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        inputMessage.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(inputMessage, out);
         
         String s = url.toString();
         URL msgout = new URL(s.substring(0, s.lastIndexOf('.')) + ".out");

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageTest.java
Thu Jan 20 14:45:01 2011
@@ -45,6 +45,7 @@ import org.apache.james.mime4j.message.B
 import org.apache.james.mime4j.message.HeaderImpl;
 import org.apache.james.mime4j.message.MessageImpl;
 import org.apache.james.mime4j.message.MimeBuilder;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.message.MultipartImpl;
 
 public class MessageTest extends TestCase {
@@ -136,7 +137,7 @@ public class MessageTest extends TestCas
         Message m = MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(inputByte));
         ByteArrayOutputStream out = new ByteArrayOutputStream();
 
-        m.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(m, out);
 
         InputStream output = new ByteArrayInputStream(out.toByteArray());
 
@@ -162,7 +163,7 @@ public class MessageTest extends TestCas
                 .getBody(), headerValue);
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        m.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(m, out);
         List<?> lines = IOUtils.readLines((new BufferedReader(
                 new InputStreamReader(new ByteArrayInputStream(out
                         .toByteArray())))));

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/test/java/org/apache/james/mime4j/dom/MessageWriteToTest.java
Thu Jan 20 14:45:01 2011
@@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream;
 
 import org.apache.james.mime4j.ExampleMail;
 import org.apache.james.mime4j.message.MimeBuilder;
+import org.apache.james.mime4j.message.MimeWriter;
 
 import junit.framework.TestCase;
 
@@ -43,7 +44,7 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.RFC822_SIMPLE_BYTES);
         assertFalse("Not multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        message.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(message, out);
         assertEquals(out.toByteArray(), ExampleMail.RFC822_SIMPLE_BYTES);
     }
     
@@ -61,7 +62,7 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        message.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(message, out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, out.toByteArray());
     }
     
@@ -69,7 +70,7 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        message.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(message, out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_NOPREAMBLE_BYTES, out.toByteArray());
     }
     
@@ -77,7 +78,7 @@ public class MessageWriteToTest extends 
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_PREAMBLE_EPILOGUE_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        message.writeTo(out);
+        MimeWriter.DEFAULT.writeMessage(message, out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_PREAMBLE_EPILOGUE_BYTES,
out.toByteArray());
     }
     

Modified: james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/MultipartMessage.java
Thu Jan 20 14:45:01 2011
@@ -36,6 +36,7 @@ import org.apache.james.mime4j.field.add
 import org.apache.james.mime4j.message.BodyFactory;
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.MessageImpl;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.message.MultipartImpl;
 import org.apache.james.mime4j.storage.Storage;
 import org.apache.james.mime4j.storage.StorageOutputStream;
@@ -88,7 +89,7 @@ public class MultipartMessage {
 
         // 4) print message to standard output
 
-        message.writeTo(System.out);
+        MimeWriter.DEFAULT.writeMessage(message, System.out);
 
         // 5) message is no longer needed and should be disposed of
 

Modified: james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/dom/TextPlainMessage.java
Thu Jan 20 14:45:01 2011
@@ -27,6 +27,7 @@ import org.apache.james.mime4j.field.add
 import org.apache.james.mime4j.field.address.ParseException;
 import org.apache.james.mime4j.message.BodyFactory;
 import org.apache.james.mime4j.message.MessageImpl;
+import org.apache.james.mime4j.message.MimeWriter;
 
 /**
  * This example generates a message very similar to the one from RFC 5322
@@ -62,7 +63,7 @@ public class TextPlainMessage {
 
         // 4) print message to standard output
 
-        message.writeTo(System.out);
+        MimeWriter.DEFAULT.writeMessage(message, System.out);
 
         // 5) message is no longer needed and should be disposed of
 

Modified: james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java?rev=1061321&r1=1061320&r2=1061321&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
Thu Jan 20 14:45:01 2011
@@ -35,6 +35,7 @@ import org.apache.james.mime4j.message.B
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.MessageImpl;
 import org.apache.james.mime4j.message.MimeBuilder;
+import org.apache.james.mime4j.message.MimeWriter;
 import org.apache.james.mime4j.message.MultipartImpl;
 import org.apache.james.mime4j.storage.DefaultStorageProvider;
 import org.apache.james.mime4j.storage.StorageProvider;
@@ -65,7 +66,7 @@ public class TransformMessage {
 
         // Print transformed message.
         System.out.println("\n\nTransformed message:\n--------------------\n");
-        transformed.writeTo(System.out);
+        MimeWriter.DEFAULT.writeMessage(transformed, System.out);
 
         // Messages should be disposed of when they are no longer needed.
         // Disposing of a message also disposes of all child elements (e.g. body
@@ -75,7 +76,7 @@ public class TransformMessage {
         // Print original message to illustrate that it was not affected by the
         // transformation.
         System.out.println("\n\nOriginal template:\n------------------\n");
-        template.writeTo(System.out);
+        MimeWriter.DEFAULT.writeMessage(template, System.out);
 
         // Original message is no longer needed.
         template.dispose();



Mime
View raw message