/**
* 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.blogs.web.internal.portlet.action;
import com.liferay.blogs.exception.NoSuchEntryException;
import com.liferay.blogs.model.BlogsEntry;
import com.liferay.blogs.web.constants.BlogsPortletKeys;
import com.liferay.blogs.web.constants.BlogsWebKeys;
import com.liferay.blogs.web.internal.BlogsItemSelectorHelper;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCRenderCommand;
import com.liferay.portal.kernel.security.auth.PrincipalException;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.WebKeys;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletRequest;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Sergio González
* @author Roberto Díaz
*/
@Component(
immediate = true,
property = {
"javax.portlet.name=" + BlogsPortletKeys.BLOGS,
"javax.portlet.name=" + BlogsPortletKeys.BLOGS_ADMIN,
"javax.portlet.name=" + BlogsPortletKeys.BLOGS_AGGREGATOR,
"mvc.command.name=/blogs/edit_entry"
},
service = MVCRenderCommand.class
)
public class EditEntryMVCRenderCommand implements MVCRenderCommand {
@Override
public String render(
RenderRequest renderRequest, RenderResponse renderResponse)
throws PortletException {
try {
BlogsEntry entry = ActionUtil.getEntry(renderRequest);
HttpServletRequest request = _portal.getHttpServletRequest(
renderRequest);
request.setAttribute(WebKeys.BLOGS_ENTRY, entry);
renderRequest.setAttribute(
BlogsWebKeys.BLOGS_ITEM_SELECTOR_HELPER,
_blogsItemSelectorHelper);
}
catch (Exception e) {
if (e instanceof NoSuchEntryException ||
e instanceof PrincipalException) {
SessionErrors.add(renderRequest, e.getClass());
return "/blogs/error.jsp";
}
else {
throw new PortletException(e);
}
}
return "/blogs/edit_entry.jsp";
}
@Reference(unbind = "-")
public void setItemSelectorHelper(
BlogsItemSelectorHelper blogsItemSelectorHelper) {
_blogsItemSelectorHelper = blogsItemSelectorHelper;
}
private BlogsItemSelectorHelper _blogsItemSelectorHelper;
@Reference
private Portal _portal;
}