001 /****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one *
003 * or more contributor license agreements. See the NOTICE file *
004 * distributed with this work for additional information *
005 * regarding copyright ownership. The ASF licenses this file *
006 * to you under the Apache License, Version 2.0 (the *
007 * "License"); you may not use this file except in compliance *
008 * with the License. You may obtain a copy of the License at *
009 * *
010 * http://www.apache.org/licenses/LICENSE-2.0 *
011 * *
012 * Unless required by applicable law or agreed to in writing, *
013 * software distributed under the License is distributed on an *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015 * KIND, either express or implied. See the License for the *
016 * specific language governing permissions and limitations *
017 * under the License. *
018 ****************************************************************/
019
020 package org.apache.james.mime4j.message;
021
022 import java.util.Date;
023 import java.util.Map;
024
025 import org.apache.james.mime4j.dom.field.ContentDispositionField;
026 import org.apache.james.mime4j.dom.field.ContentTransferEncodingField;
027 import org.apache.james.mime4j.dom.field.ContentTypeField;
028 import org.apache.james.mime4j.field.ContentTransferEncodingFieldImpl;
029 import org.apache.james.mime4j.field.ContentTypeFieldImpl;
030 import org.apache.james.mime4j.field.Fields;
031 import org.apache.james.mime4j.util.MimeUtil;
032
033 /**
034 * A MIME body part (as defined in RFC 2045).
035 */
036 public class BodyPart extends AbstractEntity {
037
038 /**
039 * Creates a new empty <code>BodyPart</code>.
040 */
041 public BodyPart() {
042 }
043
044 @Override
045 protected String newUniqueBoundary() {
046 return MimeUtil.createUniqueBoundary();
047 }
048
049 @Override
050 protected ContentDispositionField newContentDisposition(
051 String dispositionType, String filename, long size,
052 Date creationDate, Date modificationDate, Date readDate) {
053 return Fields.contentDisposition(dispositionType, filename, size,
054 creationDate, modificationDate, readDate);
055 }
056
057 @Override
058 protected ContentDispositionField newContentDisposition(
059 String dispositionType, Map<String, String> parameters) {
060 return Fields.contentDisposition(dispositionType, parameters);
061 }
062
063 @Override
064 protected ContentTypeField newContentType(String mimeType,
065 Map<String, String> parameters) {
066 return Fields.contentType(mimeType, parameters);
067 }
068
069 @Override
070 protected ContentTransferEncodingField newContentTransferEncoding(
071 String contentTransferEncoding) {
072 return Fields.contentTransferEncoding(contentTransferEncoding);
073 }
074
075 @Override
076 protected String calcTransferEncoding(ContentTransferEncodingField f) {
077 return ContentTransferEncodingFieldImpl.getEncoding(f);
078 }
079
080 @Override
081 protected String calcMimeType(ContentTypeField child, ContentTypeField parent) {
082 return ContentTypeFieldImpl.getMimeType(child, parent);
083 }
084
085 @Override
086 protected String calcCharset(ContentTypeField contentType) {
087 return ContentTypeFieldImpl.getCharset(contentType);
088 }
089
090 }