summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/java/net/MimeTypeMapper.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/net/MimeTypeMapper.java')
-rw-r--r--libjava/classpath/java/net/MimeTypeMapper.java360
1 files changed, 246 insertions, 114 deletions
diff --git a/libjava/classpath/java/net/MimeTypeMapper.java b/libjava/classpath/java/net/MimeTypeMapper.java
index 1747f4d5685..8153694b483 100644
--- a/libjava/classpath/java/net/MimeTypeMapper.java
+++ b/libjava/classpath/java/net/MimeTypeMapper.java
@@ -37,7 +37,17 @@ exception statement from your version. */
package java.net;
+import gnu.classpath.SystemProperties;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
/**
@@ -56,131 +66,230 @@ class MimeTypeMapper implements FileNameMap
*/
protected static final String[][] mime_strings =
{
- { "application/mac-binhex40", "hqx" },
- { "application/mac-compactpro", "cpt" },
- { "application/msword", "doc" },
- { "application/octet-stream", "bin" },
- { "application/octet-stream", "dms" },
- { "application/octet-stream", "lha" },
- { "application/octet-stream", "lzh" },
- { "application/octet-stream", "exe" },
- { "application/octet-stream", "class" },
- { "application/oda", "oda" },
- { "application/pdf", "pdf" },
- { "application/postscript", "ai" },
- { "application/postscript", "eps" },
- { "application/postscript", "ps" },
- { "application/powerpoint", "ppt" },
- { "application/rtf", "rtf" },
- { "application/x-bcpio", "bcpio" },
- { "application/x-cdlink", "vcd" },
- { "application/x-compress", "Z" },
- { "application/x-cpio", "cpio" },
- { "application/x-csh", "csh" },
- { "application/x-director", "dcr" },
- { "application/x-director", "dir" },
- { "application/x-director", "dxr" },
- { "application/x-dvi", "dvi" },
- { "application/x-gtar", "gtar" },
- { "application/x-gzip", "gz" },
- { "application/x-hdf", "hdf" },
- { "application/x-httpd-cgi", "cgi" },
- { "application/x-koan", "skp" },
- { "application/x-koan", "skd" },
- { "application/x-koan", "skt" },
- { "application/x-koan", "skm" },
- { "application/x-latex", "latex" },
- { "application/x-mif", "mif" },
- { "application/x-netcdf", "nc" },
- { "application/x-netcdf", "cdf" },
- { "application/x-sh", "sh" },
- { "application/x-shar", "shar" },
- { "application/x-stuffit", "sit" },
- { "application/x-sv4cpio", "sv4cpio" },
- { "application/x-sv4crc", "sv4crc" },
- { "application/x-tar", "tar" },
- { "application/x-tcl", "tcl" },
- { "application/x-tex", "tex" },
- { "application/x-texinfo", "texinfo" },
- { "application/x-texinfo", "texi" },
- { "application/x-troff", "t" },
- { "application/x-troff", "tr" },
- { "application/x-troff", "roff" },
- { "application/x-troff-man", "man" },
- { "application/x-troff-me", "me" },
- { "application/x-troff-ms", "ms" },
- { "application/x-ustar", "ustar" },
- { "application/x-wais-source", "src" },
- { "application/zip", "zip" },
- { "audio/basic", "au" },
- { "audio/basic", "snd" },
- { "audio/mpeg", "mpga" },
- { "audio/mpeg", "mp2" },
- { "audio/mpeg", "mp3" },
- { "audio/x-aiff", "aif" },
- { "audio/x-aiff", "aiff" },
- { "audio/x-aiff", "aifc" },
- { "audio/x-pn-realaudio", "ram" },
- { "audio/x-pn-realaudio-plugin", "rpm" },
- { "audio/x-realaudio", "ra" },
- { "audio/x-wav", "wav" },
- { "chemical/x-pdb", "pdb" },
- { "chemical/x-pdb", "xyz" },
- { "image/gif", "gif" },
- { "image/ief", "ief" },
- { "image/jpeg", "jpeg" },
- { "image/jpeg", "jpg" },
- { "image/jpeg", "jpe" },
- { "image/png", "png" },
- { "image/tiff", "tiff" },
- { "image/tiff", "tif" },
- { "image/x-cmu-raster", "ras" },
- { "image/x-portable-anymap", "pnm" },
- { "image/x-portable-bitmap", "pbm" },
- { "image/x-portable-graymap", "pgm" },
- { "image/x-portable-pixmap", "ppm" },
- { "image/x-rgb", "rgb" },
- { "image/x-xbitmap", "xbm" },
- { "image/x-xpixmap", "xpm" },
- { "image/x-xwindowdump", "xwd" },
- { "text/html", "html" },
- { "text/html", "htm" },
- { "text/plain", "txt" },
- { "text/richtext", "rtx" },
- { "text/tab-separated-values", "tsv" },
- { "text/x-setext", "etx" },
- { "text/x-sgml", "sgml" },
- { "text/x-sgml", "sgm" },
- { "video/mpeg", "mpeg" },
- { "video/mpeg", "mpg" },
- { "video/mpeg", "mpe" },
- { "video/quicktime", "qt" },
- { "video/quicktime", "mov" },
- { "video/x-msvideo", "avi" },
- { "video/x-sgi-movie", "movie" },
- { "x-conference/x-cooltalk", "ice" },
- { "x-world/x-vrml", "wrl" },
- { "x-world/x-vrml", "vrml" }
+ { "ai", "application/postscript" }
+ , { "aif", "audio/x-aiff" }
+ , { "aifc", "audio/x-aiff" }
+ , { "aiff", "audio/x-aiff" }
+ , { "asc", "text/plain" }
+ , { "au", "audio/basic" }
+ , { "avi", "video/x-msvideo" }
+ , { "bcpio", "application/x-bcpio" }
+ , { "bin", "application/octet-stream" }
+ , { "bmp", "image/bmp" }
+ , { "bz2", "application/x-bzip2" }
+ , { "cdf", "application/x-netcdf" }
+ , { "chrt", "application/x-kchart" }
+ , { "class", "application/octet-stream" }
+ , { "cpio", "application/x-cpio" }
+ , { "cpt", "application/mac-compactpro" }
+ , { "csh", "application/x-csh" }
+ , { "css", "text/css" }
+ , { "dcr", "application/x-director" }
+ , { "dir", "application/x-director" }
+ , { "djv", "image/vnd.djvu" }
+ , { "djvu", "image/vnd.djvu" }
+ , { "dll", "application/octet-stream" }
+ , { "dms", "application/octet-stream" }
+ , { "doc", "application/msword" }
+ , { "dvi", "application/x-dvi" }
+ , { "dxr", "application/x-director" }
+ , { "eps", "application/postscript" }
+ , { "etx", "text/x-setext" }
+ , { "exe", "application/octet-stream" }
+ , { "ez", "application/andrew-inset" }
+ , { "gif", "image/gif" }
+ , { "gtar", "application/x-gtar" }
+ , { "gz", "application/x-gzip" }
+ , { "hdf", "application/x-hdf" }
+ , { "hqx", "application/mac-binhex40" }
+ , { "htm", "text/html" }
+ , { "html", "text/html" }
+ , { "ice", "x-conference/x-cooltalk" }
+ , { "ief", "image/ief" }
+ , { "iges", "model/iges" }
+ , { "igs", "model/iges" }
+ , { "img", "application/octet-stream" }
+ , { "iso", "application/octet-stream" }
+ , { "jpe", "image/jpeg" }
+ , { "jpeg", "image/jpeg" }
+ , { "jpg", "image/jpeg" }
+ , { "js", "application/x-javascript" }
+ , { "kar", "audio/midi" }
+ , { "kil", "application/x-killustrator" }
+ , { "kpr", "application/x-kpresenter" }
+ , { "kpt", "application/x-kpresenter" }
+ , { "ksp", "application/x-kspread" }
+ , { "kwd", "application/x-kword" }
+ , { "kwt", "application/x-kword" }
+ , { "latex", "application/x-latex" }
+ , { "lha", "application/octet-stream" }
+ , { "lzh", "application/octet-stream" }
+ , { "m3u", "audio/x-mpegurl" }
+ , { "man", "application/x-troff-man" }
+ , { "me", "application/x-troff-me" }
+ , { "mesh", "model/mesh" }
+ , { "mid", "audio/midi" }
+ , { "midi", "audio/midi" }
+ , { "mif", "application/vnd.mif" }
+ , { "mov", "video/quicktime" }
+ , { "movie", "video/x-sgi-movie" }
+ , { "mp2", "audio/mpeg" }
+ , { "mp3", "audio/mpeg" }
+ , { "mpe", "video/mpeg" }
+ , { "mpeg", "video/mpeg" }
+ , { "mpg", "video/mpeg" }
+ , { "mpga", "audio/mpeg" }
+ , { "ms", "application/x-troff-ms" }
+ , { "msh", "model/mesh" }
+ , { "mxu", "video/vnd.mpegurl" }
+ , { "nc", "application/x-netcdf" }
+ , { "ogg", "application/ogg" }
+ , { "pbm", "image/x-portable-bitmap" }
+ , { "pdb", "chemical/x-pdb" }
+ , { "pdf", "application/pdf" }
+ , { "pgm", "image/x-portable-graymap" }
+ , { "pgn", "application/x-chess-pgn" }
+ , { "png", "image/png" }
+ , { "pnm", "image/x-portable-anymap" }
+ , { "ppm", "image/x-portable-pixmap" }
+ , { "ppt", "application/vnd.ms-powerpoint" }
+ , { "ps", "application/postscript" }
+ , { "qt", "video/quicktime" }
+ , { "ra", "audio/x-realaudio" }
+ , { "ram", "audio/x-pn-realaudio" }
+ , { "ras", "image/x-cmu-raster" }
+ , { "rgb", "image/x-rgb" }
+ , { "rm", "audio/x-pn-realaudio" }
+ , { "roff", "application/x-troff" }
+ , { "rpm", "application/x-rpm" }
+ , { "rtf", "text/rtf" }
+ , { "rtx", "text/richtext" }
+ , { "sgm", "text/sgml" }
+ , { "sgml", "text/sgml" }
+ , { "sh", "application/x-sh" }
+ , { "shar", "application/x-shar" }
+ , { "silo", "model/mesh" }
+ , { "sit", "application/x-stuffit" }
+ , { "skd", "application/x-koan" }
+ , { "skm", "application/x-koan" }
+ , { "skp", "application/x-koan" }
+ , { "skt", "application/x-koan" }
+ , { "smi", "application/smil" }
+ , { "smil", "application/smil" }
+ , { "snd", "audio/basic" }
+ , { "so", "application/octet-stream" }
+ , { "spl", "application/x-futuresplash" }
+ , { "src", "application/x-wais-source" }
+ , { "stc", "application/vnd.sun.xml.calc.template" }
+ , { "std", "application/vnd.sun.xml.draw.template" }
+ , { "sti", "application/vnd.sun.xml.impress.template" }
+ , { "stw", "application/vnd.sun.xml.writer.template" }
+ , { "sv4cpio", "application/x-sv4cpio" }
+ , { "sv4crc", "application/x-sv4crc" }
+ , { "swf", "application/x-shockwave-flash" }
+ , { "sxc", "application/vnd.sun.xml.calc" }
+ , { "sxd", "application/vnd.sun.xml.draw" }
+ , { "sxg", "application/vnd.sun.xml.writer.global" }
+ , { "sxi", "application/vnd.sun.xml.impress" }
+ , { "sxm", "application/vnd.sun.xml.math" }
+ , { "sxw", "application/vnd.sun.xml.writer" }
+ , { "t", "application/x-troff" }
+ , { "tar", "application/x-tar" }
+ , { "tcl", "application/x-tcl" }
+ , { "tex", "application/x-tex" }
+ , { "texi", "application/x-texinfo" }
+ , { "texinfo", "application/x-texinfo" }
+ , { "tgz", "application/x-gzip" }
+ , { "tif", "image/tiff" }
+ , { "tiff", "image/tiff" }
+ , { "torrent", "application/x-bittorrent" }
+ , { "tr", "application/x-troff" }
+ , { "tsv", "text/tab-separated-values" }
+ , { "txt", "text/plain" }
+ , { "ustar", "application/x-ustar" }
+ , { "vcd", "application/x-cdlink" }
+ , { "vrml", "model/vrml" }
+ , { "wav", "audio/x-wav" }
+ , { "wbmp", "image/vnd.wap.wbmp" }
+ , { "wbxml", "application/vnd.wap.wbxml" }
+ , { "wml", "text/vnd.wap.wml" }
+ , { "wmlc", "application/vnd.wap.wmlc" }
+ , { "wmls", "text/vnd.wap.wmlscript" }
+ , { "wmlsc", "application/vnd.wap.wmlscriptc" }
+ , { "wrl", "model/vrml" }
+ , { "xbm", "image/x-xbitmap" }
+ , { "xht", "application/xhtml+xml" }
+ , { "xhtml", "application/xhtml+xml" }
+ , { "xls", "application/vnd.ms-excel" }
+ , { "xml", "text/xml" }
+ , { "xpm", "image/x-xpixmap" }
+ , { "xsl", "text/xml" }
+ , { "xwd", "image/x-xwindowdump" }
+ , { "xyz", "chemical/x-xyz" }
+ , { "zip", "application/zip" }
};
/**
* The MIME types above are put into this Hashtable for faster lookup.
*/
- private static Hashtable mime_types = new Hashtable(150);
-
- // Static initializer to load MIME types into Hashtable
- static
- {
- for (int i = 0; i < mime_strings.length; i++)
- mime_types.put(mime_strings[i][1], mime_strings[i][0]);
- }
+ private Hashtable mime_types = new Hashtable(150);
/**
* Create a new <code>MimeTypeMapper</code> object.
*/
public MimeTypeMapper()
{
- // Do nothing here.
+ for (int i = 0; i < mime_strings.length; i++)
+ mime_types.put(mime_strings[i][0], mime_strings[i][1]);
+
+ // Now read from the system mime database, if it exists. Entries found
+ // here override our internal ones.
+ try
+ {
+ // On Linux this usually means /etc/mime.types.
+ String file
+ = SystemProperties.getProperty("gnu.classpath.mime.types.file");
+ if (file != null)
+ fillFromFile(mime_types, file);
+ }
+ catch (IOException ignore)
+ {
+ }
+ }
+
+ public static void fillFromFile (Map table, String fname)
+ throws IOException
+ {
+ LineNumberReader reader =
+ new LineNumberReader (new FileReader (fname));
+
+ while (reader.ready ())
+ {
+ StringTokenizer tokenizer =
+ new StringTokenizer (reader.readLine ());
+
+ try
+ {
+ String t = tokenizer.nextToken ();
+
+ if (! t.startsWith ("#"))
+ {
+ while (true)
+ {
+ // Read the next extension
+ String e = tokenizer.nextToken ();
+ if ((e != null) && (! e.startsWith ("#")))
+ table.put (e, t);
+ else
+ break;
+ }
+ }
+ }
+ catch (NoSuchElementException ex)
+ {
+ // Do nothing.
+ }
+ }
}
/**
@@ -210,4 +319,27 @@ class MimeTypeMapper implements FileNameMap
else
return type;
}
+
+ /**
+ * Run this class as a program to create a new mime_strings table.
+ */
+ public static void main(String[] args) throws IOException
+ {
+ TreeMap map = new TreeMap();
+ // It is fine to hard-code the name here. This is only ever
+ // used by maintainers, who can hack it if they need to re-run
+ // it.
+ fillFromFile(map, "/etc/mime.types");
+ Iterator it = map.keySet().iterator();
+ boolean first = true;
+ while (it.hasNext())
+ {
+ String key = (String) it.next();
+ String value = (String) map.get(key);
+ // Put the "," first since it is easier to make correct syntax this way.
+ System.out.println(" " + (first ? " " : ", ")
+ + "{ \"" + key + "\", \"" + value + "\" }");
+ first = false;
+ }
+ }
}
OpenPOWER on IntegriCloud