KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > bridge > BridgeResponse


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.bridge;
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.RenderResponse;
17 import javax.portlet.PortletResponse;
18 import javax.servlet.ServletOutputStream JavaDoc;
19 import javax.servlet.http.Cookie JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.jboss.portal.server.PortalResponse;
23 import org.jboss.portal.server.PortalRequest;
24
25 /**
26  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
27  * @version $Revision: 1.1.1.1 $
28  */

29 public class BridgeResponse implements HttpServletResponse JavaDoc
30 {
31
32    protected final PortalRequest preq;
33    protected final PortalResponse presp;
34    protected final PortletResponse resp;
35    protected final HttpServletResponse JavaDoc hresp;
36
37    protected ServletOutputStream JavaDoc sos;
38
39    public BridgeResponse(PortalRequest preq, PortalResponse presp, PortletResponse resp, HttpServletResponse JavaDoc hresp)
40    {
41       this.preq = preq;
42       this.presp = presp;
43       this.resp = resp;
44       this.hresp = hresp;
45       this.sos = null;
46    }
47
48    public String JavaDoc encodeRedirectURL(String JavaDoc s)
49    {
50       return null;
51    }
52
53    public String JavaDoc encodeRedirectUrl(String JavaDoc s)
54    {
55       return null;
56    }
57
58    public String JavaDoc getCharacterEncoding()
59    {
60       return "UTF-8";
61    }
62
63    public void setBufferSize(int i)
64    {
65       if (resp instanceof RenderResponse)
66       {
67          ((RenderResponse)resp).setBufferSize(i);
68       }
69       else
70       {
71          throw new IllegalStateException JavaDoc("setBufferSize called on non render response");
72       }
73    }
74
75    public void flushBuffer() throws IOException JavaDoc
76    {
77       if (resp instanceof RenderResponse)
78       {
79          ((RenderResponse)resp).flushBuffer();
80       }
81       else
82       {
83          throw new IllegalStateException JavaDoc("flushBuffer called on non render response");
84       }
85    }
86
87    public void resetBuffer()
88    {
89       if (resp instanceof RenderResponse)
90       {
91          ((RenderResponse)resp).resetBuffer();
92       }
93       else
94       {
95          throw new IllegalStateException JavaDoc("resetBuffer called on non render response");
96       }
97    }
98
99    public void reset()
100    {
101       if (resp instanceof RenderResponse)
102       {
103          ((RenderResponse)resp).reset();
104       }
105       else
106       {
107          throw new IllegalStateException JavaDoc("reset called on non render response");
108       }
109    }
110
111    public int getBufferSize()
112    {
113       if (resp instanceof RenderResponse)
114       {
115          return ((RenderResponse)resp).getBufferSize();
116       }
117       throw new IllegalStateException JavaDoc("getBufferSize called on non render response");
118    }
119
120    public boolean isCommitted()
121    {
122       if (resp instanceof RenderResponse)
123       {
124          return ((RenderResponse)resp).isCommitted();
125       }
126       throw new IllegalStateException JavaDoc("isCommited called on non render response");
127    }
128
129    public ServletOutputStream JavaDoc getOutputStream() throws IOException JavaDoc
130    {
131       if (sos == null)
132       {
133          if (resp instanceof RenderResponse)
134          {
135             sos = new ServletOutputStream JavaDoc()
136             {
137                private OutputStream JavaDoc out = ((RenderResponse)resp).getPortletOutputStream();
138                public void write(byte b[], int off, int len) throws IOException JavaDoc
139                {
140                   out.write(b, off, len);
141                }
142                public void write(byte b[]) throws IOException JavaDoc
143                {
144                   out.write(b);
145                }
146                public void write(int b) throws IOException JavaDoc
147                {
148                   out.write(b);
149                }
150             };
151          }
152          else
153          {
154             throw new IllegalStateException JavaDoc("getOutputStream called on non render response");
155          }
156       }
157       return sos;
158    }
159
160    public PrintWriter JavaDoc getWriter() throws IOException JavaDoc
161    {
162       if (resp instanceof RenderResponse)
163       {
164          RenderResponse rresp = (RenderResponse)resp;
165          if (rresp.getContentType() == null)
166          {
167             //
168
rresp.setContentType("text/html");
169          }
170          return rresp.getWriter();
171       }
172       throw new IllegalStateException JavaDoc("getWriter called on non render response");
173    }
174
175    public String JavaDoc encodeURL(String JavaDoc s)
176    {
177       // URL may not start with / or http:// so we need to defer it to the real response
178
// PortletResponse would throw an IllegalArgumentException
179
return hresp.encodeURL(s);
180    }
181
182    public String JavaDoc encodeUrl(String JavaDoc s)
183    {
184       return hresp.encodeURL(s);
185    }
186
187    // Must perform no operations
188

189    public void setContentType(String JavaDoc mimeType)
190    {
191       if (resp instanceof RenderResponse)
192       {
193          ((RenderResponse)resp).setContentType(mimeType);
194       }
195       else
196       {
197          throw new IllegalStateException JavaDoc("setContentType called on non render response");
198       }
199    }
200
201    public void setContentLength(int i)
202    {
203    }
204
205    public void setLocale(Locale JavaDoc locale)
206    {
207    }
208
209    public void addCookie(Cookie JavaDoc cookie)
210    {
211    }
212
213    public void sendError(int i) throws IOException JavaDoc
214    {
215    }
216
217    public void sendError(int i, String JavaDoc s) throws IOException JavaDoc
218    {
219    }
220
221    public void sendRedirect(String JavaDoc s) throws IOException JavaDoc
222    {
223    }
224
225    public void setDateHeader(String JavaDoc s, long l)
226    {
227    }
228
229    public void addDateHeader(String JavaDoc s, long l)
230    {
231    }
232
233    public void setHeader(String JavaDoc s, String JavaDoc s1)
234    {
235    }
236
237    public void addHeader(String JavaDoc s, String JavaDoc s1)
238    {
239    }
240
241    public void setIntHeader(String JavaDoc s, int i)
242    {
243    }
244
245    public void addIntHeader(String JavaDoc s, int i)
246    {
247    }
248
249    public void setStatus(int i)
250    {
251    }
252
253    public void setStatus(int i, String JavaDoc s)
254    {
255    }
256
257    public boolean containsHeader(String JavaDoc s)
258    {
259       return false;
260    }
261
262    public Locale JavaDoc getLocale()
263    {
264       return preq.getLocale();
265    }
266
267    public String JavaDoc getContentType()
268    {
269       throw new UnsupportedOperationException JavaDoc();
270    }
271
272    public void setCharacterEncoding(String JavaDoc s)
273    {
274       throw new UnsupportedOperationException JavaDoc();
275    }
276 }
277
278
Popular Tags