001
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.portlet.bookmarks.NoSuchFolderException;
020 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
021 import com.liferay.portlet.bookmarks.model.BookmarksFolderConstants;
022 import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
023
024 import java.util.ArrayList;
025 import java.util.List;
026
027
030 public class BookmarksFolderImpl extends BookmarksFolderBaseImpl {
031
032 public BookmarksFolderImpl() {
033 }
034
035 @Override
036 public List<Long> getAncestorFolderIds()
037 throws PortalException, SystemException {
038
039 List<Long> ancestorFolderIds = new ArrayList<Long>();
040
041 BookmarksFolder folder = this;
042
043 while (!folder.isRoot()) {
044 try {
045 folder = folder.getParentFolder();
046
047 ancestorFolderIds.add(folder.getFolderId());
048 }
049 catch (NoSuchFolderException nsfe) {
050 if (folder.isInTrash()) {
051 break;
052 }
053
054 throw nsfe;
055 }
056 }
057
058 return ancestorFolderIds;
059 }
060
061 @Override
062 public List<BookmarksFolder> getAncestors()
063 throws PortalException, SystemException {
064
065 List<BookmarksFolder> ancestors = new ArrayList<BookmarksFolder>();
066
067 BookmarksFolder folder = this;
068
069 while (!folder.isRoot()) {
070 try {
071 folder = folder.getParentFolder();
072
073 ancestors.add(folder);
074 }
075 catch (NoSuchFolderException nsfe) {
076 if (folder.isInTrash()) {
077 break;
078 }
079
080 throw nsfe;
081 }
082 }
083
084 return ancestors;
085 }
086
087 @Override
088 public BookmarksFolder getParentFolder()
089 throws PortalException, SystemException {
090
091 if (getParentFolderId() ==
092 BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
093
094 return null;
095 }
096
097 return BookmarksFolderLocalServiceUtil.getFolder(getParentFolderId());
098 }
099
100 @Override
101 public BookmarksFolder getTrashContainer() {
102 BookmarksFolder folder = null;
103
104 try {
105 folder = getParentFolder();
106 }
107 catch (Exception e) {
108 return null;
109 }
110
111 while (folder != null) {
112 if (folder.isInTrash()) {
113 return folder;
114 }
115
116 try {
117 folder = folder.getParentFolder();
118 }
119 catch (Exception e) {
120 return null;
121 }
122 }
123
124 return null;
125 }
126
127 @Override
128 public boolean isInTrashContainer() {
129 if (getTrashContainer() != null) {
130 return true;
131 }
132 else {
133 return false;
134 }
135 }
136
137 @Override
138 public boolean isRoot() {
139 if (getParentFolderId() ==
140 BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
141
142 return true;
143 }
144
145 return false;
146 }
147
148 }