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.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    }