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.model.BookmarksFolder;
022    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class BookmarksEntryImpl extends BookmarksEntryBaseImpl {
028    
029            public BookmarksEntryImpl() {
030            }
031    
032            @Override
033            public String buildTreePath() throws PortalException, SystemException {
034                    StringBundler sb = new StringBundler();
035    
036                    buildTreePath(sb, getFolder());
037    
038                    return sb.toString();
039            }
040    
041            @Override
042            public BookmarksFolder getFolder() throws PortalException, SystemException {
043                    if (getFolderId() <= 0) {
044                            return new BookmarksFolderImpl();
045                    }
046    
047                    return BookmarksFolderLocalServiceUtil.getFolder(getFolderId());
048            }
049    
050            protected void buildTreePath(StringBundler sb, BookmarksFolder folder)
051                    throws PortalException, SystemException {
052    
053                    if (folder == null) {
054                            sb.append(StringPool.SLASH);
055                    }
056                    else {
057                            buildTreePath(sb, folder.getParentFolder());
058    
059                            sb.append(folder.getFolderId());
060                            sb.append(StringPool.SLASH);
061                    }
062            }
063    
064    }