// when handling directories
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;
// Let's try with the facultative index, in case the underlying
// client connector does not handle directory listing.
if (this.targetUri.endsWith("/")) {
// In this case, the trailing "/" shows that the URIs must
// points to a directory
if (getDirectory().getIndexName() != null
&& getDirectory().getIndexName().length() > 0) {
this.directoryUri = this.targetUri;
this.baseName = getDirectory().getIndexName();
this.targetUri = this.directoryUri + this.baseName;
contextResponse = getDispatcher().get(this.targetUri);
if (contextResponse.getEntity() != null) {
this.targetDirectory = true;
this.directoryContent = new ReferenceList();
this.directoryContent
.add(new Reference(this.targetUri));
this.targetIndex = true;
}
}
} else {
// Try to determine if this target URI with no trailing "/" is a
// directory, in order to force the redirection.
if (getDirectory().getIndexName() != null
&& getDirectory().getIndexName().length() > 0) {
// Append the index name
contextResponse = getDispatcher().get(
this.targetUri + "/"
+ getDirectory().getIndexName());
if (contextResponse.getEntity() != null) {
this.directoryUri = this.targetUri + "/";
this.baseName = getDirectory().getIndexName();
this.targetUri = this.directoryUri + this.baseName;
this.targetDirectory = true;
this.directoryRedirection = true;
this.directoryContent = new ReferenceList();
this.directoryContent
.add(new Reference(this.targetUri));
this.targetIndex = true;
}
}
}
}
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) {