<commit_before><commit_msg>NOJIRA Adding user-configurable timezone support.<commit_after>package edu.yale.its.tp.portlets.calendar.mvc.controller;

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

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.portlet.mvc.SimpleFormController;

import edu.yale.its.tp.portlets.calendar.mvc.CalendarPreferencesCommand;

public class EditCalendarPreferencesController extends SimpleFormController {

	private static Log log = LogFactory.getLog(AdminCalendarController.class);

	@Override
	protected void onSubmitAction(ActionRequest request,
			ActionResponse response, Object command, BindException errors)
			throws Exception {
		
		CalendarPreferencesCommand form = (CalendarPreferencesCommand) command;

		PortletPreferences prefs = request.getPreferences();
		prefs.setValue("timezone", form.getTimezone());
		prefs.store();

		PortletSession session = request.getPortletSession();
		session.setAttribute("timezone", form.getTimezone(), PortletSession.APPLICATION_SCOPE);

		// send the user back to the main edit page
		response.setRenderParameter("action", "editSubscriptions");
		

	}

	@Override
	protected Map referenceData(PortletRequest request, Object command,
			Errors errors) throws Exception {
		
		Map data = super.referenceData(request, command, errors);
		if (data == null) {
			data = new HashMap();
		}

		data.put("timezones", TimeZone.getAvailableIDs());
		return data;
	}

	@Override
	protected Object formBackingObject(PortletRequest request) throws Exception {
		CalendarPreferencesCommand form = new CalendarPreferencesCommand();
		PortletPreferences prefs = request.getPreferences();
		form.setTimezone(prefs.getValue("timezone", "America/Los_Angeles"));
		return form;
	}

}

{'fraction_non_alphanumeric': 0.09519321394910461, 'fraction_numerical': 0.0, 'mean_word_length': 6.076666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4269666', 'n_tokens_mistral': 620, 'n_tokens_neox': 576, 'n_words': 128}