1 /* This software is published under the terms of the OpenSymphony Software
2 * License version 1.1, of which a copy has been included with this
3 * distribution in the LICENSE.txt file. */
4 package com.opensymphony.module.sitemesh.filter;
5
6 import javax.servlet.RequestDispatcher;
7 import javax.servlet.ServletException;
8 import javax.servlet.ServletRequest;
9 import javax.servlet.ServletResponse;
10 import java.io.IOException;
11
12 /**
13 * Special request dispatcher that will include when an inline decorator includes
14 * a resource that uses an internal forward.
15 *
16 * @see com.opensymphony.module.sitemesh.taglib.page.ApplyDecoratorTag
17 *
18 * @author <a href="mailto:joeo@enigmastation.com">Joseph B. Ottinger</a>
19 * @version $Revision: 1.2 $
20 */
21 public class RequestDispatcherWrapper implements RequestDispatcher {
22 private RequestDispatcher rd = null;
23 private boolean done = false;
24
25 public RequestDispatcherWrapper(RequestDispatcher rd) {
26 this.rd = rd;
27 }
28
29 public void forward(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
30 if (!done) {
31 include(servletRequest, servletResponse);
32 done = true;
33 }
34 else {
35 throw new IllegalStateException("Response has already been committed");
36 }
37 }
38
39 public void include(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
40 if (!done) {
41 rd.include(servletRequest, servletResponse);
42 }
43 else {
44 throw new IllegalStateException("Response has already been committed");
45 }
46 }
47 }