1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.bookmarks.model.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portlet.bookmarks.model.BookmarksFolder;
20  import com.liferay.portlet.bookmarks.model.BookmarksFolderConstants;
21  import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  /**
27   * <a href="BookmarksFolderImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class BookmarksFolderImpl
32      extends BookmarksFolderModelImpl implements BookmarksFolder {
33  
34      public BookmarksFolderImpl() {
35      }
36  
37      public List<BookmarksFolder> getAncestors()
38          throws PortalException, SystemException {
39  
40          List<BookmarksFolder> ancestors = new ArrayList<BookmarksFolder>();
41  
42          BookmarksFolder folder = this;
43  
44          while (true) {
45              if (!folder.isRoot()) {
46                  folder = folder.getParentFolder();
47  
48                  ancestors.add(folder);
49              }
50              else {
51                  break;
52              }
53          }
54  
55          return ancestors;
56      }
57  
58      public BookmarksFolder getParentFolder()
59          throws PortalException, SystemException {
60  
61          if (getParentFolderId() ==
62                  BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
63  
64              return null;
65          }
66  
67          return BookmarksFolderLocalServiceUtil.getFolder(getParentFolderId());
68      }
69  
70      public boolean isRoot() {
71          if (getParentFolderId() ==
72                  BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
73  
74              return true;
75          }
76          else {
77              return false;
78          }
79      }
80  
81  }