KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > mock > MockHttpServletResponse


1 /**
2  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3  * Licensed under the Common Development and Distribution License,
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.sun.com/cddl/
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */

15
16 package com.sun.facelets.mock;
17
18 import java.io.IOException JavaDoc;
19 import java.io.PrintWriter JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.util.Locale JavaDoc;
22
23 import javax.servlet.ServletOutputStream JavaDoc;
24 import javax.servlet.http.Cookie JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 /**
28  *
29  * @author Jacob Hookom
30  * @version $Id: MockHttpServletResponse.java,v 1.2 2005/07/19 00:49:01 jhook Exp $
31  */

32 public class MockHttpServletResponse implements HttpServletResponse JavaDoc {
33     
34     private boolean committed = false;
35     private int status;
36     private String JavaDoc message;
37     private Hashtable JavaDoc headers = new Hashtable JavaDoc();
38     private String JavaDoc characterEncoding = "ISO-8859-1";
39     private String JavaDoc contentType = "text/html";
40     private long contentLength = 0;
41     private int bufferSize = 0;
42     private Locale JavaDoc locale = Locale.getDefault();
43     
44     public MockHttpServletResponse() {
45         super();
46     }
47
48     public void addCookie(Cookie JavaDoc cookie) {
49         // TODO Auto-generated method stub
50

51     }
52
53     public boolean containsHeader(String JavaDoc name) {
54         return this.headers.contains(name);
55     }
56
57     public String JavaDoc encodeURL(String JavaDoc url) {
58         return url;
59     }
60
61     public String JavaDoc encodeRedirectURL(String JavaDoc url) {
62         return url;
63     }
64
65     public String JavaDoc encodeUrl(String JavaDoc url) {
66         return url;
67     }
68
69     public String JavaDoc encodeRedirectUrl(String JavaDoc url) {
70         return this.encodeRedirectURL(url);
71     }
72
73     public void sendError(int status, String JavaDoc message) throws IOException JavaDoc {
74         if (this.committed) {
75             throw new IllegalStateException JavaDoc("Response is already committed");
76         }
77         this.status = status;
78         this.message = message;
79         this.committed = true;
80     }
81
82     public void sendError(int status) throws IOException JavaDoc {
83         if (this.committed) {
84             throw new IllegalStateException JavaDoc("Response is already committed");
85         }
86         this.status = status;
87         this.committed = true;
88     }
89
90     public void sendRedirect(String JavaDoc path) throws IOException JavaDoc {
91         if (this.committed) {
92             throw new IllegalStateException JavaDoc("Response is already committed");
93         }
94         this.committed = true;
95     }
96
97     public void setDateHeader(String JavaDoc name, long date) {
98         this.headers.put(name, ""+date);
99     }
100
101     public void addDateHeader(String JavaDoc name, long date) {
102         this.headers.put(name, ""+date);
103     }
104
105     public void setHeader(String JavaDoc name, String JavaDoc value) {
106         this.headers.put(name, value);
107     }
108
109     public void addHeader(String JavaDoc name, String JavaDoc value) {
110         this.headers.put(name, value);
111     }
112
113     public void setIntHeader(String JavaDoc name, int value) {
114         this.headers.put(name, ""+value);
115     }
116
117     public void addIntHeader(String JavaDoc name, int value) {
118         this.headers.put(name, ""+value);
119     }
120
121     public void setStatus(int sc) {
122         this.status = sc;
123     }
124
125     public void setStatus(int sc, String JavaDoc message) {
126         this.status = sc;
127         this.message = message;
128     }
129
130     public String JavaDoc getCharacterEncoding() {
131         return this.characterEncoding;
132     }
133
134     public String JavaDoc getContentType() {
135         return this.contentType;
136     }
137
138     public ServletOutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
139         // TODO Auto-generated method stub
140
return null;
141     }
142
143     public PrintWriter JavaDoc getWriter() throws IOException JavaDoc {
144         // TODO Auto-generated method stub
145
return null;
146     }
147
148     public void setCharacterEncoding(String JavaDoc characterEncoding) {
149         this.characterEncoding = characterEncoding;
150     }
151
152     public void setContentLength(int contentLength) {
153         this.contentLength = contentLength;
154     }
155
156     public void setContentType(String JavaDoc contentType) {
157         this.contentType = contentType;
158     }
159
160     public void setBufferSize(int sz) {
161         this.bufferSize = sz;
162     }
163
164     public int getBufferSize() {
165         return this.bufferSize;
166     }
167
168     public void flushBuffer() throws IOException JavaDoc {
169
170     }
171
172     public void resetBuffer() {
173
174     }
175
176     public boolean isCommitted() {
177         return this.committed;
178     }
179
180     public void reset() {
181         // TODO Auto-generated method stub
182

183     }
184
185     public void setLocale(Locale JavaDoc locale) {
186         this.locale = locale;
187     }
188
189     public Locale JavaDoc getLocale() {
190         return this.locale;
191     }
192
193 }
194
Popular Tags