[6785] | 1 | /**************************************************************** |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one * |
---|
| 3 | * or more contributor license agreements. See the NOTICE file * |
---|
| 4 | * distributed with this work for additional information * |
---|
| 5 | * regarding copyright ownership. The ASF licenses this file * |
---|
| 6 | * to you under the Apache License, Version 2.0 (the * |
---|
| 7 | * "License"); you may not use this file except in compliance * |
---|
| 8 | * with the License. You may obtain a copy of the License at * |
---|
| 9 | * * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 * |
---|
| 11 | * * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, * |
---|
| 13 | * software distributed under the License is distributed on an * |
---|
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * |
---|
| 15 | * KIND, either express or implied. See the License for the * |
---|
| 16 | * specific language governing permissions and limitations * |
---|
| 17 | * under the License. * |
---|
| 18 | ****************************************************************/ |
---|
| 19 | |
---|
| 20 | package org.apache.james.mime4j.message; |
---|
| 21 | |
---|
| 22 | import java.io.IOException; |
---|
| 23 | import java.io.InputStream; |
---|
| 24 | |
---|
| 25 | import org.apache.james.mime4j.MimeException; |
---|
| 26 | import org.apache.james.mime4j.codec.DecodeMonitor; |
---|
| 27 | import org.apache.james.mime4j.dom.Message; |
---|
| 28 | import org.apache.james.mime4j.dom.MessageBuilder; |
---|
| 29 | import org.apache.james.mime4j.stream.MimeEntityConfig; |
---|
| 30 | import org.apache.james.mime4j.stream.MutableBodyDescriptorFactory; |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * Default MessageBuilder implementation delegating Message parsing to the "legacy" |
---|
| 34 | * MessageImpl object. |
---|
| 35 | */ |
---|
| 36 | public class MessageBuilderImpl implements MessageBuilder { |
---|
| 37 | |
---|
| 38 | private MimeBuilder mimeBuilder = null; |
---|
| 39 | private BodyFactory bodyFactory = null; |
---|
| 40 | private MimeEntityConfig mimeEntityConfig = null; |
---|
| 41 | private MutableBodyDescriptorFactory mutableBodyDescriptorFactory = null; |
---|
| 42 | private boolean contentDecoding = true; |
---|
| 43 | private boolean flatMode = false; |
---|
| 44 | private DecodeMonitor decodeMonitor = null; |
---|
| 45 | |
---|
| 46 | public MessageBuilderImpl() { |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | public Message newMessage() { |
---|
| 50 | return new MessageImpl(); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | private MimeBuilder getMimeBuilder() { |
---|
| 54 | if (this.mimeBuilder != null) { |
---|
| 55 | return this.mimeBuilder; |
---|
| 56 | } else { |
---|
| 57 | return MimeBuilder.DEFAULT; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | public Message newMessage(Message source) { |
---|
| 63 | return getMimeBuilder().copy(source); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | public Message parse(InputStream source) throws MimeException, IOException { |
---|
| 67 | return getMimeBuilder().parse(source, |
---|
| 68 | mimeEntityConfig, |
---|
| 69 | decodeMonitor, |
---|
| 70 | bodyFactory, |
---|
| 71 | mutableBodyDescriptorFactory, |
---|
| 72 | contentDecoding, |
---|
| 73 | flatMode); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | public void setBodyFactory(BodyFactory bodyFactory) { |
---|
| 77 | this.bodyFactory = bodyFactory; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | public void setMimeEntityConfig(MimeEntityConfig mimeEntityConfig) { |
---|
| 81 | this.mimeEntityConfig = mimeEntityConfig; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | public void setMutableBodyDescriptorFactory( |
---|
| 85 | MutableBodyDescriptorFactory mutableBodyDescriptorFactory) { |
---|
| 86 | this.mutableBodyDescriptorFactory = mutableBodyDescriptorFactory; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public void setMimeBuilder(MimeBuilder mimeBuilder) { |
---|
| 90 | this.mimeBuilder = mimeBuilder; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | public void setDecodeMonitor(DecodeMonitor decodeMonitor) { |
---|
| 94 | this.decodeMonitor = decodeMonitor; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | public void setContentDecoding(boolean contentDecoding) { |
---|
| 98 | this.contentDecoding = contentDecoding; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | public void setFlatMode(boolean flatMode) { |
---|
| 102 | this.flatMode = flatMode; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | } |
---|