001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }