1 18 19 package org.apache.struts.util; 20 21 import java.io.PrintWriter ; 22 import java.io.StringWriter ; 23 import javax.servlet.ServletContext ; 24 25 34 public class ServletContextWriter extends PrintWriter { 35 36 37 39 40 46 public ServletContextWriter(ServletContext context) { 47 48 super(new StringWriter ()); 49 this.context = context; 50 51 } 52 53 54 56 57 60 protected StringBuffer buffer = new StringBuffer (); 61 62 63 66 protected ServletContext context = null; 67 68 69 72 protected boolean error = false; 73 74 75 77 78 84 public boolean checkError() { 85 86 flush(); 87 return (error); 88 89 } 90 91 92 95 public void close() { 96 97 flush(); 98 99 } 100 101 102 105 public void flush() { 106 107 if (buffer.length() > 0) { 108 context.log(buffer.toString()); 109 buffer.setLength(0); 110 } 111 112 } 113 114 115 120 public void print(boolean b) { 121 122 write(String.valueOf(b)); 123 124 } 125 126 127 132 public void print(char c) { 133 134 write(c); 135 136 } 137 138 139 144 public void print(char c[]) { 145 146 for (int i = 0; i < c.length; i++) 147 write(c[i]); 148 149 } 150 151 152 157 public void print(double d) { 158 159 write(String.valueOf(d)); 160 161 } 162 163 164 169 public void print(float f) { 170 171 write(String.valueOf(f)); 172 173 } 174 175 176 181 public void print(int i) { 182 183 write(String.valueOf(i)); 184 185 } 186 187 188 193 public void print(long l) { 194 195 write(String.valueOf(l)); 196 197 } 198 199 200 205 public void print(Object o) { 206 207 write(o.toString()); 208 209 } 210 211 212 217 public void print(String s) { 218 219 int len = s.length(); 220 for (int i = 0; i < len; i++) 221 write(s.charAt(i)); 222 223 } 224 225 226 229 public void println() { 230 231 flush(); 232 233 } 234 235 236 241 public void println(boolean b) { 242 243 println(String.valueOf(b)); 244 245 } 246 247 248 253 public void println(char c) { 254 255 write(c); 256 println(); 257 258 } 259 260 261 266 public void println(char c[]) { 267 268 for (int i = 0; i < c.length; i++) 269 print(c[i]); 270 println(); 271 272 } 273 274 275 280 public void println(double d) { 281 282 println(String.valueOf(d)); 283 284 } 285 286 287 292 public void println(float f) { 293 294 println(String.valueOf(f)); 295 296 } 297 298 299 304 public void println(int i) { 305 306 println(String.valueOf(i)); 307 308 } 309 310 311 316 public void println(long l) { 317 318 println(String.valueOf(l)); 319 320 } 321 322 323 328 public void println(Object o) { 329 330 println(o.toString()); 331 332 } 333 334 335 340 public void println(String s) { 341 342 int len = s.length(); 343 for (int i = 0; i < len; i++) 344 print(s.charAt(i)); 345 println(); 346 347 } 348 349 350 353 public void setError() { 354 355 this.error = true; 356 357 } 358 359 360 365 public void write(char c) { 366 367 if (c == '\n') 368 flush(); 369 else if (c != '\r') 370 buffer.append(c); 371 372 } 373 374 375 380 public void write(int c) { 381 382 write((char) c); 383 384 } 385 386 387 392 public void write(char buf[]) { 393 394 for (int i = 0; i < buf.length; i++) 395 write(buf[i]); 396 397 } 398 399 400 407 public void write(char buf[], int off, int len) { 408 409 for (int i = off; i < len; i++) 410 write(buf[i]); 411 412 } 413 414 415 420 public void write(String s) { 421 422 int len = s.length(); 423 for (int i = 0; i < len; i++) 424 write(s.charAt(i)); 425 426 } 427 428 429 436 public void write(String s, int off, int len) { 437 438 for (int i = off; i < len; i++) 439 write(s.charAt(i)); 440 441 } 442 443 444 } 445 | Popular Tags |