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;
  61. import java.io.IOException;
  62. import java.io.PrintWriter;
  63. import java.io.UnsupportedEncodingException;
  64. import java.util.Locale;
  65. /**
  66. *
  67. * Provides a convenient implementation of the ServletResponse interface that
  68. * can be subclassed by developers wishing to adapt the response from a Servlet.
  69. * This class implements the Wrapper or Decorator pattern. Methods default to
  70. * calling through to the wrapped response object.
  71. *
  72. * @author Various
  73. * @version $Version$
  74. * @since v 2.3
  75. *
  76. * @see javax.servlet.ServletResponse
  77. *
  78. */
  79. public class ServletResponseWrapper implements ServletResponse {
  80. private ServletResponse response;
  81. /**
  82. * Creates a ServletResponse adaptor wrapping the given response object.
  83. * @throws java.lang.IllegalArgumentException if the response is null.
  84. */
  85. public ServletResponseWrapper(ServletResponse response) {
  86. if (response == null) {
  87. throw new IllegalArgumentException("Response cannot be null");
  88. }
  89. this.response = response;
  90. }
  91. /**
  92. * Return the wrapped ServletResponse object.
  93. */
  94. public ServletResponse getResponse() {
  95. return this.response;
  96. }
  97. /**
  98. * Sets the response being wrapped.
  99. * @throws java.lang.IllegalArgumentException if the response is null.
  100. */
  101. public void setResponse(ServletResponse response) {
  102. if (response == null) {
  103. throw new IllegalArgumentException("Response cannot be null");
  104. }
  105. this.response = response;
  106. }
  107. /**
  108. * The default behavior of this method is to return getCharacterEncoding()
  109. * on the wrapped response object.
  110. */
  111. public String getCharacterEncoding() {
  112. return this.response.getCharacterEncoding();
  113. }
  114. /**
  115. * The default behavior of this method is to return getOutputStream()
  116. * on the wrapped response object.
  117. */
  118. public ServletOutputStream getOutputStream() throws IOException {
  119. return this.response.getOutputStream();
  120. }
  121. /**
  122. * The default behavior of this method is to return getWriter()
  123. * on the wrapped response object.
  124. */
  125. public PrintWriter getWriter() throws IOException {
  126. return this.response.getWriter();
  127. }
  128. /**
  129. * The default behavior of this method is to call setContentLength(int len)
  130. * on the wrapped response object.
  131. */
  132. public void setContentLength(int len) {
  133. this.response.setContentLength(len);
  134. }
  135. /**
  136. * The default behavior of this method is to call setContentType(String type)
  137. * on the wrapped response object.
  138. */
  139. public void setContentType(String type) {
  140. this.response.setContentType(type);
  141. }
  142. /**
  143. * The default behavior of this method is to call setBufferSize(int size)
  144. * on the wrapped response object.
  145. */
  146. public void setBufferSize(int size) {
  147. this.response.setBufferSize(size);
  148. }
  149. /**
  150. * The default behavior of this method is to return getBufferSize()
  151. * on the wrapped response object.
  152. */
  153. public int getBufferSize() {
  154. return this.response.getBufferSize();
  155. }
  156. /**
  157. * The default behavior of this method is to call flushBuffer()
  158. * on the wrapped response object.
  159. */
  160. public void flushBuffer() throws IOException {
  161. this.response.flushBuffer();
  162. }
  163. /**
  164. * The default behavior of this method is to return isCommitted()
  165. * on the wrapped response object.
  166. */
  167. public boolean isCommitted() {
  168. return this.response.isCommitted();
  169. }
  170. /**
  171. * The default behavior of this method is to call reset()
  172. * on the wrapped response object.
  173. */
  174. public void reset() {
  175. this.response.reset();
  176. }
  177. /**
  178. * The default behavior of this method is to call resetBuffer()
  179. * on the wrapped response object.
  180. */
  181. public void resetBuffer() {
  182. this.response.resetBuffer();
  183. }
  184. /**
  185. * The default behavior of this method is to call setLocale(Locale loc)
  186. * on the wrapped response object.
  187. */
  188. public void setLocale(Locale loc) {
  189. this.response.setLocale(loc);
  190. }
  191. /**
  192. * The default behavior of this method is to return getLocale()
  193. * on the wrapped response object.
  194. */
  195. public Locale getLocale() {
  196. return this.response.getLocale();
  197. }
  198. }