/**
* 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.journal.content.web.internal.portlet.action;
import com.liferay.asset.kernel.AssetRendererFactoryRegistryUtil;
import com.liferay.asset.kernel.model.AssetEntry;
import com.liferay.asset.kernel.service.AssetEntryLocalService;
import com.liferay.journal.constants.JournalWebKeys;
import com.liferay.journal.content.web.constants.JournalContentPortletKeys;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.util.JournalContent;
import com.liferay.journal.web.asset.JournalArticleAssetRenderer;
import com.liferay.journal.web.asset.JournalArticleAssetRendererFactory;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.portlet.ConfigurationAction;
import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletRequest;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Brian Wing Shun Chan
* @author Douglas Wong
* @author Raymond Augé
*/
@Component(
immediate = true,
property = {
"javax.portlet.name=" + JournalContentPortletKeys.JOURNAL_CONTENT
},
service = ConfigurationAction.class
)
public class JournalContentConfigurationAction
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(JournalWebKeys.JOURNAL_CONTENT, _journalContent);
super.include(portletConfig, request, response);
}
@Override
public void processAction(
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse)
throws Exception {
String articleId = getArticleId(actionRequest);
setPreference(actionRequest, "articleId", articleId);
long articleGroupId = getArticleGroupId(actionRequest);
setPreference(actionRequest, "groupId", String.valueOf(articleGroupId));
super.processAction(portletConfig, actionRequest, actionResponse);
}
@Override
@Reference(
target = "(osgi.web.symbolicname=com.liferay.journal.content.web)",
unbind = "-"
)
public void setServletContext(ServletContext servletContext) {
super.setServletContext(servletContext);
}
protected long getArticleGroupId(PortletRequest portletRequest) {
long assetEntryId = GetterUtil.getLong(
getParameter(portletRequest, "assetEntryId"));
AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(
assetEntryId);
if (assetEntry == null) {
return 0;
}
return assetEntry.getGroupId();
}
protected String getArticleId(PortletRequest portletRequest)
throws PortalException {
long assetEntryId = GetterUtil.getLong(
getParameter(portletRequest, "assetEntryId"));
AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(
assetEntryId);
if (assetEntry == null) {
return StringPool.BLANK;
}
JournalArticleAssetRendererFactory articleAssetRendererFactory =
(JournalArticleAssetRendererFactory)
AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(
JournalArticle.class.getName());
JournalArticleAssetRenderer articleAssetRenderer =
(JournalArticleAssetRenderer)articleAssetRendererFactory.
getAssetRenderer(assetEntry.getClassPK());
JournalArticle article = articleAssetRenderer.getArticle();
return StringUtil.toUpperCase(article.getArticleId());
}
@Reference
protected void setAssetEntryLocalService(
AssetEntryLocalService assetEntryLocalService) {
_assetEntryLocalService = assetEntryLocalService;
}
@Reference
protected void setJournalContent(JournalContent journalContent) {
_journalContent = journalContent;
}
protected void unsetAssetEntryLocalService(
AssetEntryLocalService assetEntryLocalService) {
_assetEntryLocalService = null;
}
protected void unsetJournalContent(JournalContent journalContent) {
_journalContent = null;
}
private AssetEntryLocalService _assetEntryLocalService;
private JournalContent _journalContent;
}