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