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