KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Map JavaDoc;
12
13 import javax.portlet.PortletMode;
14 import javax.portlet.PortletModeException;
15 import javax.portlet.PortletSecurityException;
16 import javax.portlet.PortletURL;
17 import javax.portlet.WindowState;
18 import javax.portlet.WindowStateException;
19
20 import org.jboss.portal.server.PortalResponse;
21 import org.jboss.portal.server.Window;
22 import org.jboss.portal.server.WindowURL;
23 import org.jboss.portal.server.plugins.mode.Mode;
24 import org.jboss.portal.server.util.Parameters;
25
26 /**
27  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
28  * @version $Revision: 1.7 $
29  */

30 public class PortletURLImpl implements PortletURL
31 {
32
33    private WindowURL windowURL;
34    private Window window;
35    private String JavaDoc contentType;
36    private PortalResponse resp;
37
38    public PortletURLImpl(WindowURL windowURL,
39                          Window window,
40                          String JavaDoc contentType,
41                          PortalResponse resp)
42    {
43       this.windowURL = windowURL;
44       this.window = window;
45       this.contentType = contentType;
46       this.resp = resp;
47    }
48
49    public void setWindowState(WindowState windowState) throws WindowStateException
50    {
51       org.jboss.portal.server.plugins.windowstate.WindowState blah = org.jboss.portal.server.plugins.windowstate.WindowState.create(windowState.toString());
52       if (!window.isSupportedWindowState(blah))
53       {
54          throw new WindowStateException("Not supported", windowState);
55       }
56       windowURL.setWindowState(blah);
57    }
58
59    public void setPortletMode(PortletMode portletMode) throws PortletModeException
60    {
61       if (portletMode == null)
62       {
63          // The spec does not say the behaviour with null argument
64
// we suppose it clear the current mode
65
windowURL.setMode(null);
66       }
67       else
68       {
69          // Check possible
70
Mode mode = Mode.create(portletMode.toString());
71          if (!window.isSupportedMode(
72                contentType,
73                mode))
74          {
75             throw new PortletModeException("Not supported", portletMode);
76          }
77
78          // Set mode
79
windowURL.setMode(mode);
80       }
81    }
82
83    /**
84     * @exception IllegalArgumentException if the name is null
85     */

86    public void setParameter(String JavaDoc name, String JavaDoc value)
87    {
88       // Rely on the portal URL to throw the IllegalArgumentException for the name
89
if (value == null)
90       {
91          throw new IllegalArgumentException JavaDoc("value cannot be null");
92       }
93       windowURL.setTargetParameter(name, value);
94    }
95
96    public void setParameter(String JavaDoc name, String JavaDoc[] values)
97    {
98       // Rely on the portal URL to throw the IllegalArgumentException for the name
99
if (values == null)
100       {
101          throw new IllegalArgumentException JavaDoc("value cannot be null");
102       }
103       windowURL.setTargetParameter(name, values);
104    }
105
106    public void setParameters(Map JavaDoc parameters)
107    {
108       // Rely on the parameters object to throw the IllegalArgumentException
109
Parameters parameterMap = windowURL.getTargetParameters();
110       parameterMap.setParameterMap(parameters);
111    }
112
113    public void setSecure(boolean secure) throws PortletSecurityException
114    {
115       windowURL.setSecure(Boolean.valueOf(secure));
116    }
117
118    public String JavaDoc toString()
119    {
120       return resp.createURL(windowURL, true);
121    }
122 }
123
Popular Tags