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.journalcontentsearch.action;
016    
017    import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionMessages;
019    import com.liferay.portal.kernel.util.Constants;
020    import com.liferay.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.kernel.util.StringPool;
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 Richard Beatty
033     * @author Raymond Augé
034     */
035    public class ConfigurationActionImpl extends BaseConfigurationAction {
036    
037            public void processAction(
038                            PortletConfig portletConfig, ActionRequest actionRequest,
039                            ActionResponse actionResponse)
040                    throws Exception {
041    
042                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
043    
044                    if (!cmd.equals(Constants.UPDATE)) {
045                            return;
046                    }
047    
048                    boolean showListed = ParamUtil.getBoolean(
049                            actionRequest, "showListed");
050                    String targetPortletId = ParamUtil.getString(
051                            actionRequest, "targetPortletId");
052                    String type = ParamUtil.getString(actionRequest, "type");
053    
054                    String portletResource = ParamUtil.getString(
055                            actionRequest, "portletResource");
056    
057                    PortletPreferences preferences =
058                            PortletPreferencesFactoryUtil.getPortletSetup(
059                                    actionRequest, portletResource);
060    
061                    preferences.setValue("show-listed", String.valueOf(showListed));
062    
063                    if (!showListed) {
064                            preferences.setValue("target-portlet-id", targetPortletId);
065                    }
066                    else {
067                            preferences.setValue("target-portlet-id", StringPool.BLANK);
068                    }
069    
070                    preferences.setValue("type", type);
071    
072                    preferences.store();
073    
074                    SessionMessages.add(
075                            actionRequest, portletConfig.getPortletName() + ".doConfigure");
076            }
077    
078            public String render(
079                            PortletConfig portletConfig, RenderRequest renderRequest,
080                            RenderResponse renderResponse)
081                    throws Exception {
082    
083                    return "/html/portlet/journal_content_search/configuration.jsp";
084            }
085    
086    }