1 28 29 package org.apache.commons.httpclient.contrib.methods.multipart; 30 31 import java.io.File ; 32 33 45 46 public final class ContentType { 47 48 49 public static final String [][] MIME_TYPE_MAPPINGS = { { "abs", "audio/x-mpeg" }, { 50 "ai", "application/postscript" }, { 51 "aif", "audio/x-aiff" }, { 52 "aifc", "audio/x-aiff" }, { 53 "aiff", "audio/x-aiff" }, { 54 "aim", "application/x-aim" }, { 55 "art", "image/x-jg" }, { 56 "asf", "video/x-ms-asf" }, { 57 "asx", "video/x-ms-asf" }, { 58 "au", "audio/basic" }, { 59 "avi", "video/x-msvideo" }, { 60 "avx", "video/x-rad-screenplay" }, { 61 "bcpio", "application/x-bcpio" }, { 62 "bin", "application/octet-stream" }, { 63 "bmp", "image/bmp" }, { 64 "body", "text/html" }, { 65 "cdf", "application/x-cdf" }, { 66 "cer", "application/x-x509-ca-cert" }, { 67 "class", "application/java" }, { 68 "cpio", "application/x-cpio" }, { 69 "csh", "application/x-csh" }, { 70 "css", "text/css" }, { 71 "dib", "image/bmp" }, { 72 "doc", "application/msword" }, { 73 "dtd", "text/plain" }, { 74 "dv", "video/x-dv" }, { 75 "dvi", "application/x-dvi" }, { 76 "eps", "application/postscript" }, { 77 "etx", "text/x-setext" }, { 78 "exe", "application/octet-stream" }, { 79 "gif", "image/gif" }, { 80 "gtar", "application/x-gtar" }, { 81 "gz", "application/x-gzip" }, { 82 "hdf", "application/x-hdf" }, { 83 "hqx", "application/mac-binhex40" }, { 84 "htc", "text/x-component" }, { 85 "htm", "text/html" }, { 86 "html", "text/html" }, { 87 "hqx", "application/mac-binhex40" }, { 88 "ief", "image/ief" }, { 89 "jad", "text/vnd.sun.j2me.app-descriptor" }, { 90 "jar", "application/java-archive" }, { 91 "java", "text/plain" }, { 92 "jnlp", "application/x-java-jnlp-file" }, { 93 "jpe", "image/jpeg" }, { 94 "jpeg", "image/jpeg" }, { 95 "jpg", "image/jpeg" }, { 96 "js", "text/javascript" }, { 97 "jsf", "text/plain" }, { 98 "jspf", "text/plain" }, { 99 "kar", "audio/x-midi" }, { 100 "latex", "application/x-latex" }, { 101 "m3u", "audio/x-mpegurl" }, { 102 "mac", "image/x-macpaint" }, { 103 "man", "application/x-troff-man" }, { 104 "me", "application/x-troff-me" }, { 105 "mid", "audio/x-midi" }, { 106 "midi", "audio/x-midi" }, { 107 "mif", "application/x-mif" }, { 108 "mov", "video/quicktime" }, { 109 "movie", "video/x-sgi-movie" }, { 110 "mp1", "audio/x-mpeg" }, { 111 "mp2", "audio/x-mpeg" }, { 112 "mp3", "audio/x-mpeg" }, { 113 "mpa", "audio/x-mpeg" }, { 114 "mpe", "video/mpeg" }, { 115 "mpeg", "video/mpeg" }, { 116 "mpega", "audio/x-mpeg" }, { 117 "mpg", "video/mpeg" }, { 118 "mpv2", "video/mpeg2" }, { 119 "ms", "application/x-wais-source" }, { 120 "nc", "application/x-netcdf" }, { 121 "oda", "application/oda" }, { 122 "pbm", "image/x-portable-bitmap" }, { 123 "pct", "image/pict" }, { 124 "pdf", "application/pdf" }, { 125 "pgm", "image/x-portable-graymap" }, { 126 "pic", "image/pict" }, { 127 "pict", "image/pict" }, { 128 "pls", "audio/x-scpls" }, { 129 "png", "image/png" }, { 130 "pnm", "image/x-portable-anymap" }, { 131 "pnt", "image/x-macpaint" }, { 132 "ppm", "image/x-portable-pixmap" }, { 133 "ps", "application/postscript" }, { 134 "psd", "image/x-photoshop" }, { 135 "qt", "video/quicktime" }, { 136 "qti", "image/x-quicktime" }, { 137 "qtif", "image/x-quicktime" }, { 138 "ras", "image/x-cmu-raster" }, { 139 "rgb", "image/x-rgb" }, { 140 "rm", "application/vnd.rn-realmedia" }, { 141 "roff", "application/x-troff" }, { 142 "rtf", "application/rtf" }, { 143 "rtx", "text/richtext" }, { 144 "sh", "application/x-sh" }, { 145 "shar", "application/x-shar" }, { 146 "smf", "audio/x-midi" }, { 147 "snd", "audio/basic" }, { 148 "src", "application/x-wais-source" }, { 149 "sv4cpio", "application/x-sv4cpio" }, { 150 "sv4crc", "application/x-sv4crc" }, { 151 "swf", "application/x-shockwave-flash" }, { 152 "t", "application/x-troff" }, { 153 "tar", "application/x-tar" }, { 154 "tcl", "application/x-tcl" }, { 155 "tex", "application/x-tex" }, { 156 "texi", "application/x-texinfo" }, { 157 "texinfo", "application/x-texinfo" }, { 158 "tif", "image/tiff" }, { 159 "tiff", "image/tiff" }, { 160 "tr", "application/x-troff" }, { 161 "tsv", "text/tab-separated-values" }, { 162 "txt", "text/plain" }, { 163 "ulw", "audio/basic" }, { 164 "ustar", "application/x-ustar" }, { 165 "xbm", "image/x-xbitmap" }, { 166 "xml", "text/xml" }, { 167 "xpm", "image/x-xpixmap" }, { 168 "xsl", "text/xml" }, { 169 "xwd", "image/x-xwindowdump" }, { 170 "wav", "audio/x-wav" }, { 171 "svg", "image/svg+xml" }, { 172 "svgz", "image/svg+xml" }, { 173 "wbmp", "image/vnd.wap.wbmp" }, { 174 "wml", "text/vnd.wap.wml" }, { 175 "wmlc", "application/vnd.wap.wmlc" }, { 176 "wmls", "text/vnd.wap.wmlscript" }, { 177 "wmlscriptc", "application/vnd.wap.wmlscriptc" }, { 178 "wrl", "x-world/x-vrml" }, { 179 "Z", "application/x-compress" }, { 180 "z", "application/x-compress" }, { 181 "zip", "application/zip" } 182 }; 183 184 186 private ContentType() { 187 } 188 189 197 public static String get(String fileName) { 198 String contentType = null; 199 200 if (fileName != null) { 201 int extensionIndex = fileName.lastIndexOf('.'); 202 if (extensionIndex != -1) { 203 if (extensionIndex + 1 < fileName.length()) { 204 String extension = fileName.substring(extensionIndex + 1); 205 for (int i = 0; i < MIME_TYPE_MAPPINGS.length; i++) { 206 if (extension.equals(MIME_TYPE_MAPPINGS[i][0])) { 207 contentType = MIME_TYPE_MAPPINGS[i][1]; 208 break; 209 } 210 } 211 } 212 } 213 } 214 215 return contentType; 216 } 217 218 229 public static String get(File file) { 230 String contentType = null; 231 232 if (file != null) { 233 contentType = get(file.getName()); 234 } 235 236 return contentType; 237 } 238 } 239 | Popular Tags |