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.portlet.documentlibrary.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.repository.model.FileEntry;
022    import com.liferay.portal.kernel.repository.model.Folder;
023    import com.liferay.portal.model.Repository;
024    import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
025    import com.liferay.portal.service.RepositoryLocalServiceUtil;
026    import com.liferay.portlet.documentlibrary.model.DLFolder;
027    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
028    import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
029    import com.liferay.portlet.trash.model.TrashEntry;
030    import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     */
035    public class DLFileShortcutImpl extends DLFileShortcutBaseImpl {
036    
037            public DLFileShortcutImpl() {
038            }
039    
040            @Override
041            public String buildTreePath() throws PortalException, SystemException {
042                    DLFolder dlFolder = getDLFolder();
043    
044                    return dlFolder.buildTreePath();
045            }
046    
047            @Override
048            public DLFolder getDLFolder() throws PortalException, SystemException {
049                    Folder folder = getFolder();
050    
051                    return (DLFolder)folder.getModel();
052            }
053    
054            @Override
055            public Folder getFolder() throws PortalException, SystemException {
056                    if (getFolderId() <= 0) {
057                            return new LiferayFolder(new DLFolderImpl());
058                    }
059    
060                    return DLAppLocalServiceUtil.getFolder(getFolderId());
061            }
062    
063            @Override
064            public String getToTitle() {
065                    String toTitle = null;
066    
067                    try {
068                            FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(
069                                    getToFileEntryId());
070    
071                            toTitle = fileEntry.getTitle();
072                    }
073                    catch (Exception e) {
074                            _log.error(e, e);
075                    }
076    
077                    return toTitle;
078            }
079    
080            @Override
081            public boolean isInHiddenFolder() {
082                    try {
083                            long repositoryId = getRepositoryId();
084    
085                            Repository repository = RepositoryLocalServiceUtil.getRepository(
086                                    repositoryId);
087    
088                            long dlFolderId = repository.getDlFolderId();
089    
090                            DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(dlFolderId);
091    
092                            return dlFolder.isHidden();
093                    }
094                    catch (Exception e) {
095                    }
096    
097                    return false;
098            }
099    
100            @Override
101            public boolean isInTrashExplicitly() throws SystemException {
102                    if (!isInTrash()) {
103                            return false;
104                    }
105    
106                    TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(
107                            getModelClassName(), getTrashEntryClassPK());
108    
109                    if (trashEntry != null) {
110                            return true;
111                    }
112    
113                    return false;
114            }
115    
116            private static Log _log = LogFactoryUtil.getLog(DLFileShortcutImpl.class);
117    
118    }