// Prevent the client from accessing resources in upper directories
this.targetUri = directory.getRootRef().toString();
}
// Try to detect the presence of a directory
Response contextResponse = getDispatcher().get(this.targetUri);
if (contextResponse.getEntity() != null) {
if (MediaType.TEXT_URI_LIST.equals(contextResponse.getEntity()
.getMediaType())) {
this.targetDirectory = true;
this.targetFile = false;
this.directoryContent = new ReferenceList(contextResponse
.getEntity());
if (!request.getResourceRef().getIdentifier().endsWith("/")) {
// All requests will be automatically redirected
this.directoryRedirection = true;
}
if (!this.targetUri.endsWith("/")) {
this.targetUri += "/";
this.relativePart += "/";
}
// Append the index name
if (getDirectory().getIndexName() != null
&& getDirectory().getIndexName().length() > 0) {
this.directoryUri = this.targetUri;
this.baseName = getDirectory().getIndexName();
this.targetUri = this.directoryUri + this.baseName;
this.targetIndex = true;
} else {
this.directoryUri = this.targetUri;
this.baseName = null;
}
} else {
this.targetDirectory = false;
this.targetFile = true;
this.fileContent = contextResponse.getEntity();
}
} else {
this.targetDirectory = false;
this.targetFile = false;
}
if (!this.targetDirectory) {
int lastSlashIndex = targetUri.lastIndexOf('/');
if (lastSlashIndex == -1) {
this.directoryUri = "";
this.baseName = targetUri;
} else {
this.directoryUri = targetUri.substring(0, lastSlashIndex + 1);
this.baseName = targetUri.substring(lastSlashIndex + 1);
}
contextResponse = getDispatcher().get(this.directoryUri);
if ((contextResponse.getEntity() != null)
&& MediaType.TEXT_URI_LIST.equals(contextResponse
.getEntity().getMediaType())) {
this.directoryContent = new ReferenceList(contextResponse
.getEntity());
}
}
if (this.baseName != null) {