01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.jasper.runtime;
19:
20: import java.io.IOException;
21: import java.io.PrintWriter;
22:
23: import javax.servlet.ServletOutputStream;
24: import javax.servlet.ServletResponse;
25: import javax.servlet.http.HttpServletResponse;
26: import javax.servlet.http.HttpServletResponseWrapper;
27: import javax.servlet.jsp.JspWriter;
28:
29: /**
30: * ServletResponseWrapper used by the JSP 'include' action.
31: *
32: * This wrapper response object is passed to RequestDispatcher.include(), so
33: * that the output of the included resource is appended to that of the
34: * including page.
35: *
36: * @author Pierre Delisle
37: */
38:
39: public class ServletResponseWrapperInclude extends
40: HttpServletResponseWrapper {
41:
42: /**
43: * PrintWriter which appends to the JspWriter of the including page.
44: */
45: private PrintWriter printWriter;
46:
47: private JspWriter jspWriter;
48:
49: public ServletResponseWrapperInclude(ServletResponse response,
50: JspWriter jspWriter) {
51: super ((HttpServletResponse) response);
52: this .printWriter = new PrintWriter(jspWriter);
53: this .jspWriter = jspWriter;
54: }
55:
56: /**
57: * Returns a wrapper around the JspWriter of the including page.
58: */
59: public PrintWriter getWriter() throws IOException {
60: return printWriter;
61: }
62:
63: public ServletOutputStream getOutputStream() throws IOException {
64: throw new IllegalStateException();
65: }
66:
67: /**
68: * Clears the output buffer of the JspWriter associated with the including
69: * page.
70: */
71: public void resetBuffer() {
72: try {
73: jspWriter.clearBuffer();
74: } catch (IOException ioe) {
75: }
76: }
77: }
|