View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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.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  }