james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r895498 - in /james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j: field/impl/ message/impl/ parser/ parser/impl/
Date Sun, 03 Jan 2010 22:33:00 GMT
Author: bago
Date: Sun Jan  3 22:32:58 2010
New Revision: 895498

URL: http://svn.apache.org/viewvc?rev=895498&view=rev
Log:
Introduced DecodeMonitor as optional parameter for the entry points (DefaultFieldParser, MessageImpl,
MimeStreamParser, MimeTokenStream). (MIME4J-158)

Modified:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageBuilder.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeStreamParser.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeTokenStream.java

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java?rev=895498&r1=895497&r2=895498&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
Sun Jan  3 22:32:58 2010
@@ -20,6 +20,7 @@
 package org.apache.james.mime4j.field.impl;
 
 import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.impl.AddressListFieldImpl;
 import org.apache.james.mime4j.field.impl.ContentDispositionFieldImpl;
 import org.apache.james.mime4j.field.impl.ContentTransferEncodingFieldImpl;
@@ -56,14 +57,18 @@
      * their corresponding classes.
      * 
      * @param raw the bytes to parse.
+     * @param monitor a DecodeMonitor object used while parsing/decoding.
      * @return a <code>ParsedField</code> instance.
      * @throws MimeException if the raw string cannot be split into field name and body.
      */
-    public static ParsedField parse(final ByteSequence raw) throws MimeException {
+    public static ParsedField parse(final ByteSequence raw, DecodeMonitor monitor) throws
MimeException {
     	RawField rawField = new RawField(raw);
-        return PARSER.parse(rawField.getName(), rawField.getBody(), raw, LoggingMonitor.MONITOR);
+        return PARSER.parse(rawField.getName(), rawField.getBody(), raw, monitor);
     }
 
+    public static ParsedField parse(final ByteSequence raw) throws MimeException {
+        return parse(raw, LoggingMonitor.MONITOR);
+    }
 
     /**
      * Parses the given string and returns an instance of the 

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=895498&r1=895497&r2=895498&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
Sun Jan  3 22:32:58 2010
@@ -24,8 +24,10 @@
 import java.util.Stack;
 
 import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.field.impl.DefaultFieldParser;
+import org.apache.james.mime4j.field.impl.LoggingMonitor;
 import org.apache.james.mime4j.message.Body;
 import org.apache.james.mime4j.message.Entity;
 import org.apache.james.mime4j.message.Header;
@@ -48,15 +50,20 @@
     private final Entity entity;
     private final BodyFactory bodyFactory;
     private Stack<Object> stack = new Stack<Object>();
+    private final DecodeMonitor monitor;
     
     public MessageBuilder(Entity entity) {
-        this.entity = entity;
-        this.bodyFactory = new BodyFactory();
+        this(entity, null);
     }
     
     public MessageBuilder(Entity entity, StorageProvider storageProvider) {
+        this(entity, storageProvider, LoggingMonitor.MONITOR);
+    }
+    
+    public MessageBuilder(Entity entity, StorageProvider storageProvider, DecodeMonitor monitor)
{
         this.entity = entity;
         this.bodyFactory = new BodyFactory(storageProvider);
+        this.monitor = monitor != null ? monitor : LoggingMonitor.MONITOR;
     }
     
     private void expect(Class<?> c) {
@@ -101,7 +108,7 @@
      */
     public void field(RawField field) throws MimeException {
         expect(Header.class);
-        Field parsedField = DefaultFieldParser.parse(field.getRaw()); 
+        Field parsedField = DefaultFieldParser.parse(field.getRaw(), monitor); 
         ((Header) stack.peek()).addField(parsedField);
     }
     

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageImpl.java?rev=895498&r1=895497&r2=895498&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageImpl.java
Sun Jan  3 22:32:58 2010
@@ -29,6 +29,7 @@
 
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.MimeIOException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.field.AddressListField;
 import org.apache.james.mime4j.field.ContentDispositionField;
 import org.apache.james.mime4j.field.ContentTransferEncodingField;
@@ -43,6 +44,7 @@
 import org.apache.james.mime4j.field.impl.ContentTransferEncodingFieldImpl;
 import org.apache.james.mime4j.field.impl.ContentTypeFieldImpl;
 import org.apache.james.mime4j.field.impl.Fields;
+import org.apache.james.mime4j.field.impl.LoggingMonitor;
 import org.apache.james.mime4j.message.Body;
 import org.apache.james.mime4j.message.Header;
 import org.apache.james.mime4j.message.Message;
@@ -64,6 +66,8 @@
  */
 public class MessageImpl extends Message {
 
+    private DecodeMonitor monitor;
+
     /**
      * Creates a new empty <code>Message</code>.
      */
@@ -147,18 +151,24 @@
      *             on MIME protocol violations.
      */
     public MessageImpl(InputStream is, MimeEntityConfig config,
-            StorageProvider storageProvider) throws IOException,
+            StorageProvider storageProvider, DecodeMonitor monitor) throws IOException,
             MimeIOException {
         try {
-            MimeStreamParser parser = new MimeStreamParser(config);
+            MimeStreamParser parser = new MimeStreamParser(config, monitor);
             parser.setContentDecoding(true);
-            parser.setContentHandler(new MessageBuilder(this, storageProvider));
+            this.monitor = monitor != null ? monitor : LoggingMonitor.MONITOR;
+            parser.setContentHandler(new MessageBuilder(this, storageProvider, this.monitor));
             parser.parse(is);
         } catch (MimeException e) {
             throw new MimeIOException(e);
         }
     }
 
+    public MessageImpl(InputStream is, MimeEntityConfig config,
+            StorageProvider storageProvider) throws IOException, MimeIOException {
+        this(is, config, storageProvider, LoggingMonitor.MONITOR);
+    }
+
     /**
      * @see org.apache.james.mime4j.message.impl.Message#writeTo(java.io.OutputStream)
      */

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java?rev=895498&r1=895497&r2=895498&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/BasicMimeTokenStream.java
Sun Jan  3 22:32:58 2010
@@ -81,6 +81,7 @@
     private EntityStateMachine currentStateMachine;
     private int recursionMode = M_RECURSE;
 	private MimeEntity rootentity;
+    private final DecodeMonitor monitor;
     
     /**
      * Constructs a standard (lax) stream.
@@ -91,19 +92,19 @@
     public BasicMimeTokenStream() {
         this(new MimeEntityConfig());
     }
-    
+
     public BasicMimeTokenStream(final MimeEntityConfig config) {
+        this(config, null);
+    }
+        
+    public BasicMimeTokenStream(final MimeEntityConfig config, DecodeMonitor monitor) {
         super();
         this.config = config;
+        this.monitor = monitor != null ? monitor : (config.isStrictParsing() ? DecodeMonitor.STRICT
: DecodeMonitor.SILENT);
     }
 
     public void doParse(InputStream stream,
             MutableBodyDescriptor newBodyDescriptor, int start) {
-        doParse(stream, newBodyDescriptor, start, config.isStrictParsing() ? DecodeMonitor.STRICT
: DecodeMonitor.SILENT);
-    }
-    
-    public void doParse(InputStream stream,
-            MutableBodyDescriptor newBodyDescriptor, int start, DecodeMonitor monitor) {
         LineNumberSource lineSource = null;
         if (config.isCountLineNumbers()) {
             LineNumberInputStream lineInput = new LineNumberInputStream(stream);

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeStreamParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeStreamParser.java?rev=895498&r1=895497&r2=895498&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeStreamParser.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeStreamParser.java
Sun Jan  3 22:32:58 2010
@@ -25,6 +25,7 @@
 import java.io.SequenceInputStream;
 
 import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.parser.BodyDescriptor;
 import org.apache.james.mime4j.parser.ContentHandler;
 import org.apache.james.mime4j.parser.MimeEntityConfig;
@@ -58,14 +59,22 @@
         this.contentDecoding = false;
     }
 
+    public MimeStreamParser(final MimeEntityConfig config, DecodeMonitor monitor, boolean
clone) {
+        this(new MimeTokenStream(clone ? config.clone() : config, monitor));
+    }
+
     public MimeStreamParser(final MimeEntityConfig config, boolean clone) {
-        this(new MimeTokenStream(clone ? config.clone() : config));
+        this(new MimeTokenStream(clone ? config.clone() : config, null));
+    }
+
+    public MimeStreamParser(final MimeEntityConfig config, DecodeMonitor monitor) {
+        this(config != null ? config : new MimeEntityConfig(), monitor, config != null);
     }
 
     public MimeStreamParser(final MimeEntityConfig config) {
-        this(config != null ? config : new MimeEntityConfig(), config != null);
+        this(config, null);
     }
-    
+
     public MimeStreamParser() {
         this(new MimeEntityConfig(), false);
     }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeTokenStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeTokenStream.java?rev=895498&r1=895497&r2=895498&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeTokenStream.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/parser/impl/MimeTokenStream.java
Sun Jan  3 22:32:58 2010
@@ -21,6 +21,7 @@
 
 import java.io.InputStream;
 
+import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.parser.BasicMimeTokenStream;
 import org.apache.james.mime4j.parser.BodyDescriptor;
 import org.apache.james.mime4j.parser.MimeEntityConfig;
@@ -99,10 +100,14 @@
         this(new MimeEntityConfig());
     }
     
-    protected MimeTokenStream(final MimeEntityConfig config) {
-        super(config);
+    public MimeTokenStream(final MimeEntityConfig config) {
+        this(config, null);
     }
     
+    public MimeTokenStream(final MimeEntityConfig config, DecodeMonitor monitor) {
+        super(config, monitor);
+    }
+
     /** Instructs the {@code MimeTokenStream} to parse the given streams contents.
      * If the {@code MimeTokenStream} has already been in use, resets the streams
      * internal state.



Mime
View raw message