1 2 3 /* 4 * The contents of this file are subject to the terms 5 * of the Common Development and Distribution License 6 * (the "License"). You may not use this file except 7 * in compliance with the License. 8 * 9 * You can obtain a copy of the license at 10 * glassfish/bootstrap/legal/CDDLv1.0.txt or 11 * https://glassfish.dev.java.net/public/CDDLv1.0.html. 12 * See the License for the specific language governing 13 * permissions and limitations under the License. 14 * 15 * When distributing Covered Code, include this CDDL 16 * HEADER in each file and include the License file at 17 * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable, 18 * add the following below this CDDL HEADER, with the 19 * fields enclosed by brackets "[]" replaced with your 20 * own identifying information: Portions Copyright [yyyy] 21 * [name of copyright owner] 22 * 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * 25 * Portions Copyright Apache Software Foundation. 26 */ 27 28 package javax.servlet.http; 29 30 import java.io.IOException; 31 32 import javax.servlet.ServletResponseWrapper; 33 34 /** 35 * 36 * Provides a convenient implementation of the HttpServletResponse interface that 37 * can be subclassed by developers wishing to adapt the response from a Servlet. 38 * This class implements the Wrapper or Decorator pattern. Methods default to 39 * calling through to the wrapped response object. 40 * 41 * @author Various 42 * @since v 2.3 43 * 44 * @see javax.servlet.http.HttpServletResponse 45 * 46 */ 47 48 public class HttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse { 49 50 51 /** 52 * Constructs a response adaptor wrapping the given response. 53 * @throws java.lang.IllegalArgumentException if the response is null 54 */ 55 public HttpServletResponseWrapper(HttpServletResponse response) { 56 super(response); 57 } 58 59 private HttpServletResponse _getHttpServletResponse() { 60 return (HttpServletResponse) super.getResponse(); 61 } 62 63 /** 64 * The default behavior of this method is to call addCookie(Cookie cookie) 65 * on the wrapped response object. 66 */ 67 public void addCookie(Cookie cookie) { 68 this._getHttpServletResponse().addCookie(cookie); 69 } 70 71 /** 72 * The default behavior of this method is to call containsHeader(String name) 73 * on the wrapped response object. 74 */ 75 76 77 public boolean containsHeader(String name) { 78 return this._getHttpServletResponse().containsHeader(name); 79 } 80 81 /** 82 * The default behavior of this method is to call encodeURL(String url) 83 * on the wrapped response object. 84 */ 85 public String encodeURL(String url) { 86 return this._getHttpServletResponse().encodeURL(url); 87 } 88 89 /** 90 * The default behavior of this method is to return encodeRedirectURL(String url) 91 * on the wrapped response object. 92 */ 93 public String encodeRedirectURL(String url) { 94 return this._getHttpServletResponse().encodeRedirectURL(url); 95 } 96 97 /** 98 * The default behavior of this method is to call encodeUrl(String url) 99 * on the wrapped response object. 100 */ 101 public String encodeUrl(String url) { 102 return this._getHttpServletResponse().encodeUrl(url); 103 } 104 105 /** 106 * The default behavior of this method is to return encodeRedirectUrl(String url) 107 * on the wrapped response object. 108 */ 109 public String encodeRedirectUrl(String url) { 110 return this._getHttpServletResponse().encodeRedirectUrl(url); 111 } 112 113 /** 114 * The default behavior of this method is to call sendError(int sc, String msg) 115 * on the wrapped response object. 116 */ 117 public void sendError(int sc, String msg) throws IOException { 118 this._getHttpServletResponse().sendError(sc, msg); 119 } 120 121 /** 122 * The default behavior of this method is to call sendError(int sc) 123 * on the wrapped response object. 124 */ 125 126 127 public void sendError(int sc) throws IOException { 128 this._getHttpServletResponse().sendError(sc); 129 } 130 131 /** 132 * The default behavior of this method is to return sendRedirect(String location) 133 * on the wrapped response object. 134 */ 135 public void sendRedirect(String location) throws IOException { 136 this._getHttpServletResponse().sendRedirect(location); 137 } 138 139 /** 140 * The default behavior of this method is to call setDateHeader(String name, long date) 141 * on the wrapped response object. 142 */ 143 public void setDateHeader(String name, long date) { 144 this._getHttpServletResponse().setDateHeader(name, date); 145 } 146 147 /** 148 * The default behavior of this method is to call addDateHeader(String name, long date) 149 * on the wrapped response object. 150 */ 151 public void addDateHeader(String name, long date) { 152 this._getHttpServletResponse().addDateHeader(name, date); 153 } 154 155 /** 156 * The default behavior of this method is to return setHeader(String name, String value) 157 * on the wrapped response object. 158 */ 159 public void setHeader(String name, String value) { 160 this._getHttpServletResponse().setHeader(name, value); 161 } 162 163 /** 164 * The default behavior of this method is to return addHeader(String name, String value) 165 * on the wrapped response object. 166 */ 167 public void addHeader(String name, String value) { 168 this._getHttpServletResponse().addHeader(name, value); 169 } 170 171 /** 172 * The default behavior of this method is to call setIntHeader(String name, int value) 173 * on the wrapped response object. 174 */ 175 public void setIntHeader(String name, int value) { 176 this._getHttpServletResponse().setIntHeader(name, value); 177 } 178 179 /** 180 * The default behavior of this method is to call addIntHeader(String name, int value) 181 * on the wrapped response object. 182 */ 183 public void addIntHeader(String name, int value) { 184 this._getHttpServletResponse().addIntHeader(name, value); 185 } 186 187 /** 188 * The default behavior of this method is to call setStatus(int sc) 189 * on the wrapped response object. 190 */ 191 192 193 public void setStatus(int sc) { 194 this._getHttpServletResponse().setStatus(sc); 195 } 196 197 /** 198 * The default behavior of this method is to call setStatus(int sc, String sm) 199 * on the wrapped response object. 200 */ 201 public void setStatus(int sc, String sm) { 202 this._getHttpServletResponse().setStatus(sc, sm); 203 } 204 205 206 }