1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.servlet.taglib.ui;
16  
17  import com.liferay.portal.kernel.util.JavaConstants;
18  import com.liferay.portal.kernel.util.StringBundler;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.model.Group;
21  import com.liferay.portal.model.Layout;
22  import com.liferay.portal.security.permission.ResourceActionsUtil;
23  import com.liferay.portal.theme.ThemeDisplay;
24  import com.liferay.portal.util.WebKeys;
25  
26  import java.util.List;
27  
28  import javax.portlet.RenderResponse;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.jsp.JspException;
32  import javax.servlet.jsp.PageContext;
33  
34  /**
35   * <a href="InputPermissionsParamsTagUtil.java.html"><b><i>View Source</i></b>
36   * </a>
37   *
38   * @author Brian Chan
39   * @author Jorge Ferrer
40   */
41  public class InputPermissionsParamsTagUtil {
42  
43      public static void doEndTag(String modelName, PageContext pageContext)
44          throws JspException {
45  
46          try {
47              HttpServletRequest request =
48                  (HttpServletRequest)pageContext.getRequest();
49  
50              RenderResponse renderResponse =
51                  (RenderResponse)request.getAttribute(
52                      JavaConstants.JAVAX_PORTLET_RESPONSE);
53  
54              ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
55                  WebKeys.THEME_DISPLAY);
56  
57              Layout layout = themeDisplay.getLayout();
58  
59              Group group = themeDisplay.getScopeGroup();
60              Group layoutGroup = layout.getGroup();
61  
62              List<String> supportedActions =
63                  ResourceActionsUtil.getModelResourceActions(modelName);
64              List<String> communityDefaultActions =
65                  ResourceActionsUtil.getModelResourceCommunityDefaultActions(
66                      modelName);
67              List<String> guestDefaultActions =
68                  ResourceActionsUtil.getModelResourceGuestDefaultActions(
69                      modelName);
70              List<String> guestUnsupportedActions =
71                  ResourceActionsUtil.getModelResourceGuestUnsupportedActions(
72                      modelName);
73  
74              StringBundler sb = new StringBundler();
75  
76              for (int i = 0; i < supportedActions.size(); i++) {
77                  String action = supportedActions.get(i);
78  
79                  boolean communityChecked = communityDefaultActions.contains(
80                      action);
81                  boolean guestChecked = guestDefaultActions.contains(action);
82                  boolean guestDisabled = guestUnsupportedActions.contains(
83                      action);
84  
85                  if (guestDisabled) {
86                      guestChecked = false;
87                  }
88  
89                  if (group.isCommunity() || group.isOrganization()) {
90                      if (communityChecked) {
91                          sb.append(StringPool.AMPERSAND);
92                          sb.append(renderResponse.getNamespace());
93                          sb.append("communityPermissions=");
94                          sb.append(action);
95                      }
96                  }
97  
98                  if (guestChecked) {
99                      sb.append(StringPool.AMPERSAND);
100                     sb.append(renderResponse.getNamespace());
101                     sb.append("guestPermissions=");
102                     sb.append(action);
103                 }
104             }
105 
106             boolean inputPermissionsPublic = false;
107 
108             if (layoutGroup.isControlPanel()) {
109                 if (!group.hasPrivateLayouts()) {
110                     inputPermissionsPublic = true;
111                 }
112             }
113             else if (layout.isPublicLayout()) {
114                 inputPermissionsPublic = true;
115             }
116 
117             if (inputPermissionsPublic) {
118                 sb.append(StringPool.AMPERSAND);
119                 sb.append(renderResponse.getNamespace());
120                 sb.append("inputPermissionsPublic=1");
121             }
122 
123             pageContext.getOut().print(sb.toString());
124         }
125         catch (Exception e) {
126             throw new JspException(e);
127         }
128     }
129 
130 }