001 /** 002 * 003 * Copyright 2003-2004 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 018 // 019 // This source code implements specifications defined by the Java 020 // Community Process. In order to remain compliant with the specification 021 // DO NOT add / change / or delete method signatures! 022 // 023 024 package javax.servlet.http; 025 026 import java.io.IOException; 027 import javax.servlet.ServletResponseWrapper; 028 029 /** 030 * Provides a convenient implementation of the HttpServletResponse interface that 031 * can be subclassed by developers wishing to adapt the response from a Servlet. 032 * This class implements the Wrapper or Decorator pattern. Methods default to 033 * calling through to the wrapped response object. 034 * 035 * @since Servlet 2.3 036 * 037 * @see javax.servlet.http.HttpServletResponse 038 * 039 * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $ 040 */ 041 public class HttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse { 042 /** 043 * Constructs a response adaptor wrapping the given response. 044 * @throws java.lang.IllegalArgumentException if the response is null 045 */ 046 public HttpServletResponseWrapper(HttpServletResponse response) { 047 super(response); 048 } 049 050 private HttpServletResponse _getHttpServletResponse() { 051 return (HttpServletResponse) super.getResponse(); 052 } 053 054 /** 055 * The default behavior of this method is to call addCookie(Cookie cookie) 056 * on the wrapped response object. 057 */ 058 public void addCookie(Cookie cookie) { 059 this._getHttpServletResponse().addCookie(cookie); 060 } 061 062 /** 063 * The default behavior of this method is to call containsHeader(String name) 064 * on the wrapped response object. 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 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 }