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