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