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.Folder;
022    import com.liferay.portal.kernel.util.StringPool;
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.model.DLFolderConstants;
028    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
029    import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class DLFileShortcutImpl extends DLFileShortcutBaseImpl {
035    
036            @Override
037            public String buildTreePath() throws PortalException {
038                    if (getFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
039                            return StringPool.SLASH;
040                    }
041    
042                    DLFolder dlFolder = getDLFolder();
043    
044                    return dlFolder.buildTreePath();
045            }
046    
047            @Override
048            public DLFolder getDLFolder() throws PortalException {
049                    Folder folder = getFolder();
050    
051                    return (DLFolder)folder.getModel();
052            }
053    
054            @Override
055            public Folder getFolder() throws PortalException {
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            private static final Log _log = LogFactoryUtil.getLog(
101                    DLFileShortcutImpl.class);
102    
103    }