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