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.bookmarks.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.util.StringBundler;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portlet.bookmarks.NoSuchFolderException;
022    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
023    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class BookmarksEntryImpl extends BookmarksEntryBaseImpl {
029    
030            public BookmarksEntryImpl() {
031            }
032    
033            @Override
034            public String buildTreePath() throws PortalException, SystemException {
035                    StringBundler sb = new StringBundler();
036    
037                    buildTreePath(sb, getFolder());
038    
039                    return sb.toString();
040            }
041    
042            @Override
043            public BookmarksFolder getFolder() throws PortalException, SystemException {
044                    if (getFolderId() <= 0) {
045                            return new BookmarksFolderImpl();
046                    }
047    
048                    return BookmarksFolderLocalServiceUtil.getFolder(getFolderId());
049            }
050    
051            @Override
052            public BookmarksFolder getTrashContainer()
053                    throws PortalException, SystemException {
054    
055                    BookmarksFolder folder = null;
056    
057                    try {
058                            folder = getFolder();
059                    }
060                    catch (NoSuchFolderException nsfe) {
061                            return null;
062                    }
063    
064                    if (folder.isInTrash()) {
065                            return folder;
066                    }
067    
068                    return folder.getTrashContainer();
069            }
070    
071            @Override
072            public boolean isInTrashContainer() {
073                    try {
074                            if (getTrashContainer() != null) {
075                                    return true;
076                            }
077                    }
078                    catch (Exception e) {
079                    }
080    
081                    return false;
082            }
083    
084            protected void buildTreePath(StringBundler sb, BookmarksFolder folder)
085                    throws PortalException, SystemException {
086    
087                    if (folder == null) {
088                            sb.append(StringPool.SLASH);
089                    }
090                    else {
091                            buildTreePath(sb, folder.getParentFolder());
092    
093                            sb.append(folder.getFolderId());
094                            sb.append(StringPool.SLASH);
095                    }
096            }
097    
098    }