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            public DLFileShortcutImpl() {
037            }
038    
039            @Override
040            public String buildTreePath() throws PortalException {
041                    if (getFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
042                            return StringPool.SLASH;
043                    }
044    
045                    DLFolder dlFolder = getDLFolder();
046    
047                    return dlFolder.buildTreePath();
048            }
049    
050            @Override
051            public DLFolder getDLFolder() throws PortalException {
052                    Folder folder = getFolder();
053    
054                    return (DLFolder)folder.getModel();
055            }
056    
057            @Override
058            public Folder getFolder() throws PortalException {
059                    if (getFolderId() <= 0) {
060                            return new LiferayFolder(new DLFolderImpl());
061                    }
062    
063                    return DLAppLocalServiceUtil.getFolder(getFolderId());
064            }
065    
066            @Override
067            public String getToTitle() {
068                    String toTitle = null;
069    
070                    try {
071                            FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(
072                                    getToFileEntryId());
073    
074                            toTitle = fileEntry.getTitle();
075                    }
076                    catch (Exception e) {
077                            _log.error(e, e);
078                    }
079    
080                    return toTitle;
081            }
082    
083            @Override
084            public boolean isInHiddenFolder() {
085                    try {
086                            long repositoryId = getRepositoryId();
087    
088                            Repository repository = RepositoryLocalServiceUtil.getRepository(
089                                    repositoryId);
090    
091                            long dlFolderId = repository.getDlFolderId();
092    
093                            DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(dlFolderId);
094    
095                            return dlFolder.isHidden();
096                    }
097                    catch (Exception e) {
098                    }
099    
100                    return false;
101            }
102    
103            private static final Log _log = LogFactoryUtil.getLog(
104                    DLFileShortcutImpl.class);
105    
106    }