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