|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.felix.webconsole.internal.servlet; |
| 18 | + |
| 19 | +import java.util.Map; |
| 20 | +import java.util.HashMap; |
| 21 | + |
| 22 | +public final class MimeTypes { |
| 23 | + |
| 24 | + private static final Map<String, String> extMap = new HashMap<String, String>(); |
| 25 | + static { |
| 26 | + extMap.put("abs", "audio/x-mpeg"); |
| 27 | + extMap.put("ai", "application/postscript"); |
| 28 | + extMap.put("aif", "audio/x-aiff"); |
| 29 | + extMap.put("aifc", "audio/x-aiff"); |
| 30 | + extMap.put("aiff", "audio/x-aiff"); |
| 31 | + extMap.put("aim", "application/x-aim"); |
| 32 | + extMap.put("art", "image/x-jg"); |
| 33 | + extMap.put("asf", "video/x-ms-asf"); |
| 34 | + extMap.put("asx", "video/x-ms-asf"); |
| 35 | + extMap.put("au", "audio/basic"); |
| 36 | + extMap.put("avi", "video/x-msvideo"); |
| 37 | + extMap.put("avx", "video/x-rad-screenplay"); |
| 38 | + extMap.put("bcpio", "application/x-bcpio"); |
| 39 | + extMap.put("bin", "application/octet-stream"); |
| 40 | + extMap.put("bmp", "image/bmp"); |
| 41 | + extMap.put("body", "text/html"); |
| 42 | + extMap.put("cdf", "application/x-cdf"); |
| 43 | + extMap.put("cer", "application/x-x509-ca-cert"); |
| 44 | + extMap.put("class", "application/java"); |
| 45 | + extMap.put("cpio", "application/x-cpio"); |
| 46 | + extMap.put("csh", "application/x-csh"); |
| 47 | + extMap.put("css", "text/css"); |
| 48 | + extMap.put("dib", "image/bmp"); |
| 49 | + extMap.put("doc", "application/msword"); |
| 50 | + extMap.put("dtd", "application/xml-dtd"); |
| 51 | + extMap.put("dv", "video/x-dv"); |
| 52 | + extMap.put("dvi", "application/x-dvi"); |
| 53 | + extMap.put("eps", "application/postscript"); |
| 54 | + extMap.put("etx", "text/x-setext"); |
| 55 | + extMap.put("exe", "application/octet-stream"); |
| 56 | + extMap.put("gif", "image/gif"); |
| 57 | + extMap.put("gk", "application/octet-stream"); |
| 58 | + extMap.put("gtar", "application/x-gtar"); |
| 59 | + extMap.put("gz", "application/x-gzip"); |
| 60 | + extMap.put("hdf", "application/x-hdf"); |
| 61 | + extMap.put("hqx", "application/mac-binhex40"); |
| 62 | + extMap.put("htc", "text/x-component"); |
| 63 | + extMap.put("htm", "text/html"); |
| 64 | + extMap.put("html", "text/html"); |
| 65 | + extMap.put("hqx", "application/mac-binhex40"); |
| 66 | + extMap.put("ief", "image/ief"); |
| 67 | + extMap.put("jad", "text/vnd.sun.j2me.app-descriptor"); |
| 68 | + extMap.put("jar", "application/java-archive"); |
| 69 | + extMap.put("java", "text/plain"); |
| 70 | + extMap.put("jnlp", "application/x-java-jnlp-file"); |
| 71 | + extMap.put("jpe", "image/jpeg"); |
| 72 | + extMap.put("jpeg", "image/jpeg"); |
| 73 | + extMap.put("jpg", "image/jpeg"); |
| 74 | + extMap.put("js", "text/javascript"); |
| 75 | + extMap.put("kar", "audio/x-midi"); |
| 76 | + extMap.put("latex", "application/x-latex"); |
| 77 | + extMap.put("m3u", "audio/x-mpegurl"); |
| 78 | + extMap.put("mac", "image/x-macpaint"); |
| 79 | + extMap.put("man", "application/x-troff-man"); |
| 80 | + extMap.put("mathml", "application/mathml+xml"); |
| 81 | + extMap.put("me", "application/x-troff-me"); |
| 82 | + extMap.put("mid", "audio/x-midi"); |
| 83 | + extMap.put("midi", "audio/x-midi"); |
| 84 | + extMap.put("mif", "application/x-mif"); |
| 85 | + extMap.put("mov", "video/quicktime"); |
| 86 | + extMap.put("movie", "video/x-sgi-movie"); |
| 87 | + extMap.put("mp1", "audio/x-mpeg"); |
| 88 | + extMap.put("mp2", "audio/x-mpeg"); |
| 89 | + extMap.put("mp3", "audio/x-mpeg"); |
| 90 | + extMap.put("mpa", "audio/x-mpeg"); |
| 91 | + extMap.put("mpe", "video/mpeg"); |
| 92 | + extMap.put("mpeg", "video/mpeg"); |
| 93 | + extMap.put("mpega", "audio/x-mpeg"); |
| 94 | + extMap.put("mpg", "video/mpeg"); |
| 95 | + extMap.put("mpv2", "video/mpeg2"); |
| 96 | + extMap.put("ms", "application/x-wais-source"); |
| 97 | + extMap.put("nc", "application/x-netcdf"); |
| 98 | + extMap.put("oda", "application/oda"); |
| 99 | + extMap.put("ogg", "application/ogg"); |
| 100 | + extMap.put("pbm", "image/x-portable-bitmap"); |
| 101 | + extMap.put("pct", "image/pict"); |
| 102 | + extMap.put("pdf", "application/pdf"); |
| 103 | + extMap.put("pgm", "image/x-portable-graymap"); |
| 104 | + extMap.put("pic", "image/pict"); |
| 105 | + extMap.put("pict", "image/pict"); |
| 106 | + extMap.put("pls", "audio/x-scpls"); |
| 107 | + extMap.put("png", "image/png"); |
| 108 | + extMap.put("pnm", "image/x-portable-anymap"); |
| 109 | + extMap.put("pnt", "image/x-macpaint"); |
| 110 | + extMap.put("ppm", "image/x-portable-pixmap"); |
| 111 | + extMap.put("ppt", "application/powerpoint"); |
| 112 | + extMap.put("ps", "application/postscript"); |
| 113 | + extMap.put("psd", "image/x-photoshop"); |
| 114 | + extMap.put("qt", "video/quicktime"); |
| 115 | + extMap.put("qti", "image/x-quicktime"); |
| 116 | + extMap.put("qtif", "image/x-quicktime"); |
| 117 | + extMap.put("ras", "image/x-cmu-raster"); |
| 118 | + extMap.put("rdf", "application/rdf+xml"); |
| 119 | + extMap.put("rgb", "image/x-rgb"); |
| 120 | + extMap.put("rm", "application/vnd.rn-realmedia"); |
| 121 | + extMap.put("roff", "application/x-troff"); |
| 122 | + extMap.put("rtf", "application/rtf"); |
| 123 | + extMap.put("rtx", "text/richtext"); |
| 124 | + extMap.put("sh", "application/x-sh"); |
| 125 | + extMap.put("shar", "application/x-shar"); |
| 126 | + extMap.put("shtml", "text/x-server-parsed-html"); |
| 127 | + extMap.put("sit", "application/x-stuffit"); |
| 128 | + extMap.put("smf", "audio/x-midi"); |
| 129 | + extMap.put("snd", "audio/basic"); |
| 130 | + extMap.put("src", "application/x-wais-source"); |
| 131 | + extMap.put("sv4cpio", "application/x-sv4cpio"); |
| 132 | + extMap.put("sv4crc", "application/x-sv4crc"); |
| 133 | + extMap.put("svg", "image/svg+xml"); |
| 134 | + extMap.put("svgz", "image/svg+xml"); |
| 135 | + extMap.put("swf", "application/x-shockwave-flash"); |
| 136 | + extMap.put("t", "application/x-troff"); |
| 137 | + extMap.put("tar", "application/x-tar"); |
| 138 | + extMap.put("tcl", "application/x-tcl"); |
| 139 | + extMap.put("tex", "application/x-tex"); |
| 140 | + extMap.put("texi", "application/x-texinfo"); |
| 141 | + extMap.put("texinfo", "application/x-texinfo"); |
| 142 | + extMap.put("tif", "image/tiff"); |
| 143 | + extMap.put("tiff", "image/tiff"); |
| 144 | + extMap.put("tr", "application/x-troff"); |
| 145 | + extMap.put("tsv", "text/tab-separated-values"); |
| 146 | + extMap.put("txt", "text/plain"); |
| 147 | + extMap.put("ulw", "audio/basic"); |
| 148 | + extMap.put("ustar", "application/x-ustar"); |
| 149 | + extMap.put("xbm", "image/x-xbitmap"); |
| 150 | + extMap.put("xml", "text/xml"); |
| 151 | + extMap.put("xpm", "image/x-xpixmap"); |
| 152 | + extMap.put("xsl", "application/xml"); |
| 153 | + extMap.put("xslt", "application/xslt+xml"); |
| 154 | + extMap.put("xwd", "image/x-xwindowdump"); |
| 155 | + extMap.put("vsd", "application/x-visio"); |
| 156 | + extMap.put("vxml", "application/voicexml+xml"); |
| 157 | + extMap.put("wav", "audio/x-wav"); |
| 158 | + extMap.put("wbmp", "image/vnd.wap.wbmp"); |
| 159 | + extMap.put("wml", "text/vnd.wap.wml"); |
| 160 | + extMap.put("wmlc", "application/vnd.wap.wmlc"); |
| 161 | + extMap.put("wmls", "text/vnd.wap.wmls"); |
| 162 | + extMap.put("wmlscriptc", "application/vnd.wap.wmlscriptc"); |
| 163 | + extMap.put("wrl", "x-world/x-vrml"); |
| 164 | + extMap.put("xht", "application/xhtml+xml"); |
| 165 | + extMap.put("xhtml", "application/xhtml+xml"); |
| 166 | + extMap.put("xls", "application/vnd.ms-excel"); |
| 167 | + extMap.put("xul", "application/vnd.mozilla.xul+xml"); |
| 168 | + extMap.put("Z", "application/x-compress"); |
| 169 | + extMap.put("z", "application/x-compress"); |
| 170 | + extMap.put("zip", "application/zip"); |
| 171 | + } |
| 172 | + |
| 173 | + public static String getByFile(final String file) { |
| 174 | + if (file == null) { |
| 175 | + return null; |
| 176 | + } |
| 177 | + final int dot = file.lastIndexOf("."); |
| 178 | + if (dot < 0) { |
| 179 | + return null; |
| 180 | + } |
| 181 | + final String ext = file.substring(dot + 1).toLowerCase(); |
| 182 | + return getByExtension(ext); |
| 183 | + } |
| 184 | + |
| 185 | + public static String getByExtension(final String ext){ |
| 186 | + if (ext == null) { |
| 187 | + return null; |
| 188 | + } |
| 189 | + return extMap.get(ext); |
| 190 | + } |
| 191 | +} |
0 commit comments