001 /**
002 *
003 * Copyright 2003-2004 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 //
019 // This source code implements specifications defined by the Java
020 // Community Process. In order to remain compliant with the specification
021 // DO NOT add / change / or delete method signatures!
022 //
023
024 package javax.servlet;
025
026 import java.io.IOException;
027 import java.io.PrintWriter;
028 import java.util.Locale;
029
030 /**
031 * Provides a convenient implementation of the ServletResponse interface that
032 * can be subclassed by developers wishing to adapt the response from a Servlet.
033 * This class implements the Wrapper or Decorator pattern. Methods default to
034 * calling through to the wrapped response object.
035 *
036 * @since Servlet 2.3
037 *
038 * @see javax.servlet.ServletResponse
039 *
040 * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
041 */
042 public class ServletResponseWrapper implements ServletResponse {
043 private ServletResponse response;
044
045 /**
046 * Creates a ServletResponse adaptor wrapping the given response object.
047 * @throws java.lang.IllegalArgumentException if the response is null.
048 */
049 public ServletResponseWrapper(ServletResponse response) {
050 if (response == null) {
051 throw new IllegalArgumentException("Response cannot be null");
052 }
053 this.response = response;
054 }
055
056 /**
057 * Return the wrapped ServletResponse object.
058 */
059 public ServletResponse getResponse() {
060 return this.response;
061 }
062
063 /**
064 * Sets the response being wrapped.
065 * @throws java.lang.IllegalArgumentException if the response is null.
066 */
067 public void setResponse(ServletResponse response) {
068 if (response == null) {
069 throw new IllegalArgumentException("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 Servlet 2.4
079 */
080 public void setCharacterEncoding(String charset) {
081 this.response.setCharacterEncoding(charset);
082 }
083
084 /**
085 * The default behavior of this method is to return getCharacterEncoding()
086 * on the wrapped response object.
087 */
088 public String getCharacterEncoding() {
089 return this.response.getCharacterEncoding();
090 }
091
092 /**
093 * The default behavior of this method is to return getOutputStream()
094 * on the wrapped response object.
095 */
096 public ServletOutputStream getOutputStream() throws IOException {
097 return this.response.getOutputStream();
098 }
099
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