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.sitemap.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.Validator;
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                    String rootLayoutUuid = ParamUtil.getString(
048                            actionRequest, "rootLayoutUuid");
049                    String displayDepth = ParamUtil.getString(
050                            actionRequest, "displayDepth");
051                    boolean includeRootInTree = ParamUtil.getBoolean(
052                            actionRequest, "includeRootInTree");
053                    boolean showCurrentPage = ParamUtil.getBoolean(
054                            actionRequest, "showCurrentPage");
055                    boolean useHtmlTitle = ParamUtil.getBoolean(
056                            actionRequest, "useHtmlTitle");
057                    boolean showHiddenPages = ParamUtil.getBoolean(
058                            actionRequest, "showHiddenPages");
059    
060                    if (Validator.isNull(rootLayoutUuid)) {
061                            includeRootInTree = false;
062                    }
063    
064                    String portletResource = ParamUtil.getString(
065                            actionRequest, "portletResource");
066    
067                    PortletPreferences preferences =
068                            PortletPreferencesFactoryUtil.getPortletSetup(
069                                    actionRequest, portletResource);
070    
071                    preferences.setValue("root-layout-uuid", rootLayoutUuid);
072                    preferences.setValue("display-depth", displayDepth);
073                    preferences.setValue(
074                            "include-root-in-tree", String.valueOf(includeRootInTree));
075                    preferences.setValue(
076                            "show-current-page", String.valueOf(showCurrentPage));
077                    preferences.setValue("use-html-title", String.valueOf(useHtmlTitle));
078                    preferences.setValue(
079                            "show-hidden-pages", String.valueOf(showHiddenPages));
080    
081                    preferences.store();
082    
083                    SessionMessages.add(
084                            actionRequest, portletConfig.getPortletName() + ".doConfigure");
085            }
086    
087            public String render(
088                            PortletConfig portletConfig, RenderRequest renderRequest,
089                            RenderResponse renderResponse)
090                    throws Exception {
091    
092                    return "/html/portlet/site_map/configuration.jsp";
093            }
094    
095    }