*/
public class Head implements DAVComponent {
private static final Log log = LogFactory.getLog(Head.class);
public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
Collection col = target.getCollection();
String name = target.getName();
if (target.isRoot() || (col != null && name == null)) {
if (log.isDebugEnabled()) {
log.debug("Method Head not allowed on collections!");
}
res.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
if (col == null) {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
try {
Entry resource = col.getEntry(name);
if (resource != null) {
byte[] resultBytes;
if (resource.getEntryType() == Entry.DOCUMENT) {
resultBytes = TextWriter.toString((Document) resource.getValue()).getBytes();
res.setContentType(MimeTable.XML_MIME_TYPE);
} else {
resultBytes = (byte[]) resource.getValue();
res.setContentType(MimeTable.getMimeType(name));
}
if (resource.getModificationTime() != 0) {
res.addDateHeader("Last-Modified", resource.getModificationTime());
}
res.setContentLength(resultBytes.length);
} else {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
} catch (DBException e) {
log.error("Could not get resource " + name + " from collection " + col.getCanonicalName(), e);
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
}