001: /**********************************************************************************
002: *
003: * $Id: SelectGradebookBean.java 8234 2006-04-25 01:18:48Z ray@media.berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005, 2006 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook.ui.standalone;
022:
023: import java.io.UnsupportedEncodingException;
024: import java.net.URLEncoder;
025: import java.util.ArrayList;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.tool.gradebook.Gradebook;
032: import org.sakaiproject.tool.gradebook.facades.Authn;
033: import org.sakaiproject.tool.gradebook.ui.InitializableBean;
034:
035: public class SelectGradebookBean extends InitializableBean {
036: private static final Log logger = LogFactory
037: .getLog(SelectGradebookBean.class);
038: private Authn authnService;
039: private FrameworkManager frameworkManager;
040:
041: /**
042: * Return a list of gradebooks accessible by the currently logged-in user.
043: */
044: public List getGradebooks() {
045: String userUid = authnService.getUserUid();
046: List gradebooks = frameworkManager
047: .getAccessibleGradebooks(userUid);
048:
049: // JSF's "f:param" doesn't java.net.URLEncoder.encode the
050: // parameter value for us. If it did, we would just return the gradebooks
051: // list straight.
052: List returnList = new ArrayList(gradebooks.size());
053: for (Iterator iter = gradebooks.iterator(); iter.hasNext();) {
054: Gradebook gradebook = (Gradebook) iter.next();
055: returnList.add(new GradebookRow(gradebook));
056: }
057:
058: return returnList;
059: }
060:
061: public class GradebookRow {
062: private String name;
063: private String uid;
064:
065: public GradebookRow() {
066: }
067:
068: public GradebookRow(Gradebook gradebook) {
069: this .name = gradebook.getName();
070: try {
071: this .uid = URLEncoder.encode(gradebook.getUid(),
072: "UTF-8");
073: } catch (UnsupportedEncodingException ex) {
074: logger.error("Unlikely exception thrown", ex);
075: }
076: }
077:
078: public String getName() {
079: return name;
080: }
081:
082: public void setName(String name) {
083: this .name = name;
084: }
085:
086: public String getUid() {
087: return uid;
088: }
089:
090: public void setUid(String uid) {
091: this .uid = uid;
092: }
093: }
094:
095: public Authn getAuthnService() {
096: return authnService;
097: }
098:
099: public void setAuthnService(Authn authnService) {
100: this .authnService = authnService;
101: }
102:
103: public FrameworkManager getFrameworkManager() {
104: return frameworkManager;
105: }
106:
107: public void setFrameworkManager(FrameworkManager frameworkManager) {
108: this.frameworkManager = frameworkManager;
109: }
110: }
|