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.model.DLFolder;
023 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
024 import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
025 import com.liferay.portlet.documentlibrary.service.DLFolderServiceUtil;
026
027 import java.util.ArrayList;
028 import java.util.List;
029
030
033 public class DLFolderImpl extends DLFolderBaseImpl {
034
035 public DLFolderImpl() {
036 }
037
038 public List<DLFolder> getAncestors()
039 throws PortalException, SystemException {
040
041 List<DLFolder> ancestors = new ArrayList<DLFolder>();
042
043 DLFolder folder = this;
044
045 while (!folder.isRoot()) {
046 folder = folder.getParentFolder();
047
048 ancestors.add(folder);
049 }
050
051 return ancestors;
052 }
053
054 public DLFolder getParentFolder()
055 throws PortalException, SystemException {
056
057 if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
058 return null;
059 }
060
061 return DLFolderLocalServiceUtil.getFolder(getParentFolderId());
062 }
063
064 public String getPath() throws PortalException, SystemException {
065 StringBuilder sb = new StringBuilder();
066
067 DLFolder folder = this;
068
069 while (folder != null) {
070 sb.insert(0, folder.getName());
071 sb.insert(0, StringPool.SLASH);
072
073 folder = folder.getParentFolder();
074 }
075
076 return sb.toString();
077 }
078
079 public String[] getPathArray() throws PortalException, SystemException {
080 String path = getPath();
081
082
083
084 path = path.substring(1, path.length());
085
086 return StringUtil.split(path, CharPool.SLASH);
087 }
088
089 public boolean hasInheritableLock() {
090 try {
091 return DLFolderServiceUtil.hasInheritableLock(getFolderId());
092 }
093 catch (Exception e) {
094 }
095
096 return false;
097 }
098
099 public boolean hasLock() {
100 try {
101 return DLFolderServiceUtil.hasFolderLock(getFolderId());
102 }
103 catch (Exception e) {
104 }
105
106 return false;
107 }
108
109 public boolean isLocked() {
110 try {
111 return DLFolderServiceUtil.isFolderLocked(getFolderId());
112 }
113 catch (Exception e) {
114 }
115
116 return false;
117 }
118
119 public boolean isRoot() {
120 if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
121 return true;
122 }
123 else {
124 return false;
125 }
126 }
127
128 }