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