001: /*
002: * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationHttpResponse.java,v 1.8 2002/06/28 12:19:13 remm Exp $
003: * $Revision: 1.8 $
004: * $Date: 2002/06/28 12:19:13 $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 1999 The Apache Software Foundation. All rights
011: * reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions
015: * are met:
016: *
017: * 1. Redistributions of source code must retain the above copyright
018: * notice, this list of conditions and the following disclaimer.
019: *
020: * 2. Redistributions in binary form must reproduce the above copyright
021: * notice, this list of conditions and the following disclaimer in
022: * the documentation and/or other materials provided with the
023: * distribution.
024: *
025: * 3. The end-user documentation included with the redistribution, if
026: * any, must include the following acknowlegement:
027: * "This product includes software developed by the
028: * Apache Software Foundation (http://www.apache.org/)."
029: * Alternately, this acknowlegement may appear in the software itself,
030: * if and wherever such third-party acknowlegements normally appear.
031: *
032: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
033: * Foundation" must not be used to endorse or promote products derived
034: * from this software without prior written permission. For written
035: * permission, please contact apache@apache.org.
036: *
037: * 5. Products derived from this software may not be called "Apache"
038: * nor may "Apache" appear in their names without prior written
039: * permission of the Apache Group.
040: *
041: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
042: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
043: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
044: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
045: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
046: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
047: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
048: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
049: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
050: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
051: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
052: * SUCH DAMAGE.
053: * ====================================================================
054: *
055: * This software consists of voluntary contributions made by many
056: * individuals on behalf of the Apache Software Foundation. For more
057: * information on the Apache Software Foundation, please see
058: * <http://www.apache.org/>.
059: *
060: * [Additional notices, if required by prior licensing conditions]
061: *
062: */
063:
064: package org.apache.catalina.core;
065:
066: import java.io.IOException;
067: import java.util.Locale;
068: import javax.servlet.http.Cookie;
069: import javax.servlet.http.HttpServletResponse;
070: import javax.servlet.http.HttpServletResponseWrapper;
071: import org.apache.catalina.HttpResponse;
072: import org.apache.catalina.util.StringManager;
073:
074: /**
075: * Wrapper around a <code>javax.servlet.http.HttpServletResponse</code>
076: * that transforms an application response object (which might be the original
077: * one passed to a servlet, or might be based on the 2.3
078: * <code>javax.servlet.http.HttpServletResponseWrapper</code> class)
079: * back into an internal <code>org.apache.catalina.HttpResponse</code>.
080: * <p>
081: * <strong>WARNING</strong>: Due to Java's lack of support for multiple
082: * inheritance, all of the logic in <code>ApplicationResponse</code> is
083: * duplicated in <code>ApplicationHttpResponse</code>. Make sure that you
084: * keep these two classes in synchronization when making changes!
085: *
086: * @author Craig R. McClanahan
087: * @version $Revision: 1.8 $ $Date: 2002/06/28 12:19:13 $
088: */
089:
090: class ApplicationHttpResponse extends HttpServletResponseWrapper {
091:
092: // ----------------------------------------------------------- Constructors
093:
094: /**
095: * Construct a new wrapped response around the specified servlet response.
096: *
097: * @param response The servlet response being wrapped
098: */
099: public ApplicationHttpResponse(HttpServletResponse response) {
100:
101: this (response, false);
102:
103: }
104:
105: /**
106: * Construct a new wrapped response around the specified servlet response.
107: *
108: * @param response The servlet response being wrapped
109: * @param included <code>true</code> if this response is being processed
110: * by a <code>RequestDispatcher.include()</code> call
111: */
112: public ApplicationHttpResponse(HttpServletResponse response,
113: boolean included) {
114:
115: super (response);
116: setIncluded(included);
117:
118: }
119:
120: // ----------------------------------------------------- Instance Variables
121:
122: /**
123: * Is this wrapped response the subject of an <code>include()</code>
124: * call?
125: */
126: protected boolean included = false;
127:
128: /**
129: * Descriptive information about this implementation.
130: */
131: protected static final String info = "org.apache.catalina.core.ApplicationHttpResponse/1.0";
132:
133: /**
134: * The string manager for this package.
135: */
136: protected static StringManager sm = StringManager
137: .getManager(Constants.Package);
138:
139: // ------------------------------------------------ ServletResponse Methods
140:
141: /**
142: * Disallow <code>reset()</code> calls on a included response.
143: *
144: * @exception IllegalStateException if the response has already
145: * been committed
146: */
147: public void reset() {
148:
149: // If already committed, the wrapped response will throw ISE
150: if (!included || getResponse().isCommitted())
151: getResponse().reset();
152:
153: }
154:
155: /**
156: * Disallow <code>setContentLength()</code> calls on an included response.
157: *
158: * @param len The new content length
159: */
160: public void setContentLength(int len) {
161:
162: if (!included)
163: getResponse().setContentLength(len);
164:
165: }
166:
167: /**
168: * Disallow <code>setContentType()</code> calls on an included response.
169: *
170: * @param type The new content type
171: */
172: public void setContentType(String type) {
173:
174: if (!included)
175: getResponse().setContentType(type);
176:
177: }
178:
179: /**
180: * Disallow <code>setLocale()</code> calls on an included response.
181: *
182: * @param loc The new locale
183: */
184: public void setLocale(Locale loc) {
185:
186: if (!included)
187: getResponse().setLocale(loc);
188:
189: }
190:
191: // -------------------------------------------- HttpServletResponse Methods
192:
193: /**
194: * Disallow <code>addCookie()</code> calls on an included response.
195: *
196: * @param cookie The new cookie
197: */
198: public void addCookie(Cookie cookie) {
199:
200: if (!included)
201: ((HttpServletResponse) getResponse()).addCookie(cookie);
202:
203: }
204:
205: /**
206: * Disallow <code>addDateHeader()</code> calls on an included response.
207: *
208: * @param name The new header name
209: * @param value The new header value
210: */
211: public void addDateHeader(String name, long value) {
212:
213: if (!included)
214: ((HttpServletResponse) getResponse()).addDateHeader(name,
215: value);
216:
217: }
218:
219: /**
220: * Disallow <code>addHeader()</code> calls on an included response.
221: *
222: * @param name The new header name
223: * @param value The new header value
224: */
225: public void addHeader(String name, String value) {
226:
227: if (!included)
228: ((HttpServletResponse) getResponse())
229: .addHeader(name, value);
230:
231: }
232:
233: /**
234: * Disallow <code>addIntHeader()</code> calls on an included response.
235: *
236: * @param name The new header name
237: * @param value The new header value
238: */
239: public void addIntHeader(String name, int value) {
240:
241: if (!included)
242: ((HttpServletResponse) getResponse()).addIntHeader(name,
243: value);
244:
245: }
246:
247: /**
248: * Disallow <code>sendError()</code> calls on an included response.
249: *
250: * @param sc The new status code
251: *
252: * @exception IOException if an input/output error occurs
253: */
254: public void sendError(int sc) throws IOException {
255:
256: if (!included)
257: ((HttpServletResponse) getResponse()).sendError(sc);
258:
259: }
260:
261: /**
262: * Disallow <code>sendError()</code> calls on an included response.
263: *
264: * @param sc The new status code
265: * @param msg The new message
266: *
267: * @exception IOException if an input/output error occurs
268: */
269: public void sendError(int sc, String msg) throws IOException {
270:
271: if (!included)
272: ((HttpServletResponse) getResponse()).sendError(sc, msg);
273:
274: }
275:
276: /**
277: * Disallow <code>sendRedirect()</code> calls on an included response.
278: *
279: * @param location The new location
280: *
281: * @exception IOException if an input/output error occurs
282: */
283: public void sendRedirect(String location) throws IOException {
284:
285: if (!included)
286: ((HttpServletResponse) getResponse())
287: .sendRedirect(location);
288:
289: }
290:
291: /**
292: * Disallow <code>setDateHeader()</code> calls on an included response.
293: *
294: * @param name The new header name
295: * @param value The new header value
296: */
297: public void setDateHeader(String name, long value) {
298:
299: if (!included)
300: ((HttpServletResponse) getResponse()).setDateHeader(name,
301: value);
302:
303: }
304:
305: /**
306: * Disallow <code>setHeader()</code> calls on an included response.
307: *
308: * @param name The new header name
309: * @param value The new header value
310: */
311: public void setHeader(String name, String value) {
312:
313: if (!included)
314: ((HttpServletResponse) getResponse())
315: .setHeader(name, value);
316:
317: }
318:
319: /**
320: * Disallow <code>setIntHeader()</code> calls on an included response.
321: *
322: * @param name The new header name
323: * @param value The new header value
324: */
325: public void setIntHeader(String name, int value) {
326:
327: if (!included)
328: ((HttpServletResponse) getResponse()).setIntHeader(name,
329: value);
330:
331: }
332:
333: /**
334: * Disallow <code>setStatus()</code> calls on an included response.
335: *
336: * @param sc The new status code
337: */
338: public void setStatus(int sc) {
339:
340: if (!included)
341: ((HttpServletResponse) getResponse()).setStatus(sc);
342:
343: }
344:
345: /**
346: * Disallow <code>setStatus()</code> calls on an included response.
347: *
348: * @param sc The new status code
349: * @param msg The new message
350: */
351: public void setStatus(int sc, String msg) {
352:
353: if (!included)
354: ((HttpServletResponse) getResponse()).setStatus(sc, msg);
355:
356: }
357:
358: // -------------------------------------------------------- Package Methods
359:
360: /**
361: * Return descriptive information about this implementation.
362: */
363: public String getInfo() {
364:
365: return (this .info);
366:
367: }
368:
369: /**
370: * Return the included flag for this response.
371: */
372: boolean isIncluded() {
373:
374: return (this .included);
375:
376: }
377:
378: /**
379: * Set the included flag for this response.
380: *
381: * @param included The new included flag
382: */
383: void setIncluded(boolean included) {
384:
385: this .included = included;
386:
387: }
388:
389: /**
390: * Set the response that we are wrapping.
391: *
392: * @param response The new wrapped response
393: */
394: void setResponse(HttpServletResponse response) {
395:
396: super.setResponse(response);
397:
398: }
399:
400: }
|