View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  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  //
19  // This source code implements specifications defined by the Java
20  // Community Process. In order to remain compliant with the specification
21  // DO NOT add / change / or delete method signatures!
22  //
23  
24  package javax.servlet;
25  
26  import java.io.IOException;
27  import java.io.PrintWriter;
28  import java.util.Locale;
29  
30  /**
31   * Provides a convenient implementation of the ServletResponse interface that
32   * can be subclassed by developers wishing to adapt the response from a Servlet.
33   * This class implements the Wrapper or Decorator pattern. Methods default to
34   * calling through to the wrapped response object.
35   *
36   * @since Servlet 2.3
37   *
38   * @see javax.servlet.ServletResponse
39   *
40   * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
41   */
42  public class ServletResponseWrapper implements ServletResponse {
43      private ServletResponse response;
44  
45      /**
46       * Creates a ServletResponse adaptor wrapping the given response object.
47       * @throws java.lang.IllegalArgumentException if the response is null.
48       */
49      public ServletResponseWrapper(ServletResponse response) {
50          if (response == null) {
51              throw new IllegalArgumentException("Response cannot be null");
52          }
53          this.response = response;
54      }
55  
56      /**
57       * Return the wrapped ServletResponse object.
58       */
59      public ServletResponse getResponse() {
60          return this.response;
61      }
62  
63      /**
64       * Sets the response being wrapped.
65       * @throws java.lang.IllegalArgumentException if the response is null.
66       */
67      public void setResponse(ServletResponse response) {
68          if (response == null) {
69              throw new IllegalArgumentException("Response cannot be null");
70          }
71          this.response = response;
72      }
73  
74      /**
75       * The default behavior of this method is to call setCharacterEncoding(String charset)
76       * on the wrapped response object.
77       *
78       * @since Servlet 2.4
79       */
80      public void setCharacterEncoding(String charset) {
81          this.response.setCharacterEncoding(charset);
82      }
83  
84      /**
85       * The default behavior of this method is to return getCharacterEncoding()
86       * on the wrapped response object.
87       */
88      public String getCharacterEncoding() {
89          return this.response.getCharacterEncoding();
90      }
91  
92      /**
93       * The default behavior of this method is to return getOutputStream()
94       * on the wrapped response object.
95       */
96      public ServletOutputStream getOutputStream() throws IOException {
97          return this.response.getOutputStream();
98      }
99  
100     /**
101      * The default behavior of this method is to return getWriter()
102      * on the wrapped response object.
103      */
104     public PrintWriter getWriter() throws IOException {
105         return this.response.getWriter();
106     }
107 
108     /**
109      * The default behavior of this method is to call setContentLength(int len)
110      * on the wrapped response object.
111      */
112     public void setContentLength(int len) {
113         this.response.setContentLength(len);
114     }
115 
116     /**
117      * The default behavior of this method is to call setContentType(String type)
118      * on the wrapped response object.
119      */
120     public void setContentType(String type) {
121         this.response.setContentType(type);
122     }
123 
124     /**
125      * The default behavior of this method is to return getContentType()
126      * on the wrapped response object.
127      *
128      * @since Servlet 2.4
129      */
130     public String getContentType() {
131         return this.response.getContentType();
132     }
133 
134     /**
135      * The default behavior of this method is to call setBufferSize(int size)
136      * on the wrapped response object.
137      */
138     public void setBufferSize(int size) {
139         this.response.setBufferSize(size);
140     }
141 
142     /**
143      * The default behavior of this method is to return getBufferSize()
144      * on the wrapped response object.
145      */
146     public int getBufferSize() {
147         return this.response.getBufferSize();
148     }
149 
150     /**
151      * The default behavior of this method is to call flushBuffer()
152      * on the wrapped response object.
153      */
154 
155     public void flushBuffer() throws IOException {
156         this.response.flushBuffer();
157     }
158 
159     /**
160      * The default behavior of this method is to return isCommitted()
161      * on the wrapped response object.
162      */
163     public boolean isCommitted() {
164         return this.response.isCommitted();
165     }
166 
167     /**
168      * The default behavior of this method is to call reset()
169      * on the wrapped response object.
170      */
171     public void reset() {
172         this.response.reset();
173     }
174 
175     /**
176      * The default behavior of this method is to call resetBuffer()
177      * on the wrapped response object.
178      */
179     public void resetBuffer() {
180         this.response.resetBuffer();
181     }
182 
183     /**
184      * The default behavior of this method is to call setLocale(Locale loc)
185      * on the wrapped response object.
186      */
187     public void setLocale(Locale loc) {
188         this.response.setLocale(loc);
189     }
190 
191     /**
192      * The default behavior of this method is to return getLocale()
193      * on the wrapped response object.
194      */
195     public Locale getLocale() {
196         return this.response.getLocale();
197     }
198 }
199 
200 
201 
202 
203