1 | /* |
2 | * Copyright 2004 The Apache Software Foundation. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.apache.pluto.driver.tags; |
17 | |
18 | import java.io.IOException; |
19 | |
20 | import javax.portlet.PortletMode; |
21 | import javax.portlet.WindowState; |
22 | import javax.servlet.http.HttpServletRequest; |
23 | import javax.servlet.jsp.JspException; |
24 | import javax.servlet.jsp.tagext.BodyTagSupport; |
25 | import javax.servlet.jsp.tagext.TagSupport; |
26 | |
27 | import org.apache.pluto.driver.url.PortalURL; |
28 | import org.apache.pluto.driver.url.PortalURLFactory; |
29 | |
30 | /** |
31 | * The portlet URL tag is used to generate portal URL pointing to the current |
32 | * portlet with specified portlet mode and window state. |
33 | * |
34 | * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a> |
35 | * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a> |
36 | * @version 1.0 |
37 | * @since Oct 4, 2004 |
38 | */ |
39 | public class PortletPortalURLTag extends BodyTagSupport { |
40 | |
41 | // Private Member Variables ------------------------------------------------ |
42 | |
43 | /** The window state to be encoded in the portal URL. */ |
44 | private String windowState = null; |
45 | |
46 | /** The portlet mode to be encoded in the portal URL. */ |
47 | private String portletMode = null; |
48 | |
49 | |
50 | // Tag Attribute Accessors ------------------------------------------------- |
51 | |
52 | public String getWindowState() { |
53 | return windowState; |
54 | } |
55 | |
56 | public void setWindowState(String windowState) { |
57 | this.windowState = windowState; |
58 | } |
59 | |
60 | public String getPortletMode() { |
61 | return portletMode; |
62 | } |
63 | |
64 | public void setPortletMode(String portletMode) { |
65 | this.portletMode = portletMode; |
66 | } |
67 | |
68 | |
69 | // BodyTagSupport Impl ----------------------------------------------------- |
70 | |
71 | /** |
72 | * Creates the portal URL pointing to the current portlet with specified |
73 | * portlet mode and window state, and print the URL to the page. |
74 | * @see PortletTag |
75 | */ |
76 | public int doStartTag() throws JspException { |
77 | |
78 | // Ensure that the portlet render tag resides within a portlet tag. |
79 | PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass( |
80 | this, PortletTag.class); |
81 | if (parentTag == null) { |
82 | throw new JspException("Portlet window controls may only reside " |
83 | + "within a pluto:portlet tag."); |
84 | } |
85 | |
86 | // Create portal URL. |
87 | HttpServletRequest request = (HttpServletRequest) |
88 | pageContext.getRequest(); |
89 | PortalURL portalUrl = PortalURLFactory.getFactory() |
90 | .createPortalURL(request); |
91 | |
92 | // Encode window state of the current portlet in the portal URL. |
93 | String portletId = parentTag.getEvaluatedPortletId(); |
94 | if (windowState != null) { |
95 | portalUrl.setWindowState(portletId, new WindowState(windowState)); |
96 | } |
97 | |
98 | // Encode portlet mode of the current portlet in the portal URL. |
99 | if (portletMode != null) { |
100 | portalUrl.setPortletMode(portletId, new PortletMode(portletMode)); |
101 | } |
102 | |
103 | // Print the portal URL as a string to the page. |
104 | try { |
105 | pageContext.getOut().print(portalUrl.toString()); |
106 | } catch (IOException ex) { |
107 | throw new JspException(ex); |
108 | } |
109 | |
110 | // Skip the tag body. |
111 | return SKIP_BODY; |
112 | } |
113 | |
114 | |
115 | } |
116 | |