1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.documentlibrary.model.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.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  /**
26   * <a href="DLFolderImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class DLFolderImpl extends DLFolderModelImpl implements DLFolder {
31  
32      public DLFolderImpl() {
33      }
34  
35      public String getPath() throws PortalException, SystemException {
36          StringBuilder sb = new StringBuilder();
37  
38          DLFolder folder = this;
39  
40          while (true) {
41              sb.insert(0, folder.getName());
42              sb.insert(0, StringPool.SLASH);
43  
44              if (folder.getParentFolderId() !=
45                      DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
46  
47                  folder = DLFolderLocalServiceUtil.getFolder(
48                      folder.getParentFolderId());
49              }
50              else {
51                  break;
52              }
53          }
54  
55          return sb.toString();
56      }
57  
58      public String[] getPathArray() throws PortalException, SystemException {
59          String path = getPath();
60  
61          // Remove leading /
62  
63          path = path.substring(1, path.length());
64  
65          return StringUtil.split(path, StringPool.SLASH);
66      }
67  
68      public boolean isRoot() {
69          if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
70              return true;
71          }
72          else {
73              return false;
74          }
75      }
76  
77  }