01: /*
02: * $Id: $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.portlet.servlet;
22:
23: import java.io.IOException;
24:
25: import javax.portlet.PortletException;
26: import javax.portlet.PortletRequest;
27: import javax.portlet.PortletRequestDispatcher;
28: import javax.portlet.PortletResponse;
29: import javax.portlet.RenderRequest;
30: import javax.portlet.RenderResponse;
31: import javax.servlet.RequestDispatcher;
32: import javax.servlet.ServletException;
33: import javax.servlet.ServletRequest;
34: import javax.servlet.ServletResponse;
35:
36: public class PortletServletRequestDispatcher implements
37: RequestDispatcher {
38:
39: private PortletRequestDispatcher portletRequestDispatcher;
40:
41: public PortletServletRequestDispatcher(
42: PortletRequestDispatcher portletRequestDispatcher) {
43: this .portletRequestDispatcher = portletRequestDispatcher;
44: }
45:
46: public void forward(ServletRequest request, ServletResponse response)
47: throws ServletException, IOException {
48: throw new IllegalStateException("Not allowed in a portlet");
49:
50: }
51:
52: public void include(ServletRequest request, ServletResponse response)
53: throws ServletException, IOException {
54: if (request instanceof PortletServletRequest
55: && response instanceof PortletServletResponse) {
56: PortletRequest req = ((PortletServletRequest) request)
57: .getPortletRequest();
58: PortletResponse resp = ((PortletServletResponse) response)
59: .getPortletResponse();
60: if (req instanceof RenderRequest
61: && resp instanceof RenderResponse) {
62: try {
63: portletRequestDispatcher.include(
64: (RenderRequest) req, (RenderResponse) resp);
65: } catch (PortletException e) {
66: throw new ServletException(e);
67: }
68: } else {
69: throw new IllegalStateException(
70: "Can only be invoked in the render phase");
71: }
72: } else {
73: throw new IllegalStateException(
74: "Can only be invoked in a portlet");
75: }
76: }
77:
78: }
|