001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/common/tool-lib/src/java/org/theospi/portfolio/style/tool/ListStyleController.java $
003: * $Id: ListStyleController.java 10835 2006-06-17 03:25:03Z lance@indiana.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.style.tool;
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.security.AuthorizationFailedException;
030: import org.sakaiproject.metaobj.shared.model.Agent;
031: import org.sakaiproject.metaobj.utils.mvc.intf.ListScroll;
032: import org.sakaiproject.metaobj.utils.mvc.intf.ListScrollIndexer;
033: import org.sakaiproject.tool.cover.ToolManager;
034: import org.springframework.validation.Errors;
035: import org.springframework.web.servlet.ModelAndView;
036: import org.theospi.portfolio.style.StyleHelper;
037: import org.theospi.portfolio.style.model.Style;
038:
039: public class ListStyleController extends AbstractStyleController {
040:
041: protected final Log logger = LogFactory.getLog(getClass());
042: private ListScrollIndexer listScrollIndexer;
043:
044: public ModelAndView handleRequest(Object requestModel, Map request,
045: Map session, Map application, Errors errors) {
046:
047: Hashtable model = new Hashtable();
048: Agent agent = getAuthManager().getAgent();
049: List styles = new ArrayList();
050:
051: String selectable = (String) session
052: .get(StyleHelper.STYLE_SELECTABLE);
053: if (selectable != null) {
054: model.put("selectableStyle", selectable);
055: styles.addAll(getStyleManager().findPublishedStyles(
056: ToolManager.getCurrentPlacement().getContext()));
057: } else if (!getStyleManager().isGlobal())
058: styles.addAll(getStyleManager().findSiteStyles(
059: ToolManager.getCurrentPlacement().getContext()));
060: else
061: styles.addAll(getStyleManager().findGlobalStyles(agent));
062:
063: model.put("styleCount", String.valueOf(styles.size()));
064:
065: if (request.get("newStyleId") != null) {
066: request.put(ListScroll.ENSURE_VISIBLE_TAG, ""
067: + getStyleIndex(styles, (String) request
068: .get("newStyleId")));
069: }
070:
071: if (session.get(StyleHelper.CURRENT_STYLE_ID) != null)
072: model.put("selectedStyle", session
073: .get(StyleHelper.CURRENT_STYLE_ID));
074:
075: styles = getListScrollIndexer().indexList(request, model,
076: styles);
077: model.put("styles", styles);
078:
079: model.put("osp_agent", agent);
080: String worksiteId = getWorksiteManager().getCurrentWorksiteId()
081: .getValue();
082: model.put("worksite", getWorksiteManager().getSite(worksiteId));
083: model.put("tool", getWorksiteManager().getTool(
084: ToolManager.getCurrentPlacement().getId()));
085: model.put("isMaintainer", isMaintainer());
086: model
087: .put("isGlobal", new Boolean(getStyleManager()
088: .isGlobal()));
089:
090: return new ModelAndView("success", model);
091: }
092:
093: protected int getStyleIndex(List styles, String styleId) {
094: if (styleId == null) {
095: return 0;
096: }
097:
098: for (int i = 0; i < styles.size(); i++) {
099: Style current = (Style) styles.get(i);
100: if (current.getId().getValue().equals(styleId)) {
101: return i;
102: }
103: }
104: return 0;
105: }
106:
107: protected void checkPermission(String function)
108: throws AuthorizationFailedException {
109: getAuthzManager()
110: .checkPermission(
111: function,
112: getIdManager().getId(
113: ToolManager.getCurrentPlacement()
114: .getContext()));
115: }
116:
117: public ListScrollIndexer getListScrollIndexer() {
118: return listScrollIndexer;
119: }
120:
121: public void setListScrollIndexer(ListScrollIndexer listScrollIndexer) {
122: this.listScrollIndexer = listScrollIndexer;
123: }
124:
125: }
|