01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.preferences.web;
18:
19: import java.util.ArrayList;
20: import java.util.List;
21:
22: import javax.servlet.http.HttpServletRequest;
23: import javax.servlet.http.HttpServletResponse;
24:
25: import org.apache.struts.action.ActionForm;
26: import org.apache.struts.action.ActionForward;
27: import org.apache.struts.action.ActionMapping;
28: import org.apache.struts.action.ActionMessages;
29:
30: import edu.iu.uis.eden.EdenConstants;
31: import edu.iu.uis.eden.KEWServiceLocator;
32: import edu.iu.uis.eden.preferences.Preferences;
33: import edu.iu.uis.eden.preferences.PreferencesService;
34: import edu.iu.uis.eden.web.KeyValue;
35: import edu.iu.uis.eden.web.WorkflowAction;
36:
37: /**
38: * A Struts Action for interfaces with {@link Preferences}.
39: *
40: * @see PreferencesService
41: * @see Preferences
42: *
43: * @author rkirkend
44: * @author temay
45: */
46: public class PreferencesAction extends WorkflowAction {
47:
48: public ActionForward start(ActionMapping mapping, ActionForm form,
49: HttpServletRequest request, HttpServletResponse response)
50: throws Exception {
51: PreferencesService preferencesService = (PreferencesService) KEWServiceLocator
52: .getService(KEWServiceLocator.PREFERENCES_SERVICE);
53: PreferencesForm preferencesForm = (PreferencesForm) form;
54: preferencesForm.setPreferences(preferencesService
55: .getPreferences(getUserSession(request)
56: .getWorkflowUser()));
57: return mapping.findForward("viewPreferences");
58: }
59:
60: public ActionForward save(ActionMapping mapping, ActionForm form,
61: HttpServletRequest request, HttpServletResponse response)
62: throws Exception {
63: PreferencesService prefSrv = (PreferencesService) KEWServiceLocator
64: .getService(KEWServiceLocator.PREFERENCES_SERVICE);
65: PreferencesForm prefForm = (PreferencesForm) form;
66: prefSrv.savePreferences(getUserSession(request)
67: .getWorkflowUser(), prefForm.getPreferences());
68: getUserSession(request).setPreferences(
69: prefForm.getPreferences());
70: if (!isEmpty(prefForm.getReturnMapping())) {
71: return mapping.findForward(prefForm.getReturnMapping());
72: }
73: return mapping.findForward("viewPreferences");
74: }
75:
76: public ActionMessages establishRequiredState(
77: HttpServletRequest request, ActionForm form)
78: throws Exception {
79: request.setAttribute("actionListContent",
80: EdenConstants.ACTION_LIST_CONTENT);
81: getDelegatorFilterChoices(request);
82: return null;
83: }
84:
85: public void getDelegatorFilterChoices(HttpServletRequest request) {
86: List delegatorFilterChoices = new ArrayList();
87: delegatorFilterChoices.add(new KeyValue(
88: EdenConstants.DELEGATORS_ON_FILTER_PAGE,
89: EdenConstants.DELEGATORS_ON_FILTER_PAGE));
90: delegatorFilterChoices.add(new KeyValue(
91: EdenConstants.DELEGATORS_ON_ACTION_LIST_PAGE,
92: EdenConstants.DELEGATORS_ON_ACTION_LIST_PAGE));
93: request.setAttribute("delegatorFilter", delegatorFilterChoices);
94: }
95:
96: }
|