1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.assetcategoriesnavigation.action;
16  
17  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18  import com.liferay.portal.kernel.servlet.SessionMessages;
19  import com.liferay.portal.kernel.util.ArrayUtil;
20  import com.liferay.portal.kernel.util.Constants;
21  import com.liferay.portal.kernel.util.ParamUtil;
22  import com.liferay.portal.kernel.util.StringUtil;
23  import com.liferay.portlet.PortletPreferencesFactoryUtil;
24  
25  import javax.portlet.ActionRequest;
26  import javax.portlet.ActionResponse;
27  import javax.portlet.PortletConfig;
28  import javax.portlet.PortletPreferences;
29  import javax.portlet.RenderRequest;
30  import javax.portlet.RenderResponse;
31  
32  /**
33   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Jorge Ferrer
36   */
37  public class ConfigurationActionImpl extends BaseConfigurationAction {
38  
39      public void processAction(
40              PortletConfig portletConfig, ActionRequest actionRequest,
41              ActionResponse actionResponse)
42          throws Exception {
43  
44          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
45  
46          if (!cmd.equals(Constants.UPDATE)) {
47              return;
48          }
49  
50          boolean allAssetVocabularies = ParamUtil.getBoolean(
51              actionRequest, "allAssetVocabularies");
52          long[] assetVocabularyIds = StringUtil.split(
53              ParamUtil.getString(actionRequest, "assetVocabularyIds"), 0L);
54  
55          String portletResource = ParamUtil.getString(
56              actionRequest, "portletResource");
57  
58          PortletPreferences preferences =
59              PortletPreferencesFactoryUtil.getPortletSetup(
60                  actionRequest, portletResource);
61  
62          preferences.setValue(
63              "all-asset-vocabularies", String.valueOf(allAssetVocabularies));
64          preferences.setValues(
65              "asset-vocabulary-ids",
66              ArrayUtil.toStringArray(assetVocabularyIds));
67  
68          preferences.store();
69  
70          SessionMessages.add(
71              actionRequest, portletConfig.getPortletName() + ".doConfigure");
72      }
73  
74      public String render(
75              PortletConfig portletConfig, RenderRequest renderRequest,
76              RenderResponse renderResponse)
77          throws Exception {
78  
79          return "/html/portlet/asset_categories_navigation/configuration.jsp";
80      }
81  
82  }