de.fu_berlin.ties.io
Class ContentType

java.lang.Object
  extended byde.fu_berlin.ties.io.ContentType

public final class ContentType
extends Object

A type-safe enumeration of content types handled by the system.

Version:
$Revision: 1.1 $, $Date: 2004/02/02 18:49:56 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
static ContentType HTML
          Type used for HTML markup (both classical HTML and XHTML).
static String KEY_MIME_TYPE
          Context key recommended to store the MIME type string.
static String MIME_HTML
          MIME type for HTML.
static String MIME_PLAIN
          MIME type for plain text.
static ContentType MS_WORD
          Type used for MS Word documents.
static ContentType PDF
          Type used for PDF documents (Adobe Acrobat).
static ContentType PLAIN_TEXT
          Type used for plain text content (without any markup).
static ContentType RTF
          Type used for rich text format.
static ContentType UNKNOWN
          Type used for any other content or content whose type cannot be determined.
static ContentType URI_LIST
          Type used for lists of URIs or URLs, as defined in RFC 2483.
static ContentType XML
          Type used for XML markup.
 
Method Summary
static ContentType determineContentType(String mimeType, File file)
          Determines the content type based an MIME type and/or file name.
static ContentType determineContentType(String mimeType, URL url)
          Determines the content type based an MIME type and/or URL.
 boolean extensionMatches(String extension)
          Whether a specified file name extension is contained in the set of file name extensions typical for this content type.
 String getDefaultMimeType()
          Returns the most common MIME type used for documents of this type
 String getName()
          Returns the identifier of this content type.
static void main(String[] args)
          Some test cases.
 boolean mimeTokenMatches(String token)
          Whether a specified MIME type token is contained in the set of MIME type tokens typical for this content type.
 String toString()
          Returns a String representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_MIME_TYPE

public static final String KEY_MIME_TYPE
Context key recommended to store the MIME type string.

See Also:
Constant Field Values

MIME_HTML

public static final String MIME_HTML
MIME type for HTML.

See Also:
Constant Field Values

MIME_PLAIN

public static final String MIME_PLAIN
MIME type for plain text.

See Also:
Constant Field Values

HTML

public static final ContentType HTML
Type used for HTML markup (both classical HTML and XHTML).


MS_WORD

public static final ContentType MS_WORD
Type used for MS Word documents.


PDF

public static final ContentType PDF
Type used for PDF documents (Adobe Acrobat).


PLAIN_TEXT

public static final ContentType PLAIN_TEXT
Type used for plain text content (without any markup).


RTF

public static final ContentType RTF
Type used for rich text format.


URI_LIST

public static final ContentType URI_LIST
Type used for lists of URIs or URLs, as defined in RFC 2483.


XML

public static final ContentType XML
Type used for XML markup. Used for any kind of XML, except XHTML where the type HTML is used instead (this works as this type is defined after the HTML type -- the first match is used).


UNKNOWN

public static final ContentType UNKNOWN
Type used for any other content or content whose type cannot be determined.

Method Detail

determineContentType

public static ContentType determineContentType(String mimeType,
                                               File file)
Determines the content type based an MIME type and/or file name. The MIME type is examined first, if it is specified (not null or empty). If this does not lead to a result, the file name is examined. If neither MIME type nor extension match a content type, UNKNOWN is returned.

Parameters:
mimeType - the MIME type (might be null); the full list of MIME types is available at www.iana.org/assignments/media-types
file - the file name (might be null)
Returns:
the determined content type; or UNKNOWN if no identification was possible

determineContentType

public static ContentType determineContentType(String mimeType,
                                               URL url)
Determines the content type based an MIME type and/or URL. The MIME type is examined first, if it is specified (not null or empty). If this does not lead to a result, the URL is examined. If neither MIME type nor URL match a content type, UNKNOWN is returned.

Parameters:
mimeType - the MIME type (might be null); the full list of MIME types is available at www.iana.org/assignments/media-types
url - the URL (might be null)
Returns:
the determined content type; or UNKNOWN if no identification was possible

main

public static void main(String[] args)
Some test cases.

Parameters:
args - the command-line parameters (ignored)

extensionMatches

public boolean extensionMatches(String extension)
Whether a specified file name extension is contained in the set of file name extensions typical for this content type.

Parameters:
extension - the file name extension to inspect
Returns:
true iff the extension is typical for this content type

getDefaultMimeType

public String getDefaultMimeType()
Returns the most common MIME type used for documents of this type

Returns:
the default MIME type

getName

public String getName()
Returns the identifier of this content type.

Returns:
the identifier

mimeTokenMatches

public boolean mimeTokenMatches(String token)
Whether a specified MIME type token is contained in the set of MIME type tokens typical for this content type.

Parameters:
token - the MIME type token to inspect
Returns:
true iff the token is typical for this content type

toString

public String toString()
Returns a String representation of this object.

Returns:
a string representation of this object


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.