/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.amazon.rankings.web.internal.portlet.action;
import com.liferay.amazon.rankings.web.configuration.AmazonRankingsConfiguration;
import com.liferay.amazon.rankings.web.internal.constants.AmazonRankingsPortletKeys;
import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil;
import com.liferay.portal.kernel.portlet.ConfigurationAction;
import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
import com.liferay.portal.kernel.util.CharPool;
import com.liferay.portal.kernel.util.StringUtil;
import java.util.Arrays;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
/**
* @author Brian Wing Shun Chan
*/
@Component(
configurationPid = "com.liferay.amazon.rankings.web.configuration.AmazonRankingsConfiguration",
configurationPolicy = ConfigurationPolicy.OPTIONAL, immediate = true,
property = {
"javax.portlet.name=" + AmazonRankingsPortletKeys.AMAZON_RANKINGS
},
service = ConfigurationAction.class
)
public class AmazonRankingsConfigurationAction
extends DefaultConfigurationAction {
@Override
public String getJspPath(HttpServletRequest request) {
return "/configuration.jsp";
}
@Override
public void include(
PortletConfig portletConfig, HttpServletRequest request,
HttpServletResponse response)
throws Exception {
request.setAttribute(
AmazonRankingsConfiguration.class.getName(),
_amazonRankingsConfiguration);
super.include(portletConfig, request, response);
}
@Override
public void processAction(
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse)
throws Exception {
String[] isbns = StringUtil.split(
StringUtil.toUpperCase(getParameter(actionRequest, "isbns")),
CharPool.SPACE);
Arrays.sort(isbns);
setPreference(actionRequest, "isbns", isbns);
super.processAction(portletConfig, actionRequest, actionResponse);
}
@Override
@Reference(
target = "(osgi.web.symbolicname=com.liferay.amazon.rankings.web)",
unbind = "-"
)
public void setServletContext(ServletContext servletContext) {
super.setServletContext(servletContext);
}
@Activate
@Modified
protected void activate(Map<String, Object> properties) {
_amazonRankingsConfiguration = ConfigurableUtil.createConfigurable(
AmazonRankingsConfiguration.class, properties);
}
private volatile AmazonRankingsConfiguration _amazonRankingsConfiguration;
}