FileDocCategorySizeDatePackage
ContentTypeField.javaAPI DocAndroid 1.5 API9534Wed May 06 22:42:46 BST 2009org.apache.james.mime4j.field

ContentTypeField

public class ContentTypeField extends Field
Represents a Content-Type field.

TODO: Remove dependency on Java 1.4 regexps

version
$Id: ContentTypeField.java,v 1.6 2005/01/27 14:16:31 ntherning Exp $

Fields Summary
public static final String
TYPE_MULTIPART_PREFIX
The prefix of all multipart MIME types.
public static final String
TYPE_MULTIPART_DIGEST
The multipart/digest MIME type.
public static final String
TYPE_TEXT_PLAIN
The text/plain MIME type.
public static final String
TYPE_MESSAGE_RFC822
The message/rfc822 MIME type.
public static final String
PARAM_BOUNDARY
The name of the boundary parameter.
public static final String
PARAM_CHARSET
The name of the charset parameter.
private String
mimeType
private Map
parameters
private org.apache.james.mime4j.field.contenttype.parser.ParseException
parseException
Constructors Summary
protected ContentTypeField(String name, String body, String raw, String mimeType, Map parameters, org.apache.james.mime4j.field.contenttype.parser.ParseException parseException)


                 
        super(name, body, raw);
        this.mimeType = mimeType;
        this.parameters = parameters;
        this.parseException = parseException;
    
Methods Summary
public java.lang.StringgetBoundary()
Gets the value of the boundary parameter if set.

return
the boundary parameter value or null if not set.

        return getParameter(PARAM_BOUNDARY);
    
public java.lang.StringgetCharset()
Gets the value of the charset parameter if set.

return
the charset parameter value or null if not set.

        return getParameter(PARAM_CHARSET);
    
public static java.lang.StringgetCharset(org.apache.james.mime4j.field.ContentTypeField f)
Gets the value of the charset parameter if set for the given field. Returns the default us-ascii if not set or if f is null.

return
the charset parameter value.

        if (f != null) {
            if (f.getCharset() != null && f.getCharset().length() > 0) {
                return f.getCharset();
            }
        }
        return "us-ascii";
    
public java.lang.StringgetMimeType()
Gets the MIME type defined in this Content-Type field.

return
the MIME type or an empty string if not set.

        return mimeType;
    
public static java.lang.StringgetMimeType(org.apache.james.mime4j.field.ContentTypeField child, org.apache.james.mime4j.field.ContentTypeField parent)
Gets the MIME type defined in the child's Content-Type field or derives a MIME type from the parent if child is null or hasn't got a MIME type value set. If child's MIME type is multipart but no boundary has been set the MIME type of child will be derived from the parent.

param
child the child.
param
parent the parent.
return
the MIME type.

        
        if (child == null || child.getMimeType().length() == 0 
                || child.isMultipart() && child.getBoundary() == null) {
            
            if (parent != null && parent.isMimeType(TYPE_MULTIPART_DIGEST)) {
                return TYPE_MESSAGE_RFC822;
            } else {
                return TYPE_TEXT_PLAIN;
            }
        }
        
        return child.getMimeType();
    
public java.lang.StringgetParameter(java.lang.String name)
Gets the value of a parameter. Parameter names are case-insensitive.

param
name the name of the parameter to get.
return
the parameter value or null if not set.

        return parameters != null 
                    ? (String) parameters.get(name.toLowerCase())
                    : null;
    
public java.util.MapgetParameters()
Gets all parameters.

return
the parameters.

        return parameters != null 
                    ? Collections.unmodifiableMap(parameters)
                    : Collections.EMPTY_MAP;
    
public org.apache.james.mime4j.field.contenttype.parser.ParseExceptiongetParseException()
Gets the exception that was raised during parsing of the field value, if any; otherwise, null.

        return parseException;
    
public booleanisMimeType(java.lang.String mimeType)
Determines if the MIME type of this field matches the given one.

param
mimeType the MIME type to match against.
return
true if the MIME type of this field matches, false otherwise.

        return this.mimeType.equalsIgnoreCase(mimeType);
    
public booleanisMultipart()
Determines if the MIME type of this field is multipart/*.

return
true if this field is has a multipart/* MIME type, false otherwise.

        return mimeType.startsWith(TYPE_MULTIPART_PREFIX);