1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.servlet.taglib.security;
16  
17  import com.liferay.portal.kernel.portlet.LiferayWindowState;
18  import com.liferay.portal.kernel.util.Validator;
19  import com.liferay.portal.model.Layout;
20  import com.liferay.portal.theme.PortletDisplay;
21  import com.liferay.portal.theme.ThemeDisplay;
22  import com.liferay.portal.util.PortalUtil;
23  import com.liferay.portal.util.PortletKeys;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.PortletURLImpl;
26  
27  import javax.portlet.PortletRequest;
28  import javax.portlet.PortletURL;
29  import javax.portlet.WindowState;
30  
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.jsp.JspException;
33  import javax.servlet.jsp.PageContext;
34  import javax.servlet.jsp.tagext.TagSupport;
35  
36  /**
37   * <a href="PermissionsURLTagUtil.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class PermissionsURLTagUtil extends TagSupport {
42  
43      public static String doEndTag(
44              String redirect, String modelResource,
45              String modelResourceDescription, String resourcePrimKey, String var,
46              boolean writeOutput, PageContext pageContext)
47          throws JspException {
48  
49          try {
50              HttpServletRequest request =
51                  (HttpServletRequest)pageContext.getRequest();
52  
53              ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
54                  WebKeys.THEME_DISPLAY);
55  
56              PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
57  
58              Layout layout = themeDisplay.getLayout();
59  
60              if (Validator.isNull(redirect)) {
61                  redirect = PortalUtil.getCurrentURL(request);
62              }
63  
64              PortletURL portletURL = new PortletURLImpl(
65                  request, PortletKeys.PORTLET_CONFIGURATION, layout.getPlid(),
66                  PortletRequest.RENDER_PHASE);
67  
68              if (themeDisplay.isStatePopUp()) {
69                  portletURL.setWindowState(LiferayWindowState.POP_UP);
70              }
71              else {
72                  portletURL.setWindowState(WindowState.MAXIMIZED);
73              }
74  
75              portletURL.setParameter(
76                  "struts_action", "/portlet_configuration/edit_permissions");
77              portletURL.setParameter("redirect", redirect);
78  
79              if (!themeDisplay.isStateMaximized()) {
80                  portletURL.setParameter("returnToFullPageURL", redirect);
81              }
82  
83              portletURL.setParameter("portletResource", portletDisplay.getId());
84              portletURL.setParameter("modelResource", modelResource);
85              portletURL.setParameter(
86                  "modelResourceDescription", modelResourceDescription);
87              portletURL.setParameter("resourcePrimKey", resourcePrimKey);
88  
89              String portletURLToString = portletURL.toString();
90  
91              if (Validator.isNotNull(var)) {
92                  pageContext.setAttribute(var, portletURLToString);
93              }
94              else if (writeOutput) {
95                  pageContext.getOut().print(portletURLToString);
96              }
97  
98              return portletURL.toString();
99          }
100         catch (Exception e) {
101             throw new JspException(e);
102         }
103     }
104 
105 }