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    package javax.servlet.http;
021    
022    import java.io.IOException;
023    import java.util.Collection;
024    
025    import javax.servlet.ServletResponseWrapper;
026    
027    /**
028     * Provides a convenient implementation of the HttpServletResponse interface that
029     * can be subclassed by developers wishing to adapt the response from a Servlet.
030     * This class implements the Wrapper or Decorator pattern. Methods default to
031     * calling through to the wrapped response object.
032     *
033     * @version $Rev: 896175 $ $Date: 2010-01-05 13:46:13 -0500 (Tue, 05 Jan 2010) $
034     * @since v 2.3
035     * @see javax.servlet.http.HttpServletResponse
036     */
037    
038    public class HttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse {
039    
040    
041        /**
042         * Constructs a response adaptor wrapping the given response.
043         *
044         * @param response response to wrap
045         * @throws java.lang.IllegalArgumentException
046         *          if the response is null
047         */
048        public HttpServletResponseWrapper(HttpServletResponse response) {
049            super(response);
050        }
051    
052        private HttpServletResponse getHttpServletResponse() {
053            return (HttpServletResponse) super.getResponse();
054        }
055    
056        /**
057         * The default behavior of this method is to call addCookie(Cookie cookie)
058         * on the wrapped response object.
059         */
060        public void addCookie(Cookie cookie) {
061            getHttpServletResponse().addCookie(cookie);
062        }
063    
064        /**
065         * The default behavior of this method is to call containsHeader(String name)
066         * on the wrapped response object.
067         */
068    
069    
070        public boolean containsHeader(String name) {
071            return getHttpServletResponse().containsHeader(name);
072        }
073    
074        /**
075         * The default behavior of this method is to call encodeURL(String url)
076         * on the wrapped response object.
077         */
078        public String encodeURL(String url) {
079            return getHttpServletResponse().encodeURL(url);
080        }
081    
082        /**
083         * The default behavior of this method is to return encodeRedirectURL(String url)
084         * on the wrapped response object.
085         */
086        public String encodeRedirectURL(String url) {
087            return getHttpServletResponse().encodeRedirectURL(url);
088        }
089    
090        /**
091         * The default behavior of this method is to call encodeUrl(String url)
092         * on the wrapped response object.
093         */
094        public String encodeUrl(String url) {
095            return getHttpServletResponse().encodeUrl(url);
096        }
097    
098        /**
099         * The default behavior of this method is to return encodeRedirectUrl(String url)
100         * on the wrapped response object.
101         */
102        public String encodeRedirectUrl(String url) {
103            return getHttpServletResponse().encodeRedirectUrl(url);
104        }
105    
106        public String getHeader(String name) {
107            return getHttpServletResponse().getHeader(name);
108        }
109    
110        public Collection<String> getHeaderNames() {
111            return getHttpServletResponse().getHeaderNames();
112        }
113    
114        public Collection<String> getHeaders(String headerName) {
115            return getHttpServletResponse().getHeaders(headerName);
116        }
117    
118        public int getStatus() {
119            return getHttpServletResponse().getStatus();
120        }
121    
122        /**
123         * The default behavior of this method is to call sendError(int sc, String msg)
124         * on the wrapped response object.
125         */
126        public void sendError(int sc, String msg) throws IOException {
127            getHttpServletResponse().sendError(sc, msg);
128        }
129    
130        /**
131         * The default behavior of this method is to call sendError(int sc)
132         * on the wrapped response object.
133         */
134    
135    
136        public void sendError(int sc) throws IOException {
137            getHttpServletResponse().sendError(sc);
138        }
139    
140        /**
141         * The default behavior of this method is to return sendRedirect(String location)
142         * on the wrapped response object.
143         */
144        public void sendRedirect(String location) throws IOException {
145            getHttpServletResponse().sendRedirect(location);
146        }
147    
148        /**
149         * The default behavior of this method is to call setDateHeader(String name, long date)
150         * on the wrapped response object.
151         */
152        public void setDateHeader(String name, long date) {
153            getHttpServletResponse().setDateHeader(name, date);
154        }
155    
156        /**
157         * The default behavior of this method is to call addDateHeader(String name, long date)
158         * on the wrapped response object.
159         */
160        public void addDateHeader(String name, long date) {
161            getHttpServletResponse().addDateHeader(name, date);
162        }
163    
164        /**
165         * The default behavior of this method is to return setHeader(String name, String value)
166         * on the wrapped response object.
167         */
168        public void setHeader(String name, String value) {
169            getHttpServletResponse().setHeader(name, value);
170        }
171    
172        /**
173         * The default behavior of this method is to return addHeader(String name, String value)
174         * on the wrapped response object.
175         */
176        public void addHeader(String name, String value) {
177            getHttpServletResponse().addHeader(name, value);
178        }
179    
180        /**
181         * The default behavior of this method is to call setIntHeader(String name, int value)
182         * on the wrapped response object.
183         */
184        public void setIntHeader(String name, int value) {
185            getHttpServletResponse().setIntHeader(name, value);
186        }
187    
188        /**
189         * The default behavior of this method is to call addIntHeader(String name, int value)
190         * on the wrapped response object.
191         */
192        public void addIntHeader(String name, int value) {
193            getHttpServletResponse().addIntHeader(name, value);
194        }
195    
196        /**
197         * The default behavior of this method is to call setStatus(int sc)
198         * on the wrapped response object.
199         */
200    
201    
202        public void setStatus(int sc) {
203            getHttpServletResponse().setStatus(sc);
204        }
205    
206        /**
207         * The default behavior of this method is to call setStatus(int sc, String sm)
208         * on the wrapped response object.
209         */
210        public void setStatus(int sc, String sm) {
211            getHttpServletResponse().setStatus(sc, sm);
212        }
213    
214    
215    }