View Javadoc

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