/** * Get the resource list as a HTML directory listing. * * @param base The base URL * @param parent True if the parent directory should be included * @return String of HTML */ public String getListHTML(String base, boolean parent) throws IOException { if (!isDirectory()) return null; String[] ls = list(); if (ls == null) return null; Arrays.sort(ls); String title = "Directory: " + base; StringBuffer buf = new StringBuffer(4096); buf.append("<HTML><HEAD><TITLE>"); buf.append(title); buf.append("</TITLE></HEAD><BODY>\n<H1>"); buf.append(title); buf.append("</H1><TABLE BORDER=0>"); if (parent) { buf.append("<TR><TD><A HREF="); buf.append(URIUtil.encodePath(URIUtil.addPaths(base, "../"))); buf.append(">Parent Directory</A></TD><TD></TD><TD></TD></TR>\n"); } DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); for (int i = 0; i < ls.length; i++) { String encoded = URIUtil.encodePath(ls[i]); Resource item = addPath(encoded); buf.append("<TR><TD><A HREF=\""); String path = URIUtil.addPaths(base, encoded); if (item.isDirectory() && !path.endsWith("/")) path = URIUtil.addPaths(path, "/"); buf.append(path); buf.append("\">"); buf.append(StringUtil.replace(StringUtil.replace(ls[i], "<", "<"), ">", ">")); buf.append(" "); buf.append("</TD><TD ALIGN=right>"); buf.append(item.length()); buf.append(" bytes </TD><TD>"); buf.append(dfmt.format(new Date(item.lastModified()))); buf.append("</TD></TR>\n"); } buf.append("</TABLE>\n"); buf.append("</BODY></HTML>\n"); return buf.toString(); }
public static String encodePath(String src) { String ret = org.mortbay.util.URIUtil.encodePath(src); if (File.separatorChar == '\\') { return ret.replace('\\', '/'); } else { return ret; } }
/** * Encode according to this resource type. The default implementation calls URI.encodePath(uri) * * @param uri * @return String encoded for this resource type. */ public String encode(String uri) { return URIUtil.encodePath(uri); }
public static String encodeURL(String src) { return org.mortbay.util.URIUtil.encodePath(src); }