001    /**
002     * Copyright (c) 2000-present 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.taglib;
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
031            extends BodyContent
032            implements com.liferay.portal.kernel.servlet.taglib.BodyContentWrapper {
033    
034            public BodyContentWrapper(
035                    BodyContent bodyContent, UnsyncStringWriter unsyncStringWriter) {
036    
037                    super(bodyContent.getEnclosingWriter());
038    
039                    _bodyContent = bodyContent;
040                    _unsyncStringWriter = unsyncStringWriter;
041            }
042    
043            @Override
044            public Writer append(char c) throws IOException {
045                    return _bodyContent.append(c);
046            }
047    
048            @Override
049            public Writer append(CharSequence charSequence) throws IOException {
050                    return _bodyContent.append(charSequence);
051            }
052    
053            @Override
054            public Writer append(CharSequence charSequence, int start, int end)
055                    throws IOException {
056    
057                    return _bodyContent.append(charSequence, start, end);
058            }
059    
060            @Override
061            public void clear() throws IOException {
062                    _bodyContent.clear();
063            }
064    
065            @Override
066            public void clearBody() {
067                    _unsyncStringWriter.reset();
068            }
069    
070            @Override
071            public void clearBuffer() {
072                    _unsyncStringWriter.reset();
073            }
074    
075            @Override
076            public void close() throws IOException {
077                    _bodyContent.close();
078            }
079    
080            @Override
081            public void flush() throws IOException {
082                    _bodyContent.flush();
083            }
084    
085            @Override
086            public int getBufferSize() {
087                    return _bodyContent.getBufferSize();
088            }
089    
090            @Override
091            public JspWriter getEnclosingWriter() {
092                    return _bodyContent.getEnclosingWriter();
093            }
094    
095            @Override
096            public Reader getReader() {
097                    return _bodyContent.getReader();
098            }
099    
100            @Override
101            public int getRemaining() {
102                    return _bodyContent.getRemaining();
103            }
104    
105            @Override
106            public String getString() {
107                    return _unsyncStringWriter.toString();
108            }
109    
110            @Override
111            public StringBundler getStringBundler() {
112                    return _unsyncStringWriter.getStringBundler();
113            }
114    
115            @Override
116            public boolean isAutoFlush() {
117                    return _bodyContent.isAutoFlush();
118            }
119    
120            @Override
121            public void newLine() throws IOException {
122                    _bodyContent.newLine();
123            }
124    
125            @Override
126            public void print(boolean b) throws IOException {
127                    _bodyContent.print(b);
128            }
129    
130            @Override
131            public void print(char c) throws IOException {
132                    _bodyContent.print(c);
133            }
134    
135            @Override
136            public void print(char[] chars) throws IOException {
137                    _bodyContent.print(chars);
138            }
139    
140            @Override
141            public void print(double d) throws IOException {
142                    _bodyContent.print(d);
143            }
144    
145            @Override
146            public void print(float f) throws IOException {
147                    _bodyContent.print(f);
148            }
149    
150            @Override
151            public void print(int i) throws IOException {
152                    _bodyContent.print(i);
153            }
154    
155            @Override
156            public void print(long l) throws IOException {
157                    _bodyContent.print(l);
158            }
159    
160            @Override
161            public void print(Object object) throws IOException {
162                    _bodyContent.print(object);
163            }
164    
165            @Override
166            public void print(String string) throws IOException {
167                    _bodyContent.print(string);
168            }
169    
170            @Override
171            public void println() throws IOException {
172                    _bodyContent.println();
173            }
174    
175            @Override
176            public void println(boolean b) throws IOException {
177                    _bodyContent.println(b);
178            }
179    
180            @Override
181            public void println(char c) throws IOException {
182                    _bodyContent.println(c);
183            }
184    
185            @Override
186            public void println(char[] chars) throws IOException {
187                    _bodyContent.println(chars);
188            }
189    
190            @Override
191            public void println(double d) throws IOException {
192                    _bodyContent.println(d);
193            }
194    
195            @Override
196            public void println(float f) throws IOException {
197                    _bodyContent.println(f);
198            }
199    
200            @Override
201            public void println(int i) throws IOException {
202                    _bodyContent.println(i);
203            }
204    
205            @Override
206            public void println(long l) throws IOException {
207                    _bodyContent.println(l);
208            }
209    
210            @Override
211            public void println(Object object) throws IOException {
212                    _bodyContent.println(object);
213            }
214    
215            @Override
216            public void println(String string) throws IOException {
217                    _bodyContent.println(string);
218            }
219    
220            @Override
221            public void write(char[] chars) throws IOException {
222                    _bodyContent.write(chars);
223            }
224    
225            @Override
226            public void write(char[] chars, int offset, int length) throws IOException {
227                    _bodyContent.write(chars, offset, length);
228            }
229    
230            @Override
231            public void write(int c) throws IOException {
232                    _bodyContent.write(c);
233            }
234    
235            @Override
236            public void write(String string) throws IOException {
237                    _bodyContent.write(string);
238            }
239    
240            @Override
241            public void write(String string, int offset, int length)
242                    throws IOException {
243    
244                    _bodyContent.write(string, offset, length);
245            }
246    
247            @Override
248            public void writeOut(Writer writer) throws IOException {
249                    _bodyContent.writeOut(writer);
250            }
251    
252            private final BodyContent _bodyContent;
253            private final UnsyncStringWriter _unsyncStringWriter;
254    
255    }