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.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.repository.model.FileEntry;
020    import com.liferay.portal.kernel.repository.model.Folder;
021    import com.liferay.portal.model.Repository;
022    import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
023    import com.liferay.portal.service.RepositoryLocalServiceUtil;
024    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
025    import com.liferay.portlet.documentlibrary.model.DLFolder;
026    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
027    import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     */
032    public class DLFileShortcutImpl extends DLFileShortcutBaseImpl {
033    
034            public DLFileShortcutImpl() {
035            }
036    
037            public Folder getFolder() {
038                    Folder folder = new LiferayFolder(new DLFolderImpl());
039    
040                    if (getFolderId() > 0) {
041                            try {
042                                    folder = DLAppLocalServiceUtil.getFolder(getFolderId());
043                            }
044                            catch (NoSuchFolderException nsfe) {
045                                    try {
046                                            if (!isInTrash()) {
047                                                    _log.error(nsfe, nsfe);
048                                            }
049                                    }
050                                    catch (Exception e) {
051                                            _log.error(e, e);
052                                    }
053                            }
054                            catch (Exception e) {
055                                    _log.error(e, e);
056                            }
057                    }
058    
059                    return folder;
060            }
061    
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            public DLFolder getTrashContainer() {
079                    Folder folder = getFolder();
080    
081                    DLFolder dlFolder = (DLFolder)folder.getModel();
082    
083                    if (dlFolder.isInTrash()) {
084                            return dlFolder;
085                    }
086    
087                    return dlFolder.getTrashContainer();
088            }
089    
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            public boolean isInTrashContainer() {
110                    if (getTrashContainer() != null) {
111                            return true;
112                    }
113                    else {
114                            return false;
115                    }
116            }
117    
118            private static Log _log = LogFactoryUtil.getLog(DLFileShortcutImpl.class);
119    
120    }