org.ceryle.util
Class MIME

java.lang.Object
  extended by org.ceryle.util.MIME

public class MIME
extends Object

Defines a set of enumerated type objects used to indicate MIME types. Each object has a method to return its canonical string identifier as well as a default file extension. This is neither intended to be standard nor exhaustive, nor is it internationalized since that creates unwanted dependencies for what is meant to be a simple utility class.

For more information: MIME

This class also includes a number of static utility methods used for conversion and determination of MIME types from Strings.

Since:
JDK1.2
Version:
$Id: MIME.java,v 3.8 2007-06-20 01:28:31 altheim Exp $
Author:
Murray Altheim

Field Summary
static MIME DOCBOOK
          Indicates the MIME type for DocBook XML, "application/docbook+xml", (file extension ".xml").
static MIME GIF
          Indicates the MIME type for GIF, "image/gif", (file extension ".gif").
static MIME HTML
          Indicates the MIME type for HTML, "text/html", (file extension ".html" or ".htm").
static MIME JPEG
          Indicates the MIME type for JPEG, "image/jpeg", (file extension ".jpg").
static MIME JSP
          Indicates the MIME type for JSP, "application/jsp", (file extension ".jsp").
static MIME JSPWIKI
          Indicates the (unofficial) MIME type for Wiki text, "application/x-wiki+jspwiki", (file extension ".txt" or ".wik").
static MIME LTM
          Indicates the (unofficial) MIME type for LTM text, "text/x-ltm", (file extension ".ltm").
static MIME PDF
          Indicates the MIME type for PDF, "application/pdf", (file extension ".pdf").
static MIME PNG
          Indicates the MIME type for PNG, "image/png", (file extension ".png").
static MIME PS
          Indicates the MIME type for Postscript, "application/postscript", (file extension ".ps").
static MIME TEXT
          Indicates the MIME type for plain text, "text/plain", (file extension ".txt").
static MIME UNKNOWN
          Indicates an unknown MIME type.
static MIME WIKI
          Indicates the (unofficial) MIME type for Wiki text, "text/wiki", (file extension ".txt" or ".wik").
static MIME XHTML
          Indicates the MIME type for XHTML, "application/xhtml+xml", (file extension ".xhtml", though more commonly just ".html" or ".htm").
static MIME XML
          Indicates the MIME type for XML, "application/xml", (file extension ".xml").
static MIME XTM
          Indicates the (proposed) MIME type for XTM, "application/xtm+xml", (file extension ".xtm").
 
Constructor Summary
MIME(String id, String label, String extension)
          Constructor for a MIME object provided its MIME identifier String, a displayable label, and a String containing its file extension.
MIME(String id, String label, String[] extensions)
          Constructor for a MIME object provided its MIME identifier String, a displayable label, and an array containing one or more file extensions.
 
Method Summary
 String getExtension()
          Returns a String containing the most common MIME type identifier corresponding to this MIME type object.
 String[] getExtensions()
          Returns a String array containing the MIME type identifiers corresponding to this MIME type object.
 String getLabel()
          Returns a displayable String label for this MIME type.
static MIME getMIMEtype(String s)
          A static method that returns the MIME type object (as according to IETF RFC 1521 and 1522) provided with the MIME type String s.
static MIME getMIMETypeFromFileExtension(String ext)
          A static method that returns the MIME type based on file extension String.
static MIME getMIMETypeFromSystemId(String systemId)
          A static method that returns a guess of the MIME type as an int (as according to IETF RFC 1521 and 1522) provided with the system identifier systemId, by checking the file extension.
static boolean isTextFormat(MIME mime)
          Returns true if the MIME parameter is a known text-safe format.
static boolean isXMLFormat(MIME mime)
          Returns true if the MIME parameter is a known XML format.
 String toString()
          Returns a String containing the MIME type identifier corresponding to this MIME type object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEXT

public static final MIME TEXT
Indicates the MIME type for plain text, "text/plain", (file extension ".txt").


JSPWIKI

public static final MIME JSPWIKI
Indicates the (unofficial) MIME type for Wiki text, "application/x-wiki+jspwiki", (file extension ".txt" or ".wik").


WIKI

public static final MIME WIKI
Indicates the (unofficial) MIME type for Wiki text, "text/wiki", (file extension ".txt" or ".wik").


LTM

public static final MIME LTM
Indicates the (unofficial) MIME type for LTM text, "text/x-ltm", (file extension ".ltm").


HTML

public static final MIME HTML
Indicates the MIME type for HTML, "text/html", (file extension ".html" or ".htm").


XML

public static final MIME XML
Indicates the MIME type for XML, "application/xml", (file extension ".xml").


DOCBOOK

public static final MIME DOCBOOK
Indicates the MIME type for DocBook XML, "application/docbook+xml", (file extension ".xml").


XHTML

public static final MIME XHTML
Indicates the MIME type for XHTML, "application/xhtml+xml", (file extension ".xhtml", though more commonly just ".html" or ".htm").


XTM

public static final MIME XTM
Indicates the (proposed) MIME type for XTM, "application/xtm+xml", (file extension ".xtm").


PDF

public static final MIME PDF
Indicates the MIME type for PDF, "application/pdf", (file extension ".pdf").


JSP

public static final MIME JSP
Indicates the MIME type for JSP, "application/jsp", (file extension ".jsp").


PS

public static final MIME PS
Indicates the MIME type for Postscript, "application/postscript", (file extension ".ps").


GIF

public static final MIME GIF
Indicates the MIME type for GIF, "image/gif", (file extension ".gif").


PNG

public static final MIME PNG
Indicates the MIME type for PNG, "image/png", (file extension ".png").


JPEG

public static final MIME JPEG
Indicates the MIME type for JPEG, "image/jpeg", (file extension ".jpg").


UNKNOWN

public static final MIME UNKNOWN
Indicates an unknown MIME type.

Constructor Detail

MIME

public MIME(String id,
            String label,
            String extension)
Constructor for a MIME object provided its MIME identifier String, a displayable label, and a String containing its file extension.


MIME

public MIME(String id,
            String label,
            String[] extensions)
Constructor for a MIME object provided its MIME identifier String, a displayable label, and an array containing one or more file extensions.

Method Detail

toString

public String toString()
Returns a String containing the MIME type identifier corresponding to this MIME type object. E.g., MIME.TEXT.toString() returns "text/plain".

Overrides:
toString in class Object

getLabel

public String getLabel()
Returns a displayable String label for this MIME type.


getExtension

public String getExtension()
Returns a String containing the most common MIME type identifier corresponding to this MIME type object. E.g., MIME.TEXT.getExtension() returns "txt".


getExtensions

public String[] getExtensions()
Returns a String array containing the MIME type identifiers corresponding to this MIME type object. E.g., MIME.TEXT.getExtensions() returns both "txt" and "text".


isTextFormat

public static boolean isTextFormat(MIME mime)
Returns true if the MIME parameter is a known text-safe format. E.g., plaintext, wiki text, or LTM.


isXMLFormat

public static boolean isXMLFormat(MIME mime)
Returns true if the MIME parameter is a known XML format. This is a hardwired list that includes XML, XHTML, and XTM.


getMIMEtype

public static MIME getMIMEtype(String s)
A static method that returns the MIME type object (as according to IETF RFC 1521 and 1522) provided with the MIME type String s. A null or unknown parameter returns MIME.UNKNOWN.


getMIMETypeFromSystemId

public static MIME getMIMETypeFromSystemId(String systemId)
A static method that returns a guess of the MIME type as an int (as according to IETF RFC 1521 and 1522) provided with the system identifier systemId, by checking the file extension.

The list of identified MIME types are defined in this class:

     file extension(s)        returns:
        "*.txt" "*.text"         MIME.TEXT
        "*.xml"                  MIME.XML
        "*.html" "*.htm"         MIME.HTML
        "*.ltm"                  MIME.LTM
        "*.xtm"                  MIME.XTM
        "*.pdf"                  MIME.PDF
        "*.jsp"                  MIME.JSP
        "*.ps"                   MIME.PS
        "*.gif"                  MIME.GIF
        "*.jpg" "*.jpeg"         MIME.JPEG
        otherwise...             MIME.UNKNOWN
 

NOTE: returns MIME.UNKNOWN if the system identifier has more than one hash ("#").


getMIMETypeFromFileExtension

public static MIME getMIMETypeFromFileExtension(String ext)
A static method that returns the MIME type based on file extension String. The parameter should not include the preceding dot.

See Also:
getMIMETypeFromSystemId(String)


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.