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