package com.ticktac.controllers;

import java.io.IOException;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ticktac.utils.LogInRequestHandler;
import com.ticktac.utils.LogOutRequestHandler;
import com.ticktac.utils.AddEventRequestHandler;
/**
 * AccountController
 */
@WebServlet(description = "Controller that processes information about Registration and Log in actions.",
urlPatterns = { "*.htm" })
public class AccountController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private HashMap<String, Object> handlersMap = new HashMap<String, Object>();
	
	public AccountController() {
        super();
    }
	
	public void init() {
		handlersMap.put("/login.htm", new LogInRequestHandler());
		handlersMap.put("/logout.htm", new LogOutRequestHandler());
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String path = request.getServletPath();
		String viewURL;
		
		if(path.equals("/login.htm")) {
			Object handler = handlersMap.get(request.getServletPath());
			if(handler == null)
				request.getRequestDispatcher("notfound.html").forward(request, response);
			else {
				LogInRequestHandler logInHandler = (LogInRequestHandler) handler;
				viewURL = logInHandler.handleRequest(request, response);
				request.getRequestDispatcher(viewURL).forward(request, response);
			}
		}
		
		if(path.equals("/logout.htm")) {
			Object handler = handlersMap.get(request.getServletPath());
			if(handler == null)
				request.getRequestDispatcher("notfound.html").forward(request, response);
			else {
				LogOutRequestHandler logOutHandler = (LogOutRequestHandler) handler;
				viewURL = logOutHandler.handleRequest(request, response);
				request.getRequestDispatcher(viewURL).forward(request, response);
			}
		}
	}

}

@@ -1173,46 +1173,8 @@
 ;%0A%09%09
-%0A%09%09if(path.equals(%22/login.htm%22)) %7B%0A%09%09%09
 Obje
@@ -1206,37 +1206,19 @@
 get(
-request.getServletP
+p
 ath
-()
 );%0A%09%09
+%0A%09
 %09if(
@@ -1241,94 +1241,77 @@
 %0A%09%09%09
-%09request.getRequestDispatcher(%22notfound.html%22).forward(request, response);%0A%09%09%09else %7B%0A%09
+viewURL = %22notfound.html%22;%0A%09%09%0A%09%09switch(path) %7B%0A%09%09case %22/login.htm%22 :%0A
 %09%09%09L
@@ -1370,33 +1370,32 @@
 er) handler;%0A%09%09%09
-%09
 viewURL = logInH
@@ -1442,297 +1442,38 @@
 %0A%09%09%09
-%09request.getRequestDispatcher(viewURL).forward(request, response);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09if(path.equals(%22/logout.htm%22)) %7B%0A%09%09%09Object handler = handlersMap.get(request.getServletPath());%0A%09%09%09if(handler == null)%0A%09%09%09%09request.getRequestDispatcher(%22notfound.html%22).forward(request, response);%0A%09%09%09else %7B%0A%09
+break;%0A%09%09case %22/logout.htm%22 :%0A
 %09%09%09L
@@ -1543,17 +1543,16 @@
 ler;%0A%09%09%09
-%09
 viewURL 
@@ -1603,16 +1603,70 @@
 nse);%0A%09%09
+%09break;%0A%09%09default:%0A%09%09%09viewURL = %22notfound.html%22;%0A%09%09%7D%0A%0A
 %09%09reques
@@ -1729,17 +1729,8 @@
 e);%0A
-%09%09%09%7D%0A%09%09%7D%0A
 %09%7D%0A%0A

Improve AccountController code...