KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > http > MimeType


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: MimeType.java,v 1.1 2004/04/21 19:31:58 slobodan Exp $
23  */

24
25 package com.lutris.http;
26 import java.util.Hashtable JavaDoc;
27
28 /**
29  * Class for querying and setting mime types.
30  * Provides a default set of well known mime types.
31  *
32  * @version 1.0
33  */

34 public class MimeType {
35
36     Hashtable JavaDoc types;
37
38     /**
39      * Default Constructor
40      */

41     public MimeType() {
42         this.types = new Hashtable JavaDoc();
43
44         /* Set default well known stuff */
45         addType("application/octet-stream", "bin");
46         addType("application/astound", "asd,asn");
47         addType("application/fastman", "lcc");
48         addType("application/java-archive", "jar");
49         addType("application/java-serialized-object", "ser");
50         addType("application/java-vm", "class");
51         addType("application/mac-binhex40", "hqx");
52         addType("application/x-stuffit", "sit");
53         addType("application/mbedlet", "mbd");
54         addType("application/msword", "doc");
55         addType("application/oda", "oda");
56         addType("application/pdf", "pdf");
57         addType("application/postscript", "ai");
58         addType("application/postscript", "eps");
59         addType("application/postscript", "ps");
60         addType("application/rtf", "rtf");
61         addType("application/studiom", "smp");
62         addType("application/timbuktu", "tbt");
63         addType("application/vnd.ms-excel", "xls");
64         addType("application/vnd.ms-excel", "xlw");
65         addType("application/vnd.ms-excel", "xla");
66         addType("application/vnd.ms-excel", "xlc");
67         addType("application/vnd.ms-excel", "xlm");
68         addType("application/vnd.ms-excel", "xlt");
69         addType("application/vnd.ms-powerpoint", "ppt");
70         addType("application/vnd.ms-powerpoint", "pps");
71         addType("application/vnd.ms-powerpoint", "ppt");
72         addType("application/vnd.ms-project", "mpp");
73         addType("application/winhlp", "hlp");
74         addType("application/x-javascript", "js");
75         addType("application/x-asap", "asp");
76         addType("application/x-csh", "csh");
77         addType("application/x-dot", "dot");
78         addType("application/x-dvi", "dvi");
79         addType("application/x-earthtime", "etc");
80         addType("application/x-envoy", "evy");
81         addType("application/x-excel", "xls");
82         addType("application/x-excel", "xlc");
83         addType("application/x-excel", "xll");
84         addType("application/x-excel", "xlm");
85         addType("application/x-excel", "xlw");
86         addType("application/x-gtar", "gtar");
87         addType("application/x-cpio", "cpio");
88         addType("application/x-hdf", "hdf");
89         addType("application/x-latex", "latex");
90         addType("application/x-javascript-config", "jsc");
91         addType("application/x-maker", "fm");
92         addType("application/x-mif", "mif");
93         addType("application/x-mif", "mi");
94         addType("application/x-mocha", "mocha,moc");
95         addType("application/x-msaccess", "mdb");
96         addType("application/x-mscardfile", "crd");
97         addType("application/x-msclip", "clp");
98         addType("application/x-msmediaview", "m13");
99         addType("application/x-msmediaview", "m14");
100         addType("application/x-msmetafile", "wmf");
101         addType("application/x-msmoney", "mny");
102         addType("application/x-mspublisher", "pub");
103         addType("application/x-msschedule", "scd");
104         addType("application/x-msterminal", "trm");
105         addType("application/x-mswrite", "wri");
106         addType("application/x-NET-Install", "ins");
107         addType("application/x-netcdf", "nc");
108         addType("application/x-netcdf", "cdf");
109         addType("application/x-ns-proxy-autoconfig", "proxy");
110 /* addType("application/x-pointplus", "css"); interfered with text/css */
111         addType("application/x-salsa", "slc");
112         addType("application/x-sh", "sh");
113         addType("application/x-shar", "shar");
114         addType("application/x-sprite", "spr");
115         addType("application/x-sprite", "sprite");
116         addType("application/x-tar", "tar");
117         addType("application/x-tcl", "tcl");
118         addType("application/x-perl", "pl");
119         addType("application/x-tex", "tex");
120         addType("application/x-texinfo", "texinfo");
121         addType("application/x-texinfo", "texi");
122         addType("application/x-timbuktu", "tbp");
123         addType("application/x-tkined", "tki");
124         addType("application/x-tkined", "tkined");
125         addType("application/x-troff-man", "man");
126         addType("application/x-troff-me", "me");
127         addType("application/x-troff-ms", "ms");
128         addType("application/x-troff", "t");
129         addType("application/x-troff", "tr");
130         addType("application/x-troff", "roff");
131         addType("application/x-wais-source", "src");
132         addType("application/zip", "zip");
133
134         addType("audio/basic", "au");
135         addType("audio/basic", "snd");
136         addType("audio/echospeech", "es");
137         addType("audio/echospeech", "esl");
138         addType("audio/midi", "midi");
139         addType("audio/midi", "mid");
140         addType("audio/x-aiff", "aif");
141         addType("audio/x-aiff", "aiff");
142         addType("audio/x-aiff", "aifc");
143
144         addType("audio/x-wav", "wav");
145         addType("audio/x-pn-realaudio", "ra");
146         addType("audio/x-pn-realaudio", "ram");
147         addType("audio/x-pac", "pac");
148         addType("audio/x-epac", "pae");
149         addType("audio/x-liveaudio", "lam");
150
151         addType("image/fif", "fif");
152         addType("image/gif", "gif");
153         addType("image/ief", "ief");
154         addType("image/ifs", "ifs");
155         addType("image/jpeg", "jpeg");
156         addType("image/jpeg", "jpg");
157         addType("image/jpeg", "jpe");
158         addType("image/jpeg", "jfif");
159         addType("image/jpeg", "pjpeg");
160         addType("image/jpeg", "pjp");
161         addType("image/png", "png");
162         addType("image/tiff", "tiff");
163         addType("image/tiff", "tif");
164         addType("image/vnd", "svf");
165         addType("image/wavelet", "wi");
166         addType("image/bmp", "bmp");
167         addType("image/x-photo-cd", "pcd");
168         addType("image/x-cmu-raster", "ras");
169         addType("image/x-portable-anymap", "pnm");
170         addType("image/x-portable-bitmap", "pbm");
171         addType("image/x-portable-graymap", "pgm");
172         addType("image/x-portable-pixmap", "ppm");
173         addType("image/x-rgb", "rgb");
174         addType("image/x-xbitmap", "xbm");
175         addType("image/x-xpixmap", "xpm");
176         addType("image/x-xwindowdump", "xwd");
177         addType("image/vnd.wap.wbmp", "wbmp");
178
179         addType("text/html", "htm");
180         addType("text/html", "html");
181         addType("text/plain", "txt");
182         addType("text/richtext", "rtx");
183         addType("text/css", "css");
184         addType("text/richtext", "rtx");
185         addType("text/tab-separated-values", "tsv");
186         addType("text/x-setext", "etx");
187         addType("text/x-speech", "talk");
188         addType("text/vnd.wap.wml", "wml");
189
190         addType("video/isivideo", "fvi");
191         addType("video/mpeg", "mpeg");
192         addType("video/mpeg", "mpg");
193         addType("video/mpeg", "mpe");
194         addType("video/mpeg", "mpv");
195         addType("video/mpeg", "vbs");
196         addType("video/mpeg", "mpegv");
197         addType("video/x-mpeg2", "mpv2");
198         addType("video/x-mpeg2", "mp2v");
199         addType("video/msvideo", "avi");
200         addType("video/quicktime", "qt");
201         addType("video/quicktime", "mov");
202         addType("video/quicktime", "moov");
203         addType("video/vivo", "viv");
204         addType("video/vivo", "vivo");
205         addType("video/wavelet", "wv");
206         addType("video/x-sgi-movie", "movie");
207
208         addType("x-world/x-svr", "svr");
209         addType("x-world/x-vrml", "wrl");
210         addType("x-world/x-vrt", "vrt");
211
212         addType("x-conference/x-cooltalk", "ice");
213
214         addType("x-gzip", "gz");
215         addType("x-compress", "z");
216         addType("x-uuencode", "uu,uue");
217
218         addType("magnus-internal/imagemap", "map");
219         addType("magnus-internal/parsed-html", "shtml");
220         addType("magnus-internal/cgi", "cgi,bat");
221         addType("application/octet-stream", "exe");
222
223         addType("application/x-x509-ca-cert", "cacert");
224         addType("application/x-x509-server-cert", "scert");
225         addType("application/x-x509-user-cert", "ucert");
226         addType("application/x-x509-email-cert", "ecert");
227
228         addType("text/vnd.wap.wmlscript", "wmls");
229         addType("application/vnd.wap.wmlscriptc", "wmlsc");
230         addType("application/vnd.wap.wmlc", "wmlc");
231     }
232
233     /**
234      * Register a new mime type.
235      */

236     public void addType(String JavaDoc mimeType, String JavaDoc extension) {
237         types.put ((Object JavaDoc)extension, (Object JavaDoc)mimeType);
238     }
239
240     /**
241      * Returns the mime type associated with a file.
242      */

243     public String JavaDoc getType(String JavaDoc fileName) {
244         String JavaDoc extension;
245         int index = fileName.lastIndexOf(".") + 1;
246         if (index > 0) {
247             extension = fileName.substring(index);
248             /*
249              * Check if extension contains '#' as in the case of WMLScript
250              * function calls, which are of the form
251              * filename.wmlsc#functionname(var1,var2).
252              * Only want to extract "wmlsc" from fileName.
253              */

254             index = extension.lastIndexOf("#");
255             if (index > 0) {
256                 String JavaDoc clippedExtension = extension.substring(0, index);
257                 extension = clippedExtension;
258             }
259         } else {
260             extension = fileName;
261         }
262
263         String JavaDoc mimeType = (String JavaDoc)types.get((Object JavaDoc)extension);
264         if (mimeType == null) {
265             mimeType = "text/plain";
266         }
267         return mimeType;
268     }
269
270 }
271  
272
Popular Tags