1 22 package org.apache.webdav.ant; 23 24 import java.io.File ; 25 import java.util.Enumeration ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 import java.util.ResourceBundle ; 29 30 31 35 public class Mimetypes 36 { 37 private static Map mimetypes = new HashMap (); 38 39 static { 40 ResourceBundle rb = 41 ResourceBundle.getBundle("org.apache.webdav.ant.mimetypes"); 42 43 for(Enumeration e = rb.getKeys(); e.hasMoreElements(); ) { 44 String ext = (String )e.nextElement(); 45 mimetypes.put(ext, rb.getString(ext)); 46 } 47 } 48 49 public static String getMimeTypeForExtension(String extension, String defaultType) { 50 String mime = (String )mimetypes.get(extension); 51 if (mime == null) mime = defaultType; 52 return mime; 53 } 54 55 public static String getMimeType(File file, String defaultType) { 56 String ext = file.getName(); 57 int dotPos = ext.lastIndexOf('.'); 58 if (dotPos != -1) { 59 return getMimeTypeForExtension(ext.substring(dotPos + 1), defaultType); 60 } else { 61 return defaultType; 62 } 63 } 64 public static String getMimeType(String file, String defaultType) { 65 int dotPos = file.lastIndexOf('.'); 66 if (dotPos != -1) { 67 return getMimeTypeForExtension(file.substring(dotPos + 1), defaultType); 68 } else { 69 return defaultType; 70 } 71 } 72 73 public static String getExtension(String fileName) { 74 int dotPos = fileName.lastIndexOf('.'); 75 if (dotPos != -1) { 76 return fileName.substring(dotPos + 1); 77 } else { 78 return null; 79 } 80 } 81 } 82 | Popular Tags |