001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package javax.servlet.http;
018:
019: import java.io.IOException;
020:
021: import javax.servlet.ServletResponseWrapper;
022:
023: /**
024: *
025: * Provides a convenient implementation of the HttpServletResponse interface that
026: * can be subclassed by developers wishing to adapt the response from a Servlet.
027: * This class implements the Wrapper or Decorator pattern. Methods default to
028: * calling through to the wrapped response object.
029: *
030: * @author Various
031: * @version $Version$
032: * @since v 2.3
033: *
034: * @see javax.servlet.http.HttpServletResponse
035: *
036: */
037:
038: public class HttpServletResponseWrapper extends ServletResponseWrapper
039: implements HttpServletResponse {
040:
041: /**
042: * Constructs a response adaptor wrapping the given response.
043: * @throws java.lang.IllegalArgumentException if the response is null
044: */
045: public HttpServletResponseWrapper(HttpServletResponse response) {
046: super (response);
047: }
048:
049: private HttpServletResponse _getHttpServletResponse() {
050: return (HttpServletResponse) super .getResponse();
051: }
052:
053: /**
054: * The default behavior of this method is to call addCookie(Cookie cookie)
055: * on the wrapped response object.
056: */
057: public void addCookie(Cookie cookie) {
058: this ._getHttpServletResponse().addCookie(cookie);
059: }
060:
061: /**
062: * The default behavior of this method is to call containsHeader(String name)
063: * on the wrapped response object.
064: */
065:
066: public boolean containsHeader(String name) {
067: return this ._getHttpServletResponse().containsHeader(name);
068: }
069:
070: /**
071: * The default behavior of this method is to call encodeURL(String url)
072: * on the wrapped response object.
073: */
074: public String encodeURL(String url) {
075: return this ._getHttpServletResponse().encodeURL(url);
076: }
077:
078: /**
079: * The default behavior of this method is to return encodeRedirectURL(String url)
080: * on the wrapped response object.
081: */
082: public String encodeRedirectURL(String url) {
083: return this ._getHttpServletResponse().encodeRedirectURL(url);
084: }
085:
086: /**
087: * The default behavior of this method is to call encodeUrl(String url)
088: * on the wrapped response object.
089: */
090: public String encodeUrl(String url) {
091: return this ._getHttpServletResponse().encodeUrl(url);
092: }
093:
094: /**
095: * The default behavior of this method is to return encodeRedirectUrl(String url)
096: * on the wrapped response object.
097: */
098: public String encodeRedirectUrl(String url) {
099: 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:
115: public void sendError(int sc) throws IOException {
116: this ._getHttpServletResponse().sendError(sc);
117: }
118:
119: /**
120: * The default behavior of this method is to return sendRedirect(String location)
121: * on the wrapped response object.
122: */
123: public void sendRedirect(String location) throws IOException {
124: this ._getHttpServletResponse().sendRedirect(location);
125: }
126:
127: /**
128: * The default behavior of this method is to call setDateHeader(String name, long date)
129: * on the wrapped response object.
130: */
131: public void setDateHeader(String name, long date) {
132: this ._getHttpServletResponse().setDateHeader(name, date);
133: }
134:
135: /**
136: * The default behavior of this method is to call addDateHeader(String name, long date)
137: * on the wrapped response object.
138: */
139: public void addDateHeader(String name, long date) {
140: this ._getHttpServletResponse().addDateHeader(name, date);
141: }
142:
143: /**
144: * The default behavior of this method is to return setHeader(String name, String value)
145: * on the wrapped response object.
146: */
147: public void setHeader(String name, String value) {
148: this ._getHttpServletResponse().setHeader(name, value);
149: }
150:
151: /**
152: * The default behavior of this method is to return addHeader(String name, String value)
153: * on the wrapped response object.
154: */
155: public void addHeader(String name, String value) {
156: this ._getHttpServletResponse().addHeader(name, value);
157: }
158:
159: /**
160: * The default behavior of this method is to call setIntHeader(String name, int value)
161: * on the wrapped response object.
162: */
163: public void setIntHeader(String name, int value) {
164: this ._getHttpServletResponse().setIntHeader(name, value);
165: }
166:
167: /**
168: * The default behavior of this method is to call addIntHeader(String name, int value)
169: * on the wrapped response object.
170: */
171: public void addIntHeader(String name, int value) {
172: this ._getHttpServletResponse().addIntHeader(name, value);
173: }
174:
175: /**
176: * The default behavior of this method is to call setStatus(int sc)
177: * on the wrapped response object.
178: */
179:
180: public void setStatus(int sc) {
181: this ._getHttpServletResponse().setStatus(sc);
182: }
183:
184: /**
185: * The default behavior of this method is to call setStatus(int sc, String sm)
186: * on the wrapped response object.
187: */
188: public void setStatus(int sc, String sm) {
189: this._getHttpServletResponse().setStatus(sc, sm);
190: }
191:
192: }
|