001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/tool/src/java/org/theospi/portfolio/presentation/control/ListTemplateController.java $
003: * $Id:ListTemplateController.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.presentation.control;
021:
022: import java.util.ArrayList;
023: import java.util.Hashtable;
024: import java.util.List;
025: import java.util.Map;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.sakaiproject.metaobj.shared.model.Agent;
030: import org.sakaiproject.metaobj.utils.mvc.intf.ListScroll;
031: import org.sakaiproject.metaobj.utils.mvc.intf.ListScrollIndexer;
032: import org.sakaiproject.tool.cover.ToolManager;
033: import org.springframework.validation.Errors;
034: import org.springframework.web.servlet.ModelAndView;
035: import org.theospi.portfolio.presentation.model.PresentationTemplate;
036:
037: public class ListTemplateController extends
038: AbstractPresentationController {
039:
040: protected final Log logger = LogFactory.getLog(getClass());
041: private ListScrollIndexer listScrollIndexer;
042:
043: public ModelAndView handleRequest(Object requestModel, Map request,
044: Map session, Map application, Errors errors) {
045:
046: Hashtable model = new Hashtable();
047: Agent agent = getAuthManager().getAgent();
048: List templates = new ArrayList(getPresentationManager()
049: .findTemplatesByOwner(agent,
050: ToolManager.getCurrentPlacement().getContext()));
051: templates
052: .addAll(getPresentationManager()
053: .findPublishedTemplates(
054: ToolManager.getCurrentPlacement()
055: .getContext()));
056: model.put("templateCount", String.valueOf(templates.size()));
057:
058: if (request.get("newPresentationTemplateId") != null) {
059: request.put(ListScroll.ENSURE_VISIBLE_TAG, ""
060: + getPresentationIndex(templates, (String) request
061: .get("newPresentationTemplateId")));
062: }
063:
064: templates = getListScrollIndexer().indexList(request, model,
065: templates);
066: model.put("templates", templates);
067:
068: model.put("osp_agent", agent);
069: String worksiteId = getWorksiteManager().getCurrentWorksiteId()
070: .getValue();
071: model.put("worksite", getWorksiteManager().getSite(worksiteId));
072: model.put("tool", getWorksiteManager().getTool(
073: ToolManager.getCurrentPlacement().getId()));
074: model.put("isMaintainer", isMaintainer());
075: model.put("globalTool", ""
076: + getPresentationManager().isGlobal());
077: return new ModelAndView("success", model);
078: }
079:
080: protected int getPresentationIndex(List templates, String templateId) {
081: if (templateId == null) {
082: return 0;
083: }
084:
085: for (int i = 0; i < templates.size(); i++) {
086: PresentationTemplate current = (PresentationTemplate) templates
087: .get(i);
088: if (current.getId().getValue().equals(templateId)) {
089: return i;
090: }
091: }
092: return 0;
093: }
094:
095: public ListScrollIndexer getListScrollIndexer() {
096: return listScrollIndexer;
097: }
098:
099: public void setListScrollIndexer(ListScrollIndexer listScrollIndexer) {
100: this.listScrollIndexer = listScrollIndexer;
101: }
102:
103: }
|