01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/tool-lib/src/java/org/theospi/portfolio/shared/tool/HelperToolBase.java $
03: * $Id:HelperToolBase.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.shared.tool;
21:
22: import java.io.IOException;
23:
24: import javax.faces.context.ExternalContext;
25: import javax.faces.context.FacesContext;
26:
27: import org.sakaiproject.tool.api.Tool;
28: import org.sakaiproject.tool.api.ToolSession;
29: import org.sakaiproject.tool.cover.SessionManager;
30: import org.sakaiproject.tool.cover.ToolManager;
31:
32: /**
33: * Created by IntelliJ IDEA.
34: * User: John Ellis
35: * Date: Nov 16, 2005
36: * Time: 2:57:48 PM
37: * To change this template use File | Settings | File Templates.
38: */
39: public class HelperToolBase extends ToolBase {
40:
41: protected Object getAttribute(String attributeName) {
42: ToolSession session = SessionManager.getCurrentToolSession();
43: return session.getAttribute(attributeName);
44: }
45:
46: protected Object getAttributeOrDefault(String attributeName) {
47: ToolSession session = SessionManager.getCurrentToolSession();
48: Object returned = session.getAttribute(attributeName);
49: if (returned == null) {
50: return attributeName;
51: }
52: return returned;
53: }
54:
55: protected String returnToCaller() {
56: ExternalContext context = FacesContext.getCurrentInstance()
57: .getExternalContext();
58: Tool tool = ToolManager.getCurrentTool();
59: ToolSession session = SessionManager.getCurrentToolSession();
60: String url = (String) session.getAttribute(tool.getId()
61: + Tool.HELPER_DONE_URL);
62: String param = (String) session.getAttribute("target");
63: if (param != null) {
64: url = url.concat("?" + param);
65: }
66: session.removeAttribute("target");
67: session.removeAttribute(tool.getId() + Tool.HELPER_DONE_URL);
68:
69: try {
70:
71: context.redirect(url);
72: } catch (IOException e) {
73: throw new RuntimeException("Failed to redirect to caller",
74: e);
75: }
76: return null;
77: }
78:
79: protected void removeAttribute(String attrib) {
80: removeAttributes(new String[] { attrib });
81: }
82:
83: protected void removeAttributes(String[] attribs) {
84: ToolSession session = SessionManager.getCurrentToolSession();
85:
86: for (int i = 0; i < attribs.length; i++) {
87: session.removeAttribute(attribs[i]);
88: }
89: }
90:
91: protected void setAttribute(String attributeName, Object value) {
92: ToolSession session = SessionManager.getCurrentToolSession();
93: session.setAttribute(attributeName, value);
94: }
95:
96: }
|