View Javadoc

1   /**
2    *
3    * Copyright 2003-2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  //
19  // This source code implements specifications defined by the Java
20  // Community Process. In order to remain compliant with the specification
21  // DO NOT add / change / or delete method signatures!
22  //
23  
24  package javax.servlet.http;
25  
26  import java.io.IOException;
27  import javax.servlet.ServletResponseWrapper;
28  
29  /**
30   * Provides a convenient implementation of the HttpServletResponse interface that
31   * can be subclassed by developers wishing to adapt the response from a Servlet.
32   * This class implements the Wrapper or Decorator pattern. Methods default to
33   * calling through to the wrapped response object.
34   *
35   * @since Servlet 2.3
36   *
37   * @see javax.servlet.http.HttpServletResponse
38   *
39   * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
40   */
41  public class HttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse {
42      /**
43       * Constructs a response adaptor wrapping the given response.
44       * @throws java.lang.IllegalArgumentException if the response is null
45       */
46      public HttpServletResponseWrapper(HttpServletResponse response) {
47          super(response);
48      }
49  
50      private HttpServletResponse _getHttpServletResponse() {
51          return (HttpServletResponse) super.getResponse();
52      }
53  
54      /**
55       * The default behavior of this method is to call addCookie(Cookie cookie)
56       * on the wrapped response object.
57       */
58      public void addCookie(Cookie cookie) {
59          this._getHttpServletResponse().addCookie(cookie);
60      }
61  
62      /**
63       * The default behavior of this method is to call containsHeader(String name)
64       * on the wrapped response object.
65       */
66      public boolean containsHeader(String name) {
67          return this._getHttpServletResponse().containsHeader(name);
68      }
69  
70      /**
71       * The default behavior of this method is to call encodeURL(String url)
72       * on the wrapped response object.
73       */
74      public String encodeURL(String url) {
75          return this._getHttpServletResponse().encodeURL(url);
76      }
77  
78      /**
79       * The default behavior of this method is to return encodeRedirectURL(String url)
80       * on the wrapped response object.
81       */
82      public String encodeRedirectURL(String url) {
83          return this._getHttpServletResponse().encodeRedirectURL(url);
84      }
85  
86      /**
87       * The default behavior of this method is to call encodeUrl(String url)
88       * on the wrapped response object.
89       */
90      public String encodeUrl(String url) {
91          return this._getHttpServletResponse().encodeUrl(url);
92      }
93  
94      /**
95       * The default behavior of this method is to return encodeRedirectUrl(String url)
96       * on the wrapped response object.
97       */
98      public String encodeRedirectUrl(String url) {
99          return this._getHttpServletResponse().encodeRedirectUrl(url);
100     }
101 
102     /**
103      * The default behavior of this method is to call sendError(int sc, String msg)
104      * on the wrapped response object.
105      */
106     public void sendError(int sc, String msg) throws IOException {
107         this._getHttpServletResponse().sendError(sc, msg);
108     }
109 
110     /**
111      * The default behavior of this method is to call sendError(int sc)
112      * on the wrapped response object.
113      */
114     public void sendError(int sc) throws IOException {
115         this._getHttpServletResponse().sendError(sc);
116     }
117 
118     /**
119      * The default behavior of this method is to return sendRedirect(String location)
120      * on the wrapped response object.
121      */
122     public void sendRedirect(String location) throws IOException {
123         this._getHttpServletResponse().sendRedirect(location);
124     }
125 
126     /**
127      * The default behavior of this method is to call setDateHeader(String name, long date)
128      * on the wrapped response object.
129      */
130     public void setDateHeader(String name, long date) {
131         this._getHttpServletResponse().setDateHeader(name, date);
132     }
133 
134     /**
135      * The default behavior of this method is to call addDateHeader(String name, long date)
136      * on the wrapped response object.
137      */
138     public void addDateHeader(String name, long date) {
139         this._getHttpServletResponse().addDateHeader(name, date);
140     }
141 
142     /**
143      * The default behavior of this method is to return setHeader(String name, String value)
144      * on the wrapped response object.
145      */
146     public void setHeader(String name, String value) {
147         this._getHttpServletResponse().setHeader(name, value);
148     }
149 
150     /**
151      * The default behavior of this method is to return addHeader(String name, String value)
152      * on the wrapped response object.
153      */
154     public void addHeader(String name, String value) {
155         this._getHttpServletResponse().addHeader(name, value);
156     }
157 
158     /**
159      * The default behavior of this method is to call setIntHeader(String name, int value)
160      * on the wrapped response object.
161      */
162     public void setIntHeader(String name, int value) {
163         this._getHttpServletResponse().setIntHeader(name, value);
164     }
165 
166     /**
167      * The default behavior of this method is to call addIntHeader(String name, int value)
168      * on the wrapped response object.
169      */
170     public void addIntHeader(String name, int value) {
171         this._getHttpServletResponse().addIntHeader(name, value);
172     }
173 
174     /**
175      * The default behavior of this method is to call setStatus(int sc)
176      * on the wrapped response object.
177      */
178     public void setStatus(int sc) {
179         this._getHttpServletResponse().setStatus(sc);
180     }
181 
182     /**
183      * The default behavior of this method is to call setStatus(int sc, String sm)
184      * on the wrapped response object.
185      */
186     public void setStatus(int sc, String sm) {
187         this._getHttpServletResponse().setStatus(sc, sm);
188     }
189 }