001    /**
002     * Copyright (c) 2000-2011 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.kernel.portlet;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.kernel.util.WebKeys;
020    import com.liferay.portal.model.Portlet;
021    import com.liferay.portal.service.PortletLocalServiceUtil;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portlet.PortletConfigFactoryUtil;
024    
025    import javax.portlet.ActionRequest;
026    import javax.portlet.ActionResponse;
027    import javax.portlet.PortletConfig;
028    import javax.portlet.PortletRequest;
029    import javax.portlet.RenderRequest;
030    import javax.portlet.RenderResponse;
031    import javax.portlet.ResourceRequest;
032    import javax.portlet.ResourceResponse;
033    
034    import javax.servlet.ServletContext;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    public class BaseConfigurationAction
040            implements ConfigurationAction, ResourceServingConfigurationAction {
041    
042            public void processAction(
043                            PortletConfig portletConfig, ActionRequest actionRequest,
044                            ActionResponse actionResponse)
045                    throws Exception {
046            }
047    
048            public String render(
049                            PortletConfig portletConfig, RenderRequest renderRequest,
050                            RenderResponse renderResponse)
051                    throws Exception {
052    
053                    return "/configuration.jsp";
054            }
055    
056            public void serveResource(
057                            PortletConfig portletConfig, ResourceRequest resourceRequest,
058                            ResourceResponse resourceResponse)
059                    throws Exception {
060            }
061    
062            protected PortletConfig getSelPortletConfig(PortletRequest portletRequest)
063                    throws SystemException {
064    
065                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
066                            WebKeys.THEME_DISPLAY);
067    
068                    String portletResource = ParamUtil.getString(
069                            portletRequest, "portletResource");
070    
071                    Portlet selPortlet = PortletLocalServiceUtil.getPortletById(
072                            themeDisplay.getCompanyId(), portletResource);
073    
074                    ServletContext servletContext =
075                            (ServletContext)portletRequest.getAttribute(WebKeys.CTX);
076    
077                    PortletConfig selPortletConfig = PortletConfigFactoryUtil.create(
078                            selPortlet, servletContext);
079    
080                    return selPortletConfig;
081            }
082    
083    }