1 17 18 package org.apache.tomcat.util.http; 19 20 import java.net.*; 21 import java.util.*; 22 23 24 30 public class MimeMap implements FileNameMap { 31 32 35 public static Hashtable defaultMap=new Hashtable(101); 36 static { 37 defaultMap.put("txt", "text/plain"); 38 defaultMap.put("html","text/html"); 39 defaultMap.put("htm", "text/html"); 40 defaultMap.put("gif", "image/gif"); 41 defaultMap.put("jpg", "image/jpeg"); 42 defaultMap.put("jpe", "image/jpeg"); 43 defaultMap.put("jpeg", "image/jpeg"); 44 defaultMap.put("png", "image/png"); 45 defaultMap.put("java", "text/plain"); 46 defaultMap.put("body", "text/html"); 47 defaultMap.put("rtx", "text/richtext"); 48 defaultMap.put("tsv", "text/tab-separated-values"); 49 defaultMap.put("etx", "text/x-setext"); 50 defaultMap.put("ps", "application/x-postscript"); 51 defaultMap.put("class", "application/java"); 52 defaultMap.put("csh", "application/x-csh"); 53 defaultMap.put("sh", "application/x-sh"); 54 defaultMap.put("tcl", "application/x-tcl"); 55 defaultMap.put("tex", "application/x-tex"); 56 defaultMap.put("texinfo", "application/x-texinfo"); 57 defaultMap.put("texi", "application/x-texinfo"); 58 defaultMap.put("t", "application/x-troff"); 59 defaultMap.put("tr", "application/x-troff"); 60 defaultMap.put("roff", "application/x-troff"); 61 defaultMap.put("man", "application/x-troff-man"); 62 defaultMap.put("me", "application/x-troff-me"); 63 defaultMap.put("ms", "application/x-wais-source"); 64 defaultMap.put("src", "application/x-wais-source"); 65 defaultMap.put("zip", "application/zip"); 66 defaultMap.put("bcpio", "application/x-bcpio"); 67 defaultMap.put("cpio", "application/x-cpio"); 68 defaultMap.put("gtar", "application/x-gtar"); 69 defaultMap.put("shar", "application/x-shar"); 70 defaultMap.put("sv4cpio", "application/x-sv4cpio"); 71 defaultMap.put("sv4crc", "application/x-sv4crc"); 72 defaultMap.put("tar", "application/x-tar"); 73 defaultMap.put("ustar", "application/x-ustar"); 74 defaultMap.put("dvi", "application/x-dvi"); 75 defaultMap.put("hdf", "application/x-hdf"); 76 defaultMap.put("latex", "application/x-latex"); 77 defaultMap.put("bin", "application/octet-stream"); 78 defaultMap.put("oda", "application/oda"); 79 defaultMap.put("pdf", "application/pdf"); 80 defaultMap.put("ps", "application/postscript"); 81 defaultMap.put("eps", "application/postscript"); 82 defaultMap.put("ai", "application/postscript"); 83 defaultMap.put("rtf", "application/rtf"); 84 defaultMap.put("nc", "application/x-netcdf"); 85 defaultMap.put("cdf", "application/x-netcdf"); 86 defaultMap.put("cer", "application/x-x509-ca-cert"); 87 defaultMap.put("exe", "application/octet-stream"); 88 defaultMap.put("gz", "application/x-gzip"); 89 defaultMap.put("Z", "application/x-compress"); 90 defaultMap.put("z", "application/x-compress"); 91 defaultMap.put("hqx", "application/mac-binhex40"); 92 defaultMap.put("mif", "application/x-mif"); 93 defaultMap.put("ief", "image/ief"); 94 defaultMap.put("tiff", "image/tiff"); 95 defaultMap.put("tif", "image/tiff"); 96 defaultMap.put("ras", "image/x-cmu-raster"); 97 defaultMap.put("pnm", "image/x-portable-anymap"); 98 defaultMap.put("pbm", "image/x-portable-bitmap"); 99 defaultMap.put("pgm", "image/x-portable-graymap"); 100 defaultMap.put("ppm", "image/x-portable-pixmap"); 101 defaultMap.put("rgb", "image/x-rgb"); 102 defaultMap.put("xbm", "image/x-xbitmap"); 103 defaultMap.put("xpm", "image/x-xpixmap"); 104 defaultMap.put("xwd", "image/x-xwindowdump"); 105 defaultMap.put("au", "audio/basic"); 106 defaultMap.put("snd", "audio/basic"); 107 defaultMap.put("aif", "audio/x-aiff"); 108 defaultMap.put("aiff", "audio/x-aiff"); 109 defaultMap.put("aifc", "audio/x-aiff"); 110 defaultMap.put("wav", "audio/x-wav"); 111 defaultMap.put("mpeg", "video/mpeg"); 112 defaultMap.put("mpg", "video/mpeg"); 113 defaultMap.put("mpe", "video/mpeg"); 114 defaultMap.put("qt", "video/quicktime"); 115 defaultMap.put("mov", "video/quicktime"); 116 defaultMap.put("avi", "video/x-msvideo"); 117 defaultMap.put("movie", "video/x-sgi-movie"); 118 defaultMap.put("avx", "video/x-rad-screenplay"); 119 defaultMap.put("wrl", "x-world/x-vrml"); 120 defaultMap.put("mpv2", "video/mpeg2"); 121 122 123 124 defaultMap.put("xml", "text/xml"); 125 defaultMap.put("xsl", "text/xml"); 126 defaultMap.put("svg", "image/svg+xml"); 127 defaultMap.put("svgz", "image/svg+xml"); 128 defaultMap.put("wbmp", "image/vnd.wap.wbmp"); 129 defaultMap.put("wml", "text/vnd.wap.wml"); 130 defaultMap.put("wmlc", "application/vnd.wap.wmlc"); 131 defaultMap.put("wmls", "text/vnd.wap.wmlscript"); 132 defaultMap.put("wmlscriptc", "application/vnd.wap.wmlscriptc"); 133 } 134 135 136 private Hashtable map = new Hashtable(); 137 138 public void addContentType(String extn, String type) { 139 map.put(extn, type.toLowerCase()); 140 } 141 142 public Enumeration getExtensions() { 143 return map.keys(); 144 } 145 146 public String getContentType(String extn) { 147 String type = (String )map.get(extn.toLowerCase()); 148 if( type == null ) type=(String )defaultMap.get( extn ); 149 return type; 150 } 151 152 public void removeContentType(String extn) { 153 map.remove(extn.toLowerCase()); 154 } 155 156 158 public static String getExtension( String fileName ) { 159 int length=fileName.length(); 162 163 int newEnd = fileName.lastIndexOf('#'); 164 if( newEnd== -1 ) newEnd=length; 165 int i = fileName.lastIndexOf('.', newEnd ); 170 if (i != -1) { 171 return fileName.substring(i + 1, newEnd ); 172 } else { 173 return null; 175 } 176 } 177 178 public String getContentTypeFor(String fileName) { 179 String extn=getExtension( fileName ); 180 if (extn!=null) { 181 return getContentType(extn); 182 } else { 183 return null; 185 } 186 } 187 188 } 189 | Popular Tags |