01: /*
02: * Copyright 2002 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */
13: package com.sun.portal.portlet.impl;
14:
15: import java.io.IOException;
16:
17: import javax.portlet.PortletException;
18: import javax.portlet.RenderRequest;
19: import javax.portlet.RenderResponse;
20: import javax.portlet.PortletRequestDispatcher;
21:
22: import javax.servlet.ServletException;
23:
24: /**
25: * The <code>RequestDispatcherImpl</code> class provides a default
26: * implementation for the <code>javax.portlet.RequestDispatcher</code>
27: * interface.
28: *
29: */
30:
31: public class RequestDispatcherImpl implements PortletRequestDispatcher {
32:
33: // constants
34: private static final String PORTLET_REQUEST = "javax.portlet.request";
35: private static final String PORTLET_RESPONSE = "javax.portlet.response";
36:
37: // private data members
38: private javax.servlet.RequestDispatcher _servletRD;
39: private String _path;
40:
41: // constructors
42: public RequestDispatcherImpl(javax.servlet.RequestDispatcher sRD,
43: String path) {
44: _servletRD = sRD;
45: _path = path;
46: }
47:
48: /**
49: *
50: * Includes the content of a resource (servlet, JSP page,
51: * HTML file) in the response. In essence, this method enables
52: * programmatic server-side includes.
53: * <p>
54: * The included servlet cannot set or change the response status code
55: * or set headers; any attempt to make a change is ignored.
56: *
57: *
58: * @param request a {@link RenderRequest} object
59: * that contains the client request
60: *
61: * @param response a {@link RenderResponse} object
62: * that contains the render response
63: *
64: * @exception PortletException if the included resource throws a ServletException,
65: * or other exceptions that are not Runtime-
66: * or IOExceptions.
67: *
68: * @exception java.io.IOException if the included resource throws this exception
69: *
70: *
71: */
72: public void include(RenderRequest rRequest, RenderResponse rResponse)
73: throws PortletException, IOException {
74:
75: // create RDRequestWrapper and RDResponseWrapper objects
76: RDRequestWrapper reqWrapper = new RDRequestWrapper(rRequest,
77: _path);
78: RDResponseWrapper resWrapper = new RDResponseWrapper(
79: reqWrapper, rResponse);
80:
81: // set request attributes in RDResponseWrapper
82: // Note: "javax.portlet.PortletConfig" will be set by the PAE
83: reqWrapper.setAttribute(PORTLET_REQUEST, rRequest);
84: reqWrapper.setAttribute(PORTLET_RESPONSE, rResponse);
85:
86: // invoke the corresponding servlet's request dispatcher
87: try {
88: _servletRD.include(reqWrapper, resWrapper);
89: } catch (ServletException se) {
90: throw new PortletException(
91: "RequestDispatcher.include: A ServletException was thrown in the target servlet or JSP.",
92: se);
93: }
94: }
95: }
|