01: /*
02: * de.schlund.pfixcore.webservice.monitor.InsertPIResponseWrapper
03: */
04: package de.schlund.pfixcore.webservice;
05:
06: import java.io.ByteArrayOutputStream;
07: import java.io.IOException;
08: import java.io.OutputStream;
09: import java.io.PrintWriter;
10:
11: import javax.servlet.ServletOutputStream;
12: import javax.servlet.http.HttpServletResponse;
13: import javax.servlet.http.HttpServletResponseWrapper;
14:
15: /**
16: * InsertPIResponseWrapper.java
17: *
18: * Created: 28.07.2004
19: *
20: * @author mleidig
21: */
22: public class InsertPIResponseWrapper extends HttpServletResponseWrapper {
23:
24: MyServletOutputStream myOut;
25:
26: public InsertPIResponseWrapper(HttpServletResponse res)
27: throws IOException {
28: super (res);
29: myOut = new MyServletOutputStream(res.getOutputStream());
30: }
31:
32: public ServletOutputStream getOutputStream() throws IOException {
33: return myOut;
34: }
35:
36: public PrintWriter getWriter() throws IOException {
37: return new PrintWriter(myOut);
38: }
39:
40: public byte[] getBytes() {
41: return myOut.getBytes();
42: }
43:
44: class MyServletOutputStream extends ServletOutputStream {
45:
46: boolean inserted = false;
47: int opened = 0;
48: String pi = "<?xml-stylesheet type=\"text/css\" href=\"blank.css\"?>";
49: OutputStream reqOut;
50: ByteArrayOutputStream out;
51:
52: public MyServletOutputStream(OutputStream reqOut) {
53: this .reqOut = reqOut;
54: out = new ByteArrayOutputStream();
55: }
56:
57: public void write(int b) throws IOException {
58: if (!inserted) {
59: if (b == '<')
60: opened++;
61: if (opened == 2) {
62: reqOut.write(pi.getBytes());
63: inserted = true;
64: }
65: }
66: out.write(b);
67: reqOut.write(b);
68: }
69:
70: public byte[] getBytes() {
71: return out.toByteArray();
72: }
73:
74: }
75:
76: }
|