001
014
015 package com.liferay.portlet.documentlibrary.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.CharPool;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.util.StringUtil;
022 import com.liferay.portlet.documentlibrary.NoSuchFolderException;
023 import com.liferay.portlet.documentlibrary.model.DLFolder;
024 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
025 import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
026 import com.liferay.portlet.documentlibrary.service.DLFolderServiceUtil;
027
028 import java.util.ArrayList;
029 import java.util.List;
030
031
034 public class DLFolderImpl extends DLFolderBaseImpl {
035
036 public DLFolderImpl() {
037 }
038
039 public List<DLFolder> getAncestors()
040 throws PortalException, SystemException {
041
042 List<DLFolder> ancestors = new ArrayList<DLFolder>();
043
044 DLFolder folder = this;
045
046 while (!folder.isRoot()) {
047 try {
048 folder = folder.getParentFolder();
049
050 ancestors.add(folder);
051 }
052 catch (NoSuchFolderException nsfe) {
053 if (folder.isInTrash()) {
054 break;
055 }
056
057 throw nsfe;
058 }
059 }
060
061 return ancestors;
062 }
063
064 public DLFolder getParentFolder() throws PortalException, SystemException {
065 if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
066 return null;
067 }
068
069 return DLFolderLocalServiceUtil.getFolder(getParentFolderId());
070 }
071
072 public String getPath() throws PortalException, SystemException {
073 StringBuilder sb = new StringBuilder();
074
075 DLFolder folder = this;
076
077 while (folder != null) {
078 sb.insert(0, folder.getName());
079 sb.insert(0, StringPool.SLASH);
080
081 folder = folder.getParentFolder();
082 }
083
084 return sb.toString();
085 }
086
087 public String[] getPathArray() throws PortalException, SystemException {
088 String path = getPath();
089
090
091
092 path = path.substring(1);
093
094 return StringUtil.split(path, CharPool.SLASH);
095 }
096
097 public DLFolder getTrashContainer() {
098 DLFolder dlFolder = null;
099
100 try {
101 dlFolder = getParentFolder();
102 }
103 catch (Exception e) {
104 return null;
105 }
106
107 while (dlFolder != null) {
108 if (dlFolder.isInTrash()) {
109 return dlFolder;
110 }
111
112 try {
113 dlFolder = dlFolder.getParentFolder();
114 }
115 catch (Exception e) {
116 return null;
117 }
118 }
119
120 return null;
121 }
122
123 public boolean hasInheritableLock() {
124 try {
125 return DLFolderServiceUtil.hasInheritableLock(getFolderId());
126 }
127 catch (Exception e) {
128 }
129
130 return false;
131 }
132
133 public boolean hasLock() {
134 try {
135 return DLFolderServiceUtil.hasFolderLock(getFolderId());
136 }
137 catch (Exception e) {
138 }
139
140 return false;
141 }
142
143 public boolean isInTrashContainer() {
144 if (getTrashContainer() != null) {
145 return true;
146 }
147 else {
148 return false;
149 }
150 }
151
152 public boolean isLocked() {
153 try {
154 return DLFolderServiceUtil.isFolderLocked(getFolderId());
155 }
156 catch (Exception e) {
157 }
158
159 return false;
160 }
161
162 public boolean isRoot() {
163 if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
164 return true;
165 }
166
167 return false;
168 }
169
170 }