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