1
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
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 }