1
19
20 package com.liferay.portlet.documentlibrary.action;
21
22 import com.liferay.portal.NoSuchLayoutException;
23 import com.liferay.portal.kernel.util.ParamUtil;
24 import com.liferay.portal.model.Layout;
25 import com.liferay.portal.model.LayoutConstants;
26 import com.liferay.portal.model.LayoutTypePortlet;
27 import com.liferay.portal.service.LayoutLocalServiceUtil;
28 import com.liferay.portal.util.PortalUtil;
29 import com.liferay.portal.util.PortletKeys;
30 import com.liferay.portlet.PortletURLImpl;
31 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
32 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
33
34 import javax.portlet.PortletMode;
35 import javax.portlet.PortletRequest;
36 import javax.portlet.PortletURL;
37 import javax.portlet.WindowState;
38
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse;
41
42 import org.apache.struts.action.Action;
43 import org.apache.struts.action.ActionForm;
44 import org.apache.struts.action.ActionForward;
45 import org.apache.struts.action.ActionMapping;
46
47
53 public class FindFileEntryAction extends Action {
54
55 public ActionForward execute(
56 ActionMapping mapping, ActionForm form, HttpServletRequest request,
57 HttpServletResponse response)
58 throws Exception {
59
60 try {
61 long plid = ParamUtil.getLong(request, "p_l_id");
62 long fileEntryId = ParamUtil.getLong(request, "fileEntryId");
63
64 plid = getPlid(plid, fileEntryId);
65
66 PortletURL portletURL = new PortletURLImpl(
67 request, PortletKeys.DOCUMENT_LIBRARY, plid,
68 PortletRequest.RENDER_PHASE);
69
70 portletURL.setWindowState(WindowState.NORMAL);
71 portletURL.setPortletMode(PortletMode.VIEW);
72
73 portletURL.setParameter(
74 "struts_action", "/document_library/view_file_entry");
75
76 DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(
77 fileEntryId);
78
79 portletURL.setParameter(
80 "folderId", String.valueOf(fileEntry.getFolderId()));
81 portletURL.setParameter("name", fileEntry.getName());
82
83 response.sendRedirect(portletURL.toString());
84
85 return null;
86 }
87 catch (Exception e) {
88 PortalUtil.sendError(e, request, response);
89
90 return null;
91 }
92 }
93
94 protected long getPlid(long plid, long fileEntryId) throws Exception {
95 if (plid != LayoutConstants.DEFAULT_PLID) {
96 try {
97 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
98
99 LayoutTypePortlet layoutTypePortlet =
100 (LayoutTypePortlet)layout.getLayoutType();
101
102 if (layoutTypePortlet.hasPortletId(
103 PortletKeys.DOCUMENT_LIBRARY)) {
104
105 return plid;
106 }
107 }
108 catch (NoSuchLayoutException nsle) {
109 }
110 }
111
112 DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(
113 fileEntryId);
114
115 plid = PortalUtil.getPlidFromPortletId(
116 fileEntry.getGroupId(), PortletKeys.DOCUMENT_LIBRARY);
117
118 if (plid != LayoutConstants.DEFAULT_PLID) {
119 return plid;
120 }
121 else {
122 throw new NoSuchLayoutException(
123 "No page was found with the Document Library portlet.");
124 }
125 }
126
127 }