1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.servlet.taglib.ui;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
20  import com.liferay.portal.security.permission.ResourceActionsUtil;
21  
22  import java.util.List;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.jsp.JspException;
26  import javax.servlet.jsp.PageContext;
27  
28  /**
29   * <a href="InputPermissionsTagUtil.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Chan
32   */
33  public class InputPermissionsTagUtil {
34  
35      public static void doEndTag(
36              String page, String formName, String modelName,
37              PageContext pageContext)
38          throws JspException {
39  
40          try {
41              HttpServletRequest request =
42                  (HttpServletRequest)pageContext.getRequest();
43  
44              request.setAttribute(
45                  "liferay-ui:input-permissions:formName", formName);
46  
47              if (modelName != null) {
48                  List<String> supportedActions =
49                      ResourceActionsUtil.getModelResourceActions(modelName);
50                  List<String> communityDefaultActions =
51                      ResourceActionsUtil.getModelResourceCommunityDefaultActions(
52                          modelName);
53                  List<String> guestDefaultActions =
54                      ResourceActionsUtil.getModelResourceGuestDefaultActions(
55                          modelName);
56                  List<String> guestUnsupportedActions =
57                      ResourceActionsUtil.getModelResourceGuestUnsupportedActions(
58                          modelName);
59  
60                  request.setAttribute(
61                      "liferay-ui:input-permissions:modelName", modelName);
62                  request.setAttribute(
63                      "liferay-ui:input-permissions:supportedActions",
64                      supportedActions);
65                  request.setAttribute(
66                      "liferay-ui:input-permissions:communityDefaultActions",
67                      communityDefaultActions);
68                  request.setAttribute(
69                      "liferay-ui:input-permissions:guestDefaultActions",
70                      guestDefaultActions);
71                  request.setAttribute(
72                      "liferay-ui:input-permissions:guestUnsupportedActions",
73                      guestUnsupportedActions);
74              }
75  
76              PortalIncludeUtil.include(pageContext, page);
77          }
78          catch (Exception e) {
79              _log.error(e, e);
80  
81              throw new JspException(e);
82          }
83      }
84  
85      private static Log _log = LogFactoryUtil.getLog(
86          InputPermissionsTagUtil.class);
87  
88  }