1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.ui;
24  
25  import com.liferay.portal.security.permission.ResourceActionsUtil;
26  import com.liferay.taglib.util.IncludeTag;
27  
28  import java.util.List;
29  
30  import javax.servlet.ServletRequest;
31  
32  /**
33   * <a href="InputPermissionsTag.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   * @author Wilson S. Man
37   *
38   */
39  public class InputPermissionsTag extends IncludeTag {
40  
41      public int doStartTag() {
42          ServletRequest req = pageContext.getRequest();
43  
44          req.setAttribute("liferay-ui:input-permissions:formName", _formName);
45  
46          if (_modelName != null) {
47              List<String> supportedActions =
48                  ResourceActionsUtil.getModelResourceActions(_modelName);
49              List<String> communityDefaultActions =
50                  ResourceActionsUtil.getModelResourceCommunityDefaultActions(
51                      _modelName);
52              List<String> guestDefaultActions =
53                  ResourceActionsUtil.getModelResourceGuestDefaultActions(
54                      _modelName);
55              List<String> guestUnsupportedActions =
56                  ResourceActionsUtil.getModelResourceGuestUnsupportedActions(
57                      _modelName);
58  
59              req.setAttribute(
60                  "liferay-ui:input-permissions:modelName", _modelName);
61              req.setAttribute(
62                  "liferay-ui:input-permissions:supportedActions",
63                  supportedActions);
64              req.setAttribute(
65                  "liferay-ui:input-permissions:communityDefaultActions",
66                  communityDefaultActions);
67              req.setAttribute(
68                  "liferay-ui:input-permissions:guestDefaultActions",
69                  guestDefaultActions);
70              req.setAttribute(
71                  "liferay-ui:input-permissions:guestUnsupportedActions",
72                  guestUnsupportedActions);
73          }
74  
75          return EVAL_BODY_BUFFERED;
76      }
77  
78      public void setFormName(String formName) {
79          _formName = formName;
80      }
81  
82      public void setModelName(String modelName) {
83          _modelName = modelName;
84      }
85  
86      protected String getDefaultPage() {
87          return _PAGE;
88      }
89  
90      private static final String _PAGE =
91          "/html/taglib/ui/input_permissions/page.jsp";
92  
93      private String _formName = "fm";
94      private String _modelName = null;
95  
96  }