1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. * ====================================================================
  55. *
  56. * This source code implements specifications defined by the Java
  57. * Community Process. In order to remain compliant with the specification
  58. * DO NOT add / change / or delete method signatures!
  59. */
  60. package javax.servlet.http;
  61. import javax.servlet.ServletResponseWrapper;
  62. import javax.servlet.ServletException;
  63. import java.io.IOException;
  64. /**
  65. *
  66. * Provides a convenient implementation of the HttpServletResponse interface that
  67. * can be subclassed by developers wishing to adapt the response from a Servlet.
  68. * This class implements the Wrapper or Decorator pattern. Methods default to
  69. * calling through to the wrapped response object.
  70. *
  71. * @author Various
  72. * @version $Version$
  73. * @since v 2.3
  74. *
  75. * @see javax.servlet.http.HttpServletResponse
  76. *
  77. */
  78. public class HttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse {
  79. /**
  80. * Constructs a response adaptor wrapping the given response.
  81. * @throws java.lang.IllegalArgumentException if the response is null
  82. */
  83. public HttpServletResponseWrapper(HttpServletResponse response) {
  84. super(response);
  85. }
  86. private HttpServletResponse _getHttpServletResponse() {
  87. return (HttpServletResponse) super.getResponse();
  88. }
  89. /**
  90. * The default behavior of this method is to call addCookie(Cookie cookie)
  91. * on the wrapped response object.
  92. */
  93. public void addCookie(Cookie cookie) {
  94. this._getHttpServletResponse().addCookie(cookie);
  95. }
  96. /**
  97. * The default behavior of this method is to call containsHeader(String name)
  98. * on the wrapped response object.
  99. */
  100. public boolean containsHeader(String name) {
  101. return this._getHttpServletResponse().containsHeader(name);
  102. }
  103. /**
  104. * The default behavior of this method is to call encodeURL(String url)
  105. * on the wrapped response object.
  106. */
  107. public String encodeURL(String url) {
  108. return this._getHttpServletResponse().encodeURL(url);
  109. }
  110. /**
  111. * The default behavior of this method is to return encodeRedirectURL(String url)
  112. * on the wrapped response object.
  113. */
  114. public String encodeRedirectURL(String url) {
  115. return this._getHttpServletResponse().encodeRedirectURL(url);
  116. }
  117. /**
  118. * The default behavior of this method is to call encodeUrl(String url)
  119. * on the wrapped response object.
  120. */
  121. public String encodeUrl(String url) {
  122. return this._getHttpServletResponse().encodeUrl(url);
  123. }
  124. /**
  125. * The default behavior of this method is to return encodeRedirectUrl(String url)
  126. * on the wrapped response object.
  127. */
  128. public String encodeRedirectUrl(String url) {
  129. return this._getHttpServletResponse().encodeRedirectUrl(url);
  130. }
  131. /**
  132. * The default behavior of this method is to call sendError(int sc, String msg)
  133. * on the wrapped response object.
  134. */
  135. public void sendError(int sc, String msg) throws IOException {
  136. this._getHttpServletResponse().sendError(sc, msg);
  137. }
  138. /**
  139. * The default behavior of this method is to call sendError(int sc)
  140. * on the wrapped response object.
  141. */
  142. public void sendError(int sc) throws IOException {
  143. this._getHttpServletResponse().sendError(sc);
  144. }
  145. /**
  146. * The default behavior of this method is to return sendRedirect(String location)
  147. * on the wrapped response object.
  148. */
  149. public void sendRedirect(String location) throws IOException {
  150. this._getHttpServletResponse().sendRedirect(location);
  151. }
  152. /**
  153. * The default behavior of this method is to call setDateHeader(String name, long date)
  154. * on the wrapped response object.
  155. */
  156. public void setDateHeader(String name, long date) {
  157. this._getHttpServletResponse().setDateHeader(name, date);
  158. }
  159. /**
  160. * The default behavior of this method is to call addDateHeader(String name, long date)
  161. * on the wrapped response object.
  162. */
  163. public void addDateHeader(String name, long date) {
  164. this._getHttpServletResponse().addDateHeader(name, date);
  165. }
  166. /**
  167. * The default behavior of this method is to return setHeader(String name, String value)
  168. * on the wrapped response object.
  169. */
  170. public void setHeader(String name, String value) {
  171. this._getHttpServletResponse().setHeader(name, value);
  172. }
  173. /**
  174. * The default behavior of this method is to return addHeader(String name, String value)
  175. * on the wrapped response object.
  176. */
  177. public void addHeader(String name, String value) {
  178. this._getHttpServletResponse().addHeader(name, value);
  179. }
  180. /**
  181. * The default behavior of this method is to call setIntHeader(String name, int value)
  182. * on the wrapped response object.
  183. */
  184. public void setIntHeader(String name, int value) {
  185. this._getHttpServletResponse().setIntHeader(name, value);
  186. }
  187. /**
  188. * The default behavior of this method is to call addIntHeader(String name, int value)
  189. * on the wrapped response object.
  190. */
  191. public void addIntHeader(String name, int value) {
  192. this._getHttpServletResponse().addIntHeader(name, value);
  193. }
  194. /**
  195. * The default behavior of this method is to call setStatus(int sc)
  196. * on the wrapped response object.
  197. */
  198. public void setStatus(int sc) {
  199. this._getHttpServletResponse().setStatus(sc);
  200. }
  201. /**
  202. * The default behavior of this method is to call setStatus(int sc, String sm)
  203. * on the wrapped response object.
  204. */
  205. public void setStatus(int sc, String sm) {
  206. this._getHttpServletResponse().setStatus(sc, sm);
  207. }
  208. }