1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.sitemap.action;
21  
22  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
23  import com.liferay.portal.kernel.servlet.SessionMessages;
24  import com.liferay.portal.kernel.util.Constants;
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.model.LayoutConstants;
27  import com.liferay.portlet.PortletPreferencesFactoryUtil;
28  
29  import javax.portlet.ActionRequest;
30  import javax.portlet.ActionResponse;
31  import javax.portlet.PortletConfig;
32  import javax.portlet.PortletPreferences;
33  import javax.portlet.RenderRequest;
34  import javax.portlet.RenderResponse;
35  
36  /**
37   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class ConfigurationActionImpl extends BaseConfigurationAction {
43  
44      public void processAction(
45              PortletConfig portletConfig, ActionRequest actionRequest,
46              ActionResponse actionResponse)
47          throws Exception {
48  
49          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
50  
51          if (!cmd.equals(Constants.UPDATE)) {
52              return;
53          }
54  
55          long rootLayoutId = ParamUtil.getLong(actionRequest, "rootLayoutId");
56          String displayDepth = ParamUtil.getString(
57              actionRequest, "displayDepth");
58          boolean includeRootInTree = ParamUtil.getBoolean(
59              actionRequest, "includeRootInTree");
60          boolean showCurrentPage = ParamUtil.getBoolean(
61              actionRequest, "showCurrentPage");
62          boolean useHtmlTitle = ParamUtil.getBoolean(
63              actionRequest, "useHtmlTitle");
64          boolean showHiddenPages = ParamUtil.getBoolean(
65              actionRequest, "showHiddenPages");
66  
67          if (rootLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
68              includeRootInTree = false;
69          }
70  
71          String portletResource = ParamUtil.getString(
72              actionRequest, "portletResource");
73  
74          PortletPreferences preferences =
75              PortletPreferencesFactoryUtil.getPortletSetup(
76                  actionRequest, portletResource);
77  
78          preferences.setValue("root-layout-id", String.valueOf(rootLayoutId));
79          preferences.setValue("display-depth", displayDepth);
80          preferences.setValue(
81              "include-root-in-tree", String.valueOf(includeRootInTree));
82          preferences.setValue(
83              "show-current-page", String.valueOf(showCurrentPage));
84          preferences.setValue("use-html-title", String.valueOf(useHtmlTitle));
85          preferences.setValue(
86              "show-hidden-pages", String.valueOf(showHiddenPages));
87  
88          preferences.store();
89  
90          SessionMessages.add(
91              actionRequest, portletConfig.getPortletName() + ".doConfigure");
92      }
93  
94      public String render(
95              PortletConfig portletConfig, RenderRequest renderRequest,
96              RenderResponse renderResponse)
97          throws Exception {
98  
99          return "/html/portlet/site_map/configuration.jsp";
100     }
101 
102 }