001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portal.container;
021:
022: import java.io.IOException;
023: import java.util.Enumeration;
024: import java.util.HashMap;
025: import java.util.Hashtable;
026: import java.util.Iterator;
027: import java.util.Map;
028:
029: import javax.portlet.PortletException;
030: import javax.portlet.PortletRequestDispatcher;
031: import javax.portlet.RenderRequest;
032: import javax.portlet.RenderResponse;
033: import javax.servlet.RequestDispatcher;
034: import javax.servlet.ServletException;
035: import javax.servlet.http.HttpServletResponse;
036: import javax.servlet.http.HttpUtils;
037:
038: /**
039: *
040: *
041: * @author Padmanabh dabke
042: * (c) 2003 Nabh Information Systems, Inc. All Rights Reserved.
043: */
044: public class PortletRequestDispatcherImpl implements
045: PortletRequestDispatcher {
046: protected Hashtable prdiTransientParams = null;
047: protected RequestDispatcher prdiDispatcher = null;
048:
049: public PortletRequestDispatcherImpl(RequestDispatcher disp,
050: String incPath) {
051: prdiDispatcher = disp;
052: int index = incPath.indexOf('?');
053: if (index > -1) {
054: prdiTransientParams = HttpUtils.parseQueryString(incPath
055: .substring(index + 1));
056: }
057: if (prdiTransientParams != null) {
058: if (prdiTransientParams.size() == 0) {
059: prdiTransientParams = null;
060: }
061: }
062: }
063:
064: /* (non-Javadoc)
065: * @see javax.portlet.PortletRequestDispatcher#include(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
066: */
067: @SuppressWarnings("unchecked")
068: public void include(RenderRequest request, RenderResponse response)
069: throws PortletException, IOException {
070: HashMap permenantParams = new HashMap();
071: RenderRequestImpl rReq = null;
072: HttpServletResponse resp = ((RenderResponseImpl) response)
073: .getHttpServletResponse();
074:
075: HttpServletRequestStringbeansWrapper origReq = (HttpServletRequestStringbeansWrapper) ((RenderRequestImpl) request)
076: .getHttpServletRequest();
077: HttpServletResponseStringbeansWrapper origResp = (HttpServletResponseStringbeansWrapper) resp;
078:
079: try {
080: if (prdiTransientParams != null) {
081: rReq = (RenderRequestImpl) request;
082: Enumeration params = prdiTransientParams.keys();
083: while (params.hasMoreElements()) {
084: String key = (String) params.nextElement();
085: String[] oldValues = request
086: .getParameterValues(key);
087: if (oldValues != null)
088: permenantParams.put(key, oldValues);
089: rReq.setParameter(key,
090: (String[]) prdiTransientParams.get(key));
091: }
092: }
093:
094: origResp.setRenderResponse((RenderResponseImpl) response);
095: origReq.setRenderRequest((RenderRequestImpl) request);
096: prdiDispatcher.include(((RenderRequestImpl) request)
097: .getHttpServletRequest(), origResp);
098: } catch (ServletException se) {
099: System.out.println("**** Begin Error in dispatcher impl.");
100:
101: System.out.println(se.getMessage());
102: if (se.getRootCause() != null)
103: se.getRootCause().printStackTrace();
104: se.printStackTrace();
105: System.out
106: .println("****** End error in dispatcher impl. *****");
107: throw new PortletException(se);
108:
109: } catch (Exception se) {
110: System.out.println("**** Begin Error in dispatcher impl.");
111:
112: System.out.println(se.getMessage());
113: if (se.getCause() != null)
114: se.getCause().printStackTrace();
115: se.printStackTrace();
116: System.out
117: .println("****** End error in dispatcher impl. *****");
118: throw new PortletException(se);
119: } finally {
120: if (origResp != null)
121: origResp.setRenderResponse(null);
122: if (origReq != null)
123: origReq.setRenderRequest(null);
124: if (prdiTransientParams != null) {
125: Iterator paramIter = prdiTransientParams.keySet()
126: .iterator();
127: while (paramIter.hasNext()) {
128: rReq.removeParameter((String) paramIter.next());
129: }
130:
131: paramIter = permenantParams.entrySet().iterator();
132: while (paramIter.hasNext()) {
133: Map.Entry entry = (Map.Entry) paramIter.next();
134: rReq.setParameter((String) entry.getKey(),
135: (String[]) entry.getValue());
136: }
137: }
138: }
139:
140: }
141:
142: }
|