001    /**
002     * Copyright (c) 2000-2012 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.repository.liferayrepository.model.LiferayFolder;
022    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
023    import com.liferay.portlet.documentlibrary.model.DLFolder;
024    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class DLFileShortcutImpl extends DLFileShortcutBaseImpl {
030    
031            public DLFileShortcutImpl() {
032            }
033    
034            public Folder getFolder() {
035                    Folder folder = new LiferayFolder(new DLFolderImpl());
036    
037                    if (getFolderId() > 0) {
038                            try {
039                                    folder = DLAppLocalServiceUtil.getFolder(getFolderId());
040                            }
041                            catch (NoSuchFolderException nsfe) {
042                                    try {
043                                            if (!isInTrash()) {
044                                                    _log.error(nsfe, nsfe);
045                                            }
046                                    }
047                                    catch (Exception e) {
048                                            _log.error(e, e);
049                                    }
050                            }
051                            catch (Exception e) {
052                                    _log.error(e, e);
053                            }
054                    }
055    
056                    return folder;
057            }
058    
059            public String getToTitle() {
060                    String toTitle = null;
061    
062                    try {
063                            FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(
064                                    getToFileEntryId());
065    
066                            toTitle = fileEntry.getTitle();
067                    }
068                    catch (Exception e) {
069                            _log.error(e, e);
070                    }
071    
072                    return toTitle;
073            }
074    
075            public DLFolder getTrashFolder() {
076                    Folder folder = getFolder();
077    
078                    DLFolder dlFolder = (DLFolder)folder.getModel();
079    
080                    if (dlFolder.isInTrash()) {
081                            return dlFolder;
082                    }
083    
084                    return dlFolder.getTrashFolder();
085            }
086    
087            public boolean isInTrashFolder() {
088                    if (getTrashFolder() != null) {
089                            return true;
090                    }
091                    else {
092                            return false;
093                    }
094            }
095    
096            private static Log _log = LogFactoryUtil.getLog(DLFileShortcutImpl.class);
097    
098    }