01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/tool/src/java/org/theospi/portfolio/presentation/control/DeleteViewerController.java $
03: * $Id:DeleteViewerController.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.presentation.control;
21:
22: import java.util.ArrayList;
23: import java.util.Collection;
24: import java.util.List;
25: import java.util.Map;
26:
27: import org.apache.commons.logging.Log;
28: import org.apache.commons.logging.LogFactory;
29: import org.sakaiproject.metaobj.shared.mgt.IdManager;
30: import org.sakaiproject.metaobj.shared.model.Agent;
31: import org.sakaiproject.metaobj.shared.model.Id;
32: import org.springframework.validation.Errors;
33: import org.springframework.web.servlet.ModelAndView;
34: import org.theospi.portfolio.presentation.model.Presentation;
35:
36: /**
37: * Created by IntelliJ IDEA.
38: * User: John Ellis
39: * Date: Apr 22, 2004
40: * Time: 9:58:31 AM
41: * To change this template use File | Settings | File Templates.
42: */
43: public class DeleteViewerController extends
44: AbstractPresentationController {
45: protected final Log logger = LogFactory.getLog(getClass());
46: private IdManager idManager;
47:
48: public ModelAndView handleRequest(Object requestModel, Map request,
49: Map session, Map application, Errors errors) {
50: String[] viewerIds = new String[1];
51: if (request.get("id") instanceof String) {
52: viewerIds[0] = (String) request.get("id");
53: } else {
54: viewerIds = (String[]) request.get("id");
55: }
56:
57: Presentation presentation = (Presentation) session
58: .get("presentation");
59:
60: for (int i = 0; i < viewerIds.length; i++) {
61: if (viewerIds[i] != null && viewerIds[i].length() > 0) {
62: removeViewer(viewerIds[i], presentation.getViewers());
63: }
64: }
65: return new ModelAndView("success");
66: }
67:
68: public IdManager getIdManager() {
69: return idManager;
70: }
71:
72: public void setIdManager(IdManager idManager) {
73: this .idManager = idManager;
74: }
75:
76: protected void removeViewer(String idStr, Collection viewers) {
77: Id id = getIdManager().getId(idStr);
78: Agent viewer = getAgentManager().getAgent(id);
79: List viewerCopy = new ArrayList(viewers);
80: if (viewer != null) {
81: viewers.remove(viewer);
82: } else {
83: //un-created guest users
84: for (int i = 0; i < viewerCopy.size(); i++) {
85: Agent curViewer = (Agent) viewerCopy.get(i);
86: if (curViewer.getDisplayName().equals(idStr)) {
87: viewers.remove(curViewer);
88: }
89: }
90: }
91:
92: }
93: }
|