This project has retired. For details please refer to its Attic page.
JspPrintWriterAdapter xref
View Javadoc

1   /*
2    * $Id: JspPrintWriterAdapter.java 791161 2009-07-04 18:53:36Z 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  package org.apache.tiles.jsp.context;
22  
23  import java.io.IOException;
24  import java.io.PrintWriter;
25  
26  import javax.servlet.jsp.JspWriter;
27  
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  /***
32   * Adapts a {@link JspWriter} to a {@link PrintWriter}, swallowing {@link IOException}.
33   *
34   * @version $Rev: 791161 $ $Date: 2009-07-04 20:53:36 +0200 (sab, 04 lug 2009) $
35   * @since 2.1.2
36   */
37  public class JspPrintWriterAdapter extends PrintWriter {
38  
39      /***
40       * The JSP writer.
41       */
42      private JspWriter writer;
43  
44      /***
45       * The logging object.
46       */
47      private final Logger log = LoggerFactory.getLogger(this.getClass());
48  
49      /***
50       * Constructor.
51       *
52       * @param writer The JSP writer.
53       * @since 2.1.2
54       */
55      public JspPrintWriterAdapter(JspWriter writer) {
56          super(writer);
57          this.writer = writer;
58      }
59  
60      /***
61       * Returns the original JSP writer.
62       *
63       * @return The JSP writer.
64       * @since 2.1.2
65       */
66      public JspWriter getJspWriter() {
67          return writer;
68      }
69  
70      /*** {@inheritDoc} */
71      @Override
72      public PrintWriter append(char c) {
73          try {
74              writer.append(c);
75          } catch (IOException e) {
76              log.error("Error when writing in JspWriter", e);
77              setError();
78          }
79          return this;
80      }
81  
82      /*** {@inheritDoc} */
83      @Override
84      public PrintWriter append(CharSequence csq, int start, int end) {
85          try {
86              writer.append(csq, start, end);
87          } catch (IOException e) {
88              log.error("Error when writing in JspWriter", e);
89              setError();
90          }
91          return this;
92      }
93  
94      /*** {@inheritDoc} */
95      @Override
96      public PrintWriter append(CharSequence csq) {
97          try {
98              writer.append(csq);
99          } catch (IOException e) {
100             log.error("Error when writing in JspWriter", e);
101             setError();
102         }
103         return this;
104     }
105 
106     /*** {@inheritDoc} */
107     @Override
108     public void close() {
109         try {
110             writer.close();
111         } catch (IOException e) {
112             log.error("Error when writing in JspWriter", e);
113             setError();
114         }
115     }
116 
117     /*** {@inheritDoc} */
118     @Override
119     public void flush() {
120         try {
121             writer.flush();
122         } catch (IOException e) {
123             log.error("Error when writing in JspWriter", e);
124             setError();
125         }
126     }
127 
128     /*** {@inheritDoc} */
129     @Override
130     public void print(boolean b) {
131         try {
132             writer.print(b);
133         } catch (IOException e) {
134             log.error("Error when writing in JspWriter", e);
135             setError();
136         }
137     }
138 
139     /*** {@inheritDoc} */
140     @Override
141     public void print(char c) {
142         try {
143             writer.print(c);
144         } catch (IOException e) {
145             log.error("Error when writing in JspWriter", e);
146             setError();
147         }
148     }
149 
150     /*** {@inheritDoc} */
151     @Override
152     public void print(char[] s) {
153         try {
154             writer.print(s);
155         } catch (IOException e) {
156             log.error("Error when writing in JspWriter", e);
157             setError();
158         }
159     }
160 
161     /*** {@inheritDoc} */
162     @Override
163     public void print(double d) {
164         try {
165             writer.print(d);
166         } catch (IOException e) {
167             log.error("Error when writing in JspWriter", e);
168             setError();
169         }
170     }
171 
172     /*** {@inheritDoc} */
173     @Override
174     public void print(float f) {
175         try {
176             writer.print(f);
177         } catch (IOException e) {
178             log.error("Error when writing in JspWriter", e);
179             setError();
180         }
181     }
182 
183     /*** {@inheritDoc} */
184     @Override
185     public void print(int i) {
186         try {
187             writer.print(i);
188         } catch (IOException e) {
189             log.error("Error when writing in JspWriter", e);
190             setError();
191         }
192     }
193 
194     /*** {@inheritDoc} */
195     @Override
196     public void print(long l) {
197         try {
198             writer.print(l);
199         } catch (IOException e) {
200             log.error("Error when writing in JspWriter", e);
201             setError();
202         }
203     }
204 
205     /*** {@inheritDoc} */
206     @Override
207     public void print(Object obj) {
208         try {
209             writer.print(obj);
210         } catch (IOException e) {
211             log.error("Error when writing in JspWriter", e);
212             setError();
213         }
214     }
215 
216     /*** {@inheritDoc} */
217     @Override
218     public void print(String s) {
219         try {
220             writer.print(s);
221         } catch (IOException e) {
222             log.error("Error when writing in JspWriter", e);
223             setError();
224         }
225     }
226 
227     /*** {@inheritDoc} */
228     @Override
229     public void println() {
230         try {
231             writer.println();
232         } catch (IOException e) {
233             log.error("Error when writing in JspWriter", e);
234             setError();
235         }
236     }
237 
238     /*** {@inheritDoc} */
239     @Override
240     public void println(boolean x) {
241         try {
242             writer.println(x);
243         } catch (IOException e) {
244             log.error("Error when writing in JspWriter", e);
245             setError();
246         }
247     }
248 
249     /*** {@inheritDoc} */
250     @Override
251     public void println(char x) {
252         try {
253             writer.println(x);
254         } catch (IOException e) {
255             log.error("Error when writing in JspWriter", e);
256             setError();
257         }
258     }
259 
260     /*** {@inheritDoc} */
261     @Override
262     public void println(char[] x) {
263         try {
264             writer.println(x);
265         } catch (IOException e) {
266             log.error("Error when writing in JspWriter", e);
267             setError();
268         }
269     }
270 
271     /*** {@inheritDoc} */
272     @Override
273     public void println(double x) {
274         try {
275             writer.println(x);
276         } catch (IOException e) {
277             log.error("Error when writing in JspWriter", e);
278             setError();
279         }
280     }
281 
282     /*** {@inheritDoc} */
283     @Override
284     public void println(float x) {
285         try {
286             writer.println(x);
287         } catch (IOException e) {
288             log.error("Error when writing in JspWriter", e);
289             setError();
290         }
291     }
292 
293     /*** {@inheritDoc} */
294     @Override
295     public void println(int x) {
296         try {
297             writer.println(x);
298         } catch (IOException e) {
299             log.error("Error when writing in JspWriter", e);
300             setError();
301         }
302     }
303 
304     /*** {@inheritDoc} */
305     @Override
306     public void println(long x) {
307         try {
308             writer.println(x);
309         } catch (IOException e) {
310             log.error("Error when writing in JspWriter", e);
311             setError();
312         }
313     }
314 
315     /*** {@inheritDoc} */
316     @Override
317     public void println(Object x) {
318         try {
319             writer.println(x);
320         } catch (IOException e) {
321             log.error("Error when writing in JspWriter", e);
322             setError();
323         }
324     }
325 
326     /*** {@inheritDoc} */
327     @Override
328     public void println(String x) {
329         try {
330             writer.println(x);
331         } catch (IOException e) {
332             log.error("Error when writing in JspWriter", e);
333             setError();
334         }
335     }
336 
337     /*** {@inheritDoc} */
338     @Override
339     public void write(char[] buf, int off, int len) {
340         try {
341             writer.write(buf, off, len);
342         } catch (IOException e) {
343             log.error("Error when writing in JspWriter", e);
344             setError();
345         }
346     }
347 
348     /*** {@inheritDoc} */
349     @Override
350     public void write(char[] buf) {
351         try {
352             writer.write(buf);
353         } catch (IOException e) {
354             log.error("Error when writing in JspWriter", e);
355             setError();
356         }
357     }
358 
359     /*** {@inheritDoc} */
360     @Override
361     public void write(int c) {
362         try {
363             writer.write(c);
364         } catch (IOException e) {
365             log.error("Error when writing in JspWriter", e);
366             setError();
367         }
368     }
369 
370     /*** {@inheritDoc} */
371     @Override
372     public void write(String s, int off, int len) {
373         try {
374             writer.write(s, off, len);
375         } catch (IOException e) {
376             log.error("Error when writing in JspWriter", e);
377             setError();
378         }
379     }
380 
381     /*** {@inheritDoc} */
382     @Override
383     public void write(String s) {
384         try {
385             writer.write(s);
386         } catch (IOException e) {
387             log.error("Error when writing in JspWriter", e);
388             setError();
389         }
390     }
391 }