1 22 23 package caramel.util; 24 25 import java.io.*; 26 import java.util.*; 27 import caramel.config.*; 28 import houston.*; 29 30 public class MimeUtils 31 { 32 private static MimeUtils _instance; 33 34 private Properties _props; 35 36 private MimeUtils() 37 { 38 Properties defaultProps = new Properties(); 39 40 defaultProps.setProperty( "jnlp", "application/x-java-jnlp-file" ); 41 42 _props = new Properties( defaultProps ); 43 44 ClassLoader cl = MimeUtils.class.getClassLoader(); 45 46 try 47 { 48 InputStream in = cl.getResourceAsStream( Constants.MIME_PROPERTIES ); 49 if( in == null ) 50 Status.error( "*** failed to find properties " + Constants.MIME_PROPERTIES ); 51 else 52 _props.load( in ); 53 } 54 catch( IOException ioex ) 55 { 56 Status.error( "*** failed to load properties " + Constants.MIME_PROPERTIES + ": " + ioex.toString() ); 57 } 58 } 59 60 private static MimeUtils getInstance() 61 { 62 if( _instance == null ) 63 _instance = new MimeUtils(); 64 return _instance; 65 } 66 67 public static String guessContentTypeFromName( String name ) 68 { 69 String ext = FileUtils.getFileExtension( name, false ); 71 72 ext = ext.toLowerCase(); 73 74 String contentType = getInstance().lookupContentType( ext ); 75 76 if( contentType == null ) 77 contentType = "text/plain"; 78 79 return contentType; 80 } 81 82 public String lookupContentType( String ext ) 83 { 84 return ( String ) _props.get( ext ); 85 } 86 87 } 88 | Popular Tags |