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.DLFileEntry;
27 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
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 FindFileEntryAction 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 fileEntryId = ParamUtil.getLong(request, "fileEntryId");
57
58 plid = getPlid(plid, fileEntryId);
59
60 PortletURL portletURL = new PortletURLImpl(
61 request, PortletKeys.DOCUMENT_LIBRARY, plid,
62 PortletRequest.RENDER_PHASE);
63
64 portletURL.setWindowState(WindowState.NORMAL);
65 portletURL.setPortletMode(PortletMode.VIEW);
66
67 portletURL.setParameter(
68 "struts_action", "/document_library/view_file_entry");
69
70 DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(
71 fileEntryId);
72
73 portletURL.setParameter(
74 "folderId", String.valueOf(fileEntry.getFolderId()));
75 portletURL.setParameter("name", fileEntry.getName());
76
77 response.sendRedirect(portletURL.toString());
78
79 return null;
80 }
81 catch (Exception e) {
82 PortalUtil.sendError(e, request, response);
83
84 return null;
85 }
86 }
87
88 protected long getPlid(long plid, long fileEntryId) throws Exception {
89 if (plid != LayoutConstants.DEFAULT_PLID) {
90 try {
91 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
92
93 LayoutTypePortlet layoutTypePortlet =
94 (LayoutTypePortlet)layout.getLayoutType();
95
96 if (layoutTypePortlet.hasPortletId(
97 PortletKeys.DOCUMENT_LIBRARY)) {
98
99 return plid;
100 }
101 }
102 catch (NoSuchLayoutException nsle) {
103 }
104 }
105
106 DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(
107 fileEntryId);
108
109 plid = PortalUtil.getPlidFromPortletId(
110 fileEntry.getGroupId(), 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 }