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