1
14
15 package com.liferay.portlet.documentlibrary.model.impl;
16
17 import com.liferay.portal.kernel.exception.PortalException;
18 import com.liferay.portal.kernel.exception.SystemException;
19 import com.liferay.portal.kernel.util.StringPool;
20 import com.liferay.portal.kernel.util.StringUtil;
21 import com.liferay.portlet.documentlibrary.model.DLFolder;
22 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
23 import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28
33 public class DLFolderImpl extends DLFolderModelImpl implements DLFolder {
34
35 public DLFolderImpl() {
36 }
37
38 public List<DLFolder> getAncestors()
39 throws PortalException, SystemException {
40
41 List<DLFolder> ancestors = new ArrayList<DLFolder>();
42
43 DLFolder folder = this;
44
45 while (true) {
46 if (!folder.isRoot()) {
47 folder = folder.getParentFolder();
48
49 ancestors.add(folder);
50 }
51 else {
52 break;
53 }
54 }
55
56 return ancestors;
57 }
58
59 public DLFolder getParentFolder()
60 throws PortalException, SystemException {
61
62 if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
63 return null;
64 }
65
66 return DLFolderLocalServiceUtil.getFolder(getParentFolderId());
67 }
68
69 public String getPath() throws PortalException, SystemException {
70 StringBuilder sb = new StringBuilder();
71
72 DLFolder folder = this;
73
74 while (true) {
75 sb.insert(0, folder.getName());
76 sb.insert(0, StringPool.SLASH);
77
78 if (folder.getParentFolderId() !=
79 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
80
81 folder = DLFolderLocalServiceUtil.getFolder(
82 folder.getParentFolderId());
83 }
84 else {
85 break;
86 }
87 }
88
89 return sb.toString();
90 }
91
92 public String[] getPathArray() throws PortalException, SystemException {
93 String path = getPath();
94
95
97 path = path.substring(1, path.length());
98
99 return StringUtil.split(path, StringPool.SLASH);
100 }
101
102 public boolean isRoot() {
103 if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
104 return true;
105 }
106 else {
107 return false;
108 }
109 }
110
111 }