1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.jasper.runtime;
19
20 import javax.servlet.ServletOutputStream;
21 import javax.servlet.ServletResponse;
22 import javax.servlet.http.HttpServletResponse;
23 import javax.servlet.http.HttpServletResponseWrapper;
24 import javax.servlet.jsp.JspWriter;
25 import java.io.IOException;
26 import java.io.PrintWriter;
27
28 /***
29 * ServletResponseWrapper used by the JSP 'include' action.
30 * <p/>
31 * This wrapper response object is passed to RequestDispatcher.include(), so
32 * that the output of the included resource is appended to that of the
33 * including page.
34 *
35 * @author Pierre Delisle
36 */
37
38 public class ServletResponseWrapperInclude extends HttpServletResponseWrapper {
39
40 /***
41 * PrintWriter which appends to the JspWriter of the including page.
42 */
43 private PrintWriter printWriter;
44
45 private JspWriter jspWriter;
46
47 public ServletResponseWrapperInclude(ServletResponse response,
48 JspWriter jspWriter) {
49 super((HttpServletResponse) response);
50 this.printWriter = new PrintWriter(jspWriter);
51 this.jspWriter = jspWriter;
52 }
53
54 /***
55 * Returns a wrapper around the JspWriter of the including page.
56 */
57 public PrintWriter getWriter() throws IOException {
58 return printWriter;
59 }
60
61 public ServletOutputStream getOutputStream() throws IOException {
62 throw new IllegalStateException();
63 }
64
65 /***
66 * Clears the output buffer of the JspWriter associated with the including
67 * page.
68 */
69 public void resetBuffer() {
70 try {
71 jspWriter.clearBuffer();
72 } catch (IOException ioe) {
73 }
74 }
75 }