View Javadoc

1   /*
2   * Copyright 2004 The Apache Software Foundation
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.apache.org/licenses/LICENSE-2.0
9   *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16  package javax.servlet.http;
17  
18  import java.io.IOException;
19  
20  import javax.servlet.ServletResponseWrapper;
21  
22  /**
23   * 
24   * Provides a convenient implementation of the HttpServletResponse interface that
25   * can be subclassed by developers wishing to adapt the response from a Servlet.
26   * This class implements the Wrapper or Decorator pattern. Methods default to
27   * calling through to the wrapped response object.
28   * 
29   * @author 	Various
30   * @version 	$Version$
31    * @since	v 2.3
32   *
33   * @see 	javax.servlet.http.HttpServletResponse
34   *
35   */
36  
37  public class HttpServletResponseWrapper extends ServletResponseWrapper implements HttpServletResponse {
38  
39  
40      /** 
41      * Constructs a response adaptor wrapping the given response.
42      * @throws java.lang.IllegalArgumentException if the response is null
43      */
44      public HttpServletResponseWrapper(HttpServletResponse response) {
45  	    super(response);
46      }
47      
48      private HttpServletResponse _getHttpServletResponse() {
49  	return (HttpServletResponse) super.getResponse();
50      }
51      
52      /**
53       * The default behavior of this method is to call addCookie(Cookie cookie)
54       * on the wrapped response object.
55       */
56      public void addCookie(Cookie cookie) {
57  	this._getHttpServletResponse().addCookie(cookie);
58      }
59  
60      /**
61       * The default behavior of this method is to call containsHeader(String name)
62       * on the wrapped response object.
63       */
64  
65   
66      public boolean containsHeader(String name) {
67  	return this._getHttpServletResponse().containsHeader(name);
68      }
69      
70      /**
71       * The default behavior of this method is to call encodeURL(String url)
72       * on the wrapped response object.
73       */
74      public String encodeURL(String url) {
75  	return this._getHttpServletResponse().encodeURL(url);
76      }
77  
78      /**
79       * The default behavior of this method is to return encodeRedirectURL(String url)
80       * on the wrapped response object.
81       */
82      public String encodeRedirectURL(String url) {
83  	return this._getHttpServletResponse().encodeRedirectURL(url);
84      }
85  
86      /**
87       * The default behavior of this method is to call encodeUrl(String url)
88       * on the wrapped response object.
89       */
90      public String encodeUrl(String url) {
91  	return this._getHttpServletResponse().encodeUrl(url);
92      }
93      
94      /**
95       * The default behavior of this method is to return encodeRedirectUrl(String url)
96       * on the wrapped response object.
97       */
98      public String encodeRedirectUrl(String url) {
99  	return this._getHttpServletResponse().encodeRedirectUrl(url);
100     }
101     
102     /**
103      * The default behavior of this method is to call sendError(int sc, String msg)
104      * on the wrapped response object.
105      */
106     public void sendError(int sc, String msg) throws IOException {
107 	this._getHttpServletResponse().sendError(sc, msg);
108     }
109 
110     /**
111      * The default behavior of this method is to call sendError(int sc)
112      * on the wrapped response object.
113      */
114 
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 
181 
182     public void setStatus(int sc) {
183 	this._getHttpServletResponse().setStatus(sc);
184     }
185     
186     /**
187      * The default behavior of this method is to call setStatus(int sc, String sm)
188      * on the wrapped response object.
189      */
190      public void setStatus(int sc, String sm) {
191 	this._getHttpServletResponse().setStatus(sc, sm);
192     }
193 
194    
195 }