001
014
015 package com.liferay.taglib.security;
016
017 import com.liferay.portal.kernel.portlet.LiferayWindowState;
018 import com.liferay.portal.kernel.portlet.PortletProvider;
019 import com.liferay.portal.kernel.portlet.PortletProviderUtil;
020 import com.liferay.portal.kernel.portlet.WindowStateFactory;
021 import com.liferay.portal.kernel.util.StringUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portal.kernel.util.WebKeys;
024 import com.liferay.portal.theme.PortletDisplay;
025 import com.liferay.portal.theme.ThemeDisplay;
026 import com.liferay.portal.util.PortalUtil;
027 import com.liferay.portlet.portletconfiguration.util.PortletConfigurationApplicationType;
028
029 import javax.portlet.PortletURL;
030 import javax.portlet.WindowState;
031
032 import javax.servlet.http.HttpServletRequest;
033 import javax.servlet.jsp.JspException;
034 import javax.servlet.jsp.JspWriter;
035 import javax.servlet.jsp.tagext.TagSupport;
036
037
040 public class PermissionsURLTag extends TagSupport {
041
042
068 public static String doTag(
069 String redirect, String modelResource,
070 String modelResourceDescription, Object resourceGroupId,
071 String resourcePrimKey, String windowState, int[] roleTypes,
072 HttpServletRequest request)
073 throws Exception {
074
075 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
076 WebKeys.THEME_DISPLAY);
077
078 if (resourceGroupId instanceof Number) {
079 Number resourceGroupIdNumber = (Number)resourceGroupId;
080
081 if (resourceGroupIdNumber.longValue() < 0) {
082 resourceGroupId = null;
083 }
084 }
085 else if (resourceGroupId instanceof String) {
086 String esourceGroupIdString = (String)resourceGroupId;
087
088 if (esourceGroupIdString.length() == 0) {
089 resourceGroupId = null;
090 }
091 }
092
093 if (resourceGroupId == null) {
094 resourceGroupId = String.valueOf(themeDisplay.getScopeGroupId());
095 }
096
097 if (Validator.isNull(redirect) &&
098 (Validator.isNull(windowState) ||
099 !windowState.equals(LiferayWindowState.POP_UP.toString()))) {
100
101 redirect = PortalUtil.getCurrentURL(request);
102 }
103
104 PortletURL portletURL = PortletProviderUtil.getPortletURL(
105 request,
106 PortletConfigurationApplicationType.PortletConfiguration.CLASS_NAME,
107 PortletProvider.Action.VIEW);
108
109 if (Validator.isNotNull(windowState)) {
110 portletURL.setWindowState(
111 WindowStateFactory.getWindowState(windowState));
112 }
113 else if (themeDisplay.isStatePopUp()) {
114 portletURL.setWindowState(LiferayWindowState.POP_UP);
115 }
116 else {
117 portletURL.setWindowState(WindowState.MAXIMIZED);
118 }
119
120 portletURL.setParameter("mvcPath", "/edit_permissions.jsp");
121
122 if (Validator.isNotNull(redirect)) {
123 portletURL.setParameter("redirect", redirect);
124
125 if (!themeDisplay.isStateMaximized()) {
126 portletURL.setParameter("returnToFullPageURL", redirect);
127 }
128 }
129
130 portletURL.setParameter(
131 "portletConfiguration", Boolean.TRUE.toString());
132
133 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
134
135 portletURL.setParameter("portletResource", portletDisplay.getId());
136
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 }