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