FileDocCategorySizeDatePackage
MimeManager.javaAPI DocJMF 2.1.1e7838Mon May 12 12:20:48 BST 2003com.sun.media

MimeManager

public final class MimeManager extends Object

Fields Summary
private static Hashtable
additionalMimeTable
protected static final Hashtable
defaultHashTable
private static MimeTable
mimeTable
private static MimeTable
defaultMimeTable
protected static final Hashtable
extTable
Constructors Summary
private MimeManager()

    
      
    
Methods Summary
public static final booleanaddMimeType(java.lang.String fileExtension, java.lang.String mimeType)
Specify a mapping from a file extension to a mime type example addMimeType("urv", "video/unreal") You cannot override built-in mappings; for example you cannot change the mapping of "mov" file extension Returns true if the mapping was successfully made

	defaultHashTable = new Hashtable();
	mimeTable = new MimeTable();
	extTable = new Hashtable();

	// NOTE: The order of doPut and put is important
	// When adding to defaultHashTable, follow this
	// procedure.

	mimeTable.doPut("mov", "video/quicktime");
	defaultHashTable.put("mov", "video/quicktime");

	mimeTable.doPut("avi", "video/x_msvideo");
	defaultHashTable.put("avi", "video/x_msvideo");

	mimeTable.doPut("mpg", "video/mpeg");
	defaultHashTable.put("mpg", "video/mpeg");

	mimeTable.doPut("mpv", "video/mpeg");
	defaultHashTable.put("mpv", "video/mpeg");

	mimeTable.doPut("viv", "video/vivo");
	defaultHashTable.put("viv", "video/vivo");

	mimeTable.doPut("au", "audio/basic");
	defaultHashTable.put("au", "audio/basic");

	mimeTable.doPut("wav", "audio/x_wav");
	defaultHashTable.put("wav", "audio/x_wav");

	mimeTable.doPut("aiff", "audio/x_aiff");
	defaultHashTable.put("aiff", "audio/x_aiff"); // Default extension is aiff

	mimeTable.doPut("aif", "audio/x_aiff");
	defaultHashTable.put("aif", "audio/x_aiff");

	mimeTable.doPut("mid", "audio/midi");
	defaultHashTable.put("mid", "audio/midi");

	mimeTable.doPut("midi", "audio/midi");
	defaultHashTable.put("midi", "audio/midi");

	mimeTable.doPut("rmf", "audio/rmf");
	defaultHashTable.put("rmf", "audio/rmf");

	mimeTable.doPut("gsm", "audio/x_gsm");
	defaultHashTable.put("gsm", "audio/x_gsm");

	mimeTable.doPut("mp2", "audio/mpeg");
	defaultHashTable.put("mp2", "audio/mpeg");

	mimeTable.doPut("mp3", "audio/mpeg");
	defaultHashTable.put("mp3", "audio/mpeg");

	mimeTable.doPut("mpa", "audio/mpeg");
	defaultHashTable.put("mpa", "audio/mpeg");

	mimeTable.doPut("g728", "audio/g728");
	defaultHashTable.put("g728", "audio/g728");

	mimeTable.doPut("g729", "audio/g729");
	defaultHashTable.put("g729", "audio/g729");

	mimeTable.doPut("g729a", "audio/g729a");
	defaultHashTable.put("g729a", "audio/g729a");

	mimeTable.doPut("cda", "audio/cdaudio");
	defaultHashTable.put("cda", "audio/cdaudio");

	mimeTable.doPut("mvr", "application/mvr");
	defaultHashTable.put("mvr", "application/mvr");

	mimeTable.doPut("swf", "application/x-shockwave-flash");
	defaultHashTable.put("swf", "application/x-shockwave-flash");

	mimeTable.doPut("spl", "application/futuresplash");
	defaultHashTable.put("spl", "application/futuresplash");

	mimeTable.doPut("jmx", "application/x_jmx");
	defaultHashTable.put("jmx", "application/x_jmx");


	Object t = Registry.get("additionalMimeTable");
	if ( (t != null) && (t instanceof Hashtable) ) {
	    additionalMimeTable = (Hashtable) t;
	}

	// Remove illegal entries if any in the additionalMimeTable
	// These entries are those that remap default entries.
	if ((additionalMimeTable != null) && (!additionalMimeTable.isEmpty())) {
	    Enumeration e = additionalMimeTable.keys();
	    while (e.hasMoreElements()) {
		String ext = (String) e.nextElement();
		if (defaultHashTable.containsKey(ext)) {
		    additionalMimeTable.remove(ext);
		} else {
		    mimeTable.doPut(ext, (String) additionalMimeTable.get(ext));
		}
	    }
	}

// 	{ // TEST BLOCK
// 	    System.out.println("MimeTable: extTable is " + extTable);
// 	    System.out.println("mimeTable is " + getMimeTable());
// 	    Enumeration el = getMimeTable().elements();
// 	    while (el.hasMoreElements()) {
// 		String type = (String) el.nextElement();
// 		System.out.println("Def. extension of mimetype " + type +
// 				   " is " + getDefaultExtension(type));
// 	    }
// 	}

	defaultMimeTable =  (MimeTable) mimeTable.clone();
    

 	if (additionalMimeTable == null)
 	    additionalMimeTable = new Hashtable();
	
	if (mimeTable.doPut(fileExtension, mimeType)) {
	    additionalMimeTable.put(fileExtension, mimeType);
	    return true;
	} else {
	    return false;
	}
    
public static voidcommit()
Commit the changes

	// We should call set this even if additionalMimeTable is null
	// or empty.
	Registry.set("additionalMimeTable", additionalMimeTable);
	try {
	    Registry.commit();
	} catch (IOException e) {
	    System.err.println("IOException on commit " + e.getMessage());
	}
    
public static final java.lang.StringgetDefaultExtension(java.lang.String mimeType)

	return (String) extTable.get(mimeType);
    
public static final java.util.HashtablegetDefaultMimeTable()
Returns the mime table which doesn't include any entries that were added using addMimeType.

	    return defaultMimeTable;
    
public static final java.util.HashtablegetMimeTable()
Returns the mime table. This includes any mime entries that were added using addMimeType

	    return mimeTable;
    
public static final java.lang.StringgetMimeType(java.lang.String fileExtension)

	// System.out.println("MimeManager: getMimeType " + fileExtension);
	return (String) mimeTable.get(fileExtension);
    
public static final booleanremoveMimeType(java.lang.String fileExtension)
Only the mime types that were added using addMimeType can be removed with this method. Returns true if the mapping was successfully removed

	//	return mimeTable.doRemove(fileExtension);
	if ( mimeTable.doRemove(fileExtension) ) {
	    if (additionalMimeTable != null)
		additionalMimeTable.remove(fileExtension);
	    return true;
	} else {
	    return false;
	}