package com.javahonk;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LoadPropertiesFileServlet
 */
@WebServlet(description = "LoadPropertiesFileServlet", urlPatterns = { "/LoadPropertiesFileServlet" })
public class LoadPropertiesFileServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoadPropertiesFileServlet() {
        super();
        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		Properties properties = new Properties();
		properties.load(getServletContext().getResourceAsStream("/resources/JavaHonk.properties"));
		
		StringBuffer reponseData = new StringBuffer();
		Enumeration<?> enumeration =properties.propertyNames();
		while (enumeration.hasMoreElements()) {
			String key = (String) enumeration.nextElement();
			System.out.println("Key: "+key+"   Value: "+properties.getProperty(key));
			//Create response data
			reponseData.append("Key: "+key+"   Value: "+properties.getProperty(key)+"  ");
		}
		
		response.getWriter().write(reponseData.toString());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
