001
014
015 package com.liferay.taglib.security;
016
017 import com.liferay.portal.kernel.portlet.LiferayWindowState;
018 import com.liferay.portal.kernel.portlet.WindowStateFactory;
019 import com.liferay.portal.kernel.util.StringUtil;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portal.kernel.util.WebKeys;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.theme.PortletDisplay;
024 import com.liferay.portal.theme.ThemeDisplay;
025 import com.liferay.portal.util.PortalUtil;
026 import com.liferay.portal.util.PortletKeys;
027 import com.liferay.portlet.PortletURLFactoryUtil;
028
029 import javax.portlet.PortletRequest;
030 import javax.portlet.PortletURL;
031 import javax.portlet.WindowState;
032
033 import javax.servlet.http.HttpServletRequest;
034 import javax.servlet.jsp.JspException;
035 import javax.servlet.jsp.JspWriter;
036 import javax.servlet.jsp.tagext.TagSupport;
037
038
041 public class PermissionsURLTag extends TagSupport {
042
043
069 public static String doTag(
070 String redirect, String modelResource,
071 String modelResourceDescription, Object resourceGroupId,
072 String resourcePrimKey, String windowState, int[] roleTypes,
073 HttpServletRequest request)
074 throws Exception {
075
076 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
077 WebKeys.THEME_DISPLAY);
078
079 if (resourceGroupId instanceof Number) {
080 Number resourceGroupIdNumber = (Number)resourceGroupId;
081
082 if (resourceGroupIdNumber.longValue() < 0) {
083 resourceGroupId = null;
084 }
085 }
086 else if (resourceGroupId instanceof String) {
087 String esourceGroupIdString = (String)resourceGroupId;
088
089 if (esourceGroupIdString.length() == 0) {
090 resourceGroupId = null;
091 }
092 }
093
094 if (resourceGroupId == null) {
095 resourceGroupId = String.valueOf(themeDisplay.getScopeGroupId());
096 }
097
098 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
099
100 Layout layout = themeDisplay.getLayout();
101
102 if (Validator.isNull(redirect) &&
103 (Validator.isNull(windowState) ||
104 !windowState.equals(LiferayWindowState.POP_UP.toString()))) {
105
106 redirect = PortalUtil.getCurrentURL(request);
107 }
108
109 PortletURL portletURL = PortletURLFactoryUtil.create(
110 request, PortletKeys.PORTLET_CONFIGURATION, layout.getPlid(),
111 PortletRequest.RENDER_PHASE);
112
113 if (Validator.isNotNull(windowState)) {
114 portletURL.setWindowState(
115 WindowStateFactory.getWindowState(windowState));
116 }
117 else if (themeDisplay.isStatePopUp()) {
118 portletURL.setWindowState(LiferayWindowState.POP_UP);
119 }
120 else {
121 portletURL.setWindowState(WindowState.MAXIMIZED);
122 }
123
124 portletURL.setParameter(
125 "mvcPath",
126 "/html/portlet/portlet_configuration/edit_permissions.jsp");
127
128 if (Validator.isNotNull(redirect)) {
129 portletURL.setParameter("redirect", redirect);
130
131 if (!themeDisplay.isStateMaximized()) {
132 portletURL.setParameter("returnToFullPageURL", redirect);
133 }
134 }
135
136 portletURL.setParameter("portletResource", portletDisplay.getId());
137 portletURL.setParameter("modelResource", modelResource);
138 portletURL.setParameter(
139 "modelResourceDescription", modelResourceDescription);
140 portletURL.setParameter(
141 "resourceGroupId", String.valueOf(resourceGroupId));
142 portletURL.setParameter("resourcePrimKey", resourcePrimKey);
143
144 if (roleTypes != null) {
145 portletURL.setParameter("roleTypes", StringUtil.merge(roleTypes));
146 }
147
148 return portletURL.toString();
149 }
150
151 @Override
152 public int doEndTag() throws JspException {
153 try {
154 String portletURLToString = doTag(
155 _redirect, _modelResource, _modelResourceDescription,
156 _resourceGroupId, _resourcePrimKey, _windowState, _roleTypes,
157 (HttpServletRequest)pageContext.getRequest());
158
159 if (Validator.isNotNull(_var)) {
160 pageContext.setAttribute(_var, portletURLToString);
161 }
162 else {
163 JspWriter jspWriter = pageContext.getOut();
164
165 jspWriter.write(portletURLToString);
166 }
167 }
168 catch (Exception e) {
169 throw new JspException(e);
170 }
171
172 return EVAL_PAGE;
173 }
174
175 public void setModelResource(String modelResource) {
176 _modelResource = modelResource;
177 }
178
179 public void setModelResourceDescription(String modelResourceDescription) {
180 _modelResourceDescription = modelResourceDescription;
181 }
182
183 public void setRedirect(String redirect) {
184 _redirect = redirect;
185 }
186
187 public void setResourceGroupId(Object resourceGroupId) {
188 _resourceGroupId = resourceGroupId;
189 }
190
191 public void setResourcePrimKey(String resourcePrimKey) {
192 _resourcePrimKey = resourcePrimKey;
193 }
194
195 public void setRoleTypes(int[] roleTypes) {
196 _roleTypes = roleTypes;
197 }
198
199 public void setVar(String var) {
200 _var = var;
201 }
202
203 public void setWindowState(String windowState) {
204 _windowState = windowState;
205 }
206
207 private String _modelResource;
208 private String _modelResourceDescription;
209 private String _redirect;
210 private Object _resourceGroupId;
211 private String _resourcePrimKey;
212 private int[] _roleTypes;
213 private String _var;
214 private String _windowState;
215
216 }