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.NoSuchFolderException;
027    import com.liferay.portlet.documentlibrary.model.DLFolder;
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 Folder getFolder() throws PortalException, SystemException {
041                    if (getFolderId() <= 0) {
042                            return new LiferayFolder(new DLFolderImpl());
043                    }
044    
045                    return DLAppLocalServiceUtil.getFolder(getFolderId());
046            }
047    
048            @Override
049            public String getToTitle() {
050                    String toTitle = null;
051    
052                    try {
053                            FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(
054                                    getToFileEntryId());
055    
056                            toTitle = fileEntry.getTitle();
057                    }
058                    catch (Exception e) {
059                            _log.error(e, e);
060                    }
061    
062                    return toTitle;
063            }
064    
065            @Override
066            public DLFolder getTrashContainer()
067                    throws PortalException, SystemException {
068    
069                    Folder folder = null;
070    
071                    try {
072                            folder = getFolder();
073                    }
074                    catch (NoSuchFolderException nsfe) {
075                            return null;
076                    }
077    
078                    DLFolder dlFolder = (DLFolder)folder.getModel();
079    
080                    if (dlFolder.isInTrash()) {
081                            return dlFolder;
082                    }
083    
084                    return dlFolder.getTrashContainer();
085            }
086    
087            @Override
088            public boolean isInHiddenFolder() {
089                    try {
090                            long repositoryId = getRepositoryId();
091    
092                            Repository repository = RepositoryLocalServiceUtil.getRepository(
093                                    repositoryId);
094    
095                            long dlFolderId = repository.getDlFolderId();
096    
097                            DLFolder dlFolder = DLFolderLocalServiceUtil.getFolder(dlFolderId);
098    
099                            return dlFolder.isHidden();
100                    }
101                    catch (Exception e) {
102                    }
103    
104                    return false;
105            }
106    
107            @Override
108            public boolean isInTrashContainer()
109                    throws PortalException, SystemException {
110    
111                    if (getTrashContainer() != null) {
112                            return true;
113                    }
114                    else {
115                            return false;
116                    }
117            }
118    
119            private static Log _log = LogFactoryUtil.getLog(DLFileShortcutImpl.class);
120    
121    }