OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [java/] [net/] [MimeTypeMapper.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* MimeTypeMapper.java -- A class for mapping file names to MIME types
2
   Copyright (C) 1998, 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package java.net;
39
 
40
import java.util.Hashtable;
41
import gnu.gcj.io.MimeTypes;
42
 
43
 
44
/**
45
 * This non-public class is used to implement the FileNameMap interface
46
 * which defines a mechanism for mapping filenames to MIME types.
47
 *
48
 * @version 0.5
49
 *
50
 * @author Aaron M. Renn (arenn@urbanophile.com)
51
 */
52
class MimeTypeMapper implements FileNameMap
53
{
54
  /**
55
   * This array of strings is used to identify a MIME type based on a file
56
   * extension.  This is list is based on the Apache mime.types file.
57
   */
58
  protected static final String[][] mime_strings =
59
    {
60
      { "application/mac-binhex40", "hqx" },
61
      { "application/mac-compactpro", "cpt" },
62
      { "application/msword", "doc" },
63
      { "application/octet-stream", "bin" },
64
      { "application/octet-stream", "dms" },
65
      { "application/octet-stream", "lha" },
66
      { "application/octet-stream", "lzh" },
67
      { "application/octet-stream", "exe" },
68
      { "application/octet-stream", "class" },
69
      { "application/oda", "oda" },
70
      { "application/pdf", "pdf" },
71
      { "application/postscript", "ai" },
72
      { "application/postscript", "eps" },
73
      { "application/postscript", "ps" },
74
      { "application/powerpoint", "ppt" },
75
      { "application/rtf", "rtf" },
76
      { "application/x-bcpio", "bcpio" },
77
      { "application/x-cdlink", "vcd" },
78
      { "application/x-compress", "Z" },
79
      { "application/x-cpio", "cpio" },
80
      { "application/x-csh", "csh" },
81
      { "application/x-director", "dcr" },
82
      { "application/x-director", "dir" },
83
      { "application/x-director", "dxr" },
84
      { "application/x-dvi", "dvi" },
85
      { "application/x-gtar", "gtar" },
86
      { "application/x-gzip", "gz" },
87
      { "application/x-hdf", "hdf" },
88
      { "application/x-httpd-cgi", "cgi" },
89
      { "application/x-koan", "skp" },
90
      { "application/x-koan", "skd" },
91
      { "application/x-koan", "skt" },
92
      { "application/x-koan", "skm" },
93
      { "application/x-latex", "latex" },
94
      { "application/x-mif", "mif" },
95
      { "application/x-netcdf", "nc" },
96
      { "application/x-netcdf", "cdf" },
97
      { "application/x-sh", "sh" },
98
      { "application/x-shar", "shar" },
99
      { "application/x-stuffit", "sit" },
100
      { "application/x-sv4cpio", "sv4cpio" },
101
      { "application/x-sv4crc", "sv4crc" },
102
      { "application/x-tar", "tar" },
103
      { "application/x-tcl", "tcl" },
104
      { "application/x-tex", "tex" },
105
      { "application/x-texinfo", "texinfo" },
106
      { "application/x-texinfo", "texi" },
107
      { "application/x-troff", "t" },
108
      { "application/x-troff", "tr" },
109
      { "application/x-troff", "roff" },
110
      { "application/x-troff-man", "man" },
111
      { "application/x-troff-me", "me" },
112
      { "application/x-troff-ms", "ms" },
113
      { "application/x-ustar", "ustar" },
114
      { "application/x-wais-source", "src" },
115
      { "application/zip", "zip" },
116
      { "audio/basic", "au" },
117
      { "audio/basic", "snd" },
118
      { "audio/mpeg", "mpga" },
119
      { "audio/mpeg", "mp2" },
120
      { "audio/mpeg", "mp3" },
121
      { "audio/x-aiff", "aif" },
122
      { "audio/x-aiff", "aiff" },
123
      { "audio/x-aiff", "aifc" },
124
      { "audio/x-pn-realaudio", "ram" },
125
      { "audio/x-pn-realaudio-plugin", "rpm" },
126
      { "audio/x-realaudio", "ra" },
127
      { "audio/x-wav", "wav" },
128
      { "chemical/x-pdb", "pdb" },
129
      { "chemical/x-pdb", "xyz" },
130
      { "image/gif", "gif" },
131
      { "image/ief", "ief" },
132
      { "image/jpeg", "jpeg" },
133
      { "image/jpeg", "jpg" },
134
      { "image/jpeg", "jpe" },
135
      { "image/png", "png" },
136
      { "image/tiff", "tiff" },
137
      { "image/tiff", "tif" },
138
      { "image/x-cmu-raster", "ras" },
139
      { "image/x-portable-anymap", "pnm" },
140
      { "image/x-portable-bitmap", "pbm" },
141
      { "image/x-portable-graymap", "pgm" },
142
      { "image/x-portable-pixmap", "ppm" },
143
      { "image/x-rgb", "rgb" },
144
      { "image/x-xbitmap", "xbm" },
145
      { "image/x-xpixmap", "xpm" },
146
      { "image/x-xwindowdump", "xwd" },
147
      { "text/html", "html" },
148
      { "text/html", "htm" },
149
      { "text/plain", "txt" },
150
      { "text/richtext", "rtx" },
151
      { "text/tab-separated-values", "tsv" },
152
      { "text/x-setext", "etx" },
153
      { "text/x-sgml", "sgml" },
154
      { "text/x-sgml", "sgm" },
155
      { "video/mpeg", "mpeg" },
156
      { "video/mpeg", "mpg" },
157
      { "video/mpeg", "mpe" },
158
      { "video/quicktime", "qt" },
159
      { "video/quicktime", "mov" },
160
      { "video/x-msvideo", "avi" },
161
      { "video/x-sgi-movie", "movie" },
162
      { "x-conference/x-cooltalk", "ice" },
163
      { "x-world/x-vrml", "wrl" },
164
      { "x-world/x-vrml", "vrml" }
165
    };
166
 
167
  /**
168
   * The MIME types above are put into this Hashtable for faster lookup.
169
   */
170
  private static Hashtable mime_types = new Hashtable(150);
171
 
172
  // Static initializer to load MIME types into Hashtable
173
  static
174
  {
175
    for (int i = 0; i < mime_strings.length; i++)
176
      mime_types.put(mime_strings[i][1], mime_strings[i][0]);
177
  }
178
 
179
  /**
180
   * Create a new <code>MimeTypeMapper</code> object.
181
   */
182
  public MimeTypeMapper()
183
  {
184
    // Do nothing here.
185
  }
186
 
187
  /**
188
   * The method returns the MIME type of the filename passed as an argument.
189
   * The value returned is based on the extension of the filename.  The
190
   * default content type returned if this method cannot determine the
191
   * actual content type is "application/octet-stream"
192
   *
193
   * @param filename The name of the file to return the MIME type for
194
   *
195
   * @return The MIME type
196
   */
197
  public String getContentTypeFor(String filename)
198
  {
199
    int index = filename.lastIndexOf(".");
200
    if (index != -1)
201
      {
202
        if (index == filename.length())
203
          return "application/octet-stream";
204
        else
205
          filename = filename.substring(index + 1);
206
      }
207
 
208
    String type = (String) mime_types.get(filename);
209
    if (type == null)
210
      return MimeTypes.getMimeTypeFromExtension(filename);
211
    else
212
      return type;
213
  }
214
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.