001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.pluto.internal.impl;
018:
019: import org.apache.pluto.internal.InternalRenderRequest;
020: import org.apache.pluto.internal.InternalRenderResponse;
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023:
024: import javax.portlet.PortletException;
025: import javax.portlet.PortletRequestDispatcher;
026: import javax.portlet.RenderRequest;
027: import javax.portlet.RenderResponse;
028: import javax.servlet.RequestDispatcher;
029: import javax.servlet.ServletException;
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032:
033: import java.io.IOException;
034:
035: /**
036: * Implementation of the <code>PortletRequestDispatcher</code> interface.
037: * The portlet request dispatcher is used to dispatch <b>RenderRequest</b> and
038: * <b>RenderResponse</b> to a URI. Note that ActionRequest and ActionResponse
039: * can never be dispatched.
040: *
041: */
042: public class PortletRequestDispatcherImpl implements
043: PortletRequestDispatcher {
044:
045: /** Logger. */
046: private static final Log LOG = LogFactory
047: .getLog(PortletRequestDispatcherImpl.class);
048:
049: // Private Member Variables ------------------------------------------------
050:
051: /** The nested servlet request dispatcher instance. */
052: private final RequestDispatcher requestDispatcher;
053:
054: /** The included query string. */
055: private String queryString;
056:
057: // Constructors ------------------------------------------------------------
058:
059: /**
060: * Creates an instance. This constructor should be called to construct a
061: * named dispatcher.
062: * @param requestDispatcher the servlet request dispatcher.
063: * @see javax.portlet.PortletContext#getNamedDispatcher(String)
064: */
065: public PortletRequestDispatcherImpl(
066: RequestDispatcher requestDispatcher) {
067: this .requestDispatcher = requestDispatcher;
068: if (LOG.isDebugEnabled()) {
069: LOG.debug("Named dispatcher created.");
070: }
071: }
072:
073: /**
074: * Creates an instance. This constructor should be called to construct a
075: * portlet request dispatcher.
076: * @param requestDispatcher the servlet request dispatcher.
077: * @param queryString the included query string.
078: * @see javax.portlet.PortletContext#getRequestDispatcher(String)
079: */
080: public PortletRequestDispatcherImpl(
081: RequestDispatcher requestDispatcher, String queryString) {
082: this (requestDispatcher);
083: this .queryString = queryString;
084: if (LOG.isDebugEnabled()) {
085: LOG.debug("Request dispatcher created.");
086: }
087: }
088:
089: // PortletRequestDispatcher Impl -------------------------------------------
090:
091: public void include(RenderRequest request, RenderResponse response)
092: throws PortletException, IOException {
093:
094: InternalRenderRequest internalRequest = (InternalRenderRequest) InternalImplConverter
095: .getInternalRequest(request);
096: InternalRenderResponse internalResponse = (InternalRenderResponse) InternalImplConverter
097: .getInternalResponse(response);
098:
099: boolean isIncluded = (internalRequest.isIncluded() || internalResponse
100: .isIncluded());
101: try {
102: internalRequest.setIncluded(true);
103: internalRequest.setIncludedQueryString(queryString);
104: internalResponse.setIncluded(true);
105:
106: requestDispatcher.include(
107: (HttpServletRequest) internalRequest,
108: (HttpServletResponse) internalResponse);
109: } catch (IOException ex) {
110: throw ex;
111: } catch (ServletException ex) {
112: if (ex.getRootCause() != null) {
113: throw new PortletException(ex.getRootCause());
114: } else {
115: throw new PortletException(ex);
116: }
117: } finally {
118: internalRequest.setIncluded(isIncluded);
119: internalResponse.setIncluded(isIncluded);
120: }
121: }
122:
123: }
|