View Javadoc

1   /*
2    * $Id: StrutsBodyContent.java 720222 2008-11-24 16:41:07Z musachy $
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      private StringBuilder buffer = new StringBuilder();
38  
39      public StrutsBodyContent(JspWriter jspWriter) {
40          super(jspWriter);
41      }
42  
43      public Reader getReader() {
44          return new StringReader(buffer.toString());
45      }
46  
47      public int getRemaining() {
48          return 0;
49      }
50  
51      public String getString() {
52          return buffer.toString();
53      }
54  
55      public void clear() throws IOException {
56          buffer = new StringBuilder();
57      }
58  
59      public void clearBuffer() throws IOException {
60          clear();
61      }
62  
63      public void close() throws IOException {
64          buffer = null;
65      }
66  
67      public void newLine() throws IOException {
68          buffer.append("\n");
69      }
70  
71      public void print(boolean b) throws IOException {
72          buffer.append(b);
73      }
74  
75      public void print(char c) throws IOException {
76          buffer.append(c);
77      }
78  
79      public void print(int i) throws IOException {
80          buffer.append(i);
81      }
82  
83      public void print(long l) throws IOException {
84          buffer.append(l);
85      }
86  
87      public void print(float v) throws IOException {
88          buffer.append(v);
89      }
90  
91      public void print(double v) throws IOException {
92          buffer.append(v);
93      }
94  
95      public void print(char[] chars) throws IOException {
96          buffer.append(chars);
97      }
98  
99      public void print(String s) throws IOException {
100         buffer.append(s);
101     }
102 
103     public void print(Object o) throws IOException {
104         buffer.append(o);
105     }
106 
107     public void println() throws IOException {
108         newLine();
109     }
110 
111     public void println(boolean b) throws IOException {
112         print(b);
113         newLine();
114     }
115 
116     public void println(char c) throws IOException {
117         print(c);
118         newLine();
119     }
120 
121     public void println(int i) throws IOException {
122         print(i);
123         newLine();
124     }
125 
126     public void println(long l) throws IOException {
127         print(l);
128         newLine();
129     }
130 
131     public void println(float v) throws IOException {
132         print(v);
133         newLine();
134     }
135 
136     public void println(double v) throws IOException {
137         print(v);
138         newLine();
139     }
140 
141     public void println(char[] chars) throws IOException {
142         print(chars);
143         newLine();
144     }
145 
146     public void println(String s) throws IOException {
147         print(s);
148         newLine();
149     }
150 
151     public void println(Object o) throws IOException {
152         print(o);
153         newLine();
154     }
155 
156     /***
157      * Write a portion of an array of characters.
158      *
159      * @param cbuf Array of characters
160      * @param off  Offset from which to start writing characters
161      * @param len  Number of characters to write
162      * @throws IOException If an I/O error occurs
163      */
164     public void write(char[] cbuf, int off, int len) throws IOException {
165         buffer.append(cbuf, off, len);
166     }
167 
168     public void writeOut(Writer writer) throws IOException {
169         writer.write(buffer.toString());
170     }
171 }