james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1063315 - in /james/mime4j/branches/dom-api-refactoring: benchmark/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/parser/ dom/src/main/java/org/apache/james/mime4j/dom/ dom/src/main/java/org/apache/james/...
Date Tue, 25 Jan 2011 15:18:55 GMT
Author: olegk
Date: Tue Jan 25 15:18:52 2011
New Revision: 1063315

URL: http://svn.apache.org/viewvc?rev=1063315&view=rev
Log:
MimeBuilder API refactoring; improved exception handling in ServiceLoader; fixed #setRaw()
and #setFlat() methods in MimeStreamParser

Added:
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
  (with props)
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
  (with props)
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
  (with props)
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
  (with props)
Modified:
    james/mime4j/branches/dom-api-refactoring/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
    james/mime4j/branches/dom-api-refactoring/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.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/dom/MessageBuilderFactory.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java
    james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderFactoryImpl.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/MimeBuilder.java

Modified: james/mime4j/branches/dom-api-refactoring/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java?rev=1063315&r1=1063314&r2=1063315&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
Tue Jan 25 15:18:52 2011
@@ -171,7 +171,7 @@ public class LongMultipartReadBench {
             DefaultStorageProvider.setInstance(new MemoryStorageProvider());
 
             for (int i = 0; i < repetitions; i++) {
-                MimeBuilder.parse(new ByteArrayInputStream(content));
+                MimeBuilder.DEFAULT.parse(new ByteArrayInputStream(content));
             }
         }
     }

Modified: james/mime4j/branches/dom-api-refactoring/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java?rev=1063315&r1=1063314&r2=1063315&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
Tue Jan 25 15:18:52 2011
@@ -192,32 +192,33 @@ public class MimeStreamParser {
     }
     
     /**
-     * Enables or disables raw mode. In raw mode all future entities 
-     * (messages or body parts) in the stream will be reported to the
+     * Enables raw mode. In raw mode all future entities (messages 
+     * or body parts) in the stream will be reported to the
      * {@link ContentHandler#raw(InputStream)} handler method only.
      * The stream will contain the entire unparsed entity contents 
      * including header fields and whatever is in the body.
-     * 
-     * @param raw <code>true</code> enables raw mode, <code>false</code>
-     *        disables it.
      */
-    public void setRaw(boolean raw) {
+    public void setRaw() {
         mimeTokenStream.setRecursionMode(MimeTokenStream.M_RAW);
     }
     
     /**
-     * Enables or disables flat mode. In flat mode rfc822 parts are not
-     * recursively parsed and multipart content is handled as a single
-     * "simple" stream.
-     * 
-     * @param raw <code>true</code> enables raw mode, <code>false</code>
-     *        disables it.
+     * Enables flat mode. In flat mode rfc822 parts are not recursively 
+     * parsed and multipart content is handled as a single "simple" stream.
      */
-    public void setFlat(boolean flat) {
+    public void setFlat() {
         mimeTokenStream.setRecursionMode(MimeTokenStream.M_FLAT);
     }
     
     /**
+     * Enables recursive mode. In tihs mode rfc822 parts are recursively 
+     * parsed.
+     */
+    public void setRecurse() {
+        mimeTokenStream.setRecursionMode(MimeTokenStream.M_RECURSE);
+    }
+
+    /**
      * Finishes the parsing and stops reading lines.
      * NOTE: No more lines will be parsed but the parser
      * will still call 

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=1063315&r1=1063314&r2=1063315&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
Tue Jan 25 15:18:52 2011
@@ -21,7 +21,6 @@ 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;
@@ -29,21 +28,15 @@ import org.apache.james.mime4j.codec.Dec
 /**
  * Defines the API to obtain Message instances from a mime stream.
  */
-public abstract class MessageBuilder {
+public interface MessageBuilder {
     
-    public abstract Message newMessage();
+    Message newMessage();
+          
+    Message newMessage(Message source);
+          
+    Message parse(InputStream source) throws MimeException, IOException;
+          
+    Message parse(InputStream source, 
+            ParseParams params, DecodeMonitor decodeMonitor) throws MimeException, IOException;
 
-    public abstract Message newMessage(Message source);
-
-    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);
-
-    public abstract void setContentDecoding(boolean contentDecoding);
-    
-    public abstract void setFlatMode();
-
-}
+}
\ No newline at end of file

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilderFactory.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilderFactory.java?rev=1063315&r1=1063314&r2=1063315&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilderFactory.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageBuilderFactory.java
Tue Jan 25 15:18:52 2011
@@ -30,12 +30,14 @@ import org.apache.james.mime4j.MimeExcep
  */
 public abstract class MessageBuilderFactory {
 
-    public abstract MessageBuilder newMessageBuilder() throws MimeException;
-    
     public static MessageBuilderFactory newInstance() throws MimeException {
         return ServiceLoader.load(MessageBuilderFactory.class);
     }
 
-    public abstract void setAttribute(String name, Object value) throws IllegalArgumentException;
+    public abstract MessageBuilder newMessageBuilder();
     
+    public abstract MessageFormatter newMessageFormatter();
+    
+    public abstract void setAttribute(String name, Object value) throws IllegalArgumentException;
+        
 }

Added: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java?rev=1063315&view=auto
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
(added)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
Tue Jan 25 15:18:52 2011
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.dom;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Defines the API to write Message to an output stream.
+ */
+public interface MessageFormatter {
+    
+    void writeTo(Message message, OutputStream out) throws IOException;
+
+}

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/MessageFormatter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java?rev=1063315&view=auto
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
(added)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
Tue Jan 25 15:18:52 2011
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.dom;
+
+public class ParseParams {
+
+    private boolean flatMode;
+    private boolean contentDecoding;
+
+    public ParseParams() {
+        super();
+        this.flatMode = true;
+    }
+    
+    public boolean isFlatMode() {
+        return flatMode;
+    }
+    
+    public void setFlatMode(boolean flatMode) {
+        this.flatMode = flatMode;
+    }
+    
+    public boolean isContentDecoding() {
+        return contentDecoding;
+    }
+    
+    public void setContentDecoding(boolean contentDecoding) {
+        this.contentDecoding = contentDecoding;
+    }
+
+}

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ParseParams.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java?rev=1063315&r1=1063314&r2=1063315&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoader.java
Tue Jan 25 15:18:52 2011
@@ -20,6 +20,7 @@ package org.apache.james.mime4j.dom;
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.Enumeration;
@@ -40,56 +41,50 @@ class ServiceLoader {
     static <T> T load(Class<T> spiClass) {
         String spiResURI = "META-INF/services/" + spiClass.getName();
         ClassLoader classLoader = spiClass.getClassLoader();
-        Enumeration<URL> resources;
         try {
-            resources = classLoader.getResources(spiResURI);
-        } catch (IOException e) {
-            return null;
-        }
-
-        while (resources.hasMoreElements()) {
-            URL resource = resources.nextElement();
-            BufferedReader reader = null;
-            try {
-                reader = new BufferedReader(new InputStreamReader(resource
-                        .openStream()));
-                String line;
-                while ((line = reader.readLine()) != null) {
-                    line = line.trim();
-                    int cmtIdx = line.indexOf('#');
-                    if (cmtIdx != -1) {
-                        line = line.substring(0, cmtIdx);
+             Enumeration<URL> resources = classLoader.getResources(spiResURI);
+             while (resources.hasMoreElements()) {
+                 URL resource = resources.nextElement();
+                 InputStream instream = resource.openStream();
+                 try {
+                     BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
+                     String line;
+                     while ((line = reader.readLine()) != null) {
                         line = line.trim();
-                    }
-
-                    if (line.length() == 0) {
-                        continue;
-                    }
+                         int cmtIdx = line.indexOf('#');
+                         if (cmtIdx != -1) {
+                             line = line.substring(0, cmtIdx);
+                             line = line.trim();
+                         }
+
+                         if (line.length() == 0) {
+                             continue;
+                         }
 
-                    Class<?> implClass;
-                    try {
-                        implClass = classLoader.loadClass(line);
-                        
+                         Class<?> implClass = classLoader.loadClass(line);
                         if (spiClass.isAssignableFrom(implClass)) {
                             Object impl = implClass.newInstance();
                             return spiClass.cast(impl);
                         }
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            } finally {
-                if (reader != null) {
-                    try {
-                        reader.close();
-                    } catch (IOException e) {
                     }
+                     reader.close();
+                 } finally {
+                     instream.close();
                 }
             }
+             return null;
+         } catch (IOException ex) {
+             throw new ServiceLoaderException(ex);
+         } catch (ClassNotFoundException ex) {
+             throw new ServiceLoaderException("Unknown SPI class '" 
+                     + spiClass.getName() + "'", ex);
+         } catch (IllegalAccessException ex) {
+             // Not visible
+             return null;
+         } catch (InstantiationException ex) {
+             throw new ServiceLoaderException("SPI class '" 
+                     + spiClass.getName() + "' cannot be instantiated", ex);
         }
-
-        return null;
     }
+
 }
\ No newline at end of file

Added: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java?rev=1063315&view=auto
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
(added)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
Tue Jan 25 15:18:52 2011
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.dom;
+
+public class ServiceLoaderException extends RuntimeException {
+
+    private static final long serialVersionUID = -2801857820835508778L;
+
+    public ServiceLoaderException(String message) {
+        super(message);
+    }
+
+    public ServiceLoaderException(Throwable cause) {
+        super(cause);
+    }
+    
+    public ServiceLoaderException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/dom/ServiceLoaderException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderFactoryImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderFactoryImpl.java?rev=1063315&r1=1063314&r2=1063315&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderFactoryImpl.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilderFactoryImpl.java
Tue Jan 25 15:18:52 2011
@@ -18,9 +18,9 @@
  ****************************************************************/
 package org.apache.james.mime4j.message;
 
-import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.dom.MessageBuilder;
 import org.apache.james.mime4j.dom.MessageBuilderFactory;
+import org.apache.james.mime4j.dom.MessageFormatter;
 import org.apache.james.mime4j.storage.StorageProvider;
 import org.apache.james.mime4j.stream.MimeEntityConfig;
 import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory;
@@ -38,7 +38,7 @@ public class MessageBuilderFactoryImpl e
     private MutableBodyDescriptorFactory mutableBodyDescriptorFactory = null;
 
     @Override
-    public MessageBuilder newMessageBuilder() throws MimeException {
+    public MessageBuilder newMessageBuilder() {
         MessageBuilderImpl m = new MessageBuilderImpl();
         if (storageProvider != null) m.setStorageProvider(storageProvider);
         if (mimeEntityConfig != null) m.setMimeEntityConfig(mimeEntityConfig);
@@ -47,6 +47,12 @@ public class MessageBuilderFactoryImpl e
     }
 
     @Override
+    public MessageFormatter newMessageFormatter() {
+        MessageFormatterImpl m = new MessageFormatterImpl();
+        return m;
+    }
+    
+    @Override
     public void setAttribute(String name, Object value)
             throws IllegalArgumentException {
         if ("StorageProvider".equals(name)) {

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=1063315&r1=1063314&r2=1063315&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
Tue Jan 25 15:18:52 2011
@@ -1,13 +1,32 @@
+/****************************************************************
+ * 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;
 
 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;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.MessageBuilder;
+import org.apache.james.mime4j.dom.ParseParams;
 import org.apache.james.mime4j.storage.StorageProvider;
 import org.apache.james.mime4j.stream.MimeEntityConfig;
 import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory;
@@ -16,21 +35,16 @@ import org.apache.james.mime4j.stream.Mu
  * Default MessageBuilder implementation delegating Message parsing to the "legacy"
  * MessageImpl object.
  */
-public class MessageBuilderImpl extends MessageBuilder {
+public class MessageBuilderImpl implements MessageBuilder {
 
-    private MimeWriter mimeWriter;
-    private MimeBuilder mimeBuilder;
+    private MimeBuilder mimeBuilder = null;
     private StorageProvider storageProvider = null;
-    private DecodeMonitor decodeMonitor = null;
     private MimeEntityConfig mimeEntityConfig = null;
     private MutableBodyDescriptorFactory mutableBodyDescriptorFactory = null;
-    private boolean flatMode = false;
-    private boolean contentDecoding = true;
 
     public MessageBuilderImpl() {
     }
 
-    @Override
     public Message newMessage() {
         return new MessageImpl();
     }
@@ -44,41 +58,30 @@ public class MessageBuilderImpl extends 
         
     }
     
-    private MimeWriter getMimeWriter() {
-        if (this.mimeWriter != null) {
-            return this.mimeWriter;
-        } else {
-            return MimeWriter.DEFAULT;
-        }
-        
-    }
-    
-    @Override
     public Message newMessage(Message source) {
         return getMimeBuilder().copy(source);
     }
 
-    @Override
     public Message parse(InputStream source) throws MimeException, IOException {
         return getMimeBuilder().parse(source, 
                 mimeEntityConfig, 
                 storageProvider, 
                 mutableBodyDescriptorFactory, 
-                decodeMonitor, 
-                contentDecoding, 
-                flatMode);
+                null,
+                null);
     }
-
-    @Override
-    public void writeTo(Message message, OutputStream out) throws IOException {
-        getMimeWriter().writeMessage(message, out);
-    }
-
-    @Override
-    public void setDecodeMonitor(DecodeMonitor decodeMonitor) {
-        this.decodeMonitor = decodeMonitor;
+    
+    public Message parse(
+            InputStream source, 
+            ParseParams params, DecodeMonitor decodeMonitor) throws MimeException, IOException
{
+        return getMimeBuilder().parse(source, 
+                mimeEntityConfig, 
+                storageProvider, 
+                mutableBodyDescriptorFactory, 
+                params,
+                decodeMonitor);
     }
-
+    
     public void setStorageProvider(StorageProvider storageProvider) {
         this.storageProvider = storageProvider;
     }
@@ -92,20 +95,6 @@ public class MessageBuilderImpl extends 
         this.mutableBodyDescriptorFactory  = mutableBodyDescriptorFactory;
     }
 
-    @Override
-    public void setContentDecoding(boolean contentDecoding) {
-        this.contentDecoding  = contentDecoding;
-    }
-
-    @Override
-    public void setFlatMode() {
-        this.flatMode = true;
-    }
-
-    public void setMimeWriter(MimeWriter mimeWriter) {
-        this.mimeWriter = mimeWriter;
-    }
-
     public void setMimeBuilder(MimeBuilder mimeBuilder) {
         this.mimeBuilder = mimeBuilder;
     }

Added: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java?rev=1063315&view=auto
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
(added)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
Tue Jan 25 15:18:52 2011
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.dom.MessageFormatter;
+
+public class MessageFormatterImpl implements MessageFormatter {
+
+    private MimeWriter mimeWriter = null;
+
+    public MessageFormatterImpl() {
+    }
+
+    private MimeWriter getMimeWriter() {
+        if (this.mimeWriter != null) {
+            return this.mimeWriter;
+        } else {
+            return MimeWriter.DEFAULT;
+        }
+        
+    }
+    
+    public void writeTo(Message message, OutputStream out) throws IOException {
+        getMimeWriter().writeMessage(message, out);
+    }
+
+    public void setMimeWriter(MimeWriter mimeWriter) {
+        this.mimeWriter = mimeWriter;
+    }
+
+}

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MessageFormatterImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java?rev=1063315&r1=1063314&r2=1063315&view=diff
==============================================================================
--- james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
(original)
+++ james/mime4j/branches/dom-api-refactoring/dom/src/main/java/org/apache/james/mime4j/message/MimeBuilder.java
Tue Jan 25 15:18:52 2011
@@ -31,6 +31,7 @@ import org.apache.james.mime4j.dom.Entit
 import org.apache.james.mime4j.dom.Header;
 import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.Multipart;
+import org.apache.james.mime4j.dom.ParseParams;
 import org.apache.james.mime4j.dom.SingleBody;
 import org.apache.james.mime4j.dom.field.Field;
 import org.apache.james.mime4j.field.DefaultFieldParser;
@@ -250,16 +251,24 @@ public class MimeBuilder {
             final MimeEntityConfig config,
             final StorageProvider storageProvider, 
             final MutableBodyDescriptorFactory bodyDescFactory,
-            final DecodeMonitor monitor,
-            boolean contentDecoding,
-            boolean flatMode) throws IOException, MimeIOException {
+            final ParseParams params,
+            final DecodeMonitor monitor) throws IOException, MimeIOException {
         try {
             MessageImpl message = new MessageImpl();
             DecodeMonitor mon = monitor != null ? monitor : DecodeMonitor.SILENT;
             MimeStreamParser parser = new MimeStreamParser(config, bodyDescFactory, mon);
             parser.setContentHandler(new EntityBuilder(message, storageProvider, mon));
-            parser.setContentDecoding(contentDecoding);
-            if (flatMode) parser.setFlat(true);
+            if (params != null) {
+                parser.setContentDecoding(params.isContentDecoding());
+                if (params.isFlatMode()) {
+                    parser.setFlat();
+                } else {
+                    parser.setRecurse();
+                }
+            } else {
+                parser.setContentDecoding(true);
+                parser.setRecurse();
+            }
             parser.parse(is);
             return message;
         } catch (MimeException e) {
@@ -291,7 +300,7 @@ public class MimeBuilder {
             final StorageProvider storageProvider, 
             final MutableBodyDescriptorFactory bodyDescFactory,
             final DecodeMonitor monitor) throws IOException, MimeIOException {
-        return parse(is, config, storageProvider, bodyDescFactory, monitor, true, false);
+        return parse(is, config, storageProvider, bodyDescFactory, null, monitor);
     }
     
     public Message parse(



Mime
View raw message