1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.portal.servlet.taglib.ui;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
28  import com.liferay.portal.security.permission.ResourceActionsUtil;
29  
30  import java.util.List;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.jsp.JspException;
34  import javax.servlet.jsp.PageContext;
35  
36  /**
37   * <a href="InputPermissionsTagUtil.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Chan
40   */
41  public class InputPermissionsTagUtil {
42  
43      public static void doEndTag(
44              String page, String formName, String modelName,
45              PageContext pageContext)
46          throws JspException {
47  
48          try {
49              HttpServletRequest request =
50                  (HttpServletRequest)pageContext.getRequest();
51  
52              request.setAttribute(
53                  "liferay-ui:input-permissions:formName", formName);
54  
55              if (modelName != null) {
56                  List<String> supportedActions =
57                      ResourceActionsUtil.getModelResourceActions(modelName);
58                  List<String> communityDefaultActions =
59                      ResourceActionsUtil.getModelResourceCommunityDefaultActions(
60                          modelName);
61                  List<String> guestDefaultActions =
62                      ResourceActionsUtil.getModelResourceGuestDefaultActions(
63                          modelName);
64                  List<String> guestUnsupportedActions =
65                      ResourceActionsUtil.getModelResourceGuestUnsupportedActions(
66                          modelName);
67  
68                  request.setAttribute(
69                      "liferay-ui:input-permissions:modelName", modelName);
70                  request.setAttribute(
71                      "liferay-ui:input-permissions:supportedActions",
72                      supportedActions);
73                  request.setAttribute(
74                      "liferay-ui:input-permissions:communityDefaultActions",
75                      communityDefaultActions);
76                  request.setAttribute(
77                      "liferay-ui:input-permissions:guestDefaultActions",
78                      guestDefaultActions);
79                  request.setAttribute(
80                      "liferay-ui:input-permissions:guestUnsupportedActions",
81                      guestUnsupportedActions);
82              }
83  
84              PortalIncludeUtil.include(pageContext, page);
85          }
86          catch (Exception e) {
87              _log.error(e, e);
88  
89              throw new JspException(e);
90          }
91      }
92  
93      private static Log _log =
94          LogFactoryUtil.getLog(InputPermissionsTagUtil.class);
95  
96  }