KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > impl > RenderResponseImpl


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.impl;
10
11 import java.io.IOException JavaDoc;
12 import java.io.OutputStream JavaDoc;
13 import java.io.PrintWriter JavaDoc;
14 import java.util.Locale JavaDoc;
15
16 import javax.portlet.PortletURL;
17 import javax.portlet.RenderResponse;
18
19 import org.jboss.portal.portlet.PortletUtils;
20 import org.jboss.portal.server.PortalRequest;
21 import org.jboss.portal.server.PortalResponse;
22 import org.jboss.portal.server.Window;
23 import org.jboss.portal.server.WindowContext;
24 import org.jboss.portal.server.output.FragmentResult;
25 import org.jboss.portal.server.util.Properties;
26
27 /**
28  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
29  * @version $Revision: 1.8 $
30  */

31 public class RenderResponseImpl extends PortletResponseImpl implements RenderResponse
32 {
33
34    protected Window window;
35    protected PortalRequest req;
36    protected PortalResponse resp;
37    protected FragmentResult result;
38
39    public RenderResponseImpl(
40          Window window,
41          WindowContext windowCtx,
42          PortalRequest req,
43          PortalResponse resp,
44          FragmentResult result,
45          Properties properties)
46    {
47       super(req, resp, properties);
48       this.window = window;
49       this.req = req;
50       this.resp = resp;
51       this.result = result;
52    }
53
54    public void setTitle(String JavaDoc s)
55    {
56       result.setTitle(s);
57    }
58
59    public String JavaDoc getContentType()
60    {
61       return result.getContentType();
62    }
63
64    public void setContentType(String JavaDoc contentType)
65    {
66       int index = contentType.indexOf(';');
67       if (index != -1)
68       {
69          contentType = contentType.substring(0, index);
70       }
71       String JavaDoc responseContentType = resp.getContentType();
72       if (!responseContentType.equals(contentType))
73       {
74          throw new IllegalArgumentException JavaDoc("Content type not accepted");
75       }
76       result.setContentType(contentType);
77    }
78
79    public PrintWriter JavaDoc getWriter() throws IOException JavaDoc
80    {
81       return result.getWriter();
82    }
83
84    public OutputStream JavaDoc getPortletOutputStream() throws IOException JavaDoc
85    {
86       return result.getOutputStream();
87    }
88
89    public PortletURL createRenderURL()
90    {
91       String JavaDoc contentType = resp.getContentType();
92       return PortletUtils.createRenderURL(resp, window, contentType);
93    }
94
95    public PortletURL createActionURL()
96    {
97       String JavaDoc contentType = resp.getContentType();
98       return PortletUtils.createActionURL(resp, window, contentType);
99    }
100
101    public String JavaDoc getNamespace()
102    {
103       return "handleMetaDataEvent";
104    }
105
106    public String JavaDoc getCharacterEncoding()
107    {
108       // julien : for now we return UTF-8
109
return "UTF-8";
110    }
111
112    public Locale JavaDoc getLocale()
113    {
114       return req.getLocale();
115    }
116
117    public void setBufferSize(int i)
118    {
119       // Ignore it, it's just a wish
120
}
121
122    public int getBufferSize()
123    {
124       // 0 means no buffering - we say no buffering
125
return 0;
126    }
127
128    public void flushBuffer() throws IOException JavaDoc
129    {
130    }
131
132    public void resetBuffer()
133    {
134       // Clear the buffer
135
result.resetBuffer();
136    }
137
138    public void reset()
139    {
140       // Clear the buffer
141
result.resetBuffer();
142
143       // And properties
144
properties.clear();
145    }
146
147    public boolean isCommitted()
148    {
149       // Never afterCommit
150
return false;
151    }
152 }
153
Popular Tags