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