1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.mailsender

File MimeTypesUtil.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

10
17
2
1
101
77
7
0.41
8.5
2
3.5

Classes

Class Line # Actions
MimeTypesUtil 22 17 0% 7 29
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.plugin.mailsender;
21   
 
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   
 
72  0 toggle 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   
 
95  0 toggle 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    }