package com.rebelmonkey.userinfo;

import javax.servlet.http.HttpSession;

public class MWUserInfo {
		private final static String USER_INFO_PREFIX = "__MWUSER_";
		private static final boolean DEBUGMODE=true;
		
		private MWUserInfo(){
			// prevent instantiation
		}
	
		public static String getUserName(HttpSession session){
			String uname = getSessionAttribute(session,"UserName");
			if (DEBUGMODE){
				if (uname == null){
					uname = "TEST"+(int)(Math.random()*10000);
					setUserName(session,uname);
				}
			}
			return uname;
		}
		
		private static String getSessionAttribute(HttpSession session,
				String key) {
			return (String) session.getAttribute(USER_INFO_PREFIX+key);
		}

		public static void setUserName(HttpSession session, String uname){
			setSessionAttribute(session,"UserName",uname);
		}

		private static void setSessionAttribute(HttpSession session,
				String key, String value) {
			session.setAttribute(USER_INFO_PREFIX+key, value);
		}
}
