001: /*
002: * Copyright 1999,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.catalina.core;
018:
019: import java.util.Locale;
020:
021: import javax.servlet.ServletResponse;
022: import javax.servlet.ServletResponseWrapper;
023:
024: import org.apache.catalina.util.StringManager;
025:
026: /**
027: * Wrapper around a <code>javax.servlet.ServletResponse</code>
028: * that transforms an application response object (which might be the original
029: * one passed to a servlet, or might be based on the 2.3
030: * <code>javax.servlet.ServletResponseWrapper</code> class)
031: * back into an internal <code>org.apache.catalina.Response</code>.
032: * <p>
033: * <strong>WARNING</strong>: Due to Java's lack of support for multiple
034: * inheritance, all of the logic in <code>ApplicationResponse</code> is
035: * duplicated in <code>ApplicationHttpResponse</code>. Make sure that you
036: * keep these two classes in synchronization when making changes!
037: *
038: * @author Craig R. McClanahan
039: * @version $Revision: 1.4 $ $Date: 2004/02/27 14:58:42 $
040: */
041:
042: class ApplicationResponse extends ServletResponseWrapper {
043:
044: // ----------------------------------------------------------- Constructors
045:
046: /**
047: * Construct a new wrapped response around the specified servlet response.
048: *
049: * @param response The servlet response being wrapped
050: */
051: public ApplicationResponse(ServletResponse response) {
052:
053: this (response, false);
054:
055: }
056:
057: /**
058: * Construct a new wrapped response around the specified servlet response.
059: *
060: * @param response The servlet response being wrapped
061: * @param included <code>true</code> if this response is being processed
062: * by a <code>RequestDispatcher.include()</code> call
063: */
064: public ApplicationResponse(ServletResponse response,
065: boolean included) {
066:
067: super (response);
068: setIncluded(included);
069:
070: }
071:
072: // ----------------------------------------------------- Instance Variables
073:
074: /**
075: * Is this wrapped response the subject of an <code>include()</code>
076: * call?
077: */
078: protected boolean included = false;
079:
080: /**
081: * The string manager for this package.
082: */
083: protected static StringManager sm = StringManager
084: .getManager(Constants.Package);
085:
086: // ------------------------------------------------ ServletResponse Methods
087:
088: /**
089: * Disallow <code>reset()</code> calls on a included response.
090: *
091: * @exception IllegalStateException if the response has already
092: * been committed
093: */
094: public void reset() {
095:
096: // If already committed, the wrapped response will throw ISE
097: if (!included || getResponse().isCommitted())
098: getResponse().reset();
099:
100: }
101:
102: /**
103: * Disallow <code>setContentLength()</code> calls on an included response.
104: *
105: * @param len The new content length
106: */
107: public void setContentLength(int len) {
108:
109: if (!included)
110: getResponse().setContentLength(len);
111:
112: }
113:
114: /**
115: * Disallow <code>setContentType()</code> calls on an included response.
116: *
117: * @param type The new content type
118: */
119: public void setContentType(String type) {
120:
121: if (!included)
122: getResponse().setContentType(type);
123:
124: }
125:
126: /**
127: * Ignore <code>setLocale()</code> calls on an included response.
128: *
129: * @param loc The new locale
130: */
131: public void setLocale(Locale loc) {
132: if (!included)
133: getResponse().setLocale(loc);
134: }
135:
136: /**
137: * Ignore <code>setBufferSize()</code> calls on an included response.
138: *
139: * @param size The buffer size
140: */
141: public void setBufferSize(int size) {
142: if (!included)
143: getResponse().setBufferSize(size);
144: }
145:
146: // ----------------------------------------- ServletResponseWrapper Methods
147:
148: /**
149: * Set the response that we are wrapping.
150: *
151: * @param response The new wrapped response
152: */
153: public void setResponse(ServletResponse response) {
154:
155: super .setResponse(response);
156:
157: }
158:
159: // -------------------------------------------------------- Package Methods
160:
161: /**
162: * Return the included flag for this response.
163: */
164: boolean isIncluded() {
165:
166: return (this .included);
167:
168: }
169:
170: /**
171: * Set the included flag for this response.
172: *
173: * @param included The new included flag
174: */
175: void setIncluded(boolean included) {
176:
177: this.included = included;
178:
179: }
180:
181: }
|