Monday, November 08, 2010 at 12:04 AM.
system.verbs.builtins.mainResponder.getFileMimeType
on getFileMimeType (f) { //get the MIME type of a file (not a folder) <<Get the MIME type of a file. <<Changes: <<12/7/01; 2:11:26 PM by PBS <<Don't do caching. Caching defeats the ability of the webmaster to configure MIME settings. <<On Macs, check the file extension if there's no match on the file type. <<local (adrCache = @system.temp.mainResponder.mimeTypeCache) <<if not defined (adrCache^) //PBS 12/07/01: don't do caching <<new (tableType, adrCache) <<else <<try {return (adrCache^.[f])} //the mime type may be cached local (mimeType = "text/html"); local (objectType = file.type (f)); if system.environment.isWindows { objectType = string.replaceAll (objectType, " ", ""); // strip spaces if defined (user.webserver.prefs.ext2MIME.[objectType]) { mimeType = user.webserver.prefs.ext2MIME.[objectType]}}; if system.environment.isMac { if defined (user.webserver.prefs.type2MIME.[objectType]) { mimeType = user.webserver.prefs.type2MIME.[objectType]} else { //PBS 12/0701: try extension local (extension = string.nthField (f, ".", string.countFields (f, "."))); if defined (user.webserver.prefs.ext2MIME.[extension]) { mimeType = user.webserver.prefs.ext2MIME.[extension]}}}; <<adrCache^.[f] = mimeType //cache the mime type //PBS 12/07/01: don't do caching return (mimeType)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.