1
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
50 public class PermissionsURLTagUtil extends TagSupport {
51
52 public static String doEndTag(
53 String redirect, String modelResource,
54 String modelResourceDescription, String resourcePrimKey, String var,
55 boolean writeOutput, PageContext pageContext)
56 throws JspException {
57
58 try {
59 HttpServletRequest request =
60 (HttpServletRequest)pageContext.getRequest();
61
62 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
63 WebKeys.THEME_DISPLAY);
64
65 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
66
67 Layout layout = themeDisplay.getLayout();
68
69 if (Validator.isNull(redirect)) {
70 redirect = PortalUtil.getCurrentURL(request);
71 }
72
73 PortletURL portletURL = new PortletURLImpl(
74 request, PortletKeys.PORTLET_CONFIGURATION, layout.getPlid(),
75 PortletRequest.RENDER_PHASE);
76
77 if (themeDisplay.isStatePopUp()) {
78 portletURL.setWindowState(LiferayWindowState.POP_UP);
79 }
80 else {
81 portletURL.setWindowState(WindowState.MAXIMIZED);
82 }
83
84 portletURL.setParameter(
85 "struts_action", "/portlet_configuration/edit_permissions");
86 portletURL.setParameter("redirect", redirect);
87
88 if (!themeDisplay.isStateMaximized()) {
89 portletURL.setParameter("returnToFullPageURL", redirect);
90 }
91
92 portletURL.setParameter("portletResource", portletDisplay.getId());
93 portletURL.setParameter("modelResource", modelResource);
94 portletURL.setParameter(
95 "modelResourceDescription", modelResourceDescription);
96 portletURL.setParameter("resourcePrimKey", resourcePrimKey);
97
98 String portletURLToString = portletURL.toString();
99
100 if (Validator.isNotNull(var)) {
101 pageContext.setAttribute(var, portletURLToString);
102 }
103 else if (writeOutput) {
104 pageContext.getOut().print(portletURLToString);
105 }
106
107 return portletURL.toString();
108 }
109 catch (Exception e) {
110 throw new JspException(e);
111 }
112 }
113
114 }