try {
resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);
if (resource != null) {
if (!resource.getPermissions().validate(broker.getSubject(), Permission.READ)) {
throw new PermissionDeniedException(
"Permission to read resource " + path + " denied");
}
final DocumentMetadata metadata = resource.getMetadata();
response.setContentType(metadata.getMimeType());
// As HttpServletResponse.setContentLength is limited to integers,
// (see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4187336)
// next sentence:
// response.setContentLength(resource.getContentLength());
// must be set so
response.addHeader("Content-Length", Long.toString(resource.getContentLength()));
setCreatedAndLastModifiedHeaders(response, metadata.getCreated(), metadata.getLastModified());
} else {
final Collection col = broker.getCollection(pathUri);
//no resource or collection
if (col == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "No resource at location: " + path);
return;
}
if (!col.getPermissionsNoLock().validate(broker.getSubject(), Permission.READ)) {
throw new PermissionDeniedException(
"Permission to read resource " + path + " denied");
}
response.setContentType(MimeType.XML_TYPE.getName() + "; charset=" + encoding);
setCreatedAndLastModifiedHeaders(response, col.getCreationTime(), col.getCreationTime());
}