// Path: backend/src/main/java/org/haagensoftware/netty/webserver/util/ContentTypeUtil.java
// public class ContentTypeUtil {
// 	private static Hashtable<String, String> contentTypeHash = new Hashtable<String, String>();
// 	
// 	static {
// 		contentTypeHash.put("png", "image/png");
// 		contentTypeHash.put("PNG", "image/png");
// 		contentTypeHash.put("txt", "text/plain");
// 		contentTypeHash.put("text", "text/plain");
// 		contentTypeHash.put("TXT", "text/plain");
// 		contentTypeHash.put("js", "application/javascript");
// 		contentTypeHash.put("jpg", "image/jpeg");
// 		contentTypeHash.put("jpeg", "image/jpeg");
// 		contentTypeHash.put("JPG", "image/jpeg");
// 		contentTypeHash.put("JPEG", "image/jpeg");
// 		contentTypeHash.put("css", "text/css");
// 		contentTypeHash.put("CSS", "text/css");
// 		contentTypeHash.put("json", "text/json");
// 		contentTypeHash.put("html", "text/html");
// 		contentTypeHash.put("htm", "text/html");
// 	}
// 	
// 	public static String getContentType(String filename) {
// 		String fileEnding = filename.substring(filename.lastIndexOf(".")+1);
// 		System.out.println(fileEnding);
// 		if (contentTypeHash.get(fileEnding) != null) {
// 			return contentTypeHash.get(fileEnding);
// 		}
// 		
// 		return "text/plain";
// 	}
// }


import static org.jboss.netty.handler.codec.http.HttpHeaders.*;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.*;
import static org.jboss.netty.handler.codec.http.HttpMethod.*;
import static org.jboss.netty.handler.codec.http.HttpResponseStatus.*;
import static org.jboss.netty.handler.codec.http.HttpVersion.*;
import org.apache.log4j.Logger;
import org.haagensoftware.netty.webserver.util.ContentTypeUtil;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.*;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
import org.jboss.netty.handler.codec.http.Cookie;
import org.jboss.netty.handler.codec.http.CookieDecoder;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
import org.jboss.netty.util.CharsetUtil;
import javax.activation.MimetypesFileTypeMap;
import java.io.*;
import java.net.*;
import java.util.Set;

		return requestContent;
	}
        
    @Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
		HttpRequest request = (HttpRequest) e.getMessage();
        if (request.getMethod() != GET) {
            sendError(ctx, METHOD_NOT_ALLOWED);
            return;
        }

        String uri = request.getUri();
        
        String path = sanitizeUri(uri);
        if (path == null) {
            sendError(ctx, FORBIDDEN);
            return;
        }


        if (path.startsWith("/document")) {
            path = path.substring(9);
        }
        ChannelBuffer content = getFileContent(path);
        if (content == null) {
            logger.info("Unable to find file at path: " + path);
            sendError(ctx, NOT_FOUND);
            return;
        }


// Path: backend/src/main/java/org/haagensoftware/netty/webserver/util/ContentTypeUtil.java
// public class ContentTypeUtil {
// 	private static Hashtable<String, String> contentTypeHash = new Hashtable<String, String>();
// 	
// 	static {
// 		contentTypeHash.put("png", "image/png");
// 		contentTypeHash.put("PNG", "image/png");
// 		contentTypeHash.put("txt", "text/plain");
// 		contentTypeHash.put("text", "text/plain");
// 		contentTypeHash.put("TXT", "text/plain");
// 		contentTypeHash.put("js", "application/javascript");
// 		contentTypeHash.put("jpg", "image/jpeg");
// 		contentTypeHash.put("jpeg", "image/jpeg");
// 		contentTypeHash.put("JPG", "image/jpeg");
// 		contentTypeHash.put("JPEG", "image/jpeg");
// 		contentTypeHash.put("css", "text/css");
// 		contentTypeHash.put("CSS", "text/css");
// 		contentTypeHash.put("json", "text/json");
// 		contentTypeHash.put("html", "text/html");
// 		contentTypeHash.put("htm", "text/html");
// 	}
// 	
// 	public static String getContentType(String filename) {
// 		String fileEnding = filename.substring(filename.lastIndexOf(".")+1);
// 		System.out.println(fileEnding);
// 		if (contentTypeHash.get(fileEnding) != null) {
// 			return contentTypeHash.get(fileEnding);
// 		}
// 		
// 		return "text/plain";
// 	}
// }


// Path: backend/src/main/java/no/haagensoftware/netty/webserver/handler/FileServerHandler.java
import static org.jboss.netty.handler.codec.http.HttpHeaders.*;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.*;
import static org.jboss.netty.handler.codec.http.HttpMethod.*;
import static org.jboss.netty.handler.codec.http.HttpResponseStatus.*;
import static org.jboss.netty.handler.codec.http.HttpVersion.*;
import org.apache.log4j.Logger;
import org.haagensoftware.netty.webserver.util.ContentTypeUtil;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.*;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
import org.jboss.netty.handler.codec.http.Cookie;
import org.jboss.netty.handler.codec.http.CookieDecoder;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
import org.jboss.netty.util.CharsetUtil;
import javax.activation.MimetypesFileTypeMap;
import java.io.*;
import java.net.*;
import java.util.Set;

		return requestContent;
	}
        
    @Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
		HttpRequest request = (HttpRequest) e.getMessage();
        if (request.getMethod() != GET) {
            sendError(ctx, METHOD_NOT_ALLOWED);
            return;
        }

        String uri = request.getUri();
        
        String path = sanitizeUri(uri);
        if (path == null) {
            sendError(ctx, FORBIDDEN);
            return;
        }


        if (path.startsWith("/document")) {
            path = path.substring(9);
        }
        ChannelBuffer content = getFileContent(path);
        if (content == null) {
            logger.info("Unable to find file at path: " + path);
            sendError(ctx, NOT_FOUND);
            return;
        }


        String contentType = ContentTypeUtil.getContentType(path);
