001
014
015 package com.liferay.portlet.messageboards.action;
016
017 import com.liferay.portal.NoSuchLayoutException;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.model.Layout;
020 import com.liferay.portal.model.LayoutConstants;
021 import com.liferay.portal.model.LayoutTypePortlet;
022 import com.liferay.portal.service.LayoutLocalServiceUtil;
023 import com.liferay.portal.util.PortalUtil;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portlet.PortletURLImpl;
026 import com.liferay.portlet.messageboards.model.MBMessage;
027 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
028
029 import javax.portlet.PortletMode;
030 import javax.portlet.PortletRequest;
031 import javax.portlet.PortletURL;
032 import javax.portlet.WindowState;
033
034 import javax.servlet.http.HttpServletRequest;
035 import javax.servlet.http.HttpServletResponse;
036
037 import org.apache.struts.action.Action;
038 import org.apache.struts.action.ActionForm;
039 import org.apache.struts.action.ActionForward;
040 import org.apache.struts.action.ActionMapping;
041
042
045 public class FindMessageAction extends Action {
046
047 public ActionForward execute(
048 ActionMapping mapping, ActionForm form, HttpServletRequest request,
049 HttpServletResponse response)
050 throws Exception {
051
052 try {
053 long plid = ParamUtil.getLong(request, "p_l_id");
054 long messageId = ParamUtil.getLong(request, "messageId");
055
056 plid = getPlid(plid, messageId);
057
058 PortletURL portletURL = new PortletURLImpl(
059 request, PortletKeys.MESSAGE_BOARDS, plid,
060 PortletRequest.RENDER_PHASE);
061
062 portletURL.setWindowState(WindowState.NORMAL);
063 portletURL.setPortletMode(PortletMode.VIEW);
064
065 portletURL.setParameter(
066 "struts_action", "/message_boards/view_message");
067 portletURL.setParameter("messageId", String.valueOf(messageId));
068
069 response.sendRedirect(portletURL.toString());
070
071 return null;
072 }
073 catch (Exception e) {
074 PortalUtil.sendError(e, request, response);
075
076 return null;
077 }
078 }
079
080 protected long getPlid(long plid, long messageId) throws Exception {
081 if (plid != LayoutConstants.DEFAULT_PLID) {
082 try {
083 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
084
085 LayoutTypePortlet layoutTypePortlet =
086 (LayoutTypePortlet)layout.getLayoutType();
087
088 if (layoutTypePortlet.hasPortletId(
089 PortletKeys.MESSAGE_BOARDS)) {
090
091 return plid;
092 }
093 }
094 catch (NoSuchLayoutException nsle) {
095 }
096 }
097
098 MBMessage message = MBMessageLocalServiceUtil.getMessage(messageId);
099
100 plid = PortalUtil.getPlidFromPortletId(
101 message.getGroupId(), PortletKeys.MESSAGE_BOARDS);
102
103 if (plid != LayoutConstants.DEFAULT_PLID) {
104 return plid;
105 }
106 else {
107 throw new NoSuchLayoutException(
108 "No page was found with the Message Boards portlet.");
109 }
110 }
111
112 }