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