1
22
23 package com.liferay.portlet.documentlibrary.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.documentlibrary.model.DLFileEntry;
35 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
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 FindFileEntryAction 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 fileEntryId = ParamUtil.getLong(request, "fileEntryId");
66
67 plid = getPlid(plid, fileEntryId);
68
69 PortletURL portletURL = new PortletURLImpl(
70 request, PortletKeys.DOCUMENT_LIBRARY, plid,
71 PortletRequest.RENDER_PHASE);
72
73 portletURL.setWindowState(WindowState.NORMAL);
74 portletURL.setPortletMode(PortletMode.VIEW);
75
76 portletURL.setParameter(
77 "struts_action", "/document_library/view_file_entry");
78
79 DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(
80 fileEntryId);
81
82 portletURL.setParameter(
83 "folderId", String.valueOf(fileEntry.getFolderId()));
84 portletURL.setParameter("name", fileEntry.getName());
85
86 response.sendRedirect(portletURL.toString());
87
88 return null;
89 }
90 catch (Exception e) {
91 PortalUtil.sendError(e, request, response);
92
93 return null;
94 }
95 }
96
97 protected long getPlid(long plid, long fileEntryId) throws Exception {
98 if (plid != LayoutConstants.DEFAULT_PLID) {
99 try {
100 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
101
102 LayoutTypePortlet layoutTypePortlet =
103 (LayoutTypePortlet)layout.getLayoutType();
104
105 if (layoutTypePortlet.hasPortletId(
106 PortletKeys.DOCUMENT_LIBRARY)) {
107
108 return plid;
109 }
110 }
111 catch (NoSuchLayoutException nsle) {
112 }
113 }
114
115 DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(
116 fileEntryId);
117
118 plid = PortalUtil.getPlidFromPortletId(
119 fileEntry.getGroupId(), PortletKeys.DOCUMENT_LIBRARY);
120
121 if (plid != LayoutConstants.DEFAULT_PLID) {
122 return plid;
123 }
124 else {
125 throw new NoSuchLayoutException(
126 "No page was found with the Document Library portlet.");
127 }
128 }
129
130 }