Permalink
Browse files

Moved DefaultBodyDescriptor to the stream package as requested by Ole…

…g (MIME4J-157)

This reintroduce "commons-logging" dependency to the stream package, so this will need a bit more care later, however this is not a big issue, as MIME4J-158 was an ongoing effort, still.

git-svn-id: https://svn.apache.org/repos/asf/james/mime4j/branches/cycleclean@898843 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
Stefano Bagnara
Stefano Bagnara committed Jan 13, 2010
1 parent 4418327 commit 83b728b75bd1bf04b5c91eb2f926c36258b19985
@@ -32,6 +32,7 @@
import org.apache.james.mime4j.field.mimeversion.parser.MimeVersionParser;
import org.apache.james.mime4j.field.structured.parser.StructuredFieldParser;
import org.apache.james.mime4j.stream.BodyDescriptor;
+import org.apache.james.mime4j.stream.DefaultBodyDescriptor;
import org.apache.james.mime4j.stream.MutableBodyDescriptor;
import org.apache.james.mime4j.stream.RawField;
import org.apache.james.mime4j.util.MimeUtil;
@@ -24,9 +24,9 @@
import org.apache.james.mime4j.codec.DecodeMonitor;
import org.apache.james.mime4j.stream.BasicMimeTokenStream;
import org.apache.james.mime4j.stream.BodyDescriptor;
+import org.apache.james.mime4j.stream.DefaultBodyDescriptor;
import org.apache.james.mime4j.stream.MimeEntityConfig;
import org.apache.james.mime4j.stream.MutableBodyDescriptor;
-import org.apache.james.mime4j.stream.RawField;
/**
* <p>
@@ -108,40 +108,6 @@ 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.
- */
- public void parse(InputStream stream) {
- doParse(stream, null);
- }
-
- /** Instructs the {@code MimeTokenStream} to parse the given content with
- * the content type. The message stream is assumed to have no message header
- * and is expected to begin with a message body. This can be the case when
- * the message content is transmitted using a different transport protocol
- * such as HTTP.
- * <p/>
- * If the {@code MimeTokenStream} has already been in use, resets the streams
- * internal state.
- */
- public void parseHeadless(InputStream stream, String contentType) {
- if (contentType == null) {
- throw new IllegalArgumentException("Content type may not be null");
- }
- doParse(stream, contentType);
- }
-
- private void doParse(InputStream stream, String contentType) {
- MutableBodyDescriptor newBodyDescriptor = newBodyDescriptor();
- int start = T_START_MESSAGE;
- if (contentType != null) {
- start = T_END_HEADER;
- newBodyDescriptor.addField(new RawField("Content-Type", contentType));
- }
- doParse(stream, newBodyDescriptor, start);
- }
-
/**
* Creates a new instance of {@link BodyDescriptor}. Subclasses may override
* this in order to create body descriptors, that provide more specific
@@ -103,7 +103,46 @@ public BasicMimeTokenStream(final MimeEntityConfig config, DecodeMonitor monitor
this.monitor = monitor != null ? monitor : (config.isStrictParsing() ? DecodeMonitor.STRICT : DecodeMonitor.SILENT);
}
- public void doParse(InputStream stream,
+
+ /** Instructs the {@code MimeTokenStream} to parse the given streams contents.
+ * If the {@code MimeTokenStream} has already been in use, resets the streams
+ * internal state.
+ */
+ public void parse(InputStream stream) {
+ doParse(stream, null);
+ }
+
+ /** Instructs the {@code MimeTokenStream} to parse the given content with
+ * the content type. The message stream is assumed to have no message header
+ * and is expected to begin with a message body. This can be the case when
+ * the message content is transmitted using a different transport protocol
+ * such as HTTP.
+ * <p/>
+ * If the {@code MimeTokenStream} has already been in use, resets the streams
+ * internal state.
+ */
+ public void parseHeadless(InputStream stream, String contentType) {
+ if (contentType == null) {
+ throw new IllegalArgumentException("Content type may not be null");
+ }
+ doParse(stream, contentType);
+ }
+
+ protected void doParse(InputStream stream, String contentType) {
+ MutableBodyDescriptor newBodyDescriptor = newBodyDescriptor();
+ int start = T_START_MESSAGE;
+ if (contentType != null) {
+ start = T_END_HEADER;
+ newBodyDescriptor.addField(new RawField("Content-Type", contentType));
+ }
+ doParse(stream, newBodyDescriptor, start);
+ }
+
+ protected MutableBodyDescriptor newBodyDescriptor() {
+ return new DefaultBodyDescriptor(null);
+ }
+
+ public void doParse(InputStream stream,
MutableBodyDescriptor newBodyDescriptor, int start) {
LineNumberSource lineSource = null;
if (config.isCountLineNumbers()) {
@@ -17,16 +17,13 @@
* under the License. *
****************************************************************/
-package org.apache.james.mime4j.parser;
+package org.apache.james.mime4j.stream;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.james.mime4j.stream.BodyDescriptor;
-import org.apache.james.mime4j.stream.MutableBodyDescriptor;
-import org.apache.james.mime4j.stream.RawField;
import org.apache.james.mime4j.util.MimeUtil;
/**
@@ -20,7 +20,6 @@
package org.apache.james.mime4j.stream;
import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.parser.DefaultBodyDescriptor;
import org.apache.james.mime4j.parser.MaximalBodyDescriptor;
import org.apache.james.mime4j.parser.MimeStreamParser;
import org.apache.james.mime4j.parser.MimeTokenStream;
@@ -19,9 +19,9 @@
package org.apache.james.mime4j.parser;
-import org.apache.james.mime4j.parser.DefaultBodyDescriptor;
import org.apache.james.mime4j.stream.BaseTestForBodyDescriptors;
import org.apache.james.mime4j.stream.BodyDescriptor;
+import org.apache.james.mime4j.stream.DefaultBodyDescriptor;
import org.apache.james.mime4j.stream.MutableBodyDescriptor;
public class DefaultBodyDescriptorTest extends BaseTestForBodyDescriptors {
@@ -29,7 +29,6 @@
import org.apache.james.mime4j.io.MaxHeaderLimitException;
import org.apache.james.mime4j.io.MaxLineLimitException;
import org.apache.james.mime4j.io.LineNumberInputStream;
-import org.apache.james.mime4j.parser.DefaultBodyDescriptor;
import org.apache.james.mime4j.stream.EntityStateMachine;
import org.apache.james.mime4j.stream.EntityStates;
import org.apache.james.mime4j.stream.MimeEntity;

0 comments on commit 83b728b

Please sign in to comment.