1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class ConfigurationActionImpl extends BaseConfigurationAction {
45  
46      public void processAction(
47              PortletConfig portletConfig, ActionRequest actionRequest,
48              ActionResponse actionResponse)
49          throws Exception {
50  
51          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
52  
53          if (!cmd.equals(Constants.UPDATE)) {
54              return;
55          }
56  
57          long rootLayoutId = ParamUtil.getLong(actionRequest, "rootLayoutId");
58          String displayDepth = ParamUtil.getString(
59              actionRequest, "displayDepth");
60          boolean includeRootInTree = ParamUtil.getBoolean(
61              actionRequest, "includeRootInTree");
62          boolean showCurrentPage = ParamUtil.getBoolean(
63              actionRequest, "showCurrentPage");
64          boolean useHtmlTitle = ParamUtil.getBoolean(
65              actionRequest, "useHtmlTitle");
66          boolean showHiddenPages = ParamUtil.getBoolean(
67              actionRequest, "showHiddenPages");
68  
69          if (rootLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
70              includeRootInTree = false;
71          }
72  
73          String portletResource = ParamUtil.getString(
74              actionRequest, "portletResource");
75  
76          PortletPreferences preferences =
77              PortletPreferencesFactoryUtil.getPortletSetup(
78                  actionRequest, portletResource);
79  
80          preferences.setValue("root-layout-id", String.valueOf(rootLayoutId));
81          preferences.setValue("display-depth", displayDepth);
82          preferences.setValue(
83              "include-root-in-tree", String.valueOf(includeRootInTree));
84          preferences.setValue(
85              "show-current-page", String.valueOf(showCurrentPage));
86          preferences.setValue("use-html-title", String.valueOf(useHtmlTitle));
87          preferences.setValue(
88              "show-hidden-pages", String.valueOf(showHiddenPages));
89  
90          preferences.store();
91  
92          SessionMessages.add(
93              actionRequest, portletConfig.getPortletName() + ".doConfigure");
94      }
95  
96      public String render(
97              PortletConfig portletConfig, RenderRequest renderRequest,
98              RenderResponse renderResponse)
99          throws Exception {
100 
101         return "/html/portlet/site_map/configuration.jsp";
102     }
103 
104 }