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.connector;
018:
019: import java.io.IOException;
020:
021: import javax.servlet.http.Cookie;
022: import javax.servlet.http.HttpServletResponse;
023:
024: import org.apache.catalina.HttpResponse;
025:
026: /**
027: * Facade class that wraps a Catalina-internal <b>HttpResponse</b>
028: * object. All methods are delegated to the wrapped response.
029: *
030: * @author Remy Maucherat
031: * @author Craig R. McClanahan
032: * @version $Revision: 1.3 $ $Date: 2004/02/27 14:58:41 $
033: */
034:
035: public final class HttpResponseFacade extends ResponseFacade implements
036: HttpServletResponse {
037:
038: // ----------------------------------------------------------- Constructors
039:
040: /**
041: * Construct a wrapper for the specified response.
042: *
043: * @param response The response to be wrapped
044: */
045: public HttpResponseFacade(HttpResponse response) {
046: super (response);
047: }
048:
049: // -------------------------------------------- HttpServletResponse Methods
050:
051: public void addCookie(Cookie cookie) {
052:
053: if (isCommitted())
054: return;
055:
056: ((HttpServletResponse) response).addCookie(cookie);
057:
058: }
059:
060: public boolean containsHeader(String name) {
061: return ((HttpServletResponse) response).containsHeader(name);
062: }
063:
064: public String encodeURL(String url) {
065: return ((HttpServletResponse) response).encodeURL(url);
066: }
067:
068: public String encodeRedirectURL(String url) {
069: return ((HttpServletResponse) response).encodeRedirectURL(url);
070: }
071:
072: public String encodeUrl(String url) {
073: return ((HttpServletResponse) response).encodeURL(url);
074: }
075:
076: public String encodeRedirectUrl(String url) {
077: return ((HttpServletResponse) response).encodeRedirectURL(url);
078: }
079:
080: public void sendError(int sc, String msg) throws IOException {
081:
082: if (isCommitted())
083: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
084:
085: resp.setAppCommitted(true);
086:
087: ((HttpServletResponse) response).sendError(sc, msg);
088:
089: }
090:
091: public void sendError(int sc) throws IOException {
092:
093: if (isCommitted())
094: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
095:
096: resp.setAppCommitted(true);
097:
098: ((HttpServletResponse) response).sendError(sc);
099:
100: }
101:
102: public void sendRedirect(String location) throws IOException {
103:
104: if (isCommitted())
105: throw new IllegalStateException(/*sm.getString("responseBase.reset.ise")*/);
106:
107: resp.setAppCommitted(true);
108:
109: ((HttpServletResponse) response).sendRedirect(location);
110:
111: }
112:
113: public void setDateHeader(String name, long date) {
114:
115: if (isCommitted())
116: return;
117:
118: ((HttpServletResponse) response).setDateHeader(name, date);
119:
120: }
121:
122: public void addDateHeader(String name, long date) {
123:
124: if (isCommitted())
125: return;
126:
127: ((HttpServletResponse) response).addDateHeader(name, date);
128:
129: }
130:
131: public void setHeader(String name, String value) {
132:
133: if (isCommitted())
134: return;
135:
136: ((HttpServletResponse) response).setHeader(name, value);
137:
138: }
139:
140: public void addHeader(String name, String value) {
141:
142: if (isCommitted())
143: return;
144:
145: ((HttpServletResponse) response).addHeader(name, value);
146:
147: }
148:
149: public void setIntHeader(String name, int value) {
150:
151: if (isCommitted())
152: return;
153:
154: ((HttpServletResponse) response).setIntHeader(name, value);
155:
156: }
157:
158: public void addIntHeader(String name, int value) {
159:
160: if (isCommitted())
161: return;
162:
163: ((HttpServletResponse) response).addIntHeader(name, value);
164:
165: }
166:
167: public void setStatus(int sc) {
168:
169: if (isCommitted())
170: return;
171:
172: ((HttpServletResponse) response).setStatus(sc);
173:
174: }
175:
176: public void setStatus(int sc, String sm) {
177:
178: if (isCommitted())
179: return;
180:
181: ((HttpServletResponse) response).setStatus(sc, sm);
182:
183: }
184:
185: }
|