001
014
015 package com.liferay.portlet.journal.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portlet.journal.NoSuchFolderException;
020 import com.liferay.portlet.journal.model.JournalFolder;
021 import com.liferay.portlet.journal.model.JournalFolderConstants;
022 import com.liferay.portlet.journal.service.JournalFolderLocalServiceUtil;
023
024 import java.util.ArrayList;
025 import java.util.List;
026
027
030 public class JournalFolderImpl extends JournalFolderBaseImpl {
031
032 public JournalFolderImpl() {
033 }
034
035 @Override
036 public List<Long> getAncestorFolderIds()
037 throws PortalException, SystemException {
038
039 List<Long> ancestorFolderIds = new ArrayList<Long>();
040
041 JournalFolder 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<JournalFolder> getAncestors()
063 throws PortalException, SystemException {
064
065 List<JournalFolder> ancestors = new ArrayList<JournalFolder>();
066
067 JournalFolder folder = this;
068
069 while (!folder.isRoot()) {
070 folder = folder.getParentFolder();
071
072 ancestors.add(folder);
073 }
074
075 return ancestors;
076 }
077
078 @Override
079 public JournalFolder getParentFolder()
080 throws PortalException, SystemException {
081
082 if (getParentFolderId() ==
083 JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
084
085 return null;
086 }
087
088 return JournalFolderLocalServiceUtil.getFolder(getParentFolderId());
089 }
090
091 @Override
092 public JournalFolder getTrashContainer() {
093 JournalFolder folder = null;
094
095 try {
096 folder = getParentFolder();
097 }
098 catch (Exception e) {
099 return null;
100 }
101
102 while (folder != null) {
103 if (folder.isInTrash()) {
104 return folder;
105 }
106
107 try {
108 folder = folder.getParentFolder();
109 }
110 catch (Exception e) {
111 return null;
112 }
113 }
114
115 return null;
116 }
117
118 @Override
119 public boolean isInTrashContainer() {
120 if (getTrashContainer() != null) {
121 return true;
122 }
123 else {
124 return false;
125 }
126 }
127
128 @Override
129 public boolean isRoot() {
130 if (getParentFolderId() ==
131 JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
132
133 return true;
134 }
135
136 return false;
137 }
138
139 }