package org.yacos.web.system.controller;


import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.yacos.core.conferences.IConferenceManager;

public class ListConferenceController implements Controller{

	protected final Log logger = LogFactory.getLog(getClass());

	private IConferenceManager conferenceManager;

	public IConferenceManager getConferenceManager() {
		return conferenceManager;
	}
	public void setConferenceManager(IConferenceManager conferenceManager) {
		this.conferenceManager = conferenceManager;
	}
	
	
	/**
	 * Generate list of conference fo can choose
	 */
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception 
	{

	logger.info("Returning listConference view");
	
	// List all conference
	Map<String, Object> model = new HashMap<String, Object>();
	model.put("listConference", conferenceManager.getConferences());
	
	// Error choose conference
	String msgCode = request.getParameter("error");
	if (msgCode != null)
	{
		model.put("errorMessage", msgCode);
	}
	
	
	return new ModelAndView("listConference", model);
	}
	
}
