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.request.components.editor.inspectors.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("xml", "text/xml");
    61  		suffixToContentType.put("wsdl", "text/xml");
    62  		suffixToContentType.put("xsd", "text/xml");
    63  		suffixToContentType.put("c", "text/plain");
    64  		suffixToContentType.put("c++", "text/plain");
    65  		suffixToContentType.put("pl", "text/plain");
    66  		suffixToContentType.put("c", "text/plain");
    67  		suffixToContentType.put("h", "text/plain");
    68  		// suffixToContentType.put("", "text/richtext");
    69  		// suffixToContentType.put("", "text/x-setext");
    70  		// suffixToContentType.put("", "text/enriched");
    71  		// suffixToContentType.put("", "text/tab-separated-values");
    72  		// suffixToContentType.put("", "text/sgml");
    73  		suffixToContentType.put("talk", "text/x-speech");
    74  		suffixToContentType.put("css", "text/css");
    75  		// suffixToContentType.put("", "application/dsssl");
    76  		suffixToContentType.put("gif", "image/gif");
    77  		suffixToContentType.put("xbm", "image/x-xbitmap");
    78  		suffixToContentType.put("xpm", "image/x-xpixmap");
    79  		suffixToContentType.put("png", "image/x-png");
    80  		suffixToContentType.put("ief", "image/ief");
    81  		suffixToContentType.put("jpeg", "image/jpeg");
    82  		suffixToContentType.put("jpg", "image/jpeg");
    83  		suffixToContentType.put("jpe", "image/jpeg");
    84  		suffixToContentType.put("tiff tif", "image/tiff");
    85  		suffixToContentType.put("tif", "image/tiff");
    86  		suffixToContentType.put("rgb", "image/rgb");
    87  		// suffixToContentType.put("", "image/x-rgb");
    88  		suffixToContentType.put("g3f ", "image/g3fax");
    89  		suffixToContentType.put("xwd ", "image/x-xwindowdump");
    90  		suffixToContentType.put("pict", "image/x-pict");
    91  		suffixToContentType.put("ppm", "image/x-portable-pixmap");
    92  		suffixToContentType.put("pgm", "image/x-portable-graymap");
    93  		suffixToContentType.put("pbm", "image/x-portable-bitmap");
    94  		suffixToContentType.put("pnm", "image/x-portable-anymap");
    95  		suffixToContentType.put("bmp", "image/x-ms-bmp");
    96  		suffixToContentType.put("ras", "image/x-cmu-raster");
    97  		suffixToContentType.put("pcd", "image/x-photo-cd");
    98  		suffixToContentType.put("cgm", "image/cgm");
    99  		// suffixToContentType.put("", "image/naplps");
    100 		suffixToContentType.put("mil", "image/x-cals");
    101 		suffixToContentType.put("cal", "image/x-cals");
    102 		suffixToContentType.put("fif", "image/fif");
    103 		suffixToContentType.put("dsf", "image/x-mgx-dsf");
    104 		suffixToContentType.put("cmx", "image/x-cmx");
    105 		suffixToContentType.put("wi", "image/wavelet");
    106 		suffixToContentType.put("dwg", "image/vnd.dwg");
    107 		// suffixToContentType.put("", "image/x-dwg");
    108 		suffixToContentType.put("dxf", "image/vnd.dxf");
    109 		// suffixToContentType.put("", "image/x-dxf");
    110 		suffixToContentType.put("svf", "image/vnd.svf");
    111 		// suffixToContentType.put("", "also vector/x-svf");
    112 		suffixToContentType.put("au snd", "audio/basic");
    113 		suffixToContentType.put("snd", "audio/basic");
    114 		suffixToContentType.put("aif", "audio/x-aiff");
    115 		suffixToContentType.put("aiff", "audio/x-aiff");
    116 		suffixToContentType.put("aifc", "audio/x-aiff");
    117 		suffixToContentType.put("wav", "audio/x-wav");
    118 		suffixToContentType.put("mpa", "audio/x-mpeg");
    119 		suffixToContentType.put("abs", "audio/x-mpeg");
    120 		suffixToContentType.put("mpega", "audio/x-mpeg");
    121 		suffixToContentType.put("mp2a", "audio/x-mpeg-2");
    122 		suffixToContentType.put("mpa2", "audio/x-mpeg-2");
    123 		suffixToContentType.put("es", "audio/echospeech");
    124 		suffixToContentType.put("vox", "audio/voxware");
    125 		suffixToContentType.put("lcc", "application/fastman");
    126 		suffixToContentType.put("ra", "application/x-pn-realaudio");
    127 		suffixToContentType.put("ram", "application/x-pn-realaudio");
    128 		// suffixToContentType.put("", "application/vnd.music-niff");
    129 		suffixToContentType.put("mmid", "x-music/x-midi");
    130 		suffixToContentType.put("skp", "application/vnd.koan");
    131 		// suffixToContentType.put("", "application/x-koan");
    132 		suffixToContentType.put("talk", "text/x-speech");
    133 		suffixToContentType.put("mpeg", "video/mpeg");
    134 		suffixToContentType.put("mpg", "video/mpeg");
    135 		suffixToContentType.put("mpe", "video/mpeg");
    136 		suffixToContentType.put("mpv2", "video/mpeg-2");
    137 		suffixToContentType.put("mp2v", "video/mpeg-2");
    138 		suffixToContentType.put("qt", "video/quicktime");
    139 		suffixToContentType.put("mov", "video/quicktime");
    140 		suffixToContentType.put("avi", "video/x-msvideo");
    141 		suffixToContentType.put("movie", "video/x-sgi-movie");
    142 		suffixToContentType.put("vdo", "video/vdo");
    143 		suffixToContentType.put("viv", "video/vnd.vivo");
    144 		// suffixToContentType.put("", "video/vivo");
    145 		suffixToContentType.put("pac", "application/x-ns-proxy-autoconfig");
    146 		// suffixToContentType.put("", "application/x-www-form-urlencoded");
    147 		// suffixToContentType.put("", "application/x-www-local-exec");
    148 		// suffixToContentType.put("", "multipart/x-mixed-replace");
    149 		// suffixToContentType.put("", "multipart/form-data");
    150 		suffixToContentType.put("ice", "x-conference/x-cooltalk");
    151 		// suffixToContentType.put("", "application/x-chat");
    152 		suffixToContentType.put("ai", "application/postscript");
    153 		suffixToContentType.put("eps", "application/postscript");
    154 		suffixToContentType.put("ps", "application/postscript");
    155 		suffixToContentType.put("rtf", "application/rtf");
    156 		suffixToContentType.put("pdf", "application/pdf");
    157 		// suffixToContentType.put("", "application/x-pdf");
    158 		suffixToContentType.put("mif", "application/vnd.mif");
    159 		// suffixToContentType.put("", "application/x-mif");
    160 		suffixToContentType.put("t", "application/x-troff");
    161 		suffixToContentType.put("tr", "application/x-troff");
    162 		suffixToContentType.put("roff", "application/x-troff");
    163 		suffixToContentType.put("man", "application/x-troff-man");
    164 		suffixToContentType.put("me", "application/x-troff-me");
    165 		suffixToContentType.put("ms", "application/x-troff-ms");
    166 		suffixToContentType.put("latex", "application/x-latex");
    167 		suffixToContentType.put("tex", "application/x-tex");
    168 		suffixToContentType.put("texinfo", "application/x-texinfo");
    169 		suffixToContentType.put("texi ", "application/x-texinfo");
    170 		suffixToContentType.put("dvi", "application/x-dvi");
    171 		// suffixToContentType.put("", "application/macwriteii");
    172 		suffixToContentType.put("doc", "application/msword");
    173 		// suffixToContentType.put("", "application/wordperfect5.1");
    174 		// suffixToContentType.put("", "application/sgml");
    175 		suffixToContentType.put("oda", "application/oda");
    176 		suffixToContentType.put("evy", "application/envoy");
    177 		// suffixToContentType.put("", "application/wita");
    178 		// suffixToContentType.put("", "application/dec-dx");
    179 		// suffixToContentType.put("", "application/dca-rft");
    180 		// suffixToContentType.put("", "application/commonground");
    181 		suffixToContentType.put("fm", "application/vnd.framemaker");
    182 		suffixToContentType.put("frm", "application/vnd.framemaker");
    183 		suffixToContentType.put("frame", "application/vnd.framemaker");
    184 		// suffixToContentType.put("", "application/x-framemaker");
    185 		// suffixToContentType.put("", "application/remote-printing");
    186 		suffixToContentType.put("gtar", "application/x-gtar");
    187 		suffixToContentType.put("tar", "application/x-tar");
    188 		suffixToContentType.put("ustar", "application/x-ustar");
    189 		suffixToContentType.put("bcpio", "application/x-bcpio");
    190 		suffixToContentType.put("cpio", "application/x-cpio");
    191 		suffixToContentType.put("shar", "application/x-shar");
    192 		suffixToContentType.put("zip", "application/zip");
    193 		suffixToContentType.put("hqx", "application/mac-binhex40");
    194 		suffixToContentType.put("sit", "application/x-stuffit");
    195 		suffixToContentType.put("sea", "application/x-stuffit");
    196 		suffixToContentType.put("fif", "application/fractals");
    197 		suffixToContentType.put("bin", "application/octet-stream");
    198 		suffixToContentType.put("uu", "application/octet-stream");
    199 		suffixToContentType.put("exe", "application/octet-stream");
    200 		suffixToContentType.put("src", "application/x-wais-source");
    201 		suffixToContentType.put("wsrc", "application/x-wais-source");
    202 		suffixToContentType.put("hdf", "application/hdf");
    203 		suffixToContentType.put("js", "text/javascript");
    204 		suffixToContentType.put("ls", "text/javascript");
    205 		suffixToContentType.put("mocha", "text/javascript");
    206 		// suffixToContentType.put("", "application/x-javascript");
    207 		// suffixToContentType.put("", "text/vbscript");
    208 		suffixToContentType.put("sh", "application/x-sh");
    209 		suffixToContentType.put("csh", "application/x-csh");
    210 		suffixToContentType.put("pl", "application/x-perl");
    211 		suffixToContentType.put("tcl ", "application/x-tcl");
    212 		// suffixToContentType.put("", "application/atomicmail");
    213 		// suffixToContentType.put("", "application/slate");
    214 		// suffixToContentType.put("", "application/octet-stream");
    215 		// suffixToContentType.put("", "application/riscos");
    216 		// suffixToContentType.put("", "application/andrew-inset");
    217 		suffixToContentType.put("spl", "application/futuresplash");
    218 		suffixToContentType.put("mbd", "application/mbedlet");
    219 		// suffixToContentType.put("", "application/x-director");
    220 		// suffixToContentType.put("", "application/x-sprite");
    221 		suffixToContentType.put("rad", "application/x-rad-powermedia");
    222 		suffixToContentType.put("ppz", "application/mspowerpoint");
    223 		suffixToContentType.put("css", "application/x-pointplus");
    224 		suffixToContentType.put("asp", "application/x-asap");
    225 		suffixToContentType.put("asn", "application/astound");
    226 		suffixToContentType.put("axs", "application/x-olescript");
    227 		suffixToContentType.put("ods", "application/x-oleobject");
    228 		suffixToContentType.put("opp", "x-form/x-openscape");
    229 		suffixToContentType.put("wba", "application/x-webbasic");
    230 		suffixToContentType.put("frm", "application/x-alpha-form");
    231 		suffixToContentType.put("wfx", "x-script/x-wfxclient");
    232 		// suffixToContentType.put("", "application/octet-stream");
    233 		// suffixToContentType.put("", "application/cals-1840");
    234 		suffixToContentType.put("pcn", "application/x-pcn");
    235 		// suffixToContentType.put("", "application/vnd.ms-excel");
    236 		// suffixToContentType.put("", "application/x-msexcel");
    237 		// suffixToContentType.put("", "application/ms-excel");
    238 		suffixToContentType.put("ppt", "application/vnd.ms-powerpoint");
    239 		// suffixToContentType.put("", "application/ms-powerpoint");
    240 		// suffixToContentType.put("", "application/vnd.ms-project");
    241 		// suffixToContentType.put("", "application/vnd.ms-works");
    242 		// suffixToContentType.put("", "application/vnd.ms-tnef");
    243 		// suffixToContentType.put("", "application/vnd.artgalry");
    244 		suffixToContentType.put("svd", "application/vnd.svd");
    245 		// suffixToContentType.put("", "application/vnd.truedoc");
    246 		suffixToContentType.put("ins", "application/x-net-install");
    247 		suffixToContentType.put("ccv", "application/ccv");
    248 		suffixToContentType.put("vts", "workbook/formulaone");
    249 		// suffixToContentType.put("", "application/cybercash");
    250 		// suffixToContentType.put("", "application/applefile");
    251 		// suffixToContentType.put("", "application/activemessage");
    252 		// suffixToContentType.put("", "application/x400-bp");
    253 		// suffixToContentType.put("", "application/news-message-id");
    254 		// suffixToContentType.put("", "application/news-transmission");
    255 		// suffixToContentType.put("", "multipart/mixed");
    256 		// suffixToContentType.put("", "multipart/alternative");
    257 		// suffixToContentType.put("", "multipart/related");
    258 		// suffixToContentType.put("", "multipart/digest");
    259 		// suffixToContentType.put("", "multipart/report");
    260 		// suffixToContentType.put("", "multipart/parallel");
    261 		// suffixToContentType.put("", "multipart/appledouble");
    262 		// suffixToContentType.put("", "multipart/header-set");
    263 		// suffixToContentType.put("", "multipart/voice-message");
    264 		// suffixToContentType.put("", "multipart/form-data");
    265 		// suffixToContentType.put("", "multipart/x-mixed-replace");
    266 		// suffixToContentType.put("", "message/rfc822");
    267 		// suffixToContentType.put("", "message/partial");
    268 		// suffixToContentType.put("", "message/external-body");
    269 		// suffixToContentType.put("", "message/news");
    270 		// suffixToContentType.put("", "message/http");
    271 		suffixToContentType.put("wrl", "x-world/x-vrml");
    272 		suffixToContentType.put("vrml", "x-world/x-vrml");
    273 		suffixToContentType.put("vrw", "x-world/x-vream");
    274 		suffixToContentType.put("p3d", "application/x-p3d");
    275 		suffixToContentType.put("svr", "x-world/x-svr");
    276 		suffixToContentType.put("wvr", "x-world/x-wvr");
    277 		suffixToContentType.put("3dmf", "x-world/x-3dmf");
    278 		// suffixToContentType.put("", "chemical/*");
    279 		suffixToContentType.put("ma", "application/mathematica");
    280 		suffixToContentType.put("msh", "x-model/x-mesh");
    281 		suffixToContentType.put("v5d", "application/vis5d");
    282 		suffixToContentType.put("igs", "application/iges");
    283 		suffixToContentType.put("dwf ", "drawing/x-dwf");
    284 		suffixToContentType.put("showcase", "application/x-showcase");
    285 		suffixToContentType.put("slides", "application/x-showcase");
    286 		suffixToContentType.put("sc", "application/x-showcase");
    287 		suffixToContentType.put("show", "application/x-showcase");
    288 		suffixToContentType.put("ins", "application/x-insight");
    289 		suffixToContentType.put("insight", "application/x-insight");
    290 		suffixToContentType.put("ano", "application/x-annotator");
    291 		suffixToContentType.put("dir", "application/x-dirview");
    292 		suffixToContentType.put("lic", "application/x-enterlicense");
    293 		suffixToContentType.put("faxmgr", "application/x-fax-manager");
    294 		suffixToContentType.put("faxmgrjob", "application/x-fax-manager-job");
    295 		suffixToContentType.put("icnbk", "application/x-iconbook");
    296 		suffixToContentType.put("wb", "application/x-inpview");
    297 		suffixToContentType.put("inst ", "application/x-install");
    298 		suffixToContentType.put("mail", "application/x-mailfolder");
    299 		suffixToContentType.put("pp ppages", "application/x-ppages");
    300 		suffixToContentType.put("sgi-lpr", "application/x-sgi-lpr");
    301 		suffixToContentType.put("tardist", "application/x-tardist");
    302 		suffixToContentType.put("ztardist", "application/x-ztardist");
    303 		suffixToContentType.put("wkz", "application/x-wingz");
    304 		suffixToContentType.put("iv", "graphics/x-inventor");
    305 	}
    306
    307 }