1
22
23 package com.liferay.portlet.imagegallery.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.imagegallery.model.IGImage;
35 import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
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 FindImageAction 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 imageId = ParamUtil.getLong(request, "imageId");
66
67 plid = getPlid(plid, imageId);
68
69 PortletURL portletURL = new PortletURLImpl(
70 request, PortletKeys.IMAGE_GALLERY, plid,
71 PortletRequest.RENDER_PHASE);
72
73 portletURL.setWindowState(WindowState.MAXIMIZED);
74 portletURL.setPortletMode(PortletMode.VIEW);
75
76 portletURL.setParameter(
77 "struts_action", "/image_gallery/edit_image");
78 portletURL.setParameter("imageId", String.valueOf(imageId));
79
80 response.sendRedirect(portletURL.toString());
81
82 return null;
83 }
84 catch (Exception e) {
85 PortalUtil.sendError(e, request, response);
86
87 return null;
88 }
89 }
90
91 protected long getPlid(long plid, long imageId) throws Exception {
92 if (plid != LayoutConstants.DEFAULT_PLID) {
93 try {
94 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
95
96 LayoutTypePortlet layoutTypePortlet =
97 (LayoutTypePortlet)layout.getLayoutType();
98
99 if (layoutTypePortlet.hasPortletId(PortletKeys.IMAGE_GALLERY)) {
100 return plid;
101 }
102 }
103 catch (NoSuchLayoutException nsle) {
104 }
105 }
106
107 IGImage image = IGImageLocalServiceUtil.getImage(imageId);
108
109 plid = PortalUtil.getPlidFromPortletId(
110 image.getGroupId(), PortletKeys.IMAGE_GALLERY);
111
112 if (plid != LayoutConstants.DEFAULT_PLID) {
113 return plid;
114 }
115 else {
116 throw new NoSuchLayoutException(
117 "No page was found with the Image Gallery portlet.");
118 }
119 }
120
121 }