* @exception ResourceException if a server error occurs
*/
public synchronized Reply getDirectoryListing(Request request)
throws ProtocolException, ResourceException
{
DirectoryResource dirResource = null;
try {
dirResource = (DirectoryResource) getDirResourceRef().lock();
if (dirResource == null)
throw new ResourceException("parent is NOT a "+
"DirectoryResource. ("+
resource.getIdentifier()+")");
if (! dirResource.verify()) {
// the directory was deleted, but we can't delete it here
// (Multiple Locks)
// Emit an error back:
Reply error = request.makeReply(HTTP.NOT_FOUND) ;
error.setContent ("<h1>Document not found</h1>"+
"<p>The document "+
request.getURL()+
" is indexed but not available."+
"<p>The server is misconfigured.") ;
throw new HTTPException (error) ;
}
// Have we already an up-to-date computed a listing ?
if ((listing == null)
|| (dirResource.getDirectory().lastModified() > listing_stamp)
|| (dirResource.getLastModified() > listing_stamp)
|| (getLastModified() > listing_stamp)) {
Enumeration e = dirResource.enumerateResourceIdentifiers() ;
Vector resources = Sorter.sortStringEnumeration(e) ;
HtmlGenerator g = new HtmlGenerator("Directory listing of "+
dirResource.getIdentifier());
// Add style link
addStyleSheet(g);
g.append("<h1>Directory listing of ",
dirResource.getIdentifier(),
"</h1>");
// Link to the parent, when possible:
if ( dirResource.getParent() != null )
g.append("<p><a href=\"..\">Parent</a><br>");
g.append("\n<form method=\"POST\" action=\""+request.getURL()
+"\">\n");
String listername = getResource().getIdentifier();
// List the children:
g.append("<table border=\"0\">\n");
ResourceReference rr = null;
FramedResource resource = null;
String name = null;
//ugly hack to put CVS link first
rr = dirResource.lookup("CVS");
if (rr != null) {
g.append(getResourceLine(rr, "CVS", false));
}
boolean even = true;
for (int i = 0 ; i < resources.size() ; i++) {
name = (String) resources.elementAt(i);
if ( name.equals(listername) || name.equals("CVS"))
continue;
rr = dirResource.lookup(name);
g.append(getResourceLine(rr, name, even));
even = !even;
}
g.append("</table>\n");
g.append("<P><INPUT TYPE=\"SUBMIT\" NAME=\"SUBMIT\" VALUE=\""+