Provides a convenient implementation of the ServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped response object. @since Servlet 2.3 @se
| 32 | * @see jakarta.servlet.ServletResponse |
| 33 | */ |
| 34 | public class ServletResponseWrapper implements ServletResponse { |
| 35 | private static final String LSTRING_FILE = "jakarta.servlet.LocalStrings"; |
| 36 | private static final ResourceBundle lStrings = ResourceBundle.getBundle(LSTRING_FILE); |
| 37 | |
| 38 | private ServletResponse response; |
| 39 | |
| 40 | /** |
| 41 | * Creates a ServletResponse adaptor wrapping the given response object. |
| 42 | * |
| 43 | * @param response The response to wrap |
| 44 | * |
| 45 | * @throws java.lang.IllegalArgumentException if the response is null. |
| 46 | */ |
| 47 | public ServletResponseWrapper(ServletResponse response) { |
| 48 | if (response == null) { |
| 49 | throw new IllegalArgumentException(lStrings.getString("wrapper.nullResponse")); |
| 50 | } |
| 51 | this.response = response; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Return the wrapped ServletResponse object. |
| 56 | * |
| 57 | * @return The wrapped ServletResponse object. |
| 58 | */ |
| 59 | public ServletResponse getResponse() { |
| 60 | return this.response; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Sets the response being wrapped. |
| 65 | * |
| 66 | * @param response The new response to wrap |
| 67 | * |
| 68 | * @throws java.lang.IllegalArgumentException if the response is null. |
| 69 | */ |
| 70 | public void setResponse(ServletResponse response) { |
| 71 | if (response == null) { |
| 72 | throw new IllegalArgumentException(lStrings.getString("wrapper.nullResponse")); |
| 73 | } |
| 74 | this.response = response; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * The default behavior of this method is to call setCharacterEncoding(String charset) on the wrapped response |
| 79 | * object. |
| 80 | * |
| 81 | * @since Servlet 2.4 |
| 82 | */ |
| 83 | @Override |
| 84 | public void setCharacterEncoding(String charset) { |
| 85 | this.response.setCharacterEncoding(charset); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * The default behavior of this method is to call {@code setCharacterEncoding(Charset)} on the wrapped response |
| 90 | * object. |
| 91 | * |
nothing calls this directly
no outgoing calls
no test coverage detected