protected void folderBody( ITransaction transaction,
String path,
HttpServletResponse resp,
HttpServletRequest req ) throws IOException {
StoredObject so = store.getStoredObject(transaction, path);
if (so == null) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getRequestURI());
} else {
if (so.isNullResource()) {
String methodsAllowed = DeterminableMethod.determineMethodsAllowed(so);
resp.addHeader("Allow", methodsAllowed);
resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
return;
}
if (so.isFolder()) {
// TODO some folder response (for browsers, DAV tools use propfind) in html?
DateFormat shortDF = getDateTimeFormat(req.getLocale());
resp.setContentType("text/html");
resp.setCharacterEncoding("UTF-8");
OutputStream out = resp.getOutputStream();
String[] children = store.getChildrenNames(transaction, path);
// Make sure it's not null
children = children == null ? new String[] {} : children;
// Sort by name
Arrays.sort(children);
StringBuilder childrenTemp = new StringBuilder();
childrenTemp.append("<html><head><title>Content of folder");
childrenTemp.append(path);
childrenTemp.append("</title><style type=\"text/css\">");
childrenTemp.append(getCSS());
childrenTemp.append("</style></head>");
childrenTemp.append("<body>");
childrenTemp.append(getHeader(transaction, path, resp, req));
childrenTemp.append("<table>");
childrenTemp.append("<tr><th>Name</th><th>Size</th><th>Created</th><th>Modified</th></tr>");
childrenTemp.append("<tr>");
childrenTemp.append("<td colspan=\"4\"><a href=\"../\">Parent</a></td></tr>");
boolean isEven = false;
for (String child : children) {
isEven = !isEven;
childrenTemp.append("<tr class=\"");
childrenTemp.append(isEven ? "even" : "odd");
childrenTemp.append("\">");
childrenTemp.append("<td>");
childrenTemp.append("<a href=\"");
// CHECKSTYLE IGNORE check FOR NEXT 1 LINES
StringBuffer childURL = req.getRequestURL();
if (!(childURL.charAt(childURL.length() - 1) == '/')) {
childURL.append("/");
}
// we need to URL encode the child, but just the special chars, UTF-8 encoding is done at the end of this
// method
childURL.append(URL_ENCODER.encode(child));
StoredObject obj = store.getStoredObject(transaction, path + "/" + child);
if (obj == null) {
logger.error(new TextI18n("Should not return null for " + path + "/" + child));
}
if (obj != null && obj.isFolder()) {
childURL.append("/");
}
childrenTemp.append(childURL);
childrenTemp.append("\">");
childrenTemp.append(child);
childrenTemp.append("</a></td>");
if (obj != null && obj.isFolder()) {
childrenTemp.append("<td>Folder</td>");
} else {
childrenTemp.append("<td>");
if (obj != null) {
childrenTemp.append(obj.getResourceLength());
} else {
childrenTemp.append("Unknown");
}
childrenTemp.append(" Bytes</td>");
}
if (obj != null && obj.getCreationDate() != null) {
childrenTemp.append("<td>");
childrenTemp.append(shortDF.format(obj.getCreationDate()));
childrenTemp.append("</td>");
} else {
childrenTemp.append("<td></td>");
}
if (obj != null && obj.getLastModified() != null) {
childrenTemp.append("<td>");
childrenTemp.append(shortDF.format(obj.getLastModified()));
childrenTemp.append("</td>");
} else {
childrenTemp.append("<td></td>");
}
childrenTemp.append("</tr>");