001 /*
002 * Copyright 2004 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package javax.servlet;
017
018 import java.io.IOException;
019 import java.io.PrintWriter;
020 import java.util.Locale;
021
022 /**
023 *
024 * Provides a convenient implementation of the ServletResponse interface that
025 * can be subclassed by developers wishing to adapt the response from a Servlet.
026 * This class implements the Wrapper or Decorator pattern. Methods default to
027 * calling through to the wrapped response object.
028 *
029 * @author Various
030 * @version $Version$
031 * @since v 2.3
032 *
033 * @see javax.servlet.ServletResponse
034 *
035 */
036
037 public class ServletResponseWrapper implements ServletResponse {
038 private ServletResponse response;
039
040 /**
041 * Creates a ServletResponse adaptor wrapping the given response object.
042 * @throws java.lang.IllegalArgumentException if the response is null.
043 */
044
045 public ServletResponseWrapper(ServletResponse response) {
046 if (response == null) {
047 throw new IllegalArgumentException(
048 "Response cannot be null");
049 }
050 this .response = response;
051 }
052
053 /**
054 * Return the wrapped ServletResponse object.
055 */
056
057 public ServletResponse getResponse() {
058 return this .response;
059 }
060
061 /**
062 * Sets the response being wrapped.
063 * @throws java.lang.IllegalArgumentException if the response is null.
064 */
065
066 public void setResponse(ServletResponse response) {
067 if (response == null) {
068 throw new IllegalArgumentException(
069 "Response cannot be null");
070 }
071 this .response = response;
072 }
073
074 /**
075 * The default behavior of this method is to call setCharacterEncoding(String charset)
076 * on the wrapped response object.
077 *
078 * @since 2.4
079 */
080
081 public void setCharacterEncoding(String charset) {
082 this .response.setCharacterEncoding(charset);
083 }
084
085 /**
086 * The default behavior of this method is to return getCharacterEncoding()
087 * on the wrapped response object.
088 */
089
090 public String getCharacterEncoding() {
091 return this .response.getCharacterEncoding();
092 }
093
094 /**
095 * The default behavior of this method is to return getOutputStream()
096 * on the wrapped response object.
097 */
098
099 public ServletOutputStream getOutputStream() throws IOException {
100 return this .response.getOutputStream();
101 }
102
103 /**
104 * The default behavior of this method is to return getWriter()
105 * on the wrapped response object.
106 */
107
108 public PrintWriter getWriter() throws IOException {
109 return this .response.getWriter();
110 }
111
112 /**
113 * The default behavior of this method is to call setContentLength(int len)
114 * on the wrapped response object.
115 */
116
117 public void setContentLength(int len) {
118 this .response.setContentLength(len);
119 }
120
121 /**
122 * The default behavior of this method is to call setContentType(String type)
123 * on the wrapped response object.
124 */
125
126 public void setContentType(String type) {
127 this .response.setContentType(type);
128 }
129
130 /**
131 * The default behavior of this method is to return getContentType()
132 * on the wrapped response object.
133 *
134 * @since 2.4
135 */
136
137 public String getContentType() {
138 return this .response.getContentType();
139 }
140
141 /**
142 * The default behavior of this method is to call setBufferSize(int size)
143 * on the wrapped response object.
144 */
145 public void setBufferSize(int size) {
146 this .response.setBufferSize(size);
147 }
148
149 /**
150 * The default behavior of this method is to return getBufferSize()
151 * on the wrapped response object.
152 */
153 public int getBufferSize() {
154 return this .response.getBufferSize();
155 }
156
157 /**
158 * The default behavior of this method is to call flushBuffer()
159 * on the wrapped response object.
160 */
161
162 public void flushBuffer() throws IOException {
163 this .response.flushBuffer();
164 }
165
166 /**
167 * The default behavior of this method is to return isCommitted()
168 * on the wrapped response object.
169 */
170 public boolean isCommitted() {
171 return this .response.isCommitted();
172 }
173
174 /**
175 * The default behavior of this method is to call reset()
176 * on the wrapped response object.
177 */
178
179 public void reset() {
180 this .response.reset();
181 }
182
183 /**
184 * The default behavior of this method is to call resetBuffer()
185 * on the wrapped response object.
186 */
187
188 public void resetBuffer() {
189 this .response.resetBuffer();
190 }
191
192 /**
193 * The default behavior of this method is to call setLocale(Locale loc)
194 * on the wrapped response object.
195 */
196
197 public void setLocale(Locale loc) {
198 this .response.setLocale(loc);
199 }
200
201 /**
202 * The default behavior of this method is to return getLocale()
203 * on the wrapped response object.
204 */
205 public Locale getLocale() {
206 return this.response.getLocale();
207 }
208
209 }
|