KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > http > HttpServletResponseWrapper


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. 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 package javax.servlet.http;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.ServletResponseWrapper JavaDoc;
22
23 /**
24  *
25  * Provides a convenient implementation of the HttpServletResponse interface that
26  * can be subclassed by developers wishing to adapt the response from a Servlet.
27  * This class implements the Wrapper or Decorator pattern. Methods default to
28  * calling through to the wrapped response object.
29  *
30  * @author Various
31  * @version $Version$
32   * @since v 2.3
33  *
34  * @see javax.servlet.http.HttpServletResponse
35  *
36  */

37
38 public class HttpServletResponseWrapper extends ServletResponseWrapper JavaDoc implements HttpServletResponse JavaDoc {
39
40
41     /**
42     * Constructs a response adaptor wrapping the given response.
43     * @throws java.lang.IllegalArgumentException if the response is null
44     */

45     public HttpServletResponseWrapper(HttpServletResponse JavaDoc response) {
46         super(response);
47     }
48     
49     private HttpServletResponse JavaDoc _getHttpServletResponse() {
50     return (HttpServletResponse JavaDoc) super.getResponse();
51     }
52     
53     /**
54      * The default behavior of this method is to call addCookie(Cookie cookie)
55      * on the wrapped response object.
56      */

57     public void addCookie(Cookie JavaDoc cookie) {
58     this._getHttpServletResponse().addCookie(cookie);
59     }
60
61     /**
62      * The default behavior of this method is to call containsHeader(String name)
63      * on the wrapped response object.
64      */

65
66  
67     public boolean containsHeader(String JavaDoc name) {
68     return this._getHttpServletResponse().containsHeader(name);
69     }
70     
71     /**
72      * The default behavior of this method is to call encodeURL(String url)
73      * on the wrapped response object.
74      */

75     public String JavaDoc encodeURL(String JavaDoc url) {
76     return this._getHttpServletResponse().encodeURL(url);
77     }
78
79     /**
80      * The default behavior of this method is to return encodeRedirectURL(String url)
81      * on the wrapped response object.
82      */

83     public String JavaDoc encodeRedirectURL(String JavaDoc url) {
84     return this._getHttpServletResponse().encodeRedirectURL(url);
85     }
86
87     /**
88      * The default behavior of this method is to call encodeUrl(String url)
89      * on the wrapped response object.
90      */

91     public String JavaDoc encodeUrl(String JavaDoc url) {
92     return this._getHttpServletResponse().encodeUrl(url);
93     }
94     
95     /**
96      * The default behavior of this method is to return encodeRedirectUrl(String url)
97      * on the wrapped response object.
98      */

99     public String JavaDoc encodeRedirectUrl(String JavaDoc url) {
100     return this._getHttpServletResponse().encodeRedirectUrl(url);
101     }
102     
103     /**
104      * The default behavior of this method is to call sendError(int sc, String msg)
105      * on the wrapped response object.
106      */

107     public void sendError(int sc, String JavaDoc msg) throws IOException JavaDoc {
108     this._getHttpServletResponse().sendError(sc, msg);
109     }
110
111     /**
112      * The default behavior of this method is to call sendError(int sc)
113      * on the wrapped response object.
114      */

115
116
117     public void sendError(int sc) throws IOException JavaDoc {
118     this._getHttpServletResponse().sendError(sc);
119     }
120
121     /**
122      * The default behavior of this method is to return sendRedirect(String location)
123      * on the wrapped response object.
124      */

125     public void sendRedirect(String JavaDoc location) throws IOException JavaDoc {
126     this._getHttpServletResponse().sendRedirect(location);
127     }
128     
129     /**
130      * The default behavior of this method is to call setDateHeader(String name, long date)
131      * on the wrapped response object.
132      */

133     public void setDateHeader(String JavaDoc name, long date) {
134     this._getHttpServletResponse().setDateHeader(name, date);
135     }
136     
137     /**
138      * The default behavior of this method is to call addDateHeader(String name, long date)
139      * on the wrapped response object.
140      */

141    public void addDateHeader(String JavaDoc name, long date) {
142     this._getHttpServletResponse().addDateHeader(name, date);
143     }
144     
145     /**
146      * The default behavior of this method is to return setHeader(String name, String value)
147      * on the wrapped response object.
148      */

149     public void setHeader(String JavaDoc name, String JavaDoc value) {
150     this._getHttpServletResponse().setHeader(name, value);
151     }
152     
153     /**
154      * The default behavior of this method is to return addHeader(String name, String value)
155      * on the wrapped response object.
156      */

157      public void addHeader(String JavaDoc name, String JavaDoc value) {
158     this._getHttpServletResponse().addHeader(name, value);
159     }
160     
161     /**
162      * The default behavior of this method is to call setIntHeader(String name, int value)
163      * on the wrapped response object.
164      */

165     public void setIntHeader(String JavaDoc name, int value) {
166     this._getHttpServletResponse().setIntHeader(name, value);
167     }
168     
169     /**
170      * The default behavior of this method is to call addIntHeader(String name, int value)
171      * on the wrapped response object.
172      */

173     public void addIntHeader(String JavaDoc name, int value) {
174     this._getHttpServletResponse().addIntHeader(name, value);
175     }
176
177     /**
178      * The default behavior of this method is to call setStatus(int sc)
179      * on the wrapped response object.
180      */

181
182
183     public void setStatus(int sc) {
184     this._getHttpServletResponse().setStatus(sc);
185     }
186     
187     /**
188      * The default behavior of this method is to call setStatus(int sc, String sm)
189      * on the wrapped response object.
190      */

191      public void setStatus(int sc, String JavaDoc sm) {
192     this._getHttpServletResponse().setStatus(sc, sm);
193     }
194
195    
196 }
197
Popular Tags