KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > module > sitemesh > filter > RequestDispatcherWrapper


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 JavaDoc;
7 import javax.servlet.ServletException JavaDoc;
8 import javax.servlet.ServletRequest JavaDoc;
9 import javax.servlet.ServletResponse JavaDoc;
10 import java.io.IOException JavaDoc;
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 JavaDoc {
22     private RequestDispatcher JavaDoc rd = null;
23     private boolean done = false;
24
25     public RequestDispatcherWrapper(RequestDispatcher JavaDoc rd) {
26         this.rd = rd;
27     }
28
29     public void forward(ServletRequest JavaDoc servletRequest, ServletResponse JavaDoc servletResponse) throws ServletException JavaDoc, IOException JavaDoc {
30         if (!done) {
31             include(servletRequest, servletResponse);
32             done = true;
33         }
34         else {
35             throw new IllegalStateException JavaDoc("Response has already been committed");
36         }
37     }
38
39     public void include(ServletRequest JavaDoc servletRequest, ServletResponse JavaDoc servletResponse) throws ServletException JavaDoc, IOException JavaDoc {
40         if (!done) {
41             rd.include(servletRequest, servletResponse);
42         }
43         else {
44             throw new IllegalStateException JavaDoc("Response has already been committed");
45         }
46     }
47 }
Popular Tags