1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.tags;
17  
18  import java.io.IOException;
19  import java.io.PrintWriter;
20  import java.io.StringWriter;
21  
22  import javax.servlet.jsp.JspWriter;
23  
24  public class MockJspWriter extends JspWriter {
25  
26  	StringWriter writer = new StringWriter();
27  	PrintWriter printWriter = new PrintWriter(writer);
28  	
29  	public MockJspWriter() {
30  		this(0, true);
31  	}
32  	
33  	protected MockJspWriter(int bufferSize, boolean autoFlush) {
34  		super(bufferSize, autoFlush);
35  	}
36  	
37  	public String getResult() {
38  		return writer.toString();
39  	}
40  
41  	@Override
42  	public void clear() throws IOException {
43  		writer = new StringWriter();
44  		printWriter = new PrintWriter(writer);
45  	}
46  
47  	@Override
48  	public void clearBuffer() throws IOException {
49  		writer = new StringWriter();
50  		printWriter = new PrintWriter(writer);
51  	}
52  
53  	@Override
54  	public void close() throws IOException {
55  		writer.close();
56  	}
57  
58  	@Override
59  	public void flush() throws IOException {
60  		writer.flush();
61  	}
62  
63  	@Override
64  	public int getRemaining() {
65  		return 0;
66  	}
67  
68  	@Override
69  	public void newLine() throws IOException {
70  		printWriter.println();
71  	}
72  
73  	@Override
74  	public void print(boolean b) throws IOException {
75  		printWriter.print(b);
76  	}
77  
78  	@Override
79  	public void print(char c) throws IOException {
80  		printWriter.print(c);
81  	}
82  
83  	@Override
84  	public void print(int i) throws IOException {
85  		printWriter.print(i);
86  	}
87  
88  	@Override
89  	public void print(long l) throws IOException {
90  		printWriter.print(l);
91  	}
92  
93  	@Override
94  	public void print(float f) throws IOException {
95  		printWriter.print(f);
96  	}
97  
98  	@Override
99  	public void print(double d) throws IOException {
100 		printWriter.print(d);
101 	}
102 
103 	@Override
104 	public void print(char[] s) throws IOException {
105 		printWriter.print(s);
106 	}
107 
108 	@Override
109 	public void print(String s) throws IOException {
110 		printWriter.print(s);
111 	}
112 
113 	@Override
114 	public void print(Object obj) throws IOException {
115 		printWriter.print(obj);
116 	}
117 
118 	@Override
119 	public void println() throws IOException {
120 		printWriter.println();
121 	}
122 
123 	@Override
124 	public void println(boolean x) throws IOException {
125 		printWriter.println(x);
126 	}
127 
128 	@Override
129 	public void println(char x) throws IOException {
130 		printWriter.println(x);
131 	}
132 
133 	@Override
134 	public void println(int x) throws IOException {
135 		printWriter.println(x);
136 	}
137 
138 	@Override
139 	public void println(long x) throws IOException {
140 		printWriter.println(x);
141 	}
142 
143 	@Override
144 	public void println(float x) throws IOException {
145 		printWriter.println(x);
146 	}
147 
148 	@Override
149 	public void println(double x) throws IOException {
150 		printWriter.println(x);
151 	}
152 
153 	@Override
154 	public void println(char[] x) throws IOException {
155 		printWriter.println(x);
156 	}
157 
158 	@Override
159 	public void println(String x) throws IOException {
160 		printWriter.println(x);
161 	}
162 
163 	@Override
164 	public void println(Object x) throws IOException {
165 		printWriter.println(x);
166 	}
167 
168 	@Override
169 	public void write(char[] cbuf, int off, int len) throws IOException {
170 		printWriter.write(cbuf, off, len);
171 	}
172 
173 }