if ((ls.hasMoreComponents()) && getPutableFlag()) {
Request request = (Request) ls.getRequest() ;
if ((request == null) || request.getMethod().equals("PUT")) {
// We might well want to create a resource:
String name = ls.peekNextComponent() ;
ResourceReference rr = dresource.lookup(name);
if ((rr == null) && (dresource.getExtensibleFlag())) {
if (ls.countRemainingComponents() == 1)
rr = dresource.createResource(name, request);
else
rr = dresource.createDirectoryResource(name);
if (rr == null) {
Reply error =
request.makeReply(HTTP.UNSUPPORTED_MEDIA_TYPE);
error.setContent(
"Failed to create resource "+
name +" : "+
"Unable to create the appropriate file:"+
request.getURLPath()+
" this media type is not supported");
throw new HTTPException (error);
}
} else if (rr == null) {
Reply error = request.makeReply(HTTP.FORBIDDEN) ;
error.setContent("You are not allowed to create resource "+
name +" : "+
dresource.getIdentifier()+
" is not extensible.");
throw new HTTPException (error);
}
}
}
if ( super.lookup(ls, lr) ) {
if ( ! ls.isDirectory() && ! ls.isInternal() ) {
// The directory lookup URL doesn't end with a slash:
Request request = (Request)ls.getRequest() ;
if ( request == null ) {
lr.setTarget(null);
return true;
}
URL url = null;
try {
if ((request != null ) &&
request.hasState(Request.ORIG_URL_STATE)) {
URL oldurl;
oldurl = (URL)request.getState(Request.ORIG_URL_STATE);
url = new URL(oldurl, oldurl.getFile() + "/");
} else {
url = (ls.hasRequest()
? getURL(request)
: new URL(getServer().getURL(),
resource.getURLPath()));
}
} catch (MalformedURLException ex) {
getServer().errlog(this, "unable to build full URL.");
throw new HTTPException("Internal server error");
}
String msg = "Invalid requested URL: the directory resource "+
" you are trying to reach is available only through "+
" its full URL: <a href=\""+
url + "\">" + url + "</a>.";
if ( getRelocateFlag() ) {
// Emit an error (with reloc if allowed)
Reply reloc = request.makeReply(HTTP.FOUND);
reloc.setContent(msg) ;
reloc.setLocation(url);
lr.setTarget(null);
lr.setReply(reloc);
return true;
} else {
Reply error = request.makeReply(HTTP.NOT_FOUND) ;
error.setContent(msg) ;
lr.setTarget(null);
lr.setReply(error);
return true;
}
} else if ( ! ls.isInternal() ) {
Request request = (Request)ls.getRequest() ;
request.setState(STATE_CONTENT_LOCATION, "true");
// return the index file.
String indexes[] = getIndexes();
if (indexes != null) {
for (int i = 0 ; i < indexes.length ; i++) {
String index = indexes[i];
if ( index != null && index.length() > 0) {
DirectoryResource dir =
(DirectoryResource) resource;
ResourceReference rr = dir.lookup(index);
if (rr != null) {
try {
FramedResource rindex =
(FramedResource) rr.lock();
return rindex.lookup(ls,lr);
} catch (InvalidResourceException ex) {
} finally {
rr.unlock();
}
}
}
}
}