View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.impl.wsdl.panels.attachments;
    14
    15  import java.util.HashMap;
    16
    17  /***
    18   * Handles drop of files on the AttachementPanel
    19   *
    20   * @author ole.matzura
    21   */
    22
    23  public class ContentTypeHandler
    24  {
    25  	private static final HashMap<String, String> suffixToContentType;
    26  	public static final String DEFAULT_CONTENTTYPE = "application/octet-stream";
    27
    28  	public static String getContentTypeFromFilename(String fileName)
    29  	{
    30  		String suffix = getSuffixFromFilename(fileName);
    31
    32  		if (suffixToContentType.containsKey(suffix))
    33  			return suffixToContentType.get(suffix);
    34
    35  		return DEFAULT_CONTENTTYPE;
    36  	}
    37
    38  	public static String getSuffixFromFilename(String fileName)
    39  	{
    40  		if (fileName == null || fileName.length() == 0)
    41  			return "";
    42
    43  		int pos = fileName.lastIndexOf(".") + 1;
    44  		int len = fileName.length();
    45
    46  		String suffix = "";
    47  		if (pos < len)
    48  			suffix = fileName.substring(pos, len);
    49
    50  		return suffix;
    51
    52  	}
    53
    54  	static
    55  	{
    56  		suffixToContentType = new HashMap<String, String>();
    57  		suffixToContentType.put("html", "text/html");
    58  		suffixToContentType.put("htm", "text/html");
    59  		suffixToContentType.put("txt", "text/plain");
    60  		suffixToContentType.put("c", "text/plain");
    61  		suffixToContentType.put("c++", "text/plain");
    62  		suffixToContentType.put("pl", "text/plain");
    63  		suffixToContentType.put("c", "text/plain");
    64  		suffixToContentType.put("h", "text/plain");
    65  		// suffixToContentType.put("", "text/richtext");
    66  		// suffixToContentType.put("", "text/x-setext");
    67  		// suffixToContentType.put("", "text/enriched");
    68  		// suffixToContentType.put("", "text/tab-separated-values");
    69  		// suffixToContentType.put("", "text/sgml");
    70  		suffixToContentType.put("talk", "text/x-speech");
    71  		suffixToContentType.put("css", "text/css");
    72  		// suffixToContentType.put("", "application/dsssl");
    73  		suffixToContentType.put("gif", "image/gif");
    74  		suffixToContentType.put("xbm", "image/x-xbitmap");
    75  		suffixToContentType.put("xpm", "image/x-xpixmap");
    76  		suffixToContentType.put("png", "image/x-png");
    77  		suffixToContentType.put("ief", "image/ief");
    78  		suffixToContentType.put("jpeg", "image/jpeg");
    79  		suffixToContentType.put("jpg", "image/jpeg");
    80  		suffixToContentType.put("jpe", "image/jpeg");
    81  		suffixToContentType.put("tiff tif", "image/tiff");
    82  		suffixToContentType.put("tif", "image/tiff");
    83  		suffixToContentType.put("rgb", "image/rgb");
    84  		// suffixToContentType.put("", "image/x-rgb");
    85  		suffixToContentType.put("g3f ", "image/g3fax");
    86  		suffixToContentType.put("xwd ", "image/x-xwindowdump");
    87  		suffixToContentType.put("pict", "image/x-pict");
    88  		suffixToContentType.put("ppm", "image/x-portable-pixmap");
    89  		suffixToContentType.put("pgm", "image/x-portable-graymap");
    90  		suffixToContentType.put("pbm", "image/x-portable-bitmap");
    91  		suffixToContentType.put("pnm", "image/x-portable-anymap");
    92  		suffixToContentType.put("bmp", "image/x-ms-bmp");
    93  		suffixToContentType.put("ras", "image/x-cmu-raster");
    94  		suffixToContentType.put("pcd", "image/x-photo-cd");
    95  		suffixToContentType.put("cgm", "image/cgm");
    96  		// suffixToContentType.put("", "image/naplps");
    97  		suffixToContentType.put("mil", "image/x-cals");
    98  		suffixToContentType.put("cal", "image/x-cals");
    99  		suffixToContentType.put("fif", "image/fif");
    100 		suffixToContentType.put("dsf", "image/x-mgx-dsf");
    101 		suffixToContentType.put("cmx", "image/x-cmx");
    102 		suffixToContentType.put("wi", "image/wavelet");
    103 		suffixToContentType.put("dwg", "image/vnd.dwg");
    104 		// suffixToContentType.put("", "image/x-dwg");
    105 		suffixToContentType.put("dxf", "image/vnd.dxf");
    106 		// suffixToContentType.put("", "image/x-dxf");
    107 		suffixToContentType.put("svf", "image/vnd.svf");
    108 		// suffixToContentType.put("", "also vector/x-svf");
    109 		suffixToContentType.put("au snd", "audio/basic");
    110 		suffixToContentType.put("snd", "audio/basic");
    111 		suffixToContentType.put("aif", "audio/x-aiff");
    112 		suffixToContentType.put("aiff", "audio/x-aiff");
    113 		suffixToContentType.put("aifc", "audio/x-aiff");
    114 		suffixToContentType.put("wav", "audio/x-wav");
    115 		suffixToContentType.put("mpa", "audio/x-mpeg");
    116 		suffixToContentType.put("abs", "audio/x-mpeg");
    117 		suffixToContentType.put("mpega", "audio/x-mpeg");
    118 		suffixToContentType.put("mp2a", "audio/x-mpeg-2");
    119 		suffixToContentType.put("mpa2", "audio/x-mpeg-2");
    120 		suffixToContentType.put("es", "audio/echospeech");
    121 		suffixToContentType.put("vox", "audio/voxware");
    122 		suffixToContentType.put("lcc", "application/fastman");
    123 		suffixToContentType.put("ra", "application/x-pn-realaudio");
    124 		suffixToContentType.put("ram", "application/x-pn-realaudio");
    125 		// suffixToContentType.put("", "application/vnd.music-niff");
    126 		suffixToContentType.put("mmid", "x-music/x-midi");
    127 		suffixToContentType.put("skp", "application/vnd.koan");
    128 		// suffixToContentType.put("", "application/x-koan");
    129 		suffixToContentType.put("talk", "text/x-speech");
    130 		suffixToContentType.put("mpeg", "video/mpeg");
    131 		suffixToContentType.put("mpg", "video/mpeg");
    132 		suffixToContentType.put("mpe", "video/mpeg");
    133 		suffixToContentType.put("mpv2", "video/mpeg-2");
    134 		suffixToContentType.put("mp2v", "video/mpeg-2");
    135 		suffixToContentType.put("qt", "video/quicktime");
    136 		suffixToContentType.put("mov", "video/quicktime");
    137 		suffixToContentType.put("avi", "video/x-msvideo");
    138 		suffixToContentType.put("movie", "video/x-sgi-movie");
    139 		suffixToContentType.put("vdo", "video/vdo");
    140 		suffixToContentType.put("viv", "video/vnd.vivo");
    141 		// suffixToContentType.put("", "video/vivo");
    142 		suffixToContentType.put("pac", "application/x-ns-proxy-autoconfig");
    143 		// suffixToContentType.put("", "application/x-www-form-urlencoded");
    144 		// suffixToContentType.put("", "application/x-www-local-exec");
    145 		// suffixToContentType.put("", "multipart/x-mixed-replace");
    146 		// suffixToContentType.put("", "multipart/form-data");
    147 		suffixToContentType.put("ice", "x-conference/x-cooltalk");
    148 		// suffixToContentType.put("", "application/x-chat");
    149 		suffixToContentType.put("ai", "application/postscript");
    150 		suffixToContentType.put("eps", "application/postscript");
    151 		suffixToContentType.put("ps", "application/postscript");
    152 		suffixToContentType.put("rtf", "application/rtf");
    153 		suffixToContentType.put("pdf", "application/pdf");
    154 		// suffixToContentType.put("", "application/x-pdf");
    155 		suffixToContentType.put("mif", "application/vnd.mif");
    156 		// suffixToContentType.put("", "application/x-mif");
    157 		suffixToContentType.put("t", "application/x-troff");
    158 		suffixToContentType.put("tr", "application/x-troff");
    159 		suffixToContentType.put("roff", "application/x-troff");
    160 		suffixToContentType.put("man", "application/x-troff-man");
    161 		suffixToContentType.put("me", "application/x-troff-me");
    162 		suffixToContentType.put("ms", "application/x-troff-ms");
    163 		suffixToContentType.put("latex", "application/x-latex");
    164 		suffixToContentType.put("tex", "application/x-tex");
    165 		suffixToContentType.put("texinfo", "application/x-texinfo");
    166 		suffixToContentType.put("texi ", "application/x-texinfo");
    167 		suffixToContentType.put("dvi", "application/x-dvi");
    168 		// suffixToContentType.put("", "application/macwriteii");
    169 		suffixToContentType.put("doc", "application/msword");
    170 		// suffixToContentType.put("", "application/wordperfect5.1");
    171 		// suffixToContentType.put("", "application/sgml");
    172 		suffixToContentType.put("oda", "application/oda");
    173 		suffixToContentType.put("evy", "application/envoy");
    174 		// suffixToContentType.put("", "application/wita");
    175 		// suffixToContentType.put("", "application/dec-dx");
    176 		// suffixToContentType.put("", "application/dca-rft");
    177 		// suffixToContentType.put("", "application/commonground");
    178 		suffixToContentType.put("fm", "application/vnd.framemaker");
    179 		suffixToContentType.put("frm", "application/vnd.framemaker");
    180 		suffixToContentType.put("frame", "application/vnd.framemaker");
    181 		// suffixToContentType.put("", "application/x-framemaker");
    182 		// suffixToContentType.put("", "application/remote-printing");
    183 		suffixToContentType.put("gtar", "application/x-gtar");
    184 		suffixToContentType.put("tar", "application/x-tar");
    185 		suffixToContentType.put("ustar", "application/x-ustar");
    186 		suffixToContentType.put("bcpio", "application/x-bcpio");
    187 		suffixToContentType.put("cpio", "application/x-cpio");
    188 		suffixToContentType.put("shar", "application/x-shar");
    189 		suffixToContentType.put("zip", "application/zip");
    190 		suffixToContentType.put("hqx", "application/mac-binhex40");
    191 		suffixToContentType.put("sit", "application/x-stuffit");
    192 		suffixToContentType.put("sea", "application/x-stuffit");
    193 		suffixToContentType.put("fif", "application/fractals");
    194 		suffixToContentType.put("bin", "application/octet-stream");
    195 		suffixToContentType.put("uu", "application/octet-stream");
    196 		suffixToContentType.put("exe", "application/octet-stream");
    197 		suffixToContentType.put("src", "application/x-wais-source");
    198 		suffixToContentType.put("wsrc", "application/x-wais-source");
    199 		suffixToContentType.put("hdf", "application/hdf");
    200 		suffixToContentType.put("js", "text/javascript");
    201 		suffixToContentType.put("ls", "text/javascript");
    202 		suffixToContentType.put("mocha", "text/javascript");
    203 		// suffixToContentType.put("", "application/x-javascript");
    204 		// suffixToContentType.put("", "text/vbscript");
    205 		suffixToContentType.put("sh", "application/x-sh");
    206 		suffixToContentType.put("csh", "application/x-csh");
    207 		suffixToContentType.put("pl", "application/x-perl");
    208 		suffixToContentType.put("tcl ", "application/x-tcl");
    209 		// suffixToContentType.put("", "application/atomicmail");
    210 		// suffixToContentType.put("", "application/slate");
    211 		// suffixToContentType.put("", "application/octet-stream");
    212 		// suffixToContentType.put("", "application/riscos");
    213 		// suffixToContentType.put("", "application/andrew-inset");
    214 		suffixToContentType.put("spl", "application/futuresplash");
    215 		suffixToContentType.put("mbd", "application/mbedlet");
    216 		// suffixToContentType.put("", "application/x-director");
    217 		// suffixToContentType.put("", "application/x-sprite");
    218 		suffixToContentType.put("rad", "application/x-rad-powermedia");
    219 		suffixToContentType.put("ppz", "application/mspowerpoint");
    220 		suffixToContentType.put("css", "application/x-pointplus");
    221 		suffixToContentType.put("asp", "application/x-asap");
    222 		suffixToContentType.put("asn", "application/astound");
    223 		suffixToContentType.put("axs", "application/x-olescript");
    224 		suffixToContentType.put("ods", "application/x-oleobject");
    225 		suffixToContentType.put("opp", "x-form/x-openscape");
    226 		suffixToContentType.put("wba", "application/x-webbasic");
    227 		suffixToContentType.put("frm", "application/x-alpha-form");
    228 		suffixToContentType.put("wfx", "x-script/x-wfxclient");
    229 		// suffixToContentType.put("", "application/octet-stream");
    230 		// suffixToContentType.put("", "application/cals-1840");
    231 		suffixToContentType.put("pcn", "application/x-pcn");
    232 		// suffixToContentType.put("", "application/vnd.ms-excel");
    233 		// suffixToContentType.put("", "application/x-msexcel");
    234 		// suffixToContentType.put("", "application/ms-excel");
    235 		suffixToContentType.put("ppt", "application/vnd.ms-powerpoint");
    236 		// suffixToContentType.put("", "application/ms-powerpoint");
    237 		// suffixToContentType.put("", "application/vnd.ms-project");
    238 		// suffixToContentType.put("", "application/vnd.ms-works");
    239 		// suffixToContentType.put("", "application/vnd.ms-tnef");
    240 		// suffixToContentType.put("", "application/vnd.artgalry");
    241 		suffixToContentType.put("svd", "application/vnd.svd");
    242 		// suffixToContentType.put("", "application/vnd.truedoc");
    243 		suffixToContentType.put("ins", "application/x-net-install");
    244 		suffixToContentType.put("ccv", "application/ccv");
    245 		suffixToContentType.put("vts", "workbook/formulaone");
    246 		// suffixToContentType.put("", "application/cybercash");
    247 		// suffixToContentType.put("", "application/applefile");
    248 		// suffixToContentType.put("", "application/activemessage");
    249 		// suffixToContentType.put("", "application/x400-bp");
    250 		// suffixToContentType.put("", "application/news-message-id");
    251 		// suffixToContentType.put("", "application/news-transmission");
    252 		// suffixToContentType.put("", "multipart/mixed");
    253 		// suffixToContentType.put("", "multipart/alternative");
    254 		// suffixToContentType.put("", "multipart/related");
    255 		// suffixToContentType.put("", "multipart/digest");
    256 		// suffixToContentType.put("", "multipart/report");
    257 		// suffixToContentType.put("", "multipart/parallel");
    258 		// suffixToContentType.put("", "multipart/appledouble");
    259 		// suffixToContentType.put("", "multipart/header-set");
    260 		// suffixToContentType.put("", "multipart/voice-message");
    261 		// suffixToContentType.put("", "multipart/form-data");
    262 		// suffixToContentType.put("", "multipart/x-mixed-replace");
    263 		// suffixToContentType.put("", "message/rfc822");
    264 		// suffixToContentType.put("", "message/partial");
    265 		// suffixToContentType.put("", "message/external-body");
    266 		// suffixToContentType.put("", "message/news");
    267 		// suffixToContentType.put("", "message/http");
    268 		suffixToContentType.put("wrl", "x-world/x-vrml");
    269 		suffixToContentType.put("vrml", "x-world/x-vrml");
    270 		suffixToContentType.put("vrw", "x-world/x-vream");
    271 		suffixToContentType.put("p3d", "application/x-p3d");
    272 		suffixToContentType.put("svr", "x-world/x-svr");
    273 		suffixToContentType.put("wvr", "x-world/x-wvr");
    274 		suffixToContentType.put("3dmf", "x-world/x-3dmf");
    275 		// suffixToContentType.put("", "chemical/*");
    276 		suffixToContentType.put("ma", "application/mathematica");
    277 		suffixToContentType.put("msh", "x-model/x-mesh");
    278 		suffixToContentType.put("v5d", "application/vis5d");
    279 		suffixToContentType.put("igs", "application/iges");
    280 		suffixToContentType.put("dwf ", "drawing/x-dwf");
    281 		suffixToContentType.put("showcase", "application/x-showcase");
    282 		suffixToContentType.put("slides", "application/x-showcase");
    283 		suffixToContentType.put("sc", "application/x-showcase");
    284 		suffixToContentType.put("show", "application/x-showcase");
    285 		suffixToContentType.put("ins", "application/x-insight");
    286 		suffixToContentType.put("insight", "application/x-insight");
    287 		suffixToContentType.put("ano", "application/x-annotator");
    288 		suffixToContentType.put("dir", "application/x-dirview");
    289 		suffixToContentType.put("lic", "application/x-enterlicense");
    290 		suffixToContentType.put("faxmgr", "application/x-fax-manager");
    291 		suffixToContentType.put("faxmgrjob", "application/x-fax-manager-job");
    292 		suffixToContentType.put("icnbk", "application/x-iconbook");
    293 		suffixToContentType.put("wb", "application/x-inpview");
    294 		suffixToContentType.put("inst ", "application/x-install");
    295 		suffixToContentType.put("mail", "application/x-mailfolder");
    296 		suffixToContentType.put("pp ppages", "application/x-ppages");
    297 		suffixToContentType.put("sgi-lpr", "application/x-sgi-lpr");
    298 		suffixToContentType.put("tardist", "application/x-tardist");
    299 		suffixToContentType.put("ztardist", "application/x-ztardist");
    300 		suffixToContentType.put("wkz", "application/x-wingz");
    301 		suffixToContentType.put("iv", "graphics/x-inventor");
    302 	}
    303
    304 }