001
014
015 package com.liferay.portlet.amazonrankings.action;
016
017 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018 import com.liferay.portal.kernel.servlet.SessionErrors;
019 import com.liferay.portal.kernel.servlet.SessionMessages;
020 import com.liferay.portal.kernel.util.Constants;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.kernel.util.StringUtil;
024 import com.liferay.portlet.PortletPreferencesFactoryUtil;
025
026 import java.util.Arrays;
027
028 import javax.portlet.ActionRequest;
029 import javax.portlet.ActionResponse;
030 import javax.portlet.PortletConfig;
031 import javax.portlet.PortletPreferences;
032 import javax.portlet.RenderRequest;
033 import javax.portlet.RenderResponse;
034 import javax.portlet.ValidatorException;
035
036
039 public class ConfigurationActionImpl extends BaseConfigurationAction {
040
041 public void processAction(
042 PortletConfig portletConfig, ActionRequest actionRequest,
043 ActionResponse actionResponse)
044 throws Exception {
045
046 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
047
048 if (!cmd.equals(Constants.UPDATE)) {
049 return;
050 }
051
052 String[] isbns = StringUtil.split(
053 ParamUtil.getString(actionRequest, "isbns").toUpperCase(),
054 StringPool.SPACE);
055
056 Arrays.sort(isbns);
057
058 String portletResource = ParamUtil.getString(
059 actionRequest, "portletResource");
060
061 PortletPreferences preferences =
062 PortletPreferencesFactoryUtil.getPortletSetup(
063 actionRequest, portletResource);
064
065 preferences.setValues("isbns", isbns);
066
067 try {
068 preferences.store();
069 }
070 catch (ValidatorException ve) {
071 SessionErrors.add(
072 actionRequest, ValidatorException.class.getName(), ve);
073
074 return;
075 }
076
077 SessionMessages.add(
078 actionRequest, portletConfig.getPortletName() + ".doConfigure");
079 }
080
081 public String render(
082 PortletConfig portletConfig, RenderRequest renderRequest,
083 RenderResponse renderResponse)
084 throws Exception {
085
086 return "/html/portlet/amazon_rankings/configuration.jsp";
087 }
088
089 }