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.portlet.wiki.model.impl;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.repository.model.FileEntry;
021    import com.liferay.portal.kernel.repository.model.Folder;
022    import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portal.util.PortletKeys;
025    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
026    import com.liferay.portlet.wiki.model.WikiPage;
027    import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
028    
029    import java.util.ArrayList;
030    import java.util.List;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     */
035    public class WikiNodeImpl extends WikiNodeBaseImpl {
036    
037            public WikiNodeImpl() {
038            }
039    
040            public long getAttachmentsFolderId()
041                    throws PortalException, SystemException {
042    
043                    if (_attachmentsFolderId > 0) {
044                            return _attachmentsFolderId;
045                    }
046    
047                    ServiceContext serviceContext = new ServiceContext();
048    
049                    serviceContext.setAddGroupPermissions(true);
050                    serviceContext.setAddGuestPermissions(true);
051    
052                    long repositoryId = PortletFileRepositoryUtil.getPortletRepositoryId(
053                            getGroupId(), PortletKeys.WIKI, serviceContext);
054    
055                    Folder folder = PortletFileRepositoryUtil.getPortletFolder(
056                            getUserId(), repositoryId,
057                            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
058                            String.valueOf(getNodeId()), serviceContext);
059    
060                    _attachmentsFolderId = folder.getFolderId();
061    
062                    return _attachmentsFolderId;
063            }
064    
065            public List<FileEntry> getDeletedAttachmentsFiles()
066                    throws PortalException, SystemException {
067    
068                    List<WikiPage> wikiPages = WikiPageLocalServiceUtil.getPages(
069                            getNodeId(), true, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
070    
071                    List<FileEntry> fileEntries = new ArrayList<FileEntry>();
072    
073                    for (WikiPage wikiPage : wikiPages) {
074                            fileEntries.addAll(wikiPage.getDeletedAttachmentsFileEntries());
075                    }
076    
077                    return fileEntries;
078            }
079    
080            private long _attachmentsFolderId;
081    
082    }