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 implements HttpServletResponse { 038 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 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 116 public void sendError(int sc) throws IOException { 117 this._getHttpServletResponse().sendError(sc); 118 } 119 120 /** 121 * The default behavior of this method is to return sendRedirect(String location) 122 * on the wrapped response object. 123 */ 124 public void sendRedirect(String location) throws IOException { 125 this._getHttpServletResponse().sendRedirect(location); 126 } 127 128 /** 129 * The default behavior of this method is to call setDateHeader(String name, long date) 130 * on the wrapped response object. 131 */ 132 public void setDateHeader(String name, long date) { 133 this._getHttpServletResponse().setDateHeader(name, date); 134 } 135 136 /** 137 * The default behavior of this method is to call addDateHeader(String name, long date) 138 * on the wrapped response object. 139 */ 140 public void addDateHeader(String name, long date) { 141 this._getHttpServletResponse().addDateHeader(name, date); 142 } 143 144 /** 145 * The default behavior of this method is to return setHeader(String name, String value) 146 * on the wrapped response object. 147 */ 148 public void setHeader(String name, String value) { 149 this._getHttpServletResponse().setHeader(name, value); 150 } 151 152 /** 153 * The default behavior of this method is to return addHeader(String name, String value) 154 * on the wrapped response object. 155 */ 156 public void addHeader(String name, String value) { 157 this._getHttpServletResponse().addHeader(name, value); 158 } 159 160 /** 161 * The default behavior of this method is to call setIntHeader(String name, int value) 162 * on the wrapped response object. 163 */ 164 public void setIntHeader(String name, int value) { 165 this._getHttpServletResponse().setIntHeader(name, value); 166 } 167 168 /** 169 * The default behavior of this method is to call addIntHeader(String name, int value) 170 * on the wrapped response object. 171 */ 172 public void addIntHeader(String name, int value) { 173 this._getHttpServletResponse().addIntHeader(name, value); 174 } 175 176 /** 177 * The default behavior of this method is to call setStatus(int sc) 178 * on the wrapped response object. 179 */ 180 181 182 public void setStatus(int sc) { 183 this._getHttpServletResponse().setStatus(sc); 184 } 185 186 /** 187 * The default behavior of this method is to call setStatus(int sc, String sm) 188 * on the wrapped response object. 189 */ 190 public void setStatus(int sc, String sm) { 191 this._getHttpServletResponse().setStatus(sc, sm); 192 } 193 194 195 }