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