1 4 5 9 10 package org.openlaszlo.media; 11 12 import org.openlaszlo.utils.FileUtils; 13 14 22 public class MimeType { 23 public static final String TEXT = "text/html"; 24 public static final String SWF = "application/x-shockwave-flash"; 25 public static final String JPEG = "image/jpeg"; 26 public static final String GIF = "image/gif"; 27 public static final String PNG = "image/png"; 28 public static final String MP3 = "audio/mpeg"; 29 public static final String XMP3 = "audio/x-mpeg"; 30 public static final String XML = "text/xml"; 31 public static final String HTML = "text/html"; 32 33 public static final String UNKNOWN = "unknown"; 34 35 39 public static final String fromExtension(final String name) { 40 String extension = FileUtils.getExtension(name); 41 if (extension == null) { 42 return UNKNOWN; 43 } 44 if (extension.equals("") ) { 45 return UNKNOWN; 46 } 47 if (extension.equalsIgnoreCase("swf")) { 48 return SWF; 49 } 50 if (extension.equalsIgnoreCase("jpg") || 51 extension.equalsIgnoreCase("jpeg")) { 52 return JPEG; 53 } 54 if (extension.equalsIgnoreCase("gif")) { 55 return GIF; 56 } 57 if (extension.equalsIgnoreCase("png")) { 58 return PNG; 59 } 60 if (extension.equalsIgnoreCase("xml")) { 61 return XML; 62 } 63 if (extension.equalsIgnoreCase("lzx")) { 64 return XML; 65 } 66 if (extension.equalsIgnoreCase("html") || 67 extension.equalsIgnoreCase("htm")) { 68 return HTML; 69 } 70 if (extension.equalsIgnoreCase("mp3") || 71 extension.equalsIgnoreCase("mpeg")) { 72 return MP3; 73 } 74 return UNKNOWN; 75 } 76 77 82 public static final String toExtension(final String mimeType) { 83 84 if (mimeType == MimeType.JPEG) { 85 return "jpeg"; 86 } 87 if (mimeType == MimeType.SWF) { 88 return "swf"; 89 } 90 if (mimeType == MimeType.GIF) { 91 return "gif"; 92 } 93 if (mimeType == MimeType.PNG) { 94 return "png"; 95 } 96 if (mimeType == MimeType.MP3) { 97 return "mp3"; 98 } 99 if (mimeType == MimeType.XMP3) { 100 return "mp3"; 101 } 102 103 return mimeType; 104 } 105 } 106 | Popular Tags |