1
14
15 package com.liferay.portlet.documentlibrary.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.documentlibrary.model.DLFolder;
27 import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
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 FindFolderAction 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 groupId = ParamUtil.getLong(request,"groupId");
57 long folderId = ParamUtil.getLong(request, "folderId");
58
59 plid = getPlid(plid, groupId, folderId);
60
61 PortletURL portletURL = new PortletURLImpl(
62 request, PortletKeys.DOCUMENT_LIBRARY, plid,
63 PortletRequest.RENDER_PHASE);
64
65 portletURL.setWindowState(WindowState.NORMAL);
66 portletURL.setPortletMode(PortletMode.VIEW);
67
68 portletURL.setParameter(
69 "struts_action", "/document_library/view");
70 portletURL.setParameter("folderId", String.valueOf(folderId));
71
72 response.sendRedirect(portletURL.toString());
73
74 return null;
75 }
76 catch (Exception e) {
77 PortalUtil.sendError(e, request, response);
78
79 return null;
80 }
81 }
82
83 protected long getPlid(long plid, long groupId, long folderId)
84 throws Exception {
85
86 if (plid != LayoutConstants.DEFAULT_PLID) {
87 try {
88 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
89
90 LayoutTypePortlet layoutTypePortlet =
91 (LayoutTypePortlet)layout.getLayoutType();
92
93 if (layoutTypePortlet.hasPortletId(
94 PortletKeys.DOCUMENT_LIBRARY)) {
95
96 return plid;
97 }
98 }
99 catch (NoSuchLayoutException nsle) {
100 }
101 }
102
103 if (groupId <= 0) {
104 DLFolder folder = DLFolderLocalServiceUtil.getFolder(folderId);
105
106 groupId = folder.getGroupId();
107 }
108
109 plid = PortalUtil.getPlidFromPortletId(
110 groupId, PortletKeys.DOCUMENT_LIBRARY);
111
112 if (plid != LayoutConstants.DEFAULT_PLID) {
113 return plid;
114 }
115 else {
116 throw new NoSuchLayoutException(
117 "No page was found with the Document Library portlet.");
118 }
119 }
120
121 }