KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > JBossActionResponse


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.portlet;
10
11 import javax.portlet.PortletURL;
12
13 import org.jboss.portal.core.output.AuthenticateResult;
14 import org.jboss.portal.server.output.StreamResult;
15 import org.jboss.portal.portlet.PortletUtils;
16 import org.jboss.portal.portlet.impl.ActionResponseImpl;
17 import org.jboss.portal.server.PortalRequest;
18 import org.jboss.portal.server.PortalResponse;
19 import org.jboss.portal.server.ServerURL;
20 import org.jboss.portal.server.Window;
21 import org.jboss.portal.server.WindowContext;
22 import org.jboss.portal.server.output.NoResult;
23 import org.jboss.portal.server.output.StreamResult;
24 import org.jboss.portal.server.util.Properties;
25
26 /**
27  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
28  * @version $Revision: 1.6 $
29  */

30 public class JBossActionResponse extends ActionResponseImpl
31 {
32
33    public JBossActionResponse(
34          WindowContext windowCtx,
35          Window window,
36          PortalRequest req,
37          PortalResponse resp,
38          Properties properties)
39    {
40       super(windowCtx, window, req, resp, properties);
41    }
42
43    /**
44     * The component wants the user to be authenticated to perform the task.
45     * After this has been called all subsequent actions should not be
46     * possible (getWriter()/sendRedirect()/etc...).
47     *
48     * @throws IllegalStateException
49     */

50    public void sendAuthenticate() throws IllegalStateException JavaDoc
51    {
52       if (result instanceof NoResult || result instanceof AuthenticateResult)
53       {
54          if (result instanceof NoResult)
55          {
56             ServerURL url = PortletUtils.createWindowActionURL(resp, window);
57             result = new AuthenticateResult(portletWindowContext, url);
58          }
59       }
60       else
61       {
62          throw new IllegalStateException JavaDoc("Cannot call send authenticate");
63       }
64    }
65
66    public void sendBytes(String JavaDoc contentType, byte[] bytes)
67    {
68       if (result instanceof NoResult)
69       {
70          result = new StreamResult(portletWindowContext, contentType, bytes);
71       }
72       else
73       {
74          throw new IllegalStateException JavaDoc("Cannot call send bytes");
75       }
76    }
77
78    /**
79     * Create a render url.
80     */

81    public PortletURL createRenderURL()
82    {
83       return PortletUtils.createRenderURL(resp, window, req.getContentType());
84    }
85
86    /**
87     * Create an action url.
88     */

89    public PortletURL createActionURL()
90    {
91       return PortletUtils.createActionURL(resp, window, req.getContentType());
92    }
93
94    /**
95     * Create an URL which is absolute to the server and in particular this request.
96     */

97    public String JavaDoc createAbsoluteURL(PortletURL url)
98    {
99       return JBossRenderResponse.createAbsoluteURL(resp, url);
100    }
101 }
102
Popular Tags