1
19
20 package com.liferay.portlet.calendar.action;
21
22 import com.liferay.portal.NoSuchLayoutException;
23 import com.liferay.portal.kernel.util.ParamUtil;
24 import com.liferay.portal.model.Layout;
25 import com.liferay.portal.model.LayoutConstants;
26 import com.liferay.portal.model.LayoutTypePortlet;
27 import com.liferay.portal.service.LayoutLocalServiceUtil;
28 import com.liferay.portal.util.PortalUtil;
29 import com.liferay.portal.util.PortletKeys;
30 import com.liferay.portlet.PortletURLImpl;
31 import com.liferay.portlet.calendar.model.CalEvent;
32 import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
33
34 import javax.portlet.PortletMode;
35 import javax.portlet.PortletRequest;
36 import javax.portlet.PortletURL;
37 import javax.portlet.WindowState;
38
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse;
41
42 import org.apache.struts.action.Action;
43 import org.apache.struts.action.ActionForm;
44 import org.apache.struts.action.ActionForward;
45 import org.apache.struts.action.ActionMapping;
46
47
53 public class FindEventAction extends Action {
54
55 public ActionForward execute(
56 ActionMapping mapping, ActionForm form, HttpServletRequest request,
57 HttpServletResponse response)
58 throws Exception {
59
60 try {
61 long plid = ParamUtil.getLong(request, "p_l_id");
62 long eventId = ParamUtil.getLong(request, "eventId");
63
64 plid = getPlid(plid, eventId);
65
66 PortletURL portletURL = new PortletURLImpl(
67 request, PortletKeys.CALENDAR, plid,
68 PortletRequest.RENDER_PHASE);
69
70 portletURL.setWindowState(WindowState.MAXIMIZED);
71 portletURL.setPortletMode(PortletMode.VIEW);
72
73 portletURL.setParameter("struts_action", "/calendar/view_event");
74 portletURL.setParameter("eventId", String.valueOf(eventId));
75
76 response.sendRedirect(portletURL.toString());
77
78 return null;
79 }
80 catch (Exception e) {
81 PortalUtil.sendError(e, request, response);
82
83 return null;
84 }
85 }
86
87 protected long getPlid(long plid, long eventId) throws Exception {
88 if (plid != LayoutConstants.DEFAULT_PLID) {
89 try {
90 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
91
92 LayoutTypePortlet layoutTypePortlet =
93 (LayoutTypePortlet)layout.getLayoutType();
94
95 if (layoutTypePortlet.hasPortletId(PortletKeys.CALENDAR)) {
96 return plid;
97 }
98 }
99 catch (NoSuchLayoutException nsle) {
100 }
101 }
102
103 CalEvent event = CalEventLocalServiceUtil.getEvent(eventId);
104
105 plid = PortalUtil.getPlidFromPortletId(
106 event.getGroupId(), PortletKeys.CALENDAR);
107
108 if (plid != LayoutConstants.DEFAULT_PLID) {
109 return plid;
110 }
111 else {
112 throw new NoSuchLayoutException(
113 "No page was found with the Calendar portlet.");
114 }
115 }
116
117 }