source: contrib/MailArchiver/sources/vendor/mime4j/custom/dom/src/main/java/org/apache/james/mime4j/message/MessageServiceFactoryImpl.java @ 6785

Revision 6785, 4.5 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

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