001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/tool-lib/src/java/org/theospi/portfolio/guidance/tool/DecoratedGuidanceItem.java $
003: * $Id:DecoratedGuidanceItem.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.guidance.tool;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import javax.faces.model.SelectItem;
027:
028: import org.sakaiproject.content.api.FilePickerHelper;
029: import org.sakaiproject.entity.api.Reference;
030: import org.sakaiproject.tool.api.ToolSession;
031: import org.sakaiproject.tool.cover.SessionManager;
032: import org.theospi.portfolio.guidance.model.GuidanceItem;
033: import org.theospi.portfolio.guidance.model.GuidanceItemAttachment;
034:
035: /**
036: * Created by IntelliJ IDEA.
037: * User: John Ellis
038: * Date: Nov 14, 2005
039: * Time: 4:53:06 PM
040: * To change this template use File | Settings | File Templates.
041: */
042: public class DecoratedGuidanceItem {
043:
044: private GuidanceItem base;
045: private GuidanceTool tool;
046:
047: public DecoratedGuidanceItem(GuidanceTool tool, GuidanceItem base) {
048: this .tool = tool;
049: this .base = base;
050: }
051:
052: public GuidanceItem getBase() {
053: return base;
054: }
055:
056: public void setBase(GuidanceItem base) {
057: this .base = base;
058: }
059:
060: public List getAttachments() {
061: ToolSession session = SessionManager.getCurrentToolSession();
062: if (session.getAttribute(FilePickerHelper.FILE_PICKER_CANCEL) == null
063: && session
064: .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null
065: && session.getAttribute(GuidanceTool.ATTACHMENT_TYPE)
066: .equals(base.getType())) {
067:
068: List refs = (List) session
069: .getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
070: List newAttachments = new ArrayList();
071:
072: for (int i = 0; i < refs.size(); i++) {
073: Reference ref = (Reference) refs.get(i);
074: Reference fullRef = tool.decorateReference(ref
075: .getReference());
076: GuidanceItemAttachment attachment = new GuidanceItemAttachment(
077: base, ref, fullRef);
078:
079: if (base.getAttachments().contains(attachment)) {
080: attachment = (GuidanceItemAttachment) base
081: .getAttachments().get(
082: base.getAttachments().indexOf(
083: attachment));
084: }
085:
086: newAttachments.add(attachment);
087: }
088: session
089: .removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS);
090: session.removeAttribute(GuidanceTool.ATTACHMENT_TYPE);
091: base.getAttachments().clear();
092: base.getAttachments().addAll(newAttachments);
093: }
094:
095: return base.getAttachments();
096: }
097:
098: public String processActionManageAttachments() {
099: return tool.processActionManageAttachments(base.getType());
100: }
101:
102: public List getAttachmentLinks() {
103: List attachments = getAttachments();
104: List returned = new ArrayList();
105:
106: for (Iterator i = attachments.iterator(); i.hasNext();) {
107: GuidanceItemAttachment attachment = (GuidanceItemAttachment) i
108: .next();
109: SelectItem item = new SelectItem(attachment
110: .getFullReference().getBase().getUrl(), attachment
111: .getDisplayName());
112: returned.add(item);
113: }
114:
115: return returned;
116: }
117: }
|