1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.views.jsp;
22
23 import java.io.IOException;
24 import java.io.StringWriter;
25
26 import javax.servlet.jsp.JspWriter;
27
28
29 /***
30 * Unforunately, the MockJspWriter throws a NotImplementedException when any of the Writer methods are invoked and
31 * as you might guess, Velocity uses the Writer methods. I'velocityEngine subclassed the MockJspWriter for the time being so
32 * that we can do testing on the results until MockJspWriter gets fully implemented.
33 * <p/>
34 * todo replace this once MockJspWriter implements Writer correctly (i.e. doesn't throw NotImplementException)
35 */
36 public class StrutsMockJspWriter extends JspWriter {
37 StringWriter writer;
38
39 public StrutsMockJspWriter(StringWriter writer) {
40 super(1024, true);
41 this.writer = writer;
42 }
43
44 public void newLine() throws IOException {
45 writer.write("\n");
46 }
47
48 public void print(boolean b) throws IOException {
49 writer.write(String.valueOf(b));
50 }
51
52 public void print(char c) throws IOException {
53 writer.write(String.valueOf(c));
54 }
55
56 public void print(int i) throws IOException {
57 writer.write(i);
58 }
59
60 public void print(long l) throws IOException {
61 writer.write(String.valueOf(l));
62 }
63
64 public void print(float v) throws IOException {
65 writer.write(String.valueOf(v));
66 }
67
68 public void print(double v) throws IOException {
69 writer.write(String.valueOf(v));
70 }
71
72 public void print(char[] chars) throws IOException {
73 writer.write(chars);
74 }
75
76 public void print(String s) throws IOException {
77 writer.write(s);
78 }
79
80 public void print(Object o) throws IOException {
81 writer.write(o.toString());
82 }
83
84 public void println() throws IOException {
85 writer.write("\n");
86 }
87
88 public void println(boolean b) throws IOException {
89 print(b);
90 println();
91 }
92
93 public void println(char c) throws IOException {
94 print(c);
95 println();
96 }
97
98 public void println(int i) throws IOException {
99 print(i);
100 println();
101 }
102
103 public void println(long l) throws IOException {
104 print(l);
105 println();
106 }
107
108 public void println(float v) throws IOException {
109 print(v);
110 println();
111 }
112
113 public void println(double v) throws IOException {
114 print(v);
115 println();
116 }
117
118 public void println(char[] chars) throws IOException {
119 print(chars);
120 println();
121 }
122
123 public void println(String s) throws IOException {
124 print(s);
125 println();
126 }
127
128 public void println(Object o) throws IOException {
129 print(o);
130 println();
131 }
132
133 public void clear() throws IOException {
134 }
135
136 public void clearBuffer() throws IOException {
137 }
138
139 public void close() throws IOException {
140 writer.close();
141 }
142
143 public int getRemaining() {
144 return 0;
145 }
146
147 public void write(char cbuf[], int off, int len) throws IOException {
148 writer.write(cbuf, off, len);
149 }
150
151 public void write(String str) throws IOException {
152 writer.write(str);
153 }
154
155 public void write(int c) throws IOException {
156 writer.write(c);
157 }
158
159 public void write(char[] cbuf) throws IOException {
160 writer.write(cbuf);
161 }
162
163 public void write(String str, int off, int len) throws IOException {
164 writer.write(str, off, len);
165 }
166
167 public void flush() {
168 writer.flush();
169 }
170 }