james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r907006 - in /james/mime4j/trunk/dom: ./ src/main/java/org/apache/james/mime4j/message/ src/main/java/org/apache/james/mime4j/storage/ src/test/java/org/apache/james/mime4j/field/
Date Fri, 05 Feb 2010 17:11:36 GMT
Author: olegk
Date: Fri Feb  5 17:11:35 2010
New Revision: 907006

URL: http://svn.apache.org/viewvc?rev=907006&view=rev
Log:
MIME4J-158: Eliminated all dependencies on Commons-Logging in DOM module with the sole exception
of LoggingMonitor

Modified:
    james/mime4j/trunk/dom/pom.xml
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BodyFactory.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/storage/DefaultStorageProvider.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java

Modified: james/mime4j/trunk/dom/pom.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/pom.xml?rev=907006&r1=907005&r2=907006&view=diff
==============================================================================
--- james/mime4j/trunk/dom/pom.xml (original)
+++ james/mime4j/trunk/dom/pom.xml Fri Feb  5 17:11:35 2010
@@ -78,11 +78,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <type>jar</type>

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BodyFactory.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BodyFactory.java?rev=907006&r1=907005&r2=907006&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BodyFactory.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BodyFactory.java
Fri Feb  5 17:11:35 2010
@@ -23,8 +23,7 @@
 import java.io.InputStream;
 import java.nio.charset.Charset;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.BinaryBody;
 import org.apache.james.mime4j.dom.Disposable;
 import org.apache.james.mime4j.dom.SingleBody;
@@ -40,18 +39,17 @@
  */
 public class BodyFactory {
 
-    private static Log log = LogFactory.getLog(BodyFactory.class);
-
     private static final Charset FALLBACK_CHARSET = CharsetUtil.DEFAULT_CHARSET;
 
-    private StorageProvider storageProvider;
+    private final StorageProvider storageProvider;
+    private final DecodeMonitor monitor;
 
     /**
      * Creates a new <code>BodyFactory</code> instance that uses the default
      * storage provider for creating message bodies from input streams.
      */
     public BodyFactory() {
-        this.storageProvider = DefaultStorageProvider.getInstance();
+        this(null, null);
     }
 
     /**
@@ -62,11 +60,13 @@
      *            a storage provider or <code>null</code> to use the default
      *            one.
      */
-    public BodyFactory(StorageProvider storageProvider) {
-        if (storageProvider == null)
-            storageProvider = DefaultStorageProvider.getInstance();
-
-        this.storageProvider = storageProvider;
+    public BodyFactory(
+            final StorageProvider storageProvider,
+            final DecodeMonitor monitor) {
+        this.storageProvider = 
+            storageProvider != null ? storageProvider : DefaultStorageProvider.getInstance();
+        this.monitor = 
+            monitor != null ? monitor : DecodeMonitor.SILENT;
     }
 
     /**
@@ -169,7 +169,7 @@
             throw new IllegalArgumentException();
 
         Storage storage = storageProvider.store(is);
-        Charset charset = toJavaCharset(mimeCharset, false);
+        Charset charset = toJavaCharset(mimeCharset, false, monitor);
         return new StorageTextBody(new MultiReferenceStorage(storage), charset);
     }
 
@@ -233,7 +233,7 @@
         if (mimeCharset == null)
             throw new IllegalArgumentException();
 
-        Charset charset = toJavaCharset(mimeCharset, false);
+        Charset charset = toJavaCharset(mimeCharset, false, monitor);
         return new StorageTextBody(new MultiReferenceStorage(storage), charset);
     }
 
@@ -278,33 +278,42 @@
         if (mimeCharset == null)
             throw new IllegalArgumentException();
 
-        Charset charset = toJavaCharset(mimeCharset, true);
+        Charset charset = toJavaCharset(mimeCharset, true, monitor);
         return new StringTextBody(text, charset);
     }
 
-    private static Charset toJavaCharset(String mimeCharset, boolean forEncoding) {
+    private static Charset toJavaCharset(
+            final String mimeCharset, 
+            boolean forEncoding,
+            final DecodeMonitor monitor) {
         String charset = CharsetUtil.toJavaCharset(mimeCharset);
         if (charset == null) {
-            if (log.isWarnEnabled())
-                log.warn("MIME charset '" + mimeCharset + "' has no "
-                        + "corresponding Java charset. Using "
+            if (monitor.isListening()) {
+                monitor.warn(
+                        "MIME charset '" + mimeCharset + "' has no "
+                        + "corresponding Java charset", "Using "
                         + FALLBACK_CHARSET + " instead.");
+            }
             return FALLBACK_CHARSET;
         }
 
         if (forEncoding && !CharsetUtil.isEncodingSupported(charset)) {
-            if (log.isWarnEnabled())
-                log.warn("MIME charset '" + mimeCharset
-                        + "' does not support encoding. Using "
+            if (monitor.isListening()) {
+                monitor.warn(
+                        "MIME charset '" + mimeCharset
+                        + "' does not support encoding", "Using "
                         + FALLBACK_CHARSET + " instead.");
+            }
             return FALLBACK_CHARSET;
         }
 
         if (!forEncoding && !CharsetUtil.isDecodingSupported(charset)) {
-            if (log.isWarnEnabled())
-                log.warn("MIME charset '" + mimeCharset
-                        + "' does not support decoding. Using "
+            if (monitor.isListening()) {
+                monitor.warn(
+                        "MIME charset '" + mimeCharset
+                        + "' does not support decoding", "Using "
                         + FALLBACK_CHARSET + " instead.");
+            }
             return FALLBACK_CHARSET;
         }
 

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java?rev=907006&r1=907005&r2=907006&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/MessageBuilder.java
Fri Feb  5 17:11:35 2010
@@ -59,11 +59,14 @@
         this(entity, storageProvider, LoggingMonitor.MONITOR);
     }
     
-    public MessageBuilder(Entity entity, StorageProvider storageProvider, DecodeMonitor monitor)
{
+    public MessageBuilder(
+            final Entity entity, 
+            final StorageProvider storageProvider, 
+            final DecodeMonitor monitor) {
         this.entity = entity;
-        this.bodyFactory = new BodyFactory(storageProvider);
         this.stack = new Stack<Object>();
         this.monitor = monitor != null ? monitor : LoggingMonitor.MONITOR;
+        this.bodyFactory = new BodyFactory(storageProvider, this.monitor);
     }
     
     private void expect(Class<?> c) {

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/storage/DefaultStorageProvider.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/storage/DefaultStorageProvider.java?rev=907006&r1=907005&r2=907006&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/storage/DefaultStorageProvider.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/storage/DefaultStorageProvider.java
Fri Feb  5 17:11:35 2010
@@ -19,9 +19,6 @@
 
 package org.apache.james.mime4j.storage;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 /**
  * Allows for a default {@link StorageProvider} instance to be configured on an
  * application level.
@@ -41,8 +38,6 @@
     public static final String DEFAULT_STORAGE_PROVIDER_PROPERTY =
         "org.apache.james.mime4j.defaultStorageProvider";
 
-    private static Log log = LogFactory.getLog(DefaultStorageProvider.class);
-
     private static volatile StorageProvider instance = null;
 
     static {
@@ -82,10 +77,7 @@
                 instance = (StorageProvider) Class.forName(clazz).newInstance();
             }
         } catch (Exception e) {
-            log.warn("Unable to create or instantiate StorageProvider class '"
-                    + clazz + "'. Using default instead.", e);
         }
-
         if (instance == null) {
             StorageProvider backend = new TempFileStorageProvider();
             instance = new ThresholdStorageProvider(backend, 1024);

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java?rev=907006&r1=907005&r2=907006&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java
(original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentDispositionFieldTest.java
Fri Feb  5 17:11:35 2010
@@ -25,16 +25,9 @@
 
 import org.apache.james.mime4j.dom.field.ContentDispositionField;
 import org.apache.james.mime4j.field.DefaultFieldParser;
-import org.apache.log4j.BasicConfigurator;
 
 public class ContentDispositionFieldTest extends TestCase {
 
-    @Override
-    public void setUp() {
-        BasicConfigurator.resetConfiguration();
-        BasicConfigurator.configure();
-    }
-
     public void testDispositionTypeWithSemiColonNoParams() throws Exception {
         ContentDispositionField f = null;
 

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java?rev=907006&r1=907005&r2=907006&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java
(original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentTypeFieldTest.java
Fri Feb  5 17:11:35 2010
@@ -22,18 +22,11 @@
 import org.apache.james.mime4j.dom.field.ContentTypeField;
 import org.apache.james.mime4j.field.ContentTypeFieldImpl;
 import org.apache.james.mime4j.field.DefaultFieldParser;
-import org.apache.log4j.BasicConfigurator;
 
 import junit.framework.TestCase;
 
 public class ContentTypeFieldTest extends TestCase {
 
-    @Override
-    public void setUp() {
-        BasicConfigurator.resetConfiguration();
-        BasicConfigurator.configure();
-    }
-    
     public void testMimeTypeWithSemiColonNoParams() throws Exception  {
         ContentTypeField f = null;
         



Mime
View raw message