001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.util;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
019    import com.liferay.portal.kernel.repository.model.FileEntry;
020    import com.liferay.portal.kernel.repository.model.FileVersion;
021    import com.liferay.portal.kernel.repository.model.Folder;
022    import com.liferay.portal.kernel.search.Hits;
023    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
024    import com.liferay.portal.kernel.util.OrderByComparator;
025    import com.liferay.portal.service.ServiceContext;
026    import com.liferay.portal.theme.ThemeDisplay;
027    import com.liferay.portlet.documentlibrary.model.DLFileEntryType;
028    import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
029    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
030    
031    import java.util.List;
032    import java.util.Map;
033    import java.util.Set;
034    
035    import javax.portlet.PortletRequest;
036    import javax.portlet.PortletURL;
037    import javax.portlet.RenderRequest;
038    import javax.portlet.RenderResponse;
039    
040    import javax.servlet.http.HttpServletRequest;
041    
042    /**
043     * @author Brian Wing Shun Chan
044     * @author Julio Camarero
045     */
046    public class DLUtil {
047    
048            public static void addPortletBreadcrumbEntries(
049                            DLFileShortcut dlFileShortcut, HttpServletRequest request,
050                            RenderResponse renderResponse)
051                    throws Exception {
052    
053                    getDL().addPortletBreadcrumbEntries(
054                            dlFileShortcut, request, renderResponse);
055            }
056    
057            public static void addPortletBreadcrumbEntries(
058                            FileEntry fileEntry, HttpServletRequest request,
059                            RenderResponse renderResponse)
060                    throws Exception {
061    
062                    getDL().addPortletBreadcrumbEntries(fileEntry, request, renderResponse);
063            }
064    
065            public static void addPortletBreadcrumbEntries(
066                            Folder folder, HttpServletRequest request,
067                            LiferayPortletResponse liferayPortletResponse)
068                    throws Exception {
069    
070                    getDL().addPortletBreadcrumbEntries(
071                            folder, request, liferayPortletResponse);
072            }
073    
074            public static void addPortletBreadcrumbEntries(
075                            Folder folder, HttpServletRequest request, PortletURL portletURL)
076                    throws Exception {
077    
078                    getDL().addPortletBreadcrumbEntries(folder, request, portletURL);
079            }
080    
081            public static void addPortletBreadcrumbEntries(
082                            Folder folder, HttpServletRequest request,
083                            RenderResponse renderResponse)
084                    throws Exception {
085    
086                    getDL().addPortletBreadcrumbEntries(folder, request, renderResponse);
087            }
088    
089            public static void addPortletBreadcrumbEntries(
090                            long folderId, HttpServletRequest request,
091                            RenderResponse renderResponse)
092                    throws Exception {
093    
094                    getDL().addPortletBreadcrumbEntries(folderId, request, renderResponse);
095            }
096    
097            public static int compareVersions(String version1, String version2) {
098                    return getDL().compareVersions(version1, version2);
099            }
100    
101            public static String getAbsolutePath(
102                            PortletRequest portletRequest, long folderId)
103                    throws PortalException {
104    
105                    return getDL().getAbsolutePath(portletRequest, folderId);
106            }
107    
108            public static Set<String> getAllMediaGalleryMimeTypes() {
109                    return getDL().getAllMediaGalleryMimeTypes();
110            }
111    
112            public static String getDDMStructureKey(DLFileEntryType dlFileEntryType) {
113                    return getDL().getDDMStructureKey(dlFileEntryType);
114            }
115    
116            public static String getDDMStructureKey(String fileEntryTypeUuid) {
117                    return getDL().getDDMStructureKey(fileEntryTypeUuid);
118            }
119    
120            public static String getDeprecatedDDMStructureKey(
121                    DLFileEntryType dlFileEntryType) {
122    
123                    return getDL().getDeprecatedDDMStructureKey(dlFileEntryType);
124            }
125    
126            public static String getDeprecatedDDMStructureKey(long fileEntryTypeId) {
127                    return getDL().getDeprecatedDDMStructureKey(fileEntryTypeId);
128            }
129    
130            public static String getDividedPath(long id) {
131                    return getDL().getDividedPath(id);
132            }
133    
134            public static DL getDL() {
135                    PortalRuntimePermission.checkGetBeanProperty(DLUtil.class);
136    
137                    return _dl;
138            }
139    
140            public static String getDLFileEntryControlPanelLink(
141                            PortletRequest portletRequest, long fileEntryId)
142                    throws PortalException {
143    
144                    return getDL().getDLFileEntryControlPanelLink(
145                            portletRequest, fileEntryId);
146            }
147    
148            public static String getDLFolderControlPanelLink(
149                            PortletRequest portletRequest, long folderId)
150                    throws PortalException {
151    
152                    return getDL().getDLFolderControlPanelLink(portletRequest, folderId);
153            }
154    
155            public static String getDownloadURL(
156                    FileEntry fileEntry, FileVersion fileVersion, ThemeDisplay themeDisplay,
157                    String queryString) {
158    
159                    return getDL().getDownloadURL(
160                            fileEntry, fileVersion, themeDisplay, queryString);
161            }
162    
163            public static String getDownloadURL(
164                    FileEntry fileEntry, FileVersion fileVersion, ThemeDisplay themeDisplay,
165                    String queryString, boolean appendVersion, boolean absoluteURL) {
166    
167                    return getDL().getDownloadURL(
168                            fileEntry, fileVersion, themeDisplay, queryString, appendVersion,
169                            absoluteURL);
170            }
171    
172            public static Map<String, String> getEmailDefinitionTerms(
173                    RenderRequest request, String emailFromAddress, String emailFromName) {
174    
175                    return getDL().getEmailDefinitionTerms(
176                            request, emailFromAddress, emailFromName);
177            }
178    
179            public static Map<String, String> getEmailFromDefinitionTerms(
180                    RenderRequest request, String emailFromAddress, String emailFromName) {
181    
182                    return getDL().getEmailFromDefinitionTerms(
183                            request, emailFromAddress, emailFromName);
184            }
185    
186            public static List<Object> getEntries(Hits hits) {
187                    return getDL().getEntries(hits);
188            }
189    
190            public static List<FileEntry> getFileEntries(Hits hits) {
191                    return getDL().getFileEntries(hits);
192            }
193    
194            public static String getFileEntryImage(
195                    FileEntry fileEntry, ThemeDisplay themeDisplay) {
196    
197                    return getDL().getFileEntryImage(fileEntry, themeDisplay);
198            }
199    
200            public static Set<Long> getFileEntryTypeSubscriptionClassPKs(long userId) {
201                    return getDL().getFileEntryTypeSubscriptionClassPKs(userId);
202            }
203    
204            public static String getFileIcon(String extension) {
205                    return getDL().getFileIcon(extension);
206            }
207    
208            public static String getFileIconCssClass(String extension) {
209                    return getDL().getFileIconCssClass(extension);
210            }
211    
212            public static String getFileName(
213                    long groupId, long folderId, String tempFileName) {
214    
215                    return getDL().getFileName(groupId, folderId, tempFileName);
216            }
217    
218            public static String getGenericName(String extension) {
219                    return getDL().getGenericName(extension);
220            }
221    
222            public static String getImagePreviewURL(
223                            FileEntry fileEntry, FileVersion fileVersion,
224                            ThemeDisplay themeDisplay)
225                    throws Exception {
226    
227                    return getDL().getImagePreviewURL(fileEntry, fileVersion, themeDisplay);
228            }
229    
230            public static String getImagePreviewURL(
231                            FileEntry fileEntry, ThemeDisplay themeDisplay)
232                    throws Exception {
233    
234                    return getDL().getImagePreviewURL(fileEntry, themeDisplay);
235            }
236    
237            public static String getPreviewURL(
238                    FileEntry fileEntry, FileVersion fileVersion, ThemeDisplay themeDisplay,
239                    String queryString) {
240    
241                    return getDL().getPreviewURL(
242                            fileEntry, fileVersion, themeDisplay, queryString);
243            }
244    
245            /**
246             * @deprecated As of 6.2.0, replaced by {@link #getPreviewURL(FileEntry,
247             *             FileVersion, ThemeDisplay, String, boolean, boolean)}
248             */
249            @Deprecated
250            public static String getPreviewURL(
251                    FileEntry fileEntry, FileVersion fileVersion, ThemeDisplay themeDisplay,
252                    String queryString, boolean appendToken) {
253    
254                    return getDL().getPreviewURL(
255                            fileEntry, fileVersion, themeDisplay, queryString, appendToken);
256            }
257    
258            public static String getPreviewURL(
259                    FileEntry fileEntry, FileVersion fileVersion, ThemeDisplay themeDisplay,
260                    String queryString, boolean appendVersion, boolean absoluteURL) {
261    
262                    return getDL().getPreviewURL(
263                            fileEntry, fileVersion, themeDisplay, queryString, appendVersion,
264                            absoluteURL);
265            }
266    
267            public static <T> OrderByComparator<T> getRepositoryModelOrderByComparator(
268                    String orderByCol, String orderByType) {
269    
270                    return getDL().getRepositoryModelOrderByComparator(
271                            orderByCol, orderByType);
272            }
273    
274            public static String getSanitizedFileName(String title, String extension) {
275                    return getDL().getSanitizedFileName(title, extension);
276            }
277    
278            public static String getTempFileId(long id, String version) {
279                    return getDL().getTempFileId(id, version);
280            }
281    
282            public static String getTempFileId(
283                    long id, String version, String languageId) {
284    
285                    return getDL().getTempFileId(id, version, languageId);
286            }
287    
288            /**
289             * @deprecated As of 7.0.0, replaced by {@link #getThumbnailSrc(FileEntry,
290             *             ThemeDisplay)}
291             */
292            @Deprecated
293            public static String getThumbnailSrc(
294                            FileEntry fileEntry, DLFileShortcut dlFileShortcut,
295                            ThemeDisplay themeDisplay)
296                    throws Exception {
297    
298                    return getDL().getThumbnailSrc(fileEntry, dlFileShortcut, themeDisplay);
299            }
300    
301            /**
302             * @deprecated As of 7.0.0, replaced by {@link #getThumbnailSrc(FileEntry,
303             *             FileVersion, ThemeDisplay)}
304             */
305            @Deprecated
306            public static String getThumbnailSrc(
307                            FileEntry fileEntry, FileVersion fileVersion,
308                            DLFileShortcut dlFileShortcut, ThemeDisplay themeDisplay)
309                    throws Exception {
310    
311                    return getDL().getThumbnailSrc(
312                            fileEntry, fileVersion, dlFileShortcut, themeDisplay);
313            }
314    
315            public static String getThumbnailSrc(
316                            FileEntry fileEntry, FileVersion fileVersion,
317                            ThemeDisplay themeDisplay)
318                    throws Exception {
319    
320                    return getDL().getThumbnailSrc(fileEntry, fileVersion, themeDisplay);
321            }
322    
323            public static String getThumbnailSrc(
324                            FileEntry fileEntry, ThemeDisplay themeDisplay)
325                    throws Exception {
326    
327                    return getDL().getThumbnailSrc(fileEntry, themeDisplay);
328            }
329    
330            public static String getThumbnailStyle() throws Exception {
331                    return getDL().getThumbnailStyle();
332            }
333    
334            public static String getThumbnailStyle(boolean max, int margin)
335                    throws Exception {
336    
337                    return getDL().getThumbnailStyle(max, margin);
338            }
339    
340            public static String getTitleWithExtension(FileEntry fileEntry) {
341                    return getDL().getTitleWithExtension(fileEntry);
342            }
343    
344            public static String getTitleWithExtension(String title, String extension) {
345                    return getDL().getTitleWithExtension(title, extension);
346            }
347    
348            public static String getWebDavURL(
349                            ThemeDisplay themeDisplay, Folder folder, FileEntry fileEntry)
350                    throws PortalException {
351    
352                    return getDL().getWebDavURL(themeDisplay, folder, fileEntry);
353            }
354    
355            public static String getWebDavURL(
356                            ThemeDisplay themeDisplay, Folder folder, FileEntry fileEntry,
357                            boolean manualCheckInRequired)
358                    throws PortalException {
359    
360                    return getDL().getWebDavURL(
361                            themeDisplay, folder, fileEntry, manualCheckInRequired);
362            }
363    
364            public static String getWebDavURL(
365                            ThemeDisplay themeDisplay, Folder folder, FileEntry fileEntry,
366                            boolean manualCheckInRequired, boolean officeExtensionRequired)
367                    throws PortalException {
368    
369                    return getDL().getWebDavURL(
370                            themeDisplay, folder, fileEntry, manualCheckInRequired,
371                            officeExtensionRequired);
372            }
373    
374            public static boolean hasWorkflowDefinitionLink(
375                            long companyId, long groupId, long folderId, long fileEntryTypeId)
376                    throws Exception {
377    
378                    return getDL().hasWorkflowDefinitionLink(
379                            companyId, groupId, folderId, fileEntryTypeId);
380            }
381    
382            public static boolean isAutoGeneratedDLFileEntryTypeDDMStructureKey(
383                    String ddmStructureKey) {
384    
385                    return getDL().isAutoGeneratedDLFileEntryTypeDDMStructureKey(
386                            ddmStructureKey);
387            }
388    
389            public static boolean isOfficeExtension(String extension) {
390                    return getDL().isOfficeExtension(extension);
391            }
392    
393            public static boolean isSubscribedToFileEntryType(
394                    long companyId, long groupId, long userId, long fileEntryTypeId) {
395    
396                    return getDL().isSubscribedToFileEntryType(
397                            companyId, groupId, userId, fileEntryTypeId);
398            }
399    
400            public static boolean isSubscribedToFolder(
401                            long companyId, long groupId, long userId, long folderId)
402                    throws PortalException {
403    
404                    return getDL().isSubscribedToFolder(
405                            companyId, groupId, userId, folderId);
406            }
407    
408            public static boolean isSubscribedToFolder(
409                            long companyId, long groupId, long userId, long folderId,
410                            boolean recursive)
411                    throws PortalException {
412    
413                    return getDL().isSubscribedToFolder(
414                            companyId, groupId, userId, folderId, recursive);
415            }
416    
417            public static boolean isValidVersion(String version) {
418                    return getDL().isValidVersion(version);
419            }
420    
421            public static void startWorkflowInstance(
422                            long userId, DLFileVersion dlFileVersion, String syncEventType,
423                            ServiceContext serviceContext)
424                    throws PortalException {
425    
426                    getDL().startWorkflowInstance(
427                            userId, dlFileVersion, syncEventType, serviceContext);
428            }
429    
430            public void setDL(DL dl) {
431                    PortalRuntimePermission.checkSetBeanProperty(getClass());
432    
433                    _dl = dl;
434            }
435    
436            private static DL _dl;
437    
438    }