String containerKey = path.getContainerKey();
List containerKeyElems = WGUtils.deserializeCollection(containerKey, "/");
String containerKeyLastElement = (String) containerKeyElems.get(containerKeyElems.size() - 1);
// Fetch the file container
WGDocument fileContainer = database.getFileContainer(containerKeyLastElement);
if (fileContainer == null) {
// Container addressed by some kind of content key?
WGContent content = getContentByAnyKey(containerKeyLastElement, database, request);
// Container addressed by Title path?
if (content == null) {
TitlePathManager tpm = (TitlePathManager) database.getAttribute(WGACore.DBATTRIB_TITLEPATHMANAGER);
if (tpm != null && tpm.isGenerateTitlePathURLs()) {
TitlePathManager.TitlePath url = tpm.parseTitlePathURL(containerKeyElems);
if (url != null) {
path.setTitlePathURL(url);
content = path.getContentByTitlePath(request);
}
}
}
if (content == null || !content.mayBePublished(isBrowserInterface(request.getSession()) || isAuthoringMode(database.getDbReference(), request.getSession()), WGContent.DISPLAYTYPE_NONE)) {
sendNoFileContainerNotification(path, request, response, database);
return;
}
fileContainer = content;
}
if (info != null && fileContainer != null && fileContainer instanceof WGContent) {
info.setContent((WGContent) fileContainer);
}
String fileName = path.getFileName();
if (fileName == null || fileName.equals("")) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No file name in file URL: " + path.getCompleteURL());
return;
}
ExternalFileServingConfig externalFileServingConfig = _core.getExternalFileServingConfig();
if (externalFileServingConfig.isEnabled() && database.getBooleanAttribute(WGACore.DBATTRIB_EXTERNAL_FILE_SERVING_ENABLED, false)) {
// check if file is anonymous accessible
boolean isAnonymousAccessible = database.isAnonymousAccessible();
if (isAnonymousAccessible) {
// perform further document level checks
if (fileContainer != null && fileContainer instanceof WGContent) {
// check status
if (!((WGContent) fileContainer).getStatus().equals(WGContent.STATUS_RELEASE)) {
isAnonymousAccessible = false;
}
// check readers
if (isAnonymousAccessible) {
isAnonymousAccessible = ((WGContent) fileContainer).getReaders().size() == 0;
}
}
}
if (isAnonymousAccessible && fileContainer.getFileSize(fileName) >= externalFileServingConfig.getThreshold()) {
// file is anonymous accessible and above external serving
// threshold
dispatchFileExternalImpl(externalFileServingConfig, path, request, response, database, fileContainer);
}
else {