* The default handler for directories; writes an HTML response containing a * slightly-formatted directory listing.
(metadata, response)
| 2072 | * slightly-formatted directory listing. |
| 2073 | */ |
| 2074 | function defaultIndexHandler(metadata, response) |
| 2075 | { |
| 2076 | response.setHeader("Content-Type", "text/html;charset=utf-8", false); |
| 2077 | |
| 2078 | var path = htmlEscape(decodeURI(metadata.path)); |
| 2079 | |
| 2080 | // |
| 2081 | // Just do a very basic bit of directory listings -- no need for too much |
| 2082 | // fanciness, especially since we don't have a style sheet in which we can |
| 2083 | // stick rules (don't want to pollute the default path-space). |
| 2084 | // |
| 2085 | |
| 2086 | var body = '<html>\ |
| 2087 | <head>\ |
| 2088 | <title>' + path + '</title>\ |
| 2089 | </head>\ |
| 2090 | <body>\ |
| 2091 | <h1>' + path + '</h1>\ |
| 2092 | <ol style="list-style-type: none">'; |
| 2093 | |
| 2094 | var directory = metadata.getProperty("directory"); |
| 2095 | NS_ASSERT(directory && directory.isDirectory()); |
| 2096 | |
| 2097 | var fileList = []; |
| 2098 | var files = directory.directoryEntries; |
| 2099 | while (files.hasMoreElements()) |
| 2100 | { |
| 2101 | var f = files.getNext().QueryInterface(Ci.nsIFile); |
| 2102 | var name = f.leafName; |
| 2103 | if (!f.isHidden() && |
| 2104 | (name.charAt(name.length - 1) != HIDDEN_CHAR || |
| 2105 | name.charAt(name.length - 2) == HIDDEN_CHAR)) |
| 2106 | fileList.push(f); |
| 2107 | } |
| 2108 | |
| 2109 | fileList.sort(fileSort); |
| 2110 | |
| 2111 | for (var i = 0; i < fileList.length; i++) |
| 2112 | { |
| 2113 | var file = fileList[i]; |
| 2114 | try |
| 2115 | { |
| 2116 | var name = file.leafName; |
| 2117 | if (name.charAt(name.length - 1) == HIDDEN_CHAR) |
| 2118 | name = name.substring(0, name.length - 1); |
| 2119 | var sep = file.isDirectory() ? "/" : ""; |
| 2120 | |
| 2121 | // Note: using " to delimit the attribute here because encodeURIComponent |
| 2122 | // passes through '. |
| 2123 | var item = '<li><a href="' + encodeURIComponent(name) + sep + '">' + |
| 2124 | htmlEscape(name) + sep + |
| 2125 | '</a></li>'; |
| 2126 | |
| 2127 | body += item; |
| 2128 | } |
| 2129 | catch (e) { /* some file system error, ignore the file */ } |
| 2130 | } |
| 2131 |
nothing calls this directly
no test coverage detected