01: /**********************************************************************************
02: *
03: * $Id: LoginAsBean.java 9271 2006-05-10 21:52:49Z ray@media.berkeley.edu $
04: *
05: ***********************************************************************************
06: *
07: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
08: *
09: * Licensed under the Educational Community License, Version 1.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.opensource.org/licenses/ecl1.php
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: *
21: **********************************************************************************/package org.sakaiproject.tool.gradebook.ui.test;
22:
23: import java.io.UnsupportedEncodingException;
24: import java.net.URLEncoder;
25: import java.util.ArrayList;
26: import java.util.List;
27:
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30: import org.sakaiproject.tool.gradebook.ui.InitializableBean;
31:
32: public class LoginAsBean extends InitializableBean {
33: private static final Log logger = LogFactory
34: .getLog(LoginAsBean.class);
35:
36: private List loginChoices;
37:
38: public class WhoAndWhat {
39: private String userUid;
40: private String gradebookUid;
41: private String role;
42: private String entryPage; // TODO Replace with entry servlet
43:
44: private WhoAndWhat(String userUid, String gradebookUid,
45: String role) {
46: this .userUid = userUid;
47: this .gradebookUid = gradebookUid;
48: this .role = role;
49: if (role.equals("Student")) {
50: entryPage = "studentView.jsf";
51: } else {
52: entryPage = "overview.jsf";
53: }
54: }
55:
56: public String getUserUid() {
57: return userUid;
58: }
59:
60: public String getGradebookUid() {
61: return gradebookUid;
62: }
63:
64: public String getRole() {
65: return role;
66: }
67:
68: public String getEntryPage() {
69: return entryPage;
70: }
71: }
72:
73: public void init() {
74: String[][] users = { { "authid_teacher", "Instructor" },
75: { "stu_0", "Student" }, { "authid_ta", "TA" },
76: { "authid_nowhere", "Nobody" } };
77: String gradebookUid = "QA_6";
78: try {
79: gradebookUid = URLEncoder.encode(gradebookUid, "UTF-8"); // Since f:param won't do it
80: } catch (UnsupportedEncodingException ex) {
81: logger.error("Unlikely exception thrown", ex);
82: }
83: loginChoices = new ArrayList(users.length);
84: for (int i = 0; i < users.length; i++) {
85: String userUid = users[i][0];
86: String role = users[i][1];
87: loginChoices
88: .add(new WhoAndWhat(userUid, gradebookUid, role));
89: }
90: }
91:
92: public List getLoginChoices() {
93: return loginChoices;
94: }
95: }
|