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