KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > servlet > http > StringResponseWrapper


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.servlet.http;
8
9 import java.io.PrintWriter JavaDoc;
10 import java.io.StringWriter JavaDoc;
11
12 import javax.servlet.http.HttpServletResponse JavaDoc;
13 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
14
15 /**
16  * A Response wrapper that allows the manipulation of the Servlet Response.
17  * <p>Create a buffer based on a String.</p>
18  *
19  * @author Laurent Etiemble
20  * @version $Revision: 1.3 $
21  */

22 public class StringResponseWrapper extends HttpServletResponseWrapper JavaDoc
23 {
24    /** Buffer used to store content */
25    protected StringWriter JavaDoc output = null;
26
27
28    /**
29     * Constructor for the StringResponseWrapper object
30     *
31     * @param response Response stream to wrap
32     */

33    public StringResponseWrapper(HttpServletResponse JavaDoc response)
34    {
35       super(response);
36       output = new StringWriter JavaDoc();
37    }
38
39
40    /**
41     * Return a writer that wraps the buffered content
42     *
43     * @return The writer of the wrapper
44     */

45    public PrintWriter JavaDoc getWriter()
46    {
47       return new PrintWriter JavaDoc(output);
48    }
49
50
51    /**
52     * Return the content of the buffer
53     *
54     * @return The content as String
55     */

56    public String JavaDoc toString()
57    {
58       return output.toString();
59    }
60 }
61
Popular Tags