View Javadoc

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