001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/glossary/tool/src/java/org/theospi/portfolio/help/control/GlossaryListController.java $
003: * $Id:GlossaryListController.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.help.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.utils.mvc.intf.ListScroll;
030: import org.sakaiproject.metaobj.utils.mvc.intf.ListScrollIndexer;
031: import org.sakaiproject.tool.api.ToolManager;
032: import org.springframework.validation.Errors;
033: import org.springframework.web.servlet.ModelAndView;
034: import org.theospi.portfolio.help.model.GlossaryEntry;
035: import org.theospi.portfolio.help.model.HelpManager;
036:
037: public class GlossaryListController extends HelpController {
038: protected final transient Log logger = LogFactory
039: .getLog(getClass());
040:
041: private ListScrollIndexer listScrollIndexer;
042: private ToolManager toolManager;
043:
044: public ModelAndView handleRequest(Object requestModel, Map request,
045: Map session, Map application, Errors errors) {
046: String worksiteId = getWorksiteManager().getCurrentWorksiteId()
047: .getValue();
048:
049: Hashtable model = new Hashtable();
050: model.put("worksite", getWorksiteManager().getSite(worksiteId));
051: model.put("tool", toolManager.getCurrentPlacement());
052: model.put("global", new Boolean(getHelpManager().isGlobal()));
053: if (getHelpManager().isGlobal()) {
054: model.put("globalQualifier", getIdManager().getId(
055: HelpManager.GLOBAL_GLOSSARY_QUALIFIER));
056: }
057:
058: List terms = new ArrayList(getHelpManager().getWorksiteTerms());
059:
060: if (request.get("newTermId") != null) {
061: request.put(ListScroll.ENSURE_VISIBLE_TAG, ""
062: + getTermIndex(terms, (String) request
063: .get("newTermId")));
064: }
065:
066: terms = getListScrollIndexer().indexList(request, model, terms);
067:
068: model.put("glossary", terms);
069:
070: String msg = (String) session
071: .get(TRANSFER_CONTROLLER_SESSION_MESSAGE);
072: if (msg != null) {
073: if (msg.equals(TRANSFER_MESSAGE_IMPORT_SUCCESS))
074: model.put("import_success", "true");
075: if (msg.equals(TRANSFER_MESSAGE_IMPORT_BAD_FILE))
076: model.put("import_unrecognized_file", "true");
077: if (msg.equals(TRANSFER_MESSAGE_IMPORT_FAILED))
078: model.put("import_failed", "true");
079: if (msg.equals(TRANSFER_MESSAGE_IMPORT_BAD_PARSE))
080: model.put("import_bad_parse", "true");
081: session.remove(TRANSFER_CONTROLLER_SESSION_MESSAGE);
082: }
083:
084: return new ModelAndView("success", model);
085: }
086:
087: protected int getTermIndex(List terms, String termId) {
088: for (int i = 0; i < terms.size(); i++) {
089: GlossaryEntry entry = (GlossaryEntry) terms.get(i);
090: if (entry.getId().getValue().equals(termId)) {
091: return i;
092: }
093: }
094: return 0;
095: }
096:
097: public ListScrollIndexer getListScrollIndexer() {
098: return listScrollIndexer;
099: }
100:
101: public void setListScrollIndexer(ListScrollIndexer listScrollIndexer) {
102: this .listScrollIndexer = listScrollIndexer;
103: }
104:
105: public ToolManager getToolManager() {
106: return toolManager;
107: }
108:
109: public void setToolManager(ToolManager toolManager) {
110: this.toolManager = toolManager;
111: }
112: }
|