<commit_before>
package ser422.lab3;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletsTask1
 */
@WebServlet("/")
public class LandingPage extends HttpServlet
{

	private static final long	serialVersionUID	= 1L;

	private static String		_filename			= null;

	private UserContainer		userCont;

	// UserContainer userCont = null;
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LandingPage()
	{

		super();
	}

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	@Override
	public void init(ServletConfig config) throws ServletException
	{

		super.init(config);
		_filename= config.getInitParameter("userFile");
		this.userCont= new UserContainer(new LinkedHashSet<User>());
		;
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{

		ServletContext sc= this.getServletContext();
		response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
		response.addHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", -1);
		response.setContentType("text/html");
		PrintWriter out= response.getWriter();
		Map<String,String[]> cookiesMap= new HashMap<String,String[]>();
		if (request.getCookies() != null)
		{
			for (Cookie coo : request.getCookies())
			{
				cookiesMap.put(coo.getName(), coo.getValue().split(":"));
				coo.setMaxAge(0);
				response.addCookie(coo);
			}
			if (cookiesMap.containsKey("action") && cookiesMap.get("action")[0].equalsIgnoreCase("adduser"))
			{
				this.userCont.addUser(new User(cookiesMap));
			}
		}
		Map<String,String[]> query= request.getParameterMap();
		// UserContainer userCont= null;
		// try
		// {
		// userCont= UserContainer.getContainer(sc.getResourceAsStream(_filename));
		// }
		// catch (ClassNotFoundException e)
		// {
		// response.sendError(500);
		// }
		LinkedHashSet<User> validUsers= null;
		if (!query.isEmpty())
		{
			validUsers= this.userCont.queryUsers(query);
		}
		else
		{
			validUsers= this.userCont.getUsers();
		}
		if (validUsers != null && !validUsers.isEmpty())
		{
			for (User u : validUsers)
			{
				out.println(u.toString() + "<BR>");
			}
		}
		else
		{
			out.println("No valid Users!" + "<BR>");
		}
		try
		{
			out.println("<!DOCTYPE html>");
			out.println("<html>");
			out.println("<head>");
			out.println("<title>Lab 3 Part 2</title>");
			out.println("<style>{font-family:\"Trebuchet MS\", Calibri, Verdana, sans-serif;}</style>");
			out.println("</head>");
			out.println("<body bgcolor=\"pink\"><form method=\"post\">");
			out.println("<h2>Landing Page</h2>");
			if (cookiesMap.get("userCreationCookiesCleared") != null)
			{
				out.println("Cookies for making new user Cleared! Creating new User has been canceled.");
			}
			out.println("</body>");
			out.println("</html>");
		}
		finally
		{
			out.close();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
	{

		ServletContext sc= this.getServletContext();
		res.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
		res.addHeader("Pragma", "no-cache");
		res.setDateHeader("Expires", -1);
		res.setContentType("text/html");
		PrintWriter out= res.getWriter();
		Map<String,String[]> formData= req.getParameterMap();
		// UserContainer userCont= null;
		// try
		// {
		// userCont= UserContainer.getContainer(sc.getResourceAsStream(_filename));
		// }
		// catch (ClassNotFoundException e)
		// {
		// out.println(_filename + (new File(_filename)).exists());
		// out.close();
		// // res.sendError(500);
		// }
		this.userCont.addUser(new User(formData));
		// userCont.writeToFile(_filename);
		try
		{
			out.println("<!DOCTYPE html>");
			out.println("<html>");
			out.println("<body bgcolor=\"pink\"><form method=\"post\">");
			out.println("POST~!<BR> ");
			out.println(this.userCont.getUsers().toString() + "<BR>");
			out.println(_filename + "<BR>" + (new File(_filename)).exists() + "<BR>");
			out.println("<a href=\"" + req.getHeader("referer") + "\"/>Back to Form!</a>");
			out.println("</body></html>");
		}
		finally
		{
			out.close();
		}
	}
}

class User
{

	private String					fName;

	private String					lName;

	private LinkedHashSet<String>	langs;

	private LinkedHashSet<String>	days;

	private String					color;
<commit_msg>added button to landing page, added styling<commit_after>
package ser422.lab3;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletsTask1
 */
@WebServlet("/")
public class LandingPage extends HttpServlet
{

	private static final long	serialVersionUID	= 1L;

	private static String		_filename			= null;

	private UserContainer		userCont;

	// UserContainer userCont = null;
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LandingPage()
	{

		super();
	}

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	@Override
	public void init(ServletConfig config) throws ServletException
	{

		super.init(config);
		_filename= config.getInitParameter("userFile");
		this.userCont= new UserContainer(new LinkedHashSet<User>());
		;
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{

		ServletContext sc= this.getServletContext();
		response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
		response.addHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", -1);
		response.setContentType("text/html");
		PrintWriter out= response.getWriter();
		Map<String,String[]> cookiesMap= new HashMap<String,String[]>();
		if (request.getCookies() != null)
		{
			for (Cookie coo : request.getCookies())
			{
				cookiesMap.put(coo.getName(), coo.getValue().split(":"));
				coo.setMaxAge(0);
				response.addCookie(coo);
			}
			if (cookiesMap.containsKey("action") && cookiesMap.get("action")[0].equalsIgnoreCase("adduser"))
			{
				this.userCont.addUser(new User(cookiesMap));
			}
		}
		Map<String,String[]> query= request.getParameterMap();
		// UserContainer userCont= null;
		// try
		// {
		// userCont= UserContainer.getContainer(sc.getResourceAsStream(_filename));
		// }
		// catch (ClassNotFoundException e)
		// {
		// response.sendError(500);
		// }
		LinkedHashSet<User> validUsers= null;
		if (!query.isEmpty())
		{
			validUsers= this.userCont.queryUsers(query);
		}
		else
		{
			validUsers= this.userCont.getUsers();
		}
		if (validUsers != null && !validUsers.isEmpty())
		{
			for (User u : validUsers)
			{
				out.println(u.toString() + "<BR>");
			}
		}
		else
		{
			out.println("No valid Users!" + "<BR>");
		}
		try
		{
			out.println("<!DOCTYPE html>");
			out.println("<html>");
			out.println("<head>");
			out.println("<title>Lab 3 Part 2</title>");
			out.println("</head>");
			out.println("<body style=\"font-family:\"Trebuchet MS\", Calibri, Verdana, Tahoma, sans-serif;font-size:12pt;background-color:pink\"><form method=\"post\">");
			out.println("<h2>Landing Page</h2>");
			out.println("<input type=\"submit\" name=\"nav\" value=\"Go to form\">");
			if (cookiesMap.get("userCreationCookiesCleared") != null)
			{
				out.println("Cookies for making new user Cleared! Creating new User has been canceled.");
			}
			out.println("</body>");
			out.println("</html>");
		}
		finally
		{
			out.close();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
	{

		res.sendRedirect("/Lab3/firstName");
		/*
		 * ServletContext sc= this.getServletContext();
		 * res.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
		 * res.addHeader("Pragma", "no-cache");
		 * res.setDateHeader("Expires", -1);
		 * res.setContentType("text/html");
		 * PrintWriter out= res.getWriter();
		 * Map<String,String[]> formData= req.getParameterMap();
		 * // UserContainer userCont= null;
		 * // try
		 * // {
		 * // userCont= UserContainer.getContainer(sc.getResourceAsStream(_filename));
		 * // }
		 * // catch (ClassNotFoundException e)
		 * // {
		 * // out.println(_filename + (new File(_filename)).exists());
		 * // out.close();
		 * // // res.sendError(500);
		 * // }
		 * this.userCont.addUser(new User(formData));
		 * // userCont.writeToFile(_filename);
		 * try
		 * {
		 * out.println("<!DOCTYPE html>");
		 * out.println("<html>");
		 * out.println("<body bgcolor=\"pink\"><form method=\"post\">");
		 * out.println("POST~!<BR> ");
		 * out.println(this.userCont.getUsers().toString() + "<BR>");
		 * out.println(_filename + "<BR>" + (new File(_filename)).exists() + "<BR>");
		 * out.println("<a href=\"" + req.getHeader("referer") + "\"/>Back to Form!</a>");
		 * out.println("</body></html>");
		 * }
		 * finally
		 * {
		 * out.close();
		 * }
		 */
	}
}

class User
{

	private String					fName;

	private String					lName;

	private LinkedHashSet<String>	langs;

	private LinkedHashSet<String>	days;

	private String					color;

{'fraction_non_alphanumeric': 0.1680425087769238, 'fraction_numerical': 0.004080083499383243, 'mean_word_length': 4.116504854368932, 'pattern_counts': {'":': 2, '<': 74, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '958228', 'n_tokens_mistral': 3822, 'n_tokens_neox': 3380, 'n_words': 629}