001 /*
002 * Copyright 2004 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package javax.servlet.http;
017
018 import java.io.IOException;
019
020 import javax.servlet.ServletResponseWrapper;
021
022 /**
023 *
024 * Provides a convenient implementation of the HttpServletResponse interface that
025 * can be subclassed by developers wishing to adapt the response from a Servlet.
026 * This class implements the Wrapper or Decorator pattern. Methods default to
027 * calling through to the wrapped response object.
028 *
029 * @author Various
030 * @version $Version$
031 * @since v 2.3
032 *
033 * @see javax.servlet.http.HttpServletResponse
034 *
035 */
036
037 public class HttpServletResponseWrapper extends ServletResponseWrapper
038 implements HttpServletResponse {
039
040 /**
041 * Constructs a response adaptor wrapping the given response.
042 * @throws java.lang.IllegalArgumentException if the response is null
043 */
044 public HttpServletResponseWrapper(HttpServletResponse response) {
045 super (response);
046 }
047
048 private HttpServletResponse _getHttpServletResponse() {
049 return (HttpServletResponse) super .getResponse();
050 }
051
052 /**
053 * The default behavior of this method is to call addCookie(Cookie cookie)
054 * on the wrapped response object.
055 */
056 public void addCookie(Cookie cookie) {
057 this ._getHttpServletResponse().addCookie(cookie);
058 }
059
060 /**
061 * The default behavior of this method is to call containsHeader(String name)
062 * on the wrapped response object.
063 */
064
065 public boolean containsHeader(String name) {
066 return this ._getHttpServletResponse().containsHeader(name);
067 }
068
069 /**
070 * The default behavior of this method is to call encodeURL(String url)
071 * on the wrapped response object.
072 */
073 public String encodeURL(String url) {
074 return this ._getHttpServletResponse().encodeURL(url);
075 }
076
077 /**
078 * The default behavior of this method is to return encodeRedirectURL(String url)
079 * on the wrapped response object.
080 */
081 public String encodeRedirectURL(String url) {
082 return this ._getHttpServletResponse().encodeRedirectURL(url);
083 }
084
085 /**
086 * The default behavior of this method is to call encodeUrl(String url)
087 * on the wrapped response object.
088 */
089 public String encodeUrl(String url) {
090 return this ._getHttpServletResponse().encodeUrl(url);
091 }
092
093 /**
094 * The default behavior of this method is to return encodeRedirectUrl(String url)
095 * on the wrapped response object.
096 */
097 public String encodeRedirectUrl(String url) {
098 return this ._getHttpServletResponse().encodeRedirectUrl(url);
099 }
100
101 /**
102 * The default behavior of this method is to call sendError(int sc, String msg)
103 * on the wrapped response object.
104 */
105 public void sendError(int sc, String msg) throws IOException {
106 this ._getHttpServletResponse().sendError(sc, msg);
107 }
108
109 /**
110 * The default behavior of this method is to call sendError(int sc)
111 * on the wrapped response object.
112 */
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
179 public void setStatus(int sc) {
180 this ._getHttpServletResponse().setStatus(sc);
181 }
182
183 /**
184 * The default behavior of this method is to call setStatus(int sc, String sm)
185 * on the wrapped response object.
186 */
187 public void setStatus(int sc, String sm) {
188 this._getHttpServletResponse().setStatus(sc, sm);
189 }
190
191 }
|