1
22
23 package com.liferay.portlet.documentlibrary.action;
24
25 import com.liferay.portal.kernel.util.ParamUtil;
26 import com.liferay.portal.kernel.util.Validator;
27 import com.liferay.portal.util.PortalUtil;
28 import com.liferay.portal.util.WebKeys;
29 import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
30 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
31 import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
32 import com.liferay.portlet.documentlibrary.model.DLFolder;
33 import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
34 import com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil;
35 import com.liferay.portlet.documentlibrary.service.DLFileShortcutServiceUtil;
36 import com.liferay.portlet.documentlibrary.service.DLFolderServiceUtil;
37
38 import javax.portlet.ActionRequest;
39 import javax.portlet.RenderRequest;
40
41 import javax.servlet.http.HttpServletRequest;
42
43
49 public class ActionUtil {
50
51 public static void getFileEntry(ActionRequest req) throws Exception {
52 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
53
54 getFileEntry(httpReq);
55 }
56
57 public static void getFileEntry(RenderRequest req) throws Exception {
58 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
59
60 getFileEntry(httpReq);
61 }
62
63 public static void getFileEntry(HttpServletRequest req) throws Exception {
64 long folderId = ParamUtil.getLong(req, "folderId");
65 long newFolderId = ParamUtil.getLong(req, "newFolderId");
66 String name = ParamUtil.getString(req, "name");
67
68 DLFileEntry fileEntry = null;
69
70 if ((folderId > 0) && Validator.isNotNull(name)) {
71 try {
72 fileEntry = DLFileEntryServiceUtil.getFileEntry(folderId, name);
73 }
74 catch (NoSuchFileEntryException nsfe) {
75
76
79 fileEntry = DLFileEntryServiceUtil.getFileEntry(
80 newFolderId, name);
81 }
82 }
83
84 req.setAttribute(WebKeys.DOCUMENT_LIBRARY_FILE_ENTRY, fileEntry);
85 }
86
87 public static void getFileShortcut(ActionRequest req) throws Exception {
88 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
89
90 getFileShortcut(httpReq);
91 }
92
93 public static void getFileShortcut(RenderRequest req) throws Exception {
94 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
95
96 getFileShortcut(httpReq);
97 }
98
99 public static void getFileShortcut(HttpServletRequest req)
100 throws Exception {
101
102 long fileShortcutId = ParamUtil.getLong(req, "fileShortcutId");
103
104 DLFileShortcut fileShortcut = null;
105
106 if (fileShortcutId > 0) {
107 fileShortcut = DLFileShortcutServiceUtil.getFileShortcut(
108 fileShortcutId);
109 }
110
111 req.setAttribute(WebKeys.DOCUMENT_LIBRARY_FILE_SHORTCUT, fileShortcut);
112 }
113
114 public static void getFolder(ActionRequest req) throws Exception {
115 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
116
117 getFolder(httpReq);
118 }
119
120 public static void getFolder(RenderRequest req) throws Exception {
121 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
122
123 getFolder(httpReq);
124 }
125
126 public static void getFolder(HttpServletRequest req) throws Exception {
127 long folderId = ParamUtil.getLong(req, "folderId");
128
129 DLFolder folder = null;
130
131 if ((folderId > 0) &&
132 (folderId != DLFolderImpl.DEFAULT_PARENT_FOLDER_ID)) {
133
134 folder = DLFolderServiceUtil.getFolder(folderId);
135 }
136
137 req.setAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER, folder);
138 }
139
140 }