001: /**
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * Licensed under the Common Development and Distribution License,
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.sun.com/cddl/
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
012: * implied. See the License for the specific language governing
013: * permissions and limitations under the License.
014: */package com.sun.facelets.mock;
015:
016: import java.io.IOException;
017: import java.io.PrintWriter;
018: import java.util.Hashtable;
019: import java.util.Locale;
020:
021: import javax.servlet.ServletOutputStream;
022: import javax.servlet.http.Cookie;
023: import javax.servlet.http.HttpServletResponse;
024:
025: /**
026: *
027: * @author Jacob Hookom
028: * @version $Id: MockHttpServletResponse.java,v 1.2 2005/07/19 00:49:01 jhook Exp $
029: */
030: public class MockHttpServletResponse implements HttpServletResponse {
031:
032: private boolean committed = false;
033: private int status;
034: private String message;
035: private Hashtable headers = new Hashtable();
036: private String characterEncoding = "ISO-8859-1";
037: private String contentType = "text/html";
038: private long contentLength = 0;
039: private int bufferSize = 0;
040: private Locale locale = Locale.getDefault();
041:
042: public MockHttpServletResponse() {
043: super ();
044: }
045:
046: public void addCookie(Cookie cookie) {
047: // TODO Auto-generated method stub
048:
049: }
050:
051: public boolean containsHeader(String name) {
052: return this .headers.contains(name);
053: }
054:
055: public String encodeURL(String url) {
056: return url;
057: }
058:
059: public String encodeRedirectURL(String url) {
060: return url;
061: }
062:
063: public String encodeUrl(String url) {
064: return url;
065: }
066:
067: public String encodeRedirectUrl(String url) {
068: return this .encodeRedirectURL(url);
069: }
070:
071: public void sendError(int status, String message)
072: throws IOException {
073: if (this .committed) {
074: throw new IllegalStateException(
075: "Response is already committed");
076: }
077: this .status = status;
078: this .message = message;
079: this .committed = true;
080: }
081:
082: public void sendError(int status) throws IOException {
083: if (this .committed) {
084: throw new IllegalStateException(
085: "Response is already committed");
086: }
087: this .status = status;
088: this .committed = true;
089: }
090:
091: public void sendRedirect(String path) throws IOException {
092: if (this .committed) {
093: throw new IllegalStateException(
094: "Response is already committed");
095: }
096: this .committed = true;
097: }
098:
099: public void setDateHeader(String name, long date) {
100: this .headers.put(name, "" + date);
101: }
102:
103: public void addDateHeader(String name, long date) {
104: this .headers.put(name, "" + date);
105: }
106:
107: public void setHeader(String name, String value) {
108: this .headers.put(name, value);
109: }
110:
111: public void addHeader(String name, String value) {
112: this .headers.put(name, value);
113: }
114:
115: public void setIntHeader(String name, int value) {
116: this .headers.put(name, "" + value);
117: }
118:
119: public void addIntHeader(String name, int value) {
120: this .headers.put(name, "" + value);
121: }
122:
123: public void setStatus(int sc) {
124: this .status = sc;
125: }
126:
127: public void setStatus(int sc, String message) {
128: this .status = sc;
129: this .message = message;
130: }
131:
132: public String getCharacterEncoding() {
133: return this .characterEncoding;
134: }
135:
136: public String getContentType() {
137: return this .contentType;
138: }
139:
140: public ServletOutputStream getOutputStream() throws IOException {
141: // TODO Auto-generated method stub
142: return null;
143: }
144:
145: public PrintWriter getWriter() throws IOException {
146: // TODO Auto-generated method stub
147: return null;
148: }
149:
150: public void setCharacterEncoding(String characterEncoding) {
151: this .characterEncoding = characterEncoding;
152: }
153:
154: public void setContentLength(int contentLength) {
155: this .contentLength = contentLength;
156: }
157:
158: public void setContentType(String contentType) {
159: this .contentType = contentType;
160: }
161:
162: public void setBufferSize(int sz) {
163: this .bufferSize = sz;
164: }
165:
166: public int getBufferSize() {
167: return this .bufferSize;
168: }
169:
170: public void flushBuffer() throws IOException {
171:
172: }
173:
174: public void resetBuffer() {
175:
176: }
177:
178: public boolean isCommitted() {
179: return this .committed;
180: }
181:
182: public void reset() {
183: // TODO Auto-generated method stub
184:
185: }
186:
187: public void setLocale(Locale locale) {
188: this .locale = locale;
189: }
190:
191: public Locale getLocale() {
192: return this.locale;
193: }
194:
195: }
|