1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package javax.servlet.http;
21
22 import java.io.IOException;
23
24 import javax.servlet.ServletResponseWrapper;
25
26 /**
27 *
28 * Provides a convenient implementation of the HttpServletResponse interface that
29 * can be subclassed by developers wishing to adapt the response from a Servlet.
30 * This class implements the Wrapper or Decorator pattern. Methods default to
31 * calling through to the wrapped response object.
32 *
33 * @author Various
34 * @version $Version$
35 * @since v 2.3
36 *
37 * @see javax.servlet.http.HttpServletResponse
38 *
39 */
40
41 public class HttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse {
42
43
44 /**
45 * Constructs a response adaptor wrapping the given response.
46 * @throws java.lang.IllegalArgumentException if the response is null
47 */
48 public HttpServletResponseWrapper(HttpServletResponse response) {
49 super(response);
50 }
51
52 private HttpServletResponse _getHttpServletResponse() {
53 return (HttpServletResponse) super.getResponse();
54 }
55
56 /**
57 * The default behavior of this method is to call addCookie(Cookie cookie)
58 * on the wrapped response object.
59 */
60 public void addCookie(Cookie cookie) {
61 this._getHttpServletResponse().addCookie(cookie);
62 }
63
64 /**
65 * The default behavior of this method is to call containsHeader(String name)
66 * on the wrapped response object.
67 */
68
69
70 public boolean containsHeader(String name) {
71 return this._getHttpServletResponse().containsHeader(name);
72 }
73
74 /**
75 * The default behavior of this method is to call encodeURL(String url)
76 * on the wrapped response object.
77 */
78 public String encodeURL(String url) {
79 return this._getHttpServletResponse().encodeURL(url);
80 }
81
82 /**
83 * The default behavior of this method is to return encodeRedirectURL(String url)
84 * on the wrapped response object.
85 */
86 public String encodeRedirectURL(String url) {
87 return this._getHttpServletResponse().encodeRedirectURL(url);
88 }
89
90 /**
91 * The default behavior of this method is to call encodeUrl(String url)
92 * on the wrapped response object.
93 */
94 public String encodeUrl(String url) {
95 return this._getHttpServletResponse().encodeUrl(url);
96 }
97
98 /**
99 * 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 }