Monday, November 08, 2010 at 12:04 AM.
system.verbs.builtins.mainResponder.controlPanel.mimeTypes
on mimeTypes () {
<<Configure MIME types for serving files from disk.
<<12/7/01; 2:42:24 PM by PBS
local (pta = html.getPageTableAddress ());
local (adrTable = @user.webserver.prefs.ext2Mime);
local (htmlText = "");
local (indentLevel = 0);
local (flPost = (pta^.method == "POST"));
local (flEditing = false);
local (adrItemToEdit);
local (nameItemToEdit);
pta^.title = "MIME Types";
on add (s) {
htmlText = htmlText + string.filledString ('\t', indentLevel) + s + "\r"};
on addSeparator (s) {
add ("<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr>");
add ("<td bgcolor=\"#DCDCFF\" colspan=\"6\"><b>" + s + "</td>");
add ("</tr></table>")};
bundle { //handle POSTed form
if flPost {
if defined (pta^.postArgs.delete) { //deleting?
local (adrItem);
for adrItem in @pta^.postArgs {
local (itemName = string.lower (nameOf (adrItem^)));
if itemName == "delete" {
continue};
if defined (adrTable^.[itemName]) {
delete (@adrTable^.[itemName])}}}
else { //must be adding or editing
local (name = string.trimWhiteSpace (pta^.postArgs.suffix));
if name != "" {
name = string.lower (name);
name = string.popLeading (name, '.'); //be forgiving
local (type = string.trimWhiteSpace (pta^.postArgs.type));
adrTable^.[name] = type}}}};
<<add ("<font color=\"blue\">." + name + " has been set to " + type + ".</font><p>")
bundle { //editing?
if not flPost {
if pta^.searchArgs != "" {
local (t);
new (tableType, @t);
webserver.parseArgs (pta^.searchArgs, @t);
if defined (t.itemToEdit) {
if string.trimWhiteSpace (t.itemToEdit) != "" {
if defined (adrTable^.[t.itemToEdit]) {
flEditing = true;
adrItemToEdit = @adrTable^.[t.itemToEdit];
nameItemToEdit = nameOf (adrItemToEdit^)}}}}}};
bundle { //introduction text
if flEditing {
add ("To change the MIME type associated with the ." + nameItemToEdit + " extension, fill in the Type input box and click the Submit button.")}
else {
add ("To add a new MIME type, fill in the suffix and its MIME type, then click the Add New Type button. To delete one or more types, check one or more checkboxes and click the Delete button at the bottom of the page. To edit a type, click an Edit link on the right.")};
add ("<p>")};
bundle { //Create New or edit
local (defaultName = "", defaultValue = "");
if flEditing {
addSeparator ("Edit type for ." + nameItemToEdit + ":");
defaultName = nameItemToEdit;
defaultValue = adrItemToEdit^}
else {
addSeparator ("Add new type:")};
add ("<form method=\"post\" action=\"" + pta^.uri + "\">"); indentLevel++;
add ("<table border=\"0\" cellpadding=\"7\" cellspacing=\"0\">"); indentLevel++;
add ("<tr>"); indentLevel++;
add ("<td>Suffix:</td>");
if flEditing {
add ("<td>." + defaultName + "<input name=\"suffix\" type=\"hidden\" value=\"" + defaultName + "\"></td>")}
else {
add ("<td><input size=\"5\" name=\"suffix\" value=\"\"></td>")};
add ("</tr>"); indentLevel--;
add ("<tr>"); indentLevel++;
add ("<td>Type:</td>");
add ("<td><input size=\"30\" name=\"type\" value=\"" + defaultValue + "\"></td>");
add ("</tr>"); indentLevel--;
add ("<tr>"); indentLevel++;
add ("<td> </td>");
if flEditing {
add ("<td><input type=\"submit\" value=\"Submit\" name=\"editSubmit\"></td>")}
else {
add ("<td><input type=\"submit\" value=\"Add New Type\" name=\"newTypeSubmit\"></td>")};
add ("</tr>"); indentLevel--;
add ("</table>"); indentLevel--;
add ("</form>"); indentLevel--};
if not flEditing {
bundle { //top of form
addSeparator ("Current types:");
add ("<form method=\"post\" action=\"" + pta^.uri + "\">");
indentLevel++};
bundle { //top of table
add ("<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">");
indentLevel++;
add ("<tr>"); indentLevel++;
add ("<td> </td><td> </td><td align=\"left\"><b>Suffix</b></td><td align=\"left\"><b>Type</b></td><td> </td><td> </td>");
add ("</tr>"); indentLevel--};
local (adr, flDidSpacers = false);
for adr in adrTable { //build table
local (extension = nameOf (adr^));
local (value = adr^);
add ("<tr>"); indentLevel++;
<<Delete checkbox.
add ("<td><input type=\"checkbox\" name=\"" + extension+ "\" value=\"delete\"></td>");
if not flDidSpacers {
add ("<td> </td>")} //spacer
else {
add ("<td></td>")};
add ("<td align=\"left\">." + extension + "</td>"); //extension
add ("<td align=\"left\">" + value + "</td>"); //MIME type
if not flDidSpacers {
add ("<td> </td>"); //spacer
flDidSpacers = true}
else {
add ("<td></td>")};
add ("<td><a href=\"" + pta^.uri + "?itemToEdit=" + extension + "\">Edit</a></td>"); //edit button
add ("</tr>"); indentLevel--};
bundle { //buttons and bottom of table
add ("<tr>"); indentLevel++;
add ("<td colspan=\"6\"><input type=\"Submit\" name=\"Delete\" value=\"Delete\"></td>");
add ("</tr>"); indentLevel--;
add ("</table>");
indentLevel--};
bundle { //bottom of form
add ("</form>");
indentLevel--}};
return (string.replaceAll (htmlText, "{", "{"))}
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.