001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.servlet.taglib.ui;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
020    import com.liferay.portal.security.permission.ResourceActionsUtil;
021    
022    import java.util.List;
023    
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.jsp.JspException;
026    import javax.servlet.jsp.PageContext;
027    
028    /**
029     * @author Brian Chan
030     */
031    public class InputPermissionsTagUtil {
032    
033            public static void doEndTag(
034                            String page, String formName, String modelName,
035                            PageContext pageContext)
036                    throws JspException {
037    
038                    try {
039                            HttpServletRequest request =
040                                    (HttpServletRequest)pageContext.getRequest();
041    
042                            request.setAttribute(
043                                    "liferay-ui:input-permissions:formName", formName);
044    
045                            if (modelName != null) {
046                                    List<String> supportedActions =
047                                            ResourceActionsUtil.getModelResourceActions(modelName);
048                                    List<String> communityDefaultActions =
049                                            ResourceActionsUtil.getModelResourceCommunityDefaultActions(
050                                                    modelName);
051                                    List<String> guestDefaultActions =
052                                            ResourceActionsUtil.getModelResourceGuestDefaultActions(
053                                                    modelName);
054                                    List<String> guestUnsupportedActions =
055                                            ResourceActionsUtil.getModelResourceGuestUnsupportedActions(
056                                                    modelName);
057    
058                                    request.setAttribute(
059                                            "liferay-ui:input-permissions:modelName", modelName);
060                                    request.setAttribute(
061                                            "liferay-ui:input-permissions:supportedActions",
062                                            supportedActions);
063                                    request.setAttribute(
064                                            "liferay-ui:input-permissions:communityDefaultActions",
065                                            communityDefaultActions);
066                                    request.setAttribute(
067                                            "liferay-ui:input-permissions:guestDefaultActions",
068                                            guestDefaultActions);
069                                    request.setAttribute(
070                                            "liferay-ui:input-permissions:guestUnsupportedActions",
071                                            guestUnsupportedActions);
072                            }
073    
074                            PortalIncludeUtil.include(pageContext, page);
075                    }
076                    catch (Exception e) {
077                            _log.error(e, e);
078    
079                            throw new JspException(e);
080                    }
081            }
082    
083            private static Log _log = LogFactoryUtil.getLog(
084                    InputPermissionsTagUtil.class);
085    
086    }