001: /*
002: * $Id: StrutsBodyContent.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import java.io.IOException;
024: import java.io.Reader;
025: import java.io.StringReader;
026: import java.io.Writer;
027:
028: import javax.servlet.jsp.JspWriter;
029: import javax.servlet.jsp.tagext.BodyContent;
030:
031: /**
032: * StrutsBodyContent
033: */
034: public class StrutsBodyContent extends BodyContent {
035:
036: private StringBuffer buffer = new StringBuffer();
037:
038: public StrutsBodyContent(JspWriter jspWriter) {
039: super (jspWriter);
040: }
041:
042: public Reader getReader() {
043: return new StringReader(buffer.toString());
044: }
045:
046: public int getRemaining() {
047: return 0;
048: }
049:
050: public String getString() {
051: return buffer.toString();
052: }
053:
054: public void clear() throws IOException {
055: buffer = new StringBuffer();
056: }
057:
058: public void clearBuffer() throws IOException {
059: clear();
060: }
061:
062: public void close() throws IOException {
063: buffer = null;
064: }
065:
066: public void newLine() throws IOException {
067: buffer.append("\n");
068: }
069:
070: public void print(boolean b) throws IOException {
071: buffer.append(b);
072: }
073:
074: public void print(char c) throws IOException {
075: buffer.append(c);
076: }
077:
078: public void print(int i) throws IOException {
079: buffer.append(i);
080: }
081:
082: public void print(long l) throws IOException {
083: buffer.append(l);
084: }
085:
086: public void print(float v) throws IOException {
087: buffer.append(v);
088: }
089:
090: public void print(double v) throws IOException {
091: buffer.append(v);
092: }
093:
094: public void print(char[] chars) throws IOException {
095: buffer.append(chars);
096: }
097:
098: public void print(String s) throws IOException {
099: 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: }
|