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.portlet.journalarticles.action;
016    
017    import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionErrors;
019    import com.liferay.portal.kernel.servlet.SessionMessages;
020    import com.liferay.portal.kernel.util.Constants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portlet.PortletPreferencesFactoryUtil;
023    
024    import javax.portlet.ActionRequest;
025    import javax.portlet.ActionResponse;
026    import javax.portlet.PortletConfig;
027    import javax.portlet.PortletPreferences;
028    import javax.portlet.RenderRequest;
029    import javax.portlet.RenderResponse;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class ConfigurationActionImpl extends BaseConfigurationAction {
035    
036            public void processAction(
037                            PortletConfig portletConfig, ActionRequest actionRequest,
038                            ActionResponse actionResponse)
039                    throws Exception {
040    
041                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
042    
043                    if (!cmd.equals(Constants.UPDATE)) {
044                            return;
045                    }
046    
047                    long groupId = ParamUtil.getLong(actionRequest, "groupId");
048                    String type = ParamUtil.getString(actionRequest, "type");
049                    String structureId = ParamUtil.getString(actionRequest, "structureId");
050                    String pageURL = ParamUtil.getString(actionRequest, "pageURL");
051                    int pageDelta = ParamUtil.getInteger(actionRequest, "pageDelta");
052                    String orderByCol = ParamUtil.getString(actionRequest, "orderByCol");
053                    String orderByType = ParamUtil.getString(actionRequest, "orderByType");
054    
055                    String portletResource = ParamUtil.getString(
056                            actionRequest, "portletResource");
057    
058                    PortletPreferences preferences =
059                            PortletPreferencesFactoryUtil.getPortletSetup(
060                                    actionRequest, portletResource);
061    
062                    preferences.setValue("group-id", String.valueOf(groupId));
063                    preferences.setValue("type", type);
064                    preferences.setValue("structure-id", structureId);
065                    preferences.setValue("page-url", pageURL);
066                    preferences.setValue("page-delta", String.valueOf(pageDelta));
067                    preferences.setValue("order-by-col", orderByCol);
068                    preferences.setValue("order-by-type", orderByType);
069    
070                    if (SessionErrors.isEmpty(actionRequest)) {
071                            preferences.store();
072    
073                            SessionMessages.add(
074                                    actionRequest, portletConfig.getPortletName() + ".doConfigure");
075                    }
076    
077                    actionResponse.sendRedirect(
078                            ParamUtil.getString(actionRequest, "redirect"));
079            }
080    
081            public String render(
082                            PortletConfig portletConfig, RenderRequest renderRequest,
083                            RenderResponse renderResponse)
084                    throws Exception {
085    
086                    return "/html/portlet/journal_articles/configuration.jsp";
087            }
088    
089    }