1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.application.pss;
20
21 import javax.servlet.http.HttpServletResponseWrapper;
22 import javax.servlet.http.HttpServletResponse;
23 import javax.servlet.ServletOutputStream;
24 import java.io.IOException;
25 import java.io.PrintWriter;
26 import java.io.CharArrayWriter;
27
28
29
30
31 public class ViewHandlerResponseWrapperHelperImpl extends HttpServletResponseWrapper {
32 private TempServletOutputStream tempOS = null;
33 private PrintWriter pw = null;
34 private CharArrayWriter caw = null;
35 private int status = HttpServletResponse.SC_OK;
36
37 public PrintWriter getPw() {
38 if (pw == null) {
39 caw = new CharArrayWriter();
40 pw = new PrintWriter(caw);
41 }
42 return pw;
43 }
44
45 public ServletOutputStream getTempOS() {
46 if (tempOS == null)
47 {
48 tempOS = new TempServletOutputStream();
49 }
50 return tempOS;
51 }
52
53 public ViewHandlerResponseWrapperHelperImpl(HttpServletResponse httpServletResponse) {
54 super(httpServletResponse);
55 }
56
57
58
59 public void sendError(int i, String string) throws IOException {
60 super.sendError(i, string);
61 status = i;
62 }
63
64 public void sendError(int i) throws IOException {
65 super.sendError(i);
66 status = i;
67 }
68
69 public void setStatus(int i) {
70 super.setStatus(i);
71 status = i;
72 }
73
74 public void setStatus(int i, String string) {
75 super.setStatus(i, string);
76 status = i;
77 }
78
79
80 public String toString() {
81 String result = null;
82 if (caw != null) {
83 result = caw.toString();
84 }
85 else if (tempOS != null) {
86 result = tempOS.toString();
87 }
88
89 return result;
90 }
91
92 public PrintWriter getWriter() throws IOException {
93 return getPw();
94 }
95
96 public ServletOutputStream getOutputStream() throws IOException {
97 return getTempOS();
98 }
99
100 public void resetWriter() {
101 if (caw != null)
102 {
103 pw.flush();
104 caw.flush();
105 caw.reset();
106 }
107 }
108
109
110 }