@@ -0,0 +1,2097 @@
+package com.barchart.netty.server.http.handlers;%0A%0Aimport java.io.File;%0Aimport java.net.MalformedURLException;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Apublic final class DefaultDocumentDirectoryResolver implements ResourceResolver %7B%0A%0A%09private static final List%3CString%3E DEFAULT_DOCUMENT_NAMES = Collections.unmodifiableList(Arrays.asList(new String%5B%5D %7B %22index.html%22, %22index.htm%22 %7D));%0A%0A%09private final File directory;%0A%0A%09private final List%3CString%3E defaultDocumentNames;%0A%0A%09public DefaultDocumentDirectoryResolver(File directory_) %7B%0A%09%09this(directory_, DEFAULT_DOCUMENT_NAMES);%0A%09%7D%0A%0A%09public DefaultDocumentDirectoryResolver(File directory_, List%3CString%3E defaultDocumentNames_) %7B%0A%09%09if (directory_ == null %7C%7C !directory_.exists() %7C%7C !directory_.isDirectory())%0A%09%09%09throw new IllegalArgumentException(%22Not a directory: %22 + directory_);%0A%09%09if (defaultDocumentNames_ == null %7C%7C defaultDocumentNames_.isEmpty())%0A%09%09%09throw new IllegalArgumentException(%22Bad list of default document names: %22 + defaultDocumentNames_);%0A%09%09directory = directory_;%0A%09%09defaultDocumentNames = new ArrayList%3CString%3E(defaultDocumentNames_);%0A%09%7D%0A%0A%09@Override%0A%09public Resource resolve(String path) throws ResourceNotFoundException %7B%0A%09%09File file = new File(directory, path);%0A%09%09if (file.isDirectory()) %7B%0A%09%09%09file = findDefaultDocument(file);%0A%09%09%7D%0A%09%09return resolveFile(file);%0A%09%7D%0A%0A%09private File findDefaultDocument(File directory) throws ResourceNotFoundException %7B%0A%09%09for (String fileName : defaultDocumentNames) %7B%0A%09%09%09File newFile = new File(directory, fileName);%0A%09%09%09if (newFile.exists() && !newFile.isDirectory()) %7B%0A%09%09%09%09return newFile;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09throw new ResourceNotFoundException(directory.getAbsolutePath());%0A%09%7D%0A%0A%09private Resource resolveFile(File file) throws ResourceNotFoundException %7B%0A%09%09if (file.exists()) %7B%0A%09%09%09try %7B%0A%09%09%09%09return new StaticResource(file.lastModified(), file.length(), StaticResource.MIME_TYPES.getContentType(file), file.toURI().toURL());%0A%09%09%09%7D catch (final MalformedURLException e) %7B%0A%09%09%09%7D%0A%09%09%7D%0A%09%09throw new ResourceNotFoundException(file.getAbsolutePath());%0A%0A%09%7D%0A%0A%7D%0A

Add DefaultDocumentDirectoryResolver to serve, for example, index.html by default when a directory is requested.