1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.mailsender; |
21 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 7 |
Complexity Density: 0.41 |
|
22 |
|
public class MimeTypesUtil |
23 |
|
{ |
24 |
|
protected static final String[][] MIME_TYPES = |
25 |
|
{ {"application/mac-binhex40", "hqx"}, {"application/mac-compactpro", "cpt"}, |
26 |
|
{"application/msword", "doc"}, {"application/octet-stream", "bin"}, |
27 |
|
{"application/octet-stream", "dms"}, {"application/octet-stream", "lha"}, |
28 |
|
{"application/octet-stream", "lzh"}, {"application/octet-stream", "exe"}, |
29 |
|
{"application/octet-stream", "class"}, {"application/oda", "oda"}, |
30 |
|
{"application/pdf", "pdf"}, {"application/postscript", "ai"}, |
31 |
|
{"application/postscript", "eps"}, {"application/postscript", "ps"}, |
32 |
|
{"application/powerpoint", "ppt"}, {"application/rtf", "rtf"}, |
33 |
|
{"application/x-bcpio", "bcpio"}, {"application/x-cdlink", "vcd"}, |
34 |
|
{"application/x-compress", "Z"}, {"application/x-cpio", "cpio"}, |
35 |
|
{"application/x-csh", "csh"}, {"application/x-director", "dcr"}, |
36 |
|
{"application/x-director", "dir"}, {"application/x-director", "dxr"}, |
37 |
|
{"application/x-dvi", "dvi"}, {"application/x-gtar", "gtar"}, |
38 |
|
{"application/x-gzip", "gz"}, {"application/x-hdf", "hdf"}, |
39 |
|
{"application/x-httpd-cgi", "cgi"}, {"application/x-koan", "skp"}, |
40 |
|
{"application/x-koan", "skd"}, {"application/x-koan", "skt"}, |
41 |
|
{"application/x-koan", "skm"}, {"application/x-latex", "latex"}, |
42 |
|
{"application/x-mif", "mif"}, {"application/x-netcdf", "nc"}, |
43 |
|
{"application/x-netcdf", "cdf"}, {"application/x-sh", "sh"}, |
44 |
|
{"application/x-shar", "shar"}, {"application/x-stuffit", "sit"}, |
45 |
|
{"application/x-sv4cpio", "sv4cpio"}, {"application/x-sv4crc", "sv4crc"}, |
46 |
|
{"application/x-tar", "tar"}, {"application/x-tcl", "tcl"}, {"application/x-tex", "tex"}, |
47 |
|
{"application/x-texinfo", "texinfo"}, {"application/x-texinfo", "texi"}, |
48 |
|
{"application/x-troff", "t"}, {"application/x-troff", "tr"}, |
49 |
|
{"application/x-troff", "roff"}, {"application/x-troff-man", "man"}, |
50 |
|
{"application/x-troff-me", "me"}, {"application/x-troff-ms", "ms"}, |
51 |
|
{"application/x-ustar", "ustar"}, {"application/x-wais-source", "src"}, |
52 |
|
{"application/zip", "zip"}, {"audio/basic", "au"}, {"audio/basic", "snd"}, |
53 |
|
{"audio/mpeg", "mpga"}, {"audio/mpeg", "mp2"}, {"audio/mpeg", "mp3"}, |
54 |
|
{"audio/x-aiff", "aif"}, {"audio/x-aiff", "aiff"}, {"audio/x-aiff", "aifc"}, |
55 |
|
{"audio/x-pn-realaudio", "ram"}, {"audio/x-pn-realaudio-plugin", "rpm"}, |
56 |
|
{"audio/x-realaudio", "ra"}, {"audio/x-wav", "wav"}, {"chemical/x-pdb", "pdb"}, |
57 |
|
{"chemical/x-pdb", "xyz"}, {"image/gif", "gif"}, {"image/ief", "ief"}, |
58 |
|
{"image/jpeg", "jpeg"}, {"image/jpeg", "jpg"}, {"image/jpeg", "jpe"}, |
59 |
|
{"image/png", "png"}, {"image/tiff", "tiff"}, {"image/tiff", "tif"}, |
60 |
|
{"image/x-cmu-raster", "ras"}, {"image/x-portable-anymap", "pnm"}, |
61 |
|
{"image/x-portable-bitmap", "pbm"}, {"image/x-portable-graymap", "pgm"}, |
62 |
|
{"image/x-portable-pixmap", "ppm"}, {"image/x-rgb", "rgb"}, {"image/x-xbitmap", "xbm"}, |
63 |
|
{"image/x-xpixmap", "xpm"}, {"image/x-xwindowdump", "xwd"}, {"text/html", "html"}, |
64 |
|
{"text/html", "htm"}, {"text/plain", "txt"}, {"text/richtext", "rtx"}, |
65 |
|
{"text/tab-separated-values", "tsv"}, {"text/x-setext", "etx"}, {"text/x-sgml", "sgml"}, |
66 |
|
{"text/x-sgml", "sgm"}, {"video/mpeg", "mpeg"}, {"video/mpeg", "mpg"}, |
67 |
|
{"video/mpeg", "mpe"}, {"video/quicktime", "qt"}, {"video/quicktime", "mov"}, |
68 |
|
{"video/x-msvideo", "avi"}, {"video/x-sgi-movie", "movie"}, |
69 |
|
{"x-conference/x-cooltalk", "ice"}, {"x-world/x-vrml", "wrl"}, {"x-world/x-vrml", "vrml"}}; |
70 |
|
|
71 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 6 |
Complexity Density: 0.43 |
|
72 |
0 |
public static String getMimeTypeFromFilename(String filename)... |
73 |
|
{ |
74 |
0 |
int index = filename.lastIndexOf("."); |
75 |
0 |
String extension = filename; |
76 |
0 |
if (index != -1) { |
77 |
0 |
if (index == filename.length()) |
78 |
0 |
return ("application/octet-stream"); |
79 |
|
else |
80 |
0 |
extension = filename.substring(index + 1); |
81 |
|
} |
82 |
0 |
String type = null; |
83 |
0 |
for (int i = 0; i < MIME_TYPES.length; i++) { |
84 |
0 |
if (MIME_TYPES[i][1].equals(extension)) { |
85 |
0 |
type = MIME_TYPES[i][0]; |
86 |
0 |
break; |
87 |
|
} |
88 |
|
} |
89 |
0 |
if (type == null) |
90 |
0 |
return ("application/octet-stream"); |
91 |
|
else |
92 |
0 |
return (type); |
93 |
|
} |
94 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
95 |
0 |
public static void main(String[] args) {... |
96 |
0 |
String file = "fsd.png"; |
97 |
0 |
String type = MimeTypesUtil.getMimeTypeFromFilename(file); |
98 |
0 |
System.out.println(type); |
99 |
|
} |
100 |
|
|
101 |
|
} |