1 16 package org.apache.cocoon.portal.pluto.servlet; 17 18 import java.io.ByteArrayOutputStream ; 19 import java.io.IOException ; 20 import java.io.PrintWriter ; 21 import java.util.Locale ; 22 23 import javax.servlet.ServletOutputStream ; 24 import javax.servlet.http.HttpServletResponse ; 25 import javax.servlet.http.HttpServletResponseWrapper ; 26 27 33 public class ServletResponseImpl extends HttpServletResponseWrapper { 34 35 protected MyOutputStream stream; 36 protected PrintWriter writer; 37 38 protected boolean committed = false; 39 protected int bufferSize = 1024; 40 41 protected String redirectURL; 42 43 public ServletResponseImpl(HttpServletResponse response) { 44 super(response); 45 this.stream = new MyOutputStream(); 46 this.writer = new PrintWriter (this.stream); 47 } 48 49 52 public String getContent() { 53 this.writer.flush(); 54 try { 55 this.stream.flush(); 56 } catch (IOException ignore) { 57 } 59 final String value = new String (this.stream.stream.toByteArray()); 60 this.stream = new MyOutputStream(); 61 this.writer = new PrintWriter (this.stream); 62 return value; 63 } 64 65 68 public String getRedirectURL() { 69 return this.redirectURL; 70 } 71 72 75 public String toString() { 76 return this.getContent(); 77 } 78 79 85 public void sendError(int arg0, String arg1) throws IOException { 86 } 88 89 94 public void sendError(int arg0) throws IOException { 95 } 97 98 103 public void sendRedirect(String arg0) throws IOException { 104 this.redirectURL = arg0; 105 } 106 107 113 public void setStatus(int arg0, String arg1) { 114 } 116 117 122 public void setStatus(int arg0) { 123 } 125 126 131 public void flushBuffer() throws IOException { 132 this.committed = true; 133 } 134 135 140 public int getBufferSize() { 141 return this.bufferSize = 1024; 142 } 143 144 149 public ServletOutputStream getOutputStream() throws IOException { 150 return this.stream; 151 } 152 153 158 public PrintWriter getWriter() throws IOException { 159 return this.writer; 160 } 161 162 167 public boolean isCommitted() { 168 return this.committed; 169 } 170 171 176 public void reset() { 177 if (!this.committed) { 178 this.stream = new MyOutputStream(); 179 } 180 } 181 182 187 public void setBufferSize(int arg0) { 188 this.bufferSize = arg0; 189 } 190 191 196 public void setContentLength(int arg0) { 197 } 199 200 205 public void setContentType(String arg0) { 206 } 208 209 214 public void setLocale(Locale arg0) { 215 } 217 218 223 public void resetBuffer() { 224 } 226 227 } 228 229 class MyOutputStream extends ServletOutputStream { 230 231 ByteArrayOutputStream stream = new ByteArrayOutputStream (); 232 233 public MyOutputStream() { 234 } 236 237 242 public void write(int b) throws IOException { 243 this.stream.write(b); 244 } 245 246 251 public void flush() throws IOException { 252 super.flush(); 253 this.stream.flush(); 254 } 255 256 } 257 | Popular Tags |