~ubuntu-branches/ubuntu/utopic/apache-mime4j/utopic

« back to all changes in this revision

Viewing changes to dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java

  • Committer: Package Import Robot
  • Author(s): David Paleino
  • Date: 2013-11-03 11:13:27 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20131103111327-09huep00ex05z113
Tags: 0.7.2-2
* Upload to unstable
* Fixed Vcs-* fields in debian/control
* Updated debian/watch
* Standards-Version bump to 3.9.5, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
package org.apache.james.mime4j.message;
 
20
 
 
21
import org.apache.james.mime4j.codec.DecodeMonitor;
 
22
import org.apache.james.mime4j.dom.MessageBuilder;
 
23
import org.apache.james.mime4j.dom.MessageServiceFactory;
 
24
import org.apache.james.mime4j.dom.MessageWriter;
 
25
import org.apache.james.mime4j.stream.BodyDescriptorBuilder;
 
26
import org.apache.james.mime4j.stream.MimeConfig;
 
27
 
 
28
/**
 
29
 * The default MessageBuilderFactory bundled with Mime4j.
 
30
 *
 
31
 * Supports the "StorageProvider", "MimeEntityConfig" and "MutableBodyDescriptorFactory"
 
32
 * attributes.
 
33
 */
 
34
public class MessageServiceFactoryImpl extends MessageServiceFactory {
 
35
 
 
36
    private BodyFactory bodyFactory = null;
 
37
    private MimeConfig mimeEntityConfig = null;
 
38
    private BodyDescriptorBuilder bodyDescriptorBuilder = null;
 
39
    private DecodeMonitor decodeMonitor = null;
 
40
    private Boolean flatMode = null;
 
41
    private Boolean contentDecoding = null;
 
42
 
 
43
    @Override
 
44
    public MessageBuilder newMessageBuilder() {
 
45
        DefaultMessageBuilder m = new DefaultMessageBuilder();
 
46
        if (bodyFactory != null) m.setBodyFactory(bodyFactory);
 
47
        if (mimeEntityConfig != null) m.setMimeEntityConfig(mimeEntityConfig);
 
48
        if (bodyDescriptorBuilder != null) m.setBodyDescriptorBuilder(bodyDescriptorBuilder);
 
49
        if (flatMode != null) m.setFlatMode(flatMode.booleanValue());
 
50
        if (contentDecoding != null) m.setContentDecoding(contentDecoding.booleanValue());
 
51
        if (decodeMonitor != null) m.setDecodeMonitor(decodeMonitor);
 
52
        return m;
 
53
    }
 
54
 
 
55
    @Override
 
56
    public MessageWriter newMessageWriter() {
 
57
        return new DefaultMessageWriter();
 
58
    }
 
59
 
 
60
    @Override
 
61
    public void setAttribute(String name, Object value)
 
62
            throws IllegalArgumentException {
 
63
        if ("BodyFactory".equals(name)) {
 
64
            if (value instanceof BodyFactory) {
 
65
                this.bodyFactory  = (BodyFactory) value;
 
66
                return;
 
67
            } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a BodyFactory");
 
68
        } else if ("MimeEntityConfig".equals(name)) {
 
69
            if (value instanceof MimeConfig) {
 
70
                this.mimeEntityConfig = (MimeConfig) value;
 
71
                return;
 
72
            } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a MimeConfig");
 
73
        } else if ("MutableBodyDescriptorFactory".equals(name)) {
 
74
            if (value instanceof BodyDescriptorBuilder) {
 
75
                this.bodyDescriptorBuilder  = (BodyDescriptorBuilder) value;
 
76
                return;
 
77
            } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a MutableBodyDescriptorFactory");
 
78
        } else if ("DecodeMonitor".equals(name)) {
 
79
            if (value instanceof DecodeMonitor) {
 
80
                this.decodeMonitor = (DecodeMonitor) value;
 
81
                return;
 
82
            } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a DecodeMonitor");
 
83
        } else if ("FlatMode".equals(name)) {
 
84
            if (value instanceof Boolean) {
 
85
                this.flatMode  = (Boolean) value;
 
86
                return;
 
87
            } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a Boolean");
 
88
        } else if ("ContentDecoding".equals(name)) {
 
89
            if (value instanceof Boolean) {
 
90
                this.contentDecoding = (Boolean) value;
 
91
                return;
 
92
            } else throw new IllegalArgumentException("Unsupported attribute value type for "+name+", expected a Boolean");
 
93
        }
 
94
 
 
95
        throw new IllegalArgumentException("Unsupported attribute: "+name);
 
96
 
 
97
    }
 
98
 
 
99
}