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    
024    import javax.servlet.ServletResponseWrapper;
025    
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     * @author      Various
034     * @version     $Version$
035      * @since      v 2.3
036     *
037     * @see         javax.servlet.http.HttpServletResponse
038     *
039     */
040    
041    public class HttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse {
042    
043    
044        /** 
045        * Constructs a response adaptor wrapping the given response.
046        * @throws java.lang.IllegalArgumentException 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            this._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 this._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 this._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 this._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 this._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 this._getHttpServletResponse().encodeRedirectUrl(url);
104        }
105        
106        /**
107         * The default behavior of this method is to call sendError(int sc, String msg)
108         * on the wrapped response object.
109         */
110        public void sendError(int sc, String msg) throws IOException {
111            this._getHttpServletResponse().sendError(sc, msg);
112        }
113    
114        /**
115         * The default behavior of this method is to call sendError(int sc)
116         * on the wrapped response object.
117         */
118    
119    
120        public void sendError(int sc) throws IOException {
121            this._getHttpServletResponse().sendError(sc);
122        }
123    
124        /**
125         * The default behavior of this method is to return sendRedirect(String location)
126         * on the wrapped response object.
127         */
128        public void sendRedirect(String location) throws IOException {
129            this._getHttpServletResponse().sendRedirect(location);
130        }
131        
132        /**
133         * The default behavior of this method is to call setDateHeader(String name, long date)
134         * on the wrapped response object.
135         */
136        public void setDateHeader(String name, long date) {
137            this._getHttpServletResponse().setDateHeader(name, date);
138        }
139        
140        /**
141         * The default behavior of this method is to call addDateHeader(String name, long date)
142         * on the wrapped response object.
143         */
144       public void addDateHeader(String name, long date) {
145            this._getHttpServletResponse().addDateHeader(name, date);
146        }
147        
148        /**
149         * The default behavior of this method is to return setHeader(String name, String value)
150         * on the wrapped response object.
151         */
152        public void setHeader(String name, String value) {
153            this._getHttpServletResponse().setHeader(name, value);
154        }
155        
156        /**
157         * The default behavior of this method is to return addHeader(String name, String value)
158         * on the wrapped response object.
159         */
160         public void addHeader(String name, String value) {
161            this._getHttpServletResponse().addHeader(name, value);
162        }
163        
164        /**
165         * The default behavior of this method is to call setIntHeader(String name, int value)
166         * on the wrapped response object.
167         */
168        public void setIntHeader(String name, int value) {
169            this._getHttpServletResponse().setIntHeader(name, value);
170        }
171        
172        /**
173         * The default behavior of this method is to call addIntHeader(String name, int value)
174         * on the wrapped response object.
175         */
176        public void addIntHeader(String name, int value) {
177            this._getHttpServletResponse().addIntHeader(name, value);
178        }
179    
180        /**
181         * The default behavior of this method is to call setStatus(int sc)
182         * on the wrapped response object.
183         */
184    
185    
186        public void setStatus(int sc) {
187            this._getHttpServletResponse().setStatus(sc);
188        }
189        
190        /**
191         * The default behavior of this method is to call setStatus(int sc, String sm)
192         * on the wrapped response object.
193         */
194         public void setStatus(int sc, String sm) {
195            this._getHttpServletResponse().setStatus(sc, sm);
196        }
197    
198       
199    }