001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/portal/tags/sakai_2-4-1/portal-render-impl/impl/src/java/org/sakaiproject/portal/render/iframe/IFrameToolRenderService.java $
003: * $Id: IFrameToolRenderService.java 29143 2007-04-19 01:10:38Z ajpoland@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.sakaiproject.portal.render.iframe;
021:
022: import java.io.IOException;
023: import java.util.Map;
024:
025: import javax.servlet.ServletContext;
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.component.cover.ServerConfigurationService;
032: import org.sakaiproject.portal.api.PortalService;
033: import org.sakaiproject.portal.api.StoredState;
034: import org.sakaiproject.portal.render.api.RenderResult;
035: import org.sakaiproject.portal.render.api.ToolRenderException;
036: import org.sakaiproject.portal.render.api.ToolRenderService;
037: import org.sakaiproject.portal.util.URLUtils;
038: import org.sakaiproject.site.api.ToolConfiguration;
039: import org.sakaiproject.util.Web;
040:
041: /**
042: * I Frame tool renderer, renders the iframe header to contain the tool content
043: *
044: * @author ddwolf
045: * @since Sakai 2.4
046: * @version $Rev: 29143 $
047: */
048: public class IFrameToolRenderService implements ToolRenderService {
049:
050: private static final Log LOG = LogFactory
051: .getLog(IFrameToolRenderService.class);
052:
053: private PortalService portalService;
054:
055: // private static ResourceLoader rb = new ResourceLoader("sitenav");
056:
057: public boolean preprocess(HttpServletRequest request,
058: HttpServletResponse response, ServletContext context)
059: throws IOException, ToolRenderException {
060:
061: return true;
062: }
063:
064: public RenderResult render(ToolConfiguration configuration,
065: HttpServletRequest request, HttpServletResponse response,
066: ServletContext context) throws IOException,
067: ToolRenderException {
068:
069: final String titleString = Web.escapeHtml(configuration
070: .getTitle());
071: String toolUrl = ServerConfigurationService.getToolUrl() + "/"
072: + Web.escapeUrl(configuration.getId());
073: StoredState ss = portalService.getStoredState();
074: LOG.debug("Restoring Iframe [" + ss + "]");
075:
076: Map parametermap = ss == null ? request.getParameterMap() : ss
077: .getRequest(request).getParameterMap();
078: String URLstub = portalService.decodeToolState(parametermap,
079: configuration.getId());
080: if (URLstub != null) {
081: toolUrl += URLstub;
082: }
083: toolUrl = URLUtils.addParameter(toolUrl, "panel", "Main");
084:
085: final StringBuilder sb = new StringBuilder();
086: sb.append("<iframe").append(" name=\"").append(
087: Web.escapeJavascript("Main" + configuration.getId()))
088: .append("\"\n").append(" id=\"").append(
089: Web.escapeJavascript("Main"
090: + configuration.getId())).append("\n")
091: .append("\"").append("\n").append(" title=\"").append(
092: titleString).append(" ").
093: /* append(Web.escapeHtml(rb.getString("sit.contentporttit"))). */
094: append("\"").append("\n").append(
095: " class =\"portletMainIframe\"").append("\n")
096: .append(" height=\"50\"").append("\n").append(
097: " width=\"100%\"").append("\n").append(
098: " frameborder=\"0\"").append("\n").append(
099: " marginwidth=\"0\"").append("\n").append(
100: " marginheight=\"0\"").append("\n").append(
101: " scrolling=\"auto\"").append("\n").append(
102: " src=\"").append(toolUrl).append("\">")
103: .append("\n").append("</iframe>");
104:
105: RenderResult result = new RenderResult() {
106: public String getTitle() {
107: return titleString;
108: }
109:
110: public String getContent() {
111: return sb.toString();
112: }
113:
114: public String getJSR168EditUrl() {
115: return null;
116: }
117:
118: public String getJSR168HelpUrl() {
119: return null;
120: }
121: };
122:
123: return result;
124: }
125:
126: public boolean accept(ToolConfiguration configuration,
127: HttpServletRequest request, HttpServletResponse response,
128: ServletContext context) {
129: return true;
130: }
131:
132: public void reset(ToolConfiguration configuration) {
133: }
134:
135: /**
136: * @return the portalService
137: */
138: public PortalService getPortalService() {
139: return portalService;
140: }
141:
142: /**
143: * @param portalService
144: * the portalService to set
145: */
146: public void setPortalService(PortalService portalService) {
147: this.portalService = portalService;
148: }
149: }
|