1 15 16 package com.sun.facelets.mock; 17 18 import java.io.IOException ; 19 import java.io.PrintWriter ; 20 import java.util.Hashtable ; 21 import java.util.Locale ; 22 23 import javax.servlet.ServletOutputStream ; 24 import javax.servlet.http.Cookie ; 25 import javax.servlet.http.HttpServletResponse ; 26 27 32 public class MockHttpServletResponse implements HttpServletResponse { 33 34 private boolean committed = false; 35 private int status; 36 private String message; 37 private Hashtable headers = new Hashtable (); 38 private String characterEncoding = "ISO-8859-1"; 39 private String contentType = "text/html"; 40 private long contentLength = 0; 41 private int bufferSize = 0; 42 private Locale locale = Locale.getDefault(); 43 44 public MockHttpServletResponse() { 45 super(); 46 } 47 48 public void addCookie(Cookie cookie) { 49 51 } 52 53 public boolean containsHeader(String name) { 54 return this.headers.contains(name); 55 } 56 57 public String encodeURL(String url) { 58 return url; 59 } 60 61 public String encodeRedirectURL(String url) { 62 return url; 63 } 64 65 public String encodeUrl(String url) { 66 return url; 67 } 68 69 public String encodeRedirectUrl(String url) { 70 return this.encodeRedirectURL(url); 71 } 72 73 public void sendError(int status, String message) throws IOException { 74 if (this.committed) { 75 throw new IllegalStateException ("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 { 83 if (this.committed) { 84 throw new IllegalStateException ("Response is already committed"); 85 } 86 this.status = status; 87 this.committed = true; 88 } 89 90 public void sendRedirect(String path) throws IOException { 91 if (this.committed) { 92 throw new IllegalStateException ("Response is already committed"); 93 } 94 this.committed = true; 95 } 96 97 public void setDateHeader(String name, long date) { 98 this.headers.put(name, ""+date); 99 } 100 101 public void addDateHeader(String name, long date) { 102 this.headers.put(name, ""+date); 103 } 104 105 public void setHeader(String name, String value) { 106 this.headers.put(name, value); 107 } 108 109 public void addHeader(String name, String value) { 110 this.headers.put(name, value); 111 } 112 113 public void setIntHeader(String name, int value) { 114 this.headers.put(name, ""+value); 115 } 116 117 public void addIntHeader(String 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 message) { 126 this.status = sc; 127 this.message = message; 128 } 129 130 public String getCharacterEncoding() { 131 return this.characterEncoding; 132 } 133 134 public String getContentType() { 135 return this.contentType; 136 } 137 138 public ServletOutputStream getOutputStream() throws IOException { 139 return null; 141 } 142 143 public PrintWriter getWriter() throws IOException { 144 return null; 146 } 147 148 public void setCharacterEncoding(String characterEncoding) { 149 this.characterEncoding = characterEncoding; 150 } 151 152 public void setContentLength(int contentLength) { 153 this.contentLength = contentLength; 154 } 155 156 public void setContentType(String 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 { 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 183 } 184 185 public void setLocale(Locale locale) { 186 this.locale = locale; 187 } 188 189 public Locale getLocale() { 190 return this.locale; 191 } 192 193 } 194 | Popular Tags |