de.fu_berlin.ties.io
Class ContentType

java.lang.Object
  extended by de.fu_berlin.ties.io.ContentType

public final class ContentType
extends Object

A simple wrapper for the MIME type and the character set of a document.

Version:
$Revision: 1.5 $, $Date: 2006/10/21 16:04:21 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
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.
 
Method Summary
static ContentType determineContentType(File file, TiesConfiguration config)
          Determines the content type based on a file name.
static ContentType determineContentType(URL url, String contentTypeHeader, TiesConfiguration config)
          Helper method to determines the content type based an "Content-Type" header and/or URL extension.
 String getCharset()
          Returns the character set.
 String getMimeType()
          Returns the MIME 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
Method Detail

determineContentType

public static ContentType determineContentType(File file,
                                               TiesConfiguration config)
Determines the content type based on a file name.

Parameters:
file - the file name
config - the configuration to use
Returns:
the determined content type

determineContentType

public static ContentType determineContentType(URL url,
                                               String contentTypeHeader,
                                               TiesConfiguration config)
Helper method to determines the content type based an "Content-Type" header and/or URL extension. The "Content-Type" header is examined first, if it is specified (not null or empty). If this does not lead to a result, the extension of the URL is examined.

Parameters:
url - the URL (might be null)
contentTypeHeader - the "Content-Type" header of an URL, as returned by URLConnection.getContentType() (might be null)
config - the configuration to use
Returns:
the determined content type

getCharset

public String getCharset()
Returns the character set.

Returns:
the character set, or null if unknown

getMimeType

public String getMimeType()
Returns the MIME type.

Returns:
the MIME type, or null if unknown

toString

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

Overrides:
toString in class Object
Returns:
a textual representation


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