1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package javax.servlet;
21
22 import java.io.IOException;
23 import java.io.PrintWriter;
24 import java.util.Locale;
25
26 /**
27 *
28 * Provides a convenient implementation of the ServletResponse interface that
29 * can be subclassed by developers wishing to adapt the response from a Servlet.
30 * This class implements the Wrapper or Decorator pattern. Methods default to
31 * calling through to the wrapped response object.
32 *
33 * @author Various
34 * @version $Version$
35 * @since v 2.3
36 *
37 * @see javax.servlet.ServletResponse
38 *
39 */
40
41
42 public class ServletResponseWrapper implements ServletResponse {
43 private ServletResponse response;
44 /**
45 * Creates a ServletResponse adaptor wrapping the given response object.
46 * @throws java.lang.IllegalArgumentException if the response is null.
47 */
48
49
50 public ServletResponseWrapper(ServletResponse response) {
51 if (response == null) {
52 throw new IllegalArgumentException("Response cannot be null");
53 }
54 this.response = response;
55 }
56
57 /**
58 * Return the wrapped ServletResponse object.
59 */
60
61 public ServletResponse getResponse() {
62 return this.response;
63 }
64
65
66 /**
67 * Sets the response being wrapped.
68 * @throws java.lang.IllegalArgumentException if the response is null.
69 */
70
71 public void setResponse(ServletResponse response) {
72 if (response == null) {
73 throw new IllegalArgumentException("Response cannot be null");
74 }
75 this.response = response;
76 }
77
78 /**
79 * The default behavior of this method is to call setCharacterEncoding(String charset)
80 * on the wrapped response object.
81 *
82 * @since 2.4
83 */
84
85 public void setCharacterEncoding(String charset) {
86 this.response.setCharacterEncoding(charset);
87 }
88
89 /**
90 * The default behavior of this method is to return getCharacterEncoding()
91 * on the wrapped response object.
92 */
93
94 public String getCharacterEncoding() {
95 return this.response.getCharacterEncoding();
96 }
97
98
99 /**
100 * The default behavior of this method is to return getOutputStream()
101 * on the wrapped response object.
102 */
103
104 public ServletOutputStream getOutputStream() throws IOException {
105 return this.response.getOutputStream();
106 }
107
108 /**
109 * The default behavior of this method is to return getWriter()
110 * on the wrapped response object.
111 */
112
113
114 public PrintWriter getWriter() throws IOException {
115 return this.response.getWriter();
116 }
117
118 /**
119 * The default behavior of this method is to call setContentLength(int len)
120 * on the wrapped response object.
121 */
122
123 public void setContentLength(int len) {
124 this.response.setContentLength(len);
125 }
126
127 /**
128 * The default behavior of this method is to call setContentType(String type)
129 * on the wrapped response object.
130 */
131
132 public void setContentType(String type) {
133 this.response.setContentType(type);
134 }
135
136 /**
137 * The default behavior of this method is to return getContentType()
138 * on the wrapped response object.
139 *
140 * @since 2.4
141 */
142
143 public String getContentType() {
144 return this.response.getContentType();
145 }
146
147 /**
148 * The default behavior of this method is to call setBufferSize(int size)
149 * on the wrapped response object.
150 */
151 public void setBufferSize(int size) {
152 this.response.setBufferSize(size);
153 }
154
155 /**
156 * The default behavior of this method is to return getBufferSize()
157 * on the wrapped response object.
158 */
159 public int getBufferSize() {
160 return this.response.getBufferSize();
161 }
162
163 /**
164 * The default behavior of this method is to call flushBuffer()
165 * on the wrapped response object.
166 */
167
168 public void flushBuffer() throws IOException {
169 this.response.flushBuffer();
170 }
171
172 /**
173 * The default behavior of this method is to return isCommitted()
174 * on the wrapped response object.
175 */
176 public boolean isCommitted() {
177 return this.response.isCommitted();
178 }
179
180 /**
181 * The default behavior of this method is to call reset()
182 * on the wrapped response object.
183 */
184
185 public void reset() {
186 this.response.reset();
187 }
188
189 /**
190 * The default behavior of this method is to call resetBuffer()
191 * on the wrapped response object.
192 */
193
194 public void resetBuffer() {
195 this.response.resetBuffer();
196 }
197
198 /**
199 * The default behavior of this method is to call setLocale(Locale loc)
200 * on the wrapped response object.
201 */
202
203 public void setLocale(Locale loc) {
204 this.response.setLocale(loc);
205 }
206
207 /**
208 * The default behavior of this method is to return getLocale()
209 * on the wrapped response object.
210 */
211 public Locale getLocale() {
212 return this.response.getLocale();
213 }
214
215
216 }
217
218
219
220
221