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.coyote.tomcat4;
018:
019: import java.io.IOException;
020: import java.io.PrintWriter;
021: import java.util.Locale;
022:
023: import javax.servlet.ServletOutputStream;
024: import javax.servlet.http.Cookie;
025: import javax.servlet.http.HttpServletResponse;
026:
027: import org.apache.catalina.connector.ResponseFacade;
028:
029: /**
030: * Facade class that wraps a Coyote response object.
031: * All methods are delegated to the wrapped response.
032: *
033: * @author Remy Maucherat
034: * @version $Revision: 1.3 $ $Date: 2004/02/24 08:54:29 $
035: */
036:
037: public class CoyoteResponseFacade extends ResponseFacade implements
038: HttpServletResponse {
039:
040: // ----------------------------------------------------------- Constructors
041:
042: /**
043: * Construct a wrapper for the specified response.
044: *
045: * @param response The response to be wrapped
046: */
047: public CoyoteResponseFacade(CoyoteResponse response) {
048:
049: super (response);
050: this .response = response;
051:
052: }
053:
054: // ----------------------------------------------------- Instance Variables
055:
056: /**
057: * The wrapped response.
058: */
059: protected CoyoteResponse response = null;
060:
061: // --------------------------------------------------------- Public Methods
062:
063: /**
064: * Clear facade.
065: */
066: public void clear() {
067: response = null;
068: }
069:
070: public void finish() {
071:
072: response.setSuspended(true);
073:
074: }
075:
076: public boolean isFinished() {
077:
078: return response.isSuspended();
079:
080: }
081:
082: // ------------------------------------------------ ServletResponse Methods
083:
084: public String getCharacterEncoding() {
085: return response.getCharacterEncoding();
086: }
087:
088: public ServletOutputStream getOutputStream() throws IOException {
089:
090: // if (isFinished())
091: // throw new IllegalStateException
092: // (/*sm.getString("responseFacade.finished")*/);
093:
094: ServletOutputStream sos = response.getOutputStream();
095: if (isFinished())
096: response.setSuspended(true);
097: return (sos);
098:
099: }
100:
101: public PrintWriter getWriter() throws IOException {
102:
103: // if (isFinished())
104: // throw new IllegalStateException
105: // (/*sm.getString("responseFacade.finished")*/);
106:
107: PrintWriter writer = response.getWriter();
108: if (isFinished())
109: response.setSuspended(true);
110: return (writer);
111:
112: }
113:
114: public void setContentLength(int len) {
115:
116: if (isCommitted())
117: return;
118:
119: response.setContentLength(len);
120:
121: }
122:
123: public void setContentType(String type) {
124:
125: if (isCommitted())
126: return;
127:
128: response.setContentType(type);
129:
130: }
131:
132: public void setBufferSize(int size) {
133:
134: if (isCommitted())
135: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
136:
137: response.setBufferSize(size);
138:
139: }
140:
141: public int getBufferSize() {
142: return response.getBufferSize();
143: }
144:
145: public void flushBuffer() throws IOException {
146:
147: if (isFinished())
148: // throw new IllegalStateException
149: // (/*sm.getString("responseFacade.finished")*/);
150: return;
151:
152: response.setAppCommitted(true);
153:
154: response.flushBuffer();
155:
156: }
157:
158: public void resetBuffer() {
159:
160: if (isCommitted())
161: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
162:
163: response.resetBuffer();
164:
165: }
166:
167: public boolean isCommitted() {
168: return (response.isAppCommitted());
169: }
170:
171: public void reset() {
172:
173: if (isCommitted())
174: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
175:
176: response.reset();
177:
178: }
179:
180: public void setLocale(Locale loc) {
181:
182: if (isCommitted())
183: return;
184:
185: response.setLocale(loc);
186: }
187:
188: public Locale getLocale() {
189: return response.getLocale();
190: }
191:
192: public void addCookie(Cookie cookie) {
193:
194: if (isCommitted())
195: return;
196:
197: response.addCookie(cookie);
198:
199: }
200:
201: public boolean containsHeader(String name) {
202: return response.containsHeader(name);
203: }
204:
205: public String encodeURL(String url) {
206: return response.encodeURL(url);
207: }
208:
209: public String encodeRedirectURL(String url) {
210: return response.encodeRedirectURL(url);
211: }
212:
213: public String encodeUrl(String url) {
214: return response.encodeURL(url);
215: }
216:
217: public String encodeRedirectUrl(String url) {
218: return response.encodeRedirectURL(url);
219: }
220:
221: public void sendError(int sc, String msg) throws IOException {
222:
223: if (isCommitted())
224: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
225:
226: response.setAppCommitted(true);
227:
228: response.sendError(sc, msg);
229:
230: }
231:
232: public void sendError(int sc) throws IOException {
233:
234: if (isCommitted())
235: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
236:
237: response.setAppCommitted(true);
238:
239: response.sendError(sc);
240:
241: }
242:
243: public void sendRedirect(String location) throws IOException {
244:
245: if (isCommitted())
246: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
247:
248: response.setAppCommitted(true);
249:
250: response.sendRedirect(location);
251:
252: }
253:
254: public void setDateHeader(String name, long date) {
255:
256: if (isCommitted())
257: return;
258:
259: response.setDateHeader(name, date);
260:
261: }
262:
263: public void addDateHeader(String name, long date) {
264:
265: if (isCommitted())
266: return;
267:
268: response.addDateHeader(name, date);
269:
270: }
271:
272: public void setHeader(String name, String value) {
273:
274: if (isCommitted())
275: return;
276:
277: response.setHeader(name, value);
278:
279: }
280:
281: public void addHeader(String name, String value) {
282:
283: if (isCommitted())
284: return;
285:
286: response.addHeader(name, value);
287:
288: }
289:
290: public void setIntHeader(String name, int value) {
291:
292: if (isCommitted())
293: return;
294:
295: response.setIntHeader(name, value);
296:
297: }
298:
299: public void addIntHeader(String name, int value) {
300:
301: if (isCommitted())
302: return;
303:
304: response.addIntHeader(name, value);
305:
306: }
307:
308: public void setStatus(int sc) {
309:
310: if (isCommitted())
311: return;
312:
313: response.setStatus(sc);
314:
315: }
316:
317: public void setStatus(int sc, String sm) {
318:
319: if (isCommitted())
320: return;
321:
322: response.setStatus(sc, sm);
323:
324: }
325:
326: }
|