001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.servlet;
016    
017    import com.liferay.portal.kernel.io.unsync.UnsyncStringWriter;
018    import com.liferay.portal.kernel.util.StringBundler;
019    
020    import java.io.IOException;
021    import java.io.Reader;
022    import java.io.Writer;
023    
024    import javax.servlet.jsp.JspWriter;
025    import javax.servlet.jsp.tagext.BodyContent;
026    
027    /**
028     * @author Shuyang Zhou
029     */
030    public class BodyContentWrapper extends BodyContent {
031    
032            public BodyContentWrapper(
033                    BodyContent bodyContent, UnsyncStringWriter unsyncStringWriter) {
034    
035                    super(bodyContent.getEnclosingWriter());
036    
037                    _bodyContent = bodyContent;
038                    _unsyncStringWriter = unsyncStringWriter;
039            }
040    
041            public Writer append(char c) throws IOException {
042                    return _bodyContent.append(c);
043            }
044    
045            public Writer append(CharSequence charSequence) throws IOException {
046                    return _bodyContent.append(charSequence);
047            }
048    
049            public Writer append(CharSequence charSequence, int start, int end)
050                    throws IOException {
051    
052                    return _bodyContent.append(charSequence, start, end);
053            }
054    
055            public void clear() throws IOException {
056                    _bodyContent.clear();
057            }
058    
059            public void clearBody() {
060                    _unsyncStringWriter.reset();
061            }
062    
063            public void clearBuffer() {
064                    _unsyncStringWriter.reset();
065            }
066    
067            public void close() throws IOException {
068                    _bodyContent.close();
069            }
070    
071            public void flush() throws IOException {
072                    _bodyContent.flush();
073            }
074    
075            public int getBufferSize() {
076                    return _bodyContent.getBufferSize();
077            }
078    
079            public JspWriter getEnclosingWriter() {
080                    return _bodyContent.getEnclosingWriter();
081            }
082    
083            public Reader getReader() {
084                    return _bodyContent.getReader();
085            }
086    
087            public int getRemaining() {
088                    return _bodyContent.getRemaining();
089            }
090    
091            public String getString() {
092                    return _unsyncStringWriter.toString();
093            }
094    
095            public StringBundler getStringBundler() {
096                    return _unsyncStringWriter.getStringBundler();
097            }
098    
099            public boolean isAutoFlush() {
100                    return _bodyContent.isAutoFlush();
101            }
102    
103            public void newLine() throws IOException {
104                    _bodyContent.newLine();
105            }
106    
107            public void print(boolean b) throws IOException {
108                    _bodyContent.print(b);
109            }
110    
111            public void print(char c) throws IOException {
112                    _bodyContent.print(c);
113            }
114    
115            public void print(char[] chars) throws IOException {
116                    _bodyContent.print(chars);
117            }
118    
119            public void print(double d) throws IOException {
120                    _bodyContent.print(d);
121            }
122    
123            public void print(float f) throws IOException {
124                    _bodyContent.print(f);
125            }
126    
127            public void print(int i) throws IOException {
128                    _bodyContent.print(i);
129            }
130    
131            public void print(long l) throws IOException {
132                    _bodyContent.print(l);
133            }
134    
135            public void print(Object object) throws IOException {
136                    _bodyContent.print(object);
137            }
138    
139            public void print(String string) throws IOException {
140                    _bodyContent.print(string);
141            }
142    
143            public void println() throws IOException {
144                    _bodyContent.println();
145            }
146    
147            public void println(boolean b) throws IOException {
148                    _bodyContent.println(b);
149            }
150    
151            public void println(char c) throws IOException {
152                    _bodyContent.println(c);
153            }
154    
155            public void println(char[] charArray) throws IOException {
156                    _bodyContent.println(charArray);
157            }
158    
159            public void println(double d) throws IOException {
160                    _bodyContent.println(d);
161            }
162    
163            public void println(float f) throws IOException {
164                    _bodyContent.println(f);
165            }
166    
167            public void println(int i) throws IOException {
168                    _bodyContent.println(i);
169            }
170    
171            public void println(long l) throws IOException {
172                    _bodyContent.println(l);
173            }
174    
175            public void println(Object object) throws IOException {
176                    _bodyContent.println(object);
177            }
178    
179            public void println(String string) throws IOException {
180                    _bodyContent.println(string);
181            }
182    
183            public void write(char[] charArray) throws IOException {
184                    _bodyContent.write(charArray);
185            }
186    
187            public void write(char[] charArray, int offset, int length)
188                    throws IOException {
189    
190                    _bodyContent.write(charArray, offset, length);
191            }
192    
193            public void write(int c) throws IOException {
194                    _bodyContent.write(c);
195            }
196    
197            public void write(String string) throws IOException {
198                    _bodyContent.write(string);
199            }
200    
201            public void write(String string, int offset, int length)
202                    throws IOException {
203    
204                    _bodyContent.write(string, offset, length);
205            }
206    
207            public void writeOut(Writer writer) throws IOException {
208                    _bodyContent.writeOut(writer);
209            }
210    
211            private BodyContent _bodyContent;
212            private UnsyncStringWriter _unsyncStringWriter;
213    
214    }