476 |
476 |
else
|
477 |
477 |
throw e;
|
478 |
478 |
}
|
479 |
|
|
480 |
479 |
if (folder != null
|
481 |
480 |
|| (ranges == null || ranges.isEmpty())
|
482 |
481 |
&& req.getHeader("Range") == null
|
... | ... | |
492 |
491 |
logger.debug("contentLength=" + contentLength);
|
493 |
492 |
if (contentLength < Integer.MAX_VALUE)
|
494 |
493 |
resp.setContentLength((int) contentLength);
|
|
494 |
|
495 |
495 |
else
|
496 |
496 |
// Set the content-length as String to be able to use a long
|
497 |
497 |
resp.setHeader("content-length", "" + contentLength);
|
498 |
498 |
}
|
499 |
499 |
|
500 |
500 |
InputStream renderResult = null;
|
501 |
|
if (content)
|
|
501 |
String relativePath = getRelativePath(req);
|
|
502 |
String contextPath = req.getContextPath();
|
|
503 |
String servletPath = req.getServletPath();
|
|
504 |
String contextServletPath = contextPath + servletPath;
|
|
505 |
if (folder != null && content)
|
502 |
506 |
// Serve the directory browser for a public folder
|
503 |
507 |
if (isContentHtml)
|
504 |
|
renderResult = renderHtml(req.getContextPath(), path, folder,user);
|
|
508 |
renderResult = renderHtml(contextServletPath, relativePath, folder,user);
|
505 |
509 |
// Serve the directory for an ordinary folder
|
506 |
510 |
else
|
507 |
511 |
try {
|
... | ... | |
2177 |
2181 |
* directory.
|
2178 |
2182 |
*
|
2179 |
2183 |
* @param contextPath Context path to which our internal paths are relative
|
2180 |
|
* @param path the requested path to the resource
|
|
2184 |
* @param relativePath the requested relative path to the resource
|
2181 |
2185 |
* @param folder the specified directory
|
2182 |
2186 |
* @param req the HTTP request
|
2183 |
2187 |
* @return an input stream with the rendered contents
|
2184 |
2188 |
* @throws IOException
|
2185 |
2189 |
* @throws ServletException
|
2186 |
2190 |
*/
|
2187 |
|
private InputStream renderHtml(String contextPath, String path, FolderDTO folder, User user) throws IOException, ServletException {
|
|
2191 |
private InputStream renderHtml(String contextPath, String relativePath, FolderDTO folder, User user) throws IOException, ServletException {
|
2188 |
2192 |
String name = folder.getName();
|
2189 |
2193 |
// Prepare a writer to a buffered area
|
2190 |
2194 |
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
... | ... | |
2208 |
2212 |
sb.append("Index of " + name);
|
2209 |
2213 |
|
2210 |
2214 |
// Render the link to our parent (if required)
|
2211 |
|
String parentDirectory = path;
|
|
2215 |
String folderPath = folder.getPath();
|
|
2216 |
int indexFolderPath = relativePath.indexOf(folderPath);
|
|
2217 |
String relativePathNoFolderName = relativePath.substring(0, indexFolderPath);
|
|
2218 |
String parentDirectory = folderPath;
|
|
2219 |
//String rewrittenParentDirectory = rewriteUrl(parentDirectory);
|
2212 |
2220 |
if (parentDirectory.endsWith("/"))
|
2213 |
2221 |
parentDirectory = parentDirectory.substring(0, parentDirectory.length() - 1);
|
2214 |
2222 |
int slash = parentDirectory.lastIndexOf('/');
|
2215 |
2223 |
if (slash >= 0) {
|
2216 |
|
String parent = path.substring(0, slash);
|
|
2224 |
String parent = folderPath.substring(0, slash);
|
2217 |
2225 |
sb.append(" - <a href=\"");
|
2218 |
2226 |
sb.append(rewrittenContextPath);
|
2219 |
|
if (parent.equals(""))
|
2220 |
|
parent = "/";
|
2221 |
|
sb.append(rewriteUrl(parent));
|
2222 |
|
if (!parent.endsWith("/"))
|
2223 |
|
sb.append("/");
|
|
2227 |
sb.append(relativePathNoFolderName);
|
|
2228 |
//sb.append(folderPath);
|
|
2229 |
//if (parent.equals(""))
|
|
2230 |
//parent = "/";
|
|
2231 |
sb.append(parent);
|
|
2232 |
//if (!parent.endsWith("/"))
|
|
2233 |
// sb.append("/");
|
2224 |
2234 |
sb.append("\">");
|
2225 |
2235 |
sb.append("<b>");
|
2226 |
|
sb.append("Up To " + parent);
|
|
2236 |
sb.append("Up To " + parentDirectory);
|
2227 |
2237 |
sb.append("</b>");
|
2228 |
2238 |
sb.append("</a>");
|
2229 |
2239 |
}
|
... | ... | |
2263 |
2273 |
sb.append("<td align=\"left\"> \r\n");
|
2264 |
2274 |
sb.append("<a href=\"");
|
2265 |
2275 |
sb.append(rewrittenContextPath);
|
2266 |
|
sb.append(rewriteUrl(path + resourceName));
|
|
2276 |
sb.append(relativePathNoFolderName);
|
|
2277 |
sb.append(folderPath + resourceName);
|
2267 |
2278 |
sb.append("/");
|
2268 |
2279 |
sb.append("\"><tt>");
|
2269 |
2280 |
sb.append(RequestUtil.filter(resourceName));
|
... | ... | |
2304 |
2315 |
sb.append("<td align=\"left\"> \r\n");
|
2305 |
2316 |
sb.append("<a href=\"");
|
2306 |
2317 |
sb.append(rewrittenContextPath);
|
2307 |
|
sb.append(rewriteUrl(path + resourceName));
|
|
2318 |
sb.append(relativePath);
|
|
2319 |
if(!relativePath.endsWith("/"))
|
|
2320 |
sb.append("/");
|
|
2321 |
sb.append(rewriteUrl(resourceName));
|
2308 |
2322 |
sb.append("\"><tt>");
|
2309 |
2323 |
sb.append(RequestUtil.filter(resourceName));
|
2310 |
2324 |
sb.append("</tt></a></td>\r\n");
|