context.getContextManager().handleStatus( req, res, 404);
return;
}
}
OutputBuffer buf=res.getBuffer();
if( sbNote==0 ) {
//sbNote=req.getContextManager().
// getNoteId(ContextManager.REQUEST_NOTE,
// "RedirectHandler.buff");
sbNote=req.getContextManager().
getNoteId(ContextManager.REQUEST_NOTE,"uft8encoder");
}
// we can recycle it because
// we don't call toString();
// StringBuffer buf=(StringBuffer)req.getNote( sbNote );
// if( buf==null ) {
// buf = new StringBuffer();
// req.setNote( sbNote, buf );
// }
UEncoder utfEncoder=(UEncoder)req.getNote( sbNote );
if( utfEncoder==null ) {
utfEncoder=new UEncoder();
utfEncoder.addSafeCharacter( '/' );
}
if (! inInclude) {
if (charset == null || charset.equalsIgnoreCase("ISO-8859-1"))
res.setContentType("text/html");
else {
res.setContentType("text/html; charset=" + charset);
res.setUsingWriter(true);
}
buf.write("<html>\r\n");
buf.write("<head>\r\n");
buf.write("<title>");
buf.write(sm.getString("defaultservlet.directorylistingfor"));
buf.write(requestURI);
buf.write("</title>\r\n</head><body bgcolor=white>\r\n");
}
buf.write("<table width=90% cellspacing=0 ");
buf.write("cellpadding=5 align=center>");
buf.write("<tr><td colspan=3><font size=+2><strong>");
buf.write(sm.getString("defaultservlet.directorylistingfor"));
buf.write(requestURI);
buf.write("</strong></td></tr>\r\n");
if (! pathInfo.equals("/")) {
buf.write("<tr><td colspan=3 bgcolor=#ffffff>");
//buf.write("<a href=\"../\">Up one directory");
String toPath = requestURI;
if (toPath.endsWith("/")) {
toPath = toPath.substring(0, toPath.length() - 1);
}
toPath = toPath.substring(0, toPath.lastIndexOf("/"));
//if (toPath.length() == 0) {
//toPath = "/";
//}
// Add trailing "/"
toPath += "/";
buf.write("<a href=\"");
utfEncoder.urlEncode( buf, toPath);
buf.write( "\"><tt>" );
buf.write( sm.getString("defaultservlet.upto"));
buf.write( toPath);
buf.write("</tt></a></td></tr>\r\n");
}
// Pre-calculate the request URI for efficiency
// Make another URI that definitely ends with a /
String slashedRequestURI = null;
if (requestURI.endsWith("/")) {
slashedRequestURI = requestURI;
} else {
slashedRequestURI = requestURI + "/";
}
String[] fileNames = file.list();
boolean dirsHead=true;
boolean shaderow = false;
for (int i = 0; i < fileNames.length; i++) {
String fileName = fileNames[i];
// Don't display special dirs at top level
if( (pathInfo.length() == 0 || "/".equals(pathInfo)) &&
"WEB-INF".equalsIgnoreCase(fileName) ||
"META-INF".equalsIgnoreCase(fileName) )
continue;
File f = new File(file, fileName);
if (f.isDirectory()) {
if( dirsHead ) {
dirsHead=false;
buf.write("<tr><td colspan=3 bgcolor=#cccccc>");
buf.write("<font size=+2><strong>");
buf.write( sm.getString("defaultservlet.subdirectories"));
buf.write( "</strong>\r\n");
buf.write("</font></td></tr>\r\n");
}
String fileN = f.getName();
buf.write("<tr");
if (shaderow) buf.write(" bgcolor=#eeeeee");
shaderow=!shaderow;
buf.write("><td> ");
buf.write("<tt><a href=\"");
utfEncoder.urlEncode( buf, slashedRequestURI);
utfEncoder.urlEncode( buf, fileN);
buf.write("/\">");
buf.write(fileN);
buf.write("/</a> ");
buf.write("</tt>\r\n");
buf.write("</td><td><tt> </tt></td>");
buf.write("<td align=right><tt>");
buf.write(dateFormat.format(new Date(f.lastModified())));
buf.write("</tt></td></tr>\r\n");
}
}
shaderow = false;
buf.write("<tr><td colspan=3 bgcolor=#ffffff> </td></tr>");
boolean fileHead=true;
for (int i = 0; i < fileNames.length; i++) {
File f = new File(file, fileNames[i]);
if (f.isFile()) {
String fileN = f.getName();
if( fileHead ) {
fileHead=false;
buf.write("<tr><td colspan=4 bgcolor=#cccccc>");
buf.write("<font size=+2><strong>");
buf.write(sm.getString("defaultservlet.files"));
buf.write("</strong></font></td></tr>");
}
buf.write("<tr");
if (shaderow) buf.write(" bgcolor=#eeeeee");
shaderow = ! shaderow;
buf.write("><td> \r\n");
buf.write("<tt><a href=\"");
utfEncoder.urlEncode( buf, slashedRequestURI);
utfEncoder.urlEncode( buf, fileN);
buf.write("\">");
buf.write( fileN );
buf.write( "</a>");
buf.write(" </tt>");
buf.write("</td>\r\n");
buf.write("<td align=right><tt>");
displaySize( buf, (int)f.length());
buf.write("</tt></td>");
buf.write("<td align=right><tt>");
buf.write(dateFormat.format(new Date(f.lastModified())));
buf.write("</tt></td></tr>\r\n");
}
buf.write("\r\n");
}
buf.write("<tr><td colspan=3 bgcolor=#ffffff> </td></tr>");
buf.write("<tr><td colspan=3 bgcolor=#cccccc>");
buf.write("<font size=-1>");
buf.write(ContextManager.TOMCAT_NAME);
buf.write(" v");
buf.write(ContextManager.TOMCAT_VERSION);
buf.write("</font></td></tr></table>");
if (! inInclude) buf.write("</body></html>\r\n");
// res.getBuffer().write(buf);
// buf.setLength(0);
}