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