001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/portal/tags/sakai_2-4-1/portal-render-impl/impl/src/java/org/sakaiproject/portal/render/compat/CompatibilityToolRenderService.java $
003: * $Id: CompatibilityToolRenderService.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.compat;
021:
022: import java.io.IOException;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import javax.servlet.ServletContext;
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.http.HttpServletResponse;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.sakaiproject.portal.render.api.RenderResult;
033: import org.sakaiproject.portal.render.api.ToolRenderException;
034: import org.sakaiproject.portal.render.api.ToolRenderService;
035: import org.sakaiproject.site.api.ToolConfiguration;
036:
037: /**
038: * Render serivice used to support both Portlet and iframe based tools.
039: *
040: * @author ddwolf
041: * @since Sakai 2.4
042: * @version $Rev: 29143 $
043: */
044: public class CompatibilityToolRenderService implements
045: ToolRenderService {
046:
047: private static final Log LOG = LogFactory
048: .getLog(CompatibilityToolRenderService.class);
049:
050: private List renderServices = null;
051:
052: /**
053: * @param request
054: * @param response
055: * @param context
056: * @return
057: * @throws IOException
058: */
059: public boolean preprocess(HttpServletRequest request,
060: HttpServletResponse response, ServletContext context)
061: throws IOException {
062:
063: boolean continueProcessing = true;
064: for (Iterator i = renderServices.iterator(); i.hasNext();) {
065: ToolRenderService trs = (ToolRenderService) i.next();
066: LOG.debug("Preprocessing with " + trs);
067: continueProcessing = continueProcessing
068: && trs.preprocess(request, response, context);
069: }
070: return continueProcessing;
071: }
072:
073: public RenderResult render(ToolConfiguration configuration,
074: HttpServletRequest request, HttpServletResponse response,
075: ServletContext context) throws IOException {
076:
077: for (Iterator i = renderServices.iterator(); i.hasNext();) {
078: ToolRenderService trs = (ToolRenderService) i.next();
079: if (trs.accept(configuration, request, response, context)) {
080: LOG.debug("Rendering with " + trs);
081: return trs.render(configuration, request, response,
082: context);
083: }
084: }
085: throw new ToolRenderException(
086: "No available Tool Render Service for the tool "
087: + configuration.getToolId());
088: }
089:
090: public boolean accept(ToolConfiguration configuration,
091: HttpServletRequest request, HttpServletResponse response,
092: ServletContext context) {
093: for (Iterator i = renderServices.iterator(); i.hasNext();) {
094: ToolRenderService trs = (ToolRenderService) i.next();
095: if (trs.accept(configuration, request, response, context)) {
096: return true;
097: }
098: }
099: return false;
100: }
101:
102: /**
103: * @return the renderServices
104: */
105: public List getRenderServices() {
106: return renderServices;
107: }
108:
109: /**
110: * @param renderServices
111: * the renderServices to set
112: */
113: public void setRenderServices(List renderServices) {
114: this .renderServices = renderServices;
115: }
116:
117: public void reset(ToolConfiguration configuration) {
118: for (Iterator i = renderServices.iterator(); i.hasNext();) {
119: ToolRenderService trs = (ToolRenderService) i.next();
120: trs.reset(configuration);
121: }
122: }
123:
124: }
|