/** * Makes sure the last character is a slash. * * @param path * @return */ public String getNormalizedDirectoryPath(final String path) { if (isDirectoryPath(path)) { return path; } return path + SLASH; }
@Test public void shouldSayWhetherDirectoryPath() { assertThat(pathHelper.isDirectoryPath("somepath"), is(false)); assertThat(pathHelper.isDirectoryPath("somepath/"), is(true)); } }
private void handleDirectoryIndex(final HttpServletResponseImpl response, final HttpServletRequestImpl request, final String requestedPath) throws IOException { DirectoryIndexDescriptor indexDescriptor = loadDirectoryIndexResource(requestedPath); if (indexDescriptor == null) { throw new NotFoundException(); } else { if (!pathHelper.isDirectoryPath(requestedPath)) { sendRedirectToDirectorySlashedPath(response, requestedPath); } else { indexDescriptor.getResourceProvider().load( indexDescriptor.getDirectoryPath(), request, response); } } }