package org.dyndns.widerstand.ajax;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for Servlet: TestAjaxServlet
 * 
 */
public class TestAjaxServlet extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {

	private String names[] = { "Anna", "Brittany", "Cinderella", "Diana",
			"Eva", "Fiona", "Gunda", "Hege", "Inga", "Johanna", "Kitty",
			"Linda", "Nina", "Ophelia", "Petunia", "Amanda", "Raquel", "Cindy",
			"Doris", "Eve", "Evita", "Sunniva", "Tove", "Unni", "Violet",
			"Liza", "Elizabeth", "Ellen", "Wenche", "Vicky" };

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public TestAjaxServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String query = request.getParameter("q");

		if (query != null) {
			for (String name : names) {
				if (name.toLowerCase().startsWith(query.toLowerCase())) {
					response.getWriter().write(name);
					break;
				}
			}
			response.getWriter().write("");
		} else {
			response.getWriter().write("");
		}
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
}