1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.sitemap.action;
24  
25  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
26  import com.liferay.portal.kernel.servlet.SessionMessages;
27  import com.liferay.portal.kernel.util.Constants;
28  import com.liferay.portal.kernel.util.ParamUtil;
29  import com.liferay.portal.model.LayoutConstants;
30  import com.liferay.portlet.PortletPreferencesFactoryUtil;
31  
32  import javax.portlet.ActionRequest;
33  import javax.portlet.ActionResponse;
34  import javax.portlet.PortletConfig;
35  import javax.portlet.PortletPreferences;
36  import javax.portlet.RenderRequest;
37  import javax.portlet.RenderResponse;
38  
39  /**
40   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class ConfigurationActionImpl extends BaseConfigurationAction {
46  
47      public void processAction(
48              PortletConfig portletConfig, ActionRequest actionRequest,
49              ActionResponse actionResponse)
50          throws Exception {
51  
52          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
53  
54          if (!cmd.equals(Constants.UPDATE)) {
55              return;
56          }
57  
58          long rootLayoutId = ParamUtil.getLong(actionRequest, "rootLayoutId");
59          String displayDepth = ParamUtil.getString(
60              actionRequest, "displayDepth");
61          boolean includeRootInTree = ParamUtil.getBoolean(
62              actionRequest, "includeRootInTree");
63          boolean showCurrentPage = ParamUtil.getBoolean(
64              actionRequest, "showCurrentPage");
65          boolean useHtmlTitle = ParamUtil.getBoolean(
66              actionRequest, "useHtmlTitle");
67          boolean showHiddenPages = ParamUtil.getBoolean(
68              actionRequest, "showHiddenPages");
69  
70          if (rootLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
71              includeRootInTree = false;
72          }
73  
74          String portletResource = ParamUtil.getString(
75              actionRequest, "portletResource");
76  
77          PortletPreferences preferences =
78              PortletPreferencesFactoryUtil.getPortletSetup(
79                  actionRequest, portletResource);
80  
81          preferences.setValue("root-layout-id", String.valueOf(rootLayoutId));
82          preferences.setValue("display-depth", displayDepth);
83          preferences.setValue(
84              "include-root-in-tree", String.valueOf(includeRootInTree));
85          preferences.setValue(
86              "show-current-page", String.valueOf(showCurrentPage));
87          preferences.setValue("use-html-title", String.valueOf(useHtmlTitle));
88          preferences.setValue(
89              "show-hidden-pages", String.valueOf(showHiddenPages));
90  
91          preferences.store();
92  
93          SessionMessages.add(
94              actionRequest, portletConfig.getPortletName() + ".doConfigure");
95      }
96  
97      public String render(
98              PortletConfig portletConfig, RenderRequest renderRequest,
99              RenderResponse renderResponse)
100         throws Exception {
101 
102         return "/html/portlet/site_map/configuration.jsp";
103     }
104 
105 }