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