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.portal.portletfilerepository;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.repository.model.FileEntry;
021    import com.liferay.portal.kernel.repository.model.Folder;
022    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
023    import com.liferay.portal.kernel.util.ObjectValuePair;
024    import com.liferay.portal.kernel.util.OrderByComparator;
025    import com.liferay.portal.model.Repository;
026    import com.liferay.portal.service.ServiceContext;
027    import com.liferay.portal.theme.ThemeDisplay;
028    
029    import java.io.File;
030    import java.io.InputStream;
031    
032    import java.util.List;
033    
034    /**
035     * @author Eudaldo Alonso
036     * @author Alexander Chow
037     */
038    @ProviderType
039    public class PortletFileRepositoryUtil {
040    
041            public static void addPortletFileEntries(
042                            long groupId, long userId, String className, long classPK,
043                            String portletId, long folderId,
044                            List<ObjectValuePair<String, InputStream>> inputStreamOVPs)
045                    throws PortalException {
046    
047                    getPortletFileRepository().addPortletFileEntries(
048                            groupId, userId, className, classPK, portletId, folderId,
049                            inputStreamOVPs);
050            }
051    
052            public static FileEntry addPortletFileEntry(
053                            long groupId, long userId, String className, long classPK,
054                            String portletId, long folderId, File file, String fileName,
055                            String mimeType, boolean indexingEnabled)
056                    throws PortalException {
057    
058                    return getPortletFileRepository().addPortletFileEntry(
059                            groupId, userId, className, classPK, portletId, folderId, file,
060                            fileName, mimeType, indexingEnabled);
061            }
062    
063            public static FileEntry addPortletFileEntry(
064                            long groupId, long userId, String className, long classPK,
065                            String portletId, long folderId, InputStream inputStream,
066                            String fileName, String mimeType, boolean indexingEnabled)
067                    throws PortalException {
068    
069                    return getPortletFileRepository().addPortletFileEntry(
070                            groupId, userId, className, classPK, portletId, folderId,
071                            inputStream, fileName, mimeType, indexingEnabled);
072            }
073    
074            public static Folder addPortletFolder(
075                            long userId, long repositoryId, long parentFolderId,
076                            String folderName, ServiceContext serviceContext)
077                    throws PortalException {
078    
079                    return getPortletFileRepository().addPortletFolder(
080                            userId, repositoryId, parentFolderId, folderName, serviceContext);
081            }
082    
083            public static Folder addPortletFolder(
084                            long groupId, long userId, String portletId, long parentFolderId,
085                            String folderName, ServiceContext serviceContext)
086                    throws PortalException {
087    
088                    return getPortletFileRepository().addPortletFolder(
089                            groupId, userId, portletId, parentFolderId, folderName,
090                            serviceContext);
091            }
092    
093            public static Repository addPortletRepository(
094                            long groupId, String portletId, ServiceContext serviceContext)
095                    throws PortalException {
096    
097                    return getPortletFileRepository().addPortletRepository(
098                            groupId, portletId, serviceContext);
099            }
100    
101            /**
102             * @deprecated As of 7.0.0, replaced by {@link #deletePortletFolder}
103             */
104            @Deprecated
105            public static void deleteFolder(long folderId) throws PortalException {
106                    getPortletFileRepository().deleteFolder(folderId);
107            }
108    
109            public static void deletePortletFileEntries(long groupId, long folderId)
110                    throws PortalException {
111    
112                    getPortletFileRepository().deletePortletFileEntries(groupId, folderId);
113            }
114    
115            public static void deletePortletFileEntries(
116                            long groupId, long folderId, int status)
117                    throws PortalException {
118    
119                    getPortletFileRepository().deletePortletFileEntries(
120                            groupId, folderId, status);
121            }
122    
123            public static void deletePortletFileEntry(long fileEntryId)
124                    throws PortalException {
125    
126                    getPortletFileRepository().deletePortletFileEntry(fileEntryId);
127            }
128    
129            public static void deletePortletFileEntry(
130                            long groupId, long folderId, String fileName)
131                    throws PortalException {
132    
133                    getPortletFileRepository().deletePortletFileEntry(
134                            groupId, folderId, fileName);
135            }
136    
137            public static void deletePortletFolder(long folderId)
138                    throws PortalException {
139    
140                    getPortletFileRepository().deletePortletFolder(folderId);
141            }
142    
143            public static void deletePortletRepository(long groupId, String portletId)
144                    throws PortalException {
145    
146                    getPortletFileRepository().deletePortletRepository(groupId, portletId);
147            }
148    
149            public static Repository fetchPortletRepository(
150                    long groupId, String portletId) {
151    
152                    return getPortletFileRepository().fetchPortletRepository(
153                            groupId, portletId);
154            }
155    
156            public static String getDownloadPortletFileEntryURL(
157                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString) {
158    
159                    return getPortletFileRepository().getDownloadPortletFileEntryURL(
160                            themeDisplay, fileEntry, queryString);
161            }
162    
163            public static String getDownloadPortletFileEntryURL(
164                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString,
165                    boolean absoluteURL) {
166    
167                    return getPortletFileRepository().getDownloadPortletFileEntryURL(
168                            themeDisplay, fileEntry, queryString, absoluteURL);
169            }
170    
171            public static List<FileEntry> getPortletFileEntries(
172                            long groupId, long folderId)
173                    throws PortalException {
174    
175                    return getPortletFileRepository().getPortletFileEntries(
176                            groupId, folderId);
177            }
178    
179            public static List<FileEntry> getPortletFileEntries(
180                            long groupId, long folderId, int status)
181                    throws PortalException {
182    
183                    return getPortletFileRepository().getPortletFileEntries(
184                            groupId, folderId, status);
185            }
186    
187            public static List<FileEntry> getPortletFileEntries(
188                            long groupId, long folderId, int status, int start, int end,
189                            OrderByComparator<FileEntry> obc)
190                    throws PortalException {
191    
192                    return getPortletFileRepository().getPortletFileEntries(
193                            groupId, folderId, status, start, end, obc);
194            }
195    
196            public static List<FileEntry> getPortletFileEntries(
197                            long groupId, long folderId, OrderByComparator<FileEntry> obc)
198                    throws PortalException {
199    
200                    return getPortletFileRepository().getPortletFileEntries(
201                            groupId, folderId, obc);
202            }
203    
204            public static int getPortletFileEntriesCount(long groupId, long folderId)
205                    throws PortalException {
206    
207                    return getPortletFileRepository().getPortletFileEntriesCount(
208                            groupId, folderId);
209            }
210    
211            public static int getPortletFileEntriesCount(
212                            long groupId, long folderId, int status)
213                    throws PortalException {
214    
215                    return getPortletFileRepository().getPortletFileEntriesCount(
216                            groupId, folderId, status);
217            }
218    
219            public static FileEntry getPortletFileEntry(long fileEntryId)
220                    throws PortalException {
221    
222                    return getPortletFileRepository().getPortletFileEntry(fileEntryId);
223            }
224    
225            public static FileEntry getPortletFileEntry(
226                            long groupId, long folderId, String fileName)
227                    throws PortalException {
228    
229                    return getPortletFileRepository().getPortletFileEntry(
230                            groupId, folderId, fileName);
231            }
232    
233            public static FileEntry getPortletFileEntry(String uuid, long groupId)
234                    throws PortalException {
235    
236                    return getPortletFileRepository().getPortletFileEntry(uuid, groupId);
237            }
238    
239            public static String getPortletFileEntryURL(
240                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString) {
241    
242                    return getPortletFileRepository().getPortletFileEntryURL(
243                            themeDisplay, fileEntry, queryString);
244            }
245    
246            public static String getPortletFileEntryURL(
247                    ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString,
248                    boolean absoluteURL) {
249    
250                    return getPortletFileRepository().getPortletFileEntryURL(
251                            themeDisplay, fileEntry, queryString, absoluteURL);
252            }
253    
254            public static PortletFileRepository getPortletFileRepository() {
255                    PortalRuntimePermission.checkGetBeanProperty(
256                            PortletFileRepositoryUtil.class);
257    
258                    return _portletFileRepository;
259            }
260    
261            public static Folder getPortletFolder(long folderId)
262                    throws PortalException {
263    
264                    return getPortletFileRepository().getPortletFolder(folderId);
265            }
266    
267            public static Folder getPortletFolder(
268                            long repositoryId, long parentFolderId, String folderName)
269                    throws PortalException {
270    
271                    return getPortletFileRepository().getPortletFolder(
272                            repositoryId, parentFolderId, folderName);
273            }
274    
275            public static Repository getPortletRepository(
276                            long groupId, String portletId)
277                    throws PortalException {
278    
279                    return getPortletFileRepository().getPortletRepository(
280                            groupId, portletId);
281            }
282    
283            public static FileEntry movePortletFileEntryToTrash(
284                            long userId, long fileEntryId)
285                    throws PortalException {
286    
287                    return getPortletFileRepository().movePortletFileEntryToTrash(
288                            userId, fileEntryId);
289            }
290    
291            public static FileEntry movePortletFileEntryToTrash(
292                            long groupId, long userId, long folderId, String fileName)
293                    throws PortalException {
294    
295                    return getPortletFileRepository().movePortletFileEntryToTrash(
296                            groupId, userId, folderId, fileName);
297            }
298    
299            public static void restorePortletFileEntryFromTrash(
300                            long userId, long fileEntryId)
301                    throws PortalException {
302    
303                    getPortletFileRepository().restorePortletFileEntryFromTrash(
304                            userId, fileEntryId);
305            }
306    
307            public static void restorePortletFileEntryFromTrash(
308                            long groupId, long userId, long folderId, String fileName)
309                    throws PortalException {
310    
311                    getPortletFileRepository().restorePortletFileEntryFromTrash(
312                            groupId, userId, folderId, fileName);
313            }
314    
315            public void setPortletFileRepository(
316                    PortletFileRepository portletFileRepository) {
317    
318                    PortalRuntimePermission.checkSetBeanProperty(getClass());
319    
320                    _portletFileRepository = portletFileRepository;
321            }
322    
323            private static PortletFileRepository _portletFileRepository;
324    
325    }