KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jboss.portal.portlet.impl.RenderResponseImpl;
12 import org.jboss.portal.portlet.impl.PortletURLImpl;
13 import org.jboss.portal.server.PortalRequest;
14 import org.jboss.portal.server.PortalResponse;
15 import org.jboss.portal.server.Window;
16 import org.jboss.portal.server.WindowContext;
17 import org.jboss.portal.server.WindowURL;
18 import org.jboss.portal.server.output.FragmentResult;
19 import org.jboss.portal.server.util.Properties;
20
21 import javax.portlet.PortletURL;
22 import java.lang.reflect.Field JavaDoc;
23
24 /**
25  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
26  * @version $Revision: 1.4 $
27  */

28 public class JBossRenderResponse extends RenderResponseImpl
29 {
30    public JBossRenderResponse(
31          Window window,
32          WindowContext windowContext,
33          PortalRequest req,
34          PortalResponse resp,
35          FragmentResult result,
36          Properties properties)
37    {
38       super(window, windowContext, req, resp, result, properties);
39    }
40
41    /**
42     * Create an URL which is absolute to the server and in particular this request.
43     */

44    public String JavaDoc createAbsoluteURL(PortletURL url)
45    {
46       return createAbsoluteURL(resp, url);
47    }
48
49    //
50

51    static String JavaDoc createAbsoluteURL(PortalResponse resp, PortletURL url)
52    {
53       if (url == null)
54       {
55          throw new IllegalArgumentException JavaDoc("No null URL accepted");
56       }
57
58       // We assume that the PortletURL object is an instance of PortletURLImpl
59
try
60       {
61          Field JavaDoc f = ((PortletURLImpl)url).getClass().getDeclaredField("windowURL");
62          if (!f.isAccessible())
63          {
64             f.setAccessible(true);
65          }
66          WindowURL windowURL = (WindowURL)f.get(url);
67          return resp.createURL(windowURL, false);
68       }
69       catch (NoSuchFieldException JavaDoc e)
70       {
71          IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc("No windowURL field on portlet url");
72          iae.initCause(e);
73          throw iae;
74       }
75       catch (IllegalAccessException JavaDoc e)
76       {
77          IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc("Cannot have access to the windowURL field");
78          iae.initCause(e);
79          throw iae;
80       }
81    }
82 }
83
Popular Tags