1
2
3 /*
4 * The contents of this file are subject to the terms
5 * of the Common Development and Distribution License
6 * (the "License"). You may not use this file except
7 * in compliance with the License.
8 *
9 * You can obtain a copy of the license at
10 * glassfish/bootstrap/legal/CDDLv1.0.txt or
11 * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12 * See the License for the specific language governing
13 * permissions and limitations under the License.
14 *
15 * When distributing Covered Code, include this CDDL
16 * HEADER in each file and include the License file at
17 * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18 * add the following below this CDDL HEADER, with the
19 * fields enclosed by brackets "[]" replaced with your
20 * own identifying information: Portions Copyright [yyyy]
21 * [name of copyright owner]
22 *
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 *
25 * Portions Copyright Apache Software Foundation.
26 */
27
28 package javax.servlet;
29
30 import java.io.IOException;
31 import java.io.PrintWriter;
32 import java.util.Locale;
33
34 /**
35 *
36 * Provides a convenient implementation of the ServletResponse interface that
37 * can be subclassed by developers wishing to adapt the response from a Servlet.
38 * This class implements the Wrapper or Decorator pattern. Methods default to
39 * calling through to the wrapped response object.
40 *
41 * @author Various
42 * @since v 2.3
43 *
44 * @see javax.servlet.ServletResponse
45 *
46 */
47
48
49 public class ServletResponseWrapper implements ServletResponse {
50 private ServletResponse response;
51 /**
52 * Creates a ServletResponse adaptor wrapping the given response object.
53 * @throws java.lang.IllegalArgumentException if the response is null.
54 */
55
56
57 public ServletResponseWrapper(ServletResponse response) {
58 if (response == null) {
59 throw new IllegalArgumentException("Response cannot be null");
60 }
61 this.response = response;
62 }
63
64 /**
65 * Return the wrapped ServletResponse object.
66 */
67
68 public ServletResponse getResponse() {
69 return this.response;
70 }
71
72
73 /**
74 * Sets the response being wrapped.
75 * @throws java.lang.IllegalArgumentException if the response is null.
76 */
77
78 public void setResponse(ServletResponse response) {
79 if (response == null) {
80 throw new IllegalArgumentException("Response cannot be null");
81 }
82 this.response = response;
83 }
84
85 /**
86 * The default behavior of this method is to call setCharacterEncoding(String charset)
87 * on the wrapped response object.
88 *
89 * @since 2.4
90 */
91
92 public void setCharacterEncoding(String charset) {
93 this.response.setCharacterEncoding(charset);
94 }
95
96 /**
97 * The default behavior of this method is to return getCharacterEncoding()
98 * on the wrapped response object.
99 */
100
101 public String getCharacterEncoding() {
102 return this.response.getCharacterEncoding();
103 }
104
105
106 /**
107 * The default behavior of this method is to return getOutputStream()
108 * on the wrapped response object.
109 */
110
111 public ServletOutputStream getOutputStream() throws IOException {
112 return this.response.getOutputStream();
113 }
114
115 /**
116 * The default behavior of this method is to return getWriter()
117 * on the wrapped response object.
118 */
119
120
121 public PrintWriter getWriter() throws IOException {
122 return this.response.getWriter();
123 }
124
125 /**
126 * The default behavior of this method is to call setContentLength(int len)
127 * on the wrapped response object.
128 */
129
130 public void setContentLength(int len) {
131 this.response.setContentLength(len);
132 }
133
134 /**
135 * The default behavior of this method is to call setContentType(String type)
136 * on the wrapped response object.
137 */
138
139 public void setContentType(String type) {
140 this.response.setContentType(type);
141 }
142
143 /**
144 * The default behavior of this method is to return getContentType()
145 * on the wrapped response object.
146 *
147 * @since 2.4
148 */
149
150 public String getContentType() {
151 return this.response.getContentType();
152 }
153
154 /**
155 * The default behavior of this method is to call setBufferSize(int size)
156 * on the wrapped response object.
157 */
158 public void setBufferSize(int size) {
159 this.response.setBufferSize(size);
160 }
161
162 /**
163 * The default behavior of this method is to return getBufferSize()
164 * on the wrapped response object.
165 */
166 public int getBufferSize() {
167 return this.response.getBufferSize();
168 }
169
170 /**
171 * The default behavior of this method is to call flushBuffer()
172 * on the wrapped response object.
173 */
174
175 public void flushBuffer() throws IOException {
176 this.response.flushBuffer();
177 }
178
179 /**
180 * The default behavior of this method is to return isCommitted()
181 * on the wrapped response object.
182 */
183 public boolean isCommitted() {
184 return this.response.isCommitted();
185 }
186
187 /**
188 * The default behavior of this method is to call reset()
189 * on the wrapped response object.
190 */
191
192 public void reset() {
193 this.response.reset();
194 }
195
196 /**
197 * The default behavior of this method is to call resetBuffer()
198 * on the wrapped response object.
199 */
200
201 public void resetBuffer() {
202 this.response.resetBuffer();
203 }
204
205 /**
206 * The default behavior of this method is to call setLocale(Locale loc)
207 * on the wrapped response object.
208 */
209
210 public void setLocale(Locale loc) {
211 this.response.setLocale(loc);
212 }
213
214 /**
215 * The default behavior of this method is to return getLocale()
216 * on the wrapped response object.
217 */
218 public Locale getLocale() {
219 return this.response.getLocale();
220 }
221
222
223 }
224
225
226
227
228