1   /*
2    * Copyright 2004-2010 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  
17  package org.seasar.cubby.tags;
18  
19  import java.io.IOException;
20  import java.io.Reader;
21  import java.io.StringReader;
22  import java.io.Writer;
23  
24  import javax.servlet.jsp.JspWriter;
25  import javax.servlet.jsp.tagext.BodyContent;
26  
27  public class MockBodyContent extends BodyContent {
28  	private MockJspWriter body;
29  
30  	public MockBodyContent(JspWriter writer) {
31  		super(writer);
32  		body = new MockJspWriter();
33  	}
34  
35  	public String getOutputAsString() {
36  		return getString();
37  	}
38  
39  	public String toString() {
40  		return getString();
41  	}
42  
43  	public Reader getReader() {
44  		return new StringReader(getString());
45  	}
46  
47  	public String getString() {
48  		return body.toString();
49  	}
50  
51  	public void writeOut(Writer writer) throws IOException {
52  		writer.write(getString());
53  	}
54  
55  	public void clearBody() {
56  		body = new MockJspWriter();
57  	}
58  
59  	public void newLine() throws IOException {
60  		body.newLine();
61  	}
62  
63  	public void print(boolean arg0) throws IOException {
64  		body.print(arg0);
65  	}
66  
67  	public void print(char arg0) throws IOException {
68  		body.print(arg0);
69  	}
70  
71  	public void print(int arg0) throws IOException {
72  		body.print(arg0);
73  	}
74  
75  	public void print(long arg0) throws IOException {
76  		body.print(arg0);
77  	}
78  
79  	public void print(float arg0) throws IOException {
80  		body.print(arg0);
81  	}
82  
83  	public void print(double arg0) throws IOException {
84  		body.print(arg0);
85  	}
86  
87  	public void print(char[] arg0) throws IOException {
88  		body.print(arg0);
89  	}
90  
91  	public void print(String arg0) throws IOException {
92  		body.print(arg0);
93  	}
94  
95  	public void print(Object arg0) throws IOException {
96  		body.print(arg0);
97  	}
98  
99  	public void println() throws IOException {
100 		body.println();
101 	}
102 
103 	public void println(boolean arg0) throws IOException {
104 		body.println(arg0);
105 	}
106 
107 	public void println(char arg0) throws IOException {
108 		body.println(arg0);
109 	}
110 
111 	public void println(int arg0) throws IOException {
112 		body.println(arg0);
113 	}
114 
115 	public void println(long arg0) throws IOException {
116 		body.println(arg0);
117 	}
118 
119 	public void println(float arg0) throws IOException {
120 		body.println(arg0);
121 	}
122 
123 	public void println(double arg0) throws IOException {
124 		body.println(arg0);
125 	}
126 
127 	public void println(char[] arg0) throws IOException {
128 		body.println(arg0);
129 	}
130 
131 	public void println(String arg0) throws IOException {
132 		body.println(arg0);
133 	}
134 
135 	public void println(Object arg0) throws IOException {
136 		body.println(arg0);
137 	}
138 
139 	public void clear() throws IOException {
140 		body.clear();
141 	}
142 
143 	public void clearBuffer() throws IOException {
144 		body.clearBuffer();
145 	}
146 
147 	public void close() throws IOException {
148 		body.close();
149 	}
150 
151 	public int getRemaining() {
152 		return body.getRemaining();
153 	}
154 
155 	public void write(char[] cbuf, int off, int len) throws IOException {
156 		body.write(cbuf, off, len);
157 	}
158 }