01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/portal/tags/sakai_2-4-1/portal-render-impl/impl/src/java/org/sakaiproject/portal/render/portlet/servlet/BufferedServletResponse.java $
03: * $Id: BufferedServletResponse.java 29143 2007-04-19 01:10:38Z ajpoland@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.portal.render.portlet.servlet;
21:
22: import java.io.PrintWriter;
23: import java.io.StringWriter;
24:
25: import javax.servlet.http.HttpServletResponse;
26: import javax.servlet.http.HttpServletResponseWrapper;
27:
28: /**
29: * ServletResponse instance used to buffer content. This buffering allows for
30: * the portlets title to be captured prior to rendering and other similar
31: * features. <p/> NOTE: Access the output stream for this response had
32: * undertermined results. It is expected that in most situations an
33: * IllegalArgumentException will be thrown.
34: *
35: * @since Sakai 2.2.4
36: * @version $Rev: 29143 $
37: */
38: public class BufferedServletResponse extends HttpServletResponseWrapper {
39:
40: /**
41: * The writer to which content will be buffered
42: */
43: private StringWriter buffer = null;
44:
45: /**
46: * The printWriter which will be exposed to the requesting resources.
47: */
48: private PrintWriter writer = null;
49:
50: /**
51: * The default content type for all portlets.
52: */
53: private String contentType = "text/html";
54:
55: /**
56: * Sole Constructor. Initializes the response wrapper and the buffered
57: * writer.
58: *
59: * @param response
60: * the original servlet response.
61: */
62: public BufferedServletResponse(HttpServletResponse response) {
63: super (response);
64: buffer = new StringWriter();
65: writer = new PrintWriter(buffer);
66: }
67:
68: @Override
69: public String getContentType() {
70: return contentType;
71: }
72:
73: @Override
74: public PrintWriter getWriter() {
75: return writer;
76: }
77:
78: /**
79: * Retrieve the buffer.
80: *
81: * @return
82: */
83: public StringWriter getInternalBuffer() {
84: return buffer;
85: }
86: }
|