001    /**
002     * Copyright (c) 2000-2013 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 com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.repository.model.FileEntry;
020    import com.liferay.portal.kernel.repository.model.Folder;
021    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
022    import com.liferay.portal.kernel.util.ObjectValuePair;
023    import com.liferay.portal.kernel.util.OrderByComparator;
024    import com.liferay.portal.model.Repository;
025    import com.liferay.portal.service.ServiceContext;
026    
027    import java.io.File;
028    import java.io.InputStream;
029    
030    import java.util.List;
031    
032    /**
033     * @author Eudaldo Alonso
034     * @author Alexander Chow
035     */
036    public class PortletFileRepositoryUtil {
037    
038            public static void addPortletFileEntries(
039                            long groupId, long userId, String className, long classPK,
040                            String portletId, long folderId,
041                            List<ObjectValuePair<String, InputStream>> inputStreamOVPs)
042                    throws PortalException, SystemException {
043    
044                    getPortletFileRepository().addPortletFileEntries(
045                            groupId, userId, className, classPK, portletId, folderId,
046                            inputStreamOVPs);
047            }
048    
049            public static FileEntry addPortletFileEntry(
050                            long groupId, long userId, String className, long classPK,
051                            String portletId, long folderId, File file, String fileName,
052                            String mimeType, boolean indexingEnabled)
053                    throws PortalException, SystemException {
054    
055                    return getPortletFileRepository().addPortletFileEntry(
056                            groupId, userId, className, classPK, portletId, folderId, file,
057                            fileName, mimeType, indexingEnabled);
058            }
059    
060            public static FileEntry addPortletFileEntry(
061                            long groupId, long userId, String className, long classPK,
062                            String portletId, long folderId, InputStream inputStream,
063                            String fileName, String mimeType, boolean indexingEnabled)
064                    throws PortalException, SystemException {
065    
066                    return getPortletFileRepository().addPortletFileEntry(
067                            groupId, userId, className, classPK, portletId, folderId,
068                            inputStream, fileName, mimeType, indexingEnabled);
069            }
070    
071            public static Folder addPortletFolder(
072                            long userId, long repositoryId, long parentFolderId,
073                            String folderName, ServiceContext serviceContext)
074                    throws PortalException, SystemException {
075    
076                    return getPortletFileRepository().addPortletFolder(
077                            userId, repositoryId, parentFolderId, folderName, serviceContext);
078            }
079    
080            public static Repository addPortletRepository(
081                            long groupId, String portletId, ServiceContext serviceContext)
082                    throws PortalException, SystemException {
083    
084                    return getPortletFileRepository().addPortletRepository(
085                            groupId, portletId, serviceContext);
086            }
087    
088            public static void deleteFolder(long folderId)
089                    throws PortalException, SystemException {
090    
091                    getPortletFileRepository().deleteFolder(folderId);
092            }
093    
094            public static void deletePortletFileEntries(long groupId, long folderId)
095                    throws PortalException, SystemException {
096    
097                    getPortletFileRepository().deletePortletFileEntries(groupId, folderId);
098            }
099    
100            public static void deletePortletFileEntries(
101                            long groupId, long folderId, int status)
102                    throws PortalException, SystemException {
103    
104                    getPortletFileRepository().deletePortletFileEntries(
105                            groupId, folderId, status);
106            }
107    
108            public static void deletePortletFileEntry(long fileEntryId)
109                    throws PortalException, SystemException {
110    
111                    getPortletFileRepository().deletePortletFileEntry(fileEntryId);
112            }
113    
114            public static void deletePortletFileEntry(
115                            long groupId, long folderId, String fileName)
116                    throws PortalException, SystemException {
117    
118                    getPortletFileRepository().deletePortletFileEntry(
119                            groupId, folderId, fileName);
120            }
121    
122            public static void deletePortletRepository(long groupId, String portletId)
123                    throws PortalException, SystemException {
124    
125                    getPortletFileRepository().deletePortletRepository(groupId, portletId);
126            }
127    
128            public static Repository fetchPortletRepository(
129                            long groupId, String portletId)
130                    throws SystemException {
131    
132                    return getPortletFileRepository().fetchPortletRepository(
133                            groupId, portletId);
134            }
135    
136            public static List<FileEntry> getPortletFileEntries(
137                            long groupId, long folderId)
138                    throws SystemException {
139    
140                    return getPortletFileRepository().getPortletFileEntries(
141                            groupId, folderId);
142            }
143    
144            public static List<FileEntry> getPortletFileEntries(
145                            long groupId, long folderId, int status)
146                    throws SystemException {
147    
148                    return getPortletFileRepository().getPortletFileEntries(
149                            groupId, folderId, status);
150            }
151    
152            public static List<FileEntry> getPortletFileEntries(
153                            long groupId, long folderId, int status, int start, int end,
154                            OrderByComparator obc)
155                    throws SystemException {
156    
157                    return getPortletFileRepository().getPortletFileEntries(
158                            groupId, folderId, status, start, end, obc);
159            }
160    
161            public static int getPortletFileEntriesCount(long groupId, long folderId)
162                    throws SystemException {
163    
164                    return getPortletFileRepository().getPortletFileEntriesCount(
165                            groupId, folderId);
166            }
167    
168            public static int getPortletFileEntriesCount(
169                            long groupId, long folderId, int status)
170                    throws SystemException {
171    
172                    return getPortletFileRepository().getPortletFileEntriesCount(
173                            groupId, folderId, status);
174            }
175    
176            public static FileEntry getPortletFileEntry(long fileEntryId)
177                    throws PortalException, SystemException {
178    
179                    return getPortletFileRepository().getPortletFileEntry(fileEntryId);
180            }
181    
182            public static FileEntry getPortletFileEntry(
183                            long groupId, long folderId, String fileName)
184                    throws PortalException, SystemException {
185    
186                    return getPortletFileRepository().getPortletFileEntry(
187                            groupId, folderId, fileName);
188            }
189    
190            public static PortletFileRepository getPortletFileRepository() {
191                    PortalRuntimePermission.checkGetBeanProperty(
192                            PortletFileRepositoryUtil.class);
193    
194                    return _portletFileRepository;
195            }
196    
197            public static Folder getPortletFolder(long folderId)
198                    throws PortalException, SystemException {
199    
200                    return getPortletFileRepository().getPortletFolder(folderId);
201            }
202    
203            public static Folder getPortletFolder(
204                            long userId, long repositoryId, long parentFolderId,
205                            String folderName, ServiceContext serviceContext)
206                    throws PortalException, SystemException {
207    
208                    return getPortletFileRepository().getPortletFolder(
209                            repositoryId, parentFolderId, folderName);
210            }
211    
212            public static Repository getPortletRepository(
213                            long groupId, String portletId)
214                    throws PortalException, SystemException {
215    
216                    return getPortletFileRepository().getPortletRepository(
217                            groupId, portletId);
218            }
219    
220            public static FileEntry movePortletFileEntryToTrash(
221                            long userId, long fileEntryId)
222                    throws PortalException, SystemException {
223    
224                    return getPortletFileRepository().movePortletFileEntryToTrash(
225                            userId, fileEntryId);
226            }
227    
228            public static FileEntry movePortletFileEntryToTrash(
229                            long groupId, long userId, long folderId, String fileName)
230                    throws PortalException, SystemException {
231    
232                    return getPortletFileRepository().movePortletFileEntryToTrash(
233                            groupId, userId, folderId, fileName);
234            }
235    
236            public static void restorePortletFileEntryFromTrash(
237                            long userId, long fileEntryId)
238                    throws PortalException, SystemException {
239    
240                    getPortletFileRepository().restorePortletFileEntryFromTrash(
241                            userId, fileEntryId);
242            }
243    
244            public static void restorePortletFileEntryFromTrash(
245                            long groupId, long userId, long folderId, String fileName)
246                    throws PortalException, SystemException {
247    
248                    getPortletFileRepository().restorePortletFileEntryFromTrash(
249                            groupId, userId, folderId, fileName);
250            }
251    
252            public void setPortletFileRepository(
253                    PortletFileRepository portletFileRepository) {
254    
255                    PortalRuntimePermission.checkSetBeanProperty(getClass());
256    
257                    _portletFileRepository = portletFileRepository;
258            }
259    
260            private static PortletFileRepository _portletFileRepository;
261    
262    }