KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > PortletUtils


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;
10
11 import javax.portlet.PortletMode;
12 import javax.portlet.PortletURL;
13 import javax.portlet.WindowState;
14
15 import org.apache.log4j.Logger;
16 import org.jboss.portal.portlet.impl.PortletURLImpl;
17 import org.jboss.portal.server.PortalResponse;
18 import org.jboss.portal.server.Window;
19 import org.jboss.portal.server.WindowURL;
20
21 /**
22  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
23  * @version $Revision: 1.3 $
24  */

25 public class PortletUtils
26 {
27
28    private static Logger log = Logger.getLogger(PortletUtils.class);
29
30    public static WindowState decodeWindowState(String JavaDoc s)
31    {
32       if (WindowState.NORMAL.toString().equals(s))
33       {
34          return WindowState.NORMAL;
35       }
36       else if (WindowState.MINIMIZED.toString().equals(s))
37       {
38          return WindowState.MINIMIZED;
39       }
40       else if (WindowState.MAXIMIZED.toString().equals(s))
41       {
42          return WindowState.MAXIMIZED;
43       }
44       else
45       {
46          return new WindowState(s);
47       }
48    }
49
50    public static PortletMode decodePortletMode(String JavaDoc s)
51    {
52       if (PortletMode.EDIT.toString().equalsIgnoreCase(s))
53       {
54          return PortletMode.EDIT;
55       }
56       else if (PortletMode.HELP.toString().equalsIgnoreCase(s))
57       {
58          return PortletMode.HELP;
59       }
60       else if (PortletMode.VIEW.toString().equalsIgnoreCase(s))
61       {
62          return PortletMode.VIEW;
63       }
64       else
65       {
66          return new PortletMode(s);
67       }
68    }
69
70    /**
71     * Creates an action URL.
72     */

73    public static PortletURL createActionURL(
74          PortalResponse resp,
75          Window window,
76          String JavaDoc contentType)
77    {
78       return new PortletURLImpl(createWindowActionURL(resp, window), window, contentType, resp);
79    }
80
81    /**
82     * Creates an render URL.
83     */

84    public static PortletURL createRenderURL(
85          PortalResponse resp,
86          Window window,
87          String JavaDoc contentType)
88    {
89       WindowURL portalURL = createWindowRenderURL(resp, window);
90       return new PortletURLImpl(portalURL, window, contentType, resp);
91    }
92
93    /**
94     * Creates an action URL.
95     */

96    public static WindowURL createWindowActionURL(
97          PortalResponse resp,
98          Window window)
99    {
100       WindowURL windowURL = (WindowURL)window.createURL();
101       windowURL.setType(WindowURL.TYPE_ACTION);
102       return windowURL;
103    }
104
105    /**
106     * Creates an render URL.
107     */

108    public static WindowURL createWindowRenderURL(
109          PortalResponse resp,
110          Window window)
111    {
112       WindowURL windowURL = (WindowURL)window.createURL();
113       windowURL.setType(WindowURL.TYPE_RENDER);
114       return windowURL;
115    }
116
117    public static PortletURL createUpdateWindowStateURL(
118          PortalResponse resp,
119          Window window,
120          String JavaDoc contentType)
121    {
122       return createNavigationURL(resp, window, contentType);
123    }
124
125    public static PortletURL createUpdatePortletModeURL(
126          PortalResponse resp,
127          Window window,
128          String JavaDoc contentType)
129    {
130       return createNavigationURL(resp, window, contentType);
131    }
132
133    public static PortletURL createNavigationURL(
134          PortalResponse resp,
135          Window window,
136          String JavaDoc contentType)
137    {
138       WindowURL windowURL = (WindowURL)window.createURL();
139       windowURL.setType(WindowURL.TYPE_NAVIGATION);
140       return new PortletURLImpl(windowURL, window, contentType, resp);
141    }
142 }
143
Popular Tags