001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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    /**
031     * @author Brian Wing Shun Chan
032     */
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() throws PortalException, SystemException {
055                    if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
056                            return null;
057                    }
058    
059                    return DLFolderLocalServiceUtil.getFolder(getParentFolderId());
060            }
061    
062            public String getPath() throws PortalException, SystemException {
063                    StringBuilder sb = new StringBuilder();
064    
065                    DLFolder folder = this;
066    
067                    while (folder != null) {
068                            sb.insert(0, folder.getName());
069                            sb.insert(0, StringPool.SLASH);
070    
071                            folder = folder.getParentFolder();
072                    }
073    
074                    return sb.toString();
075            }
076    
077            public String[] getPathArray() throws PortalException, SystemException {
078                    String path = getPath();
079    
080                    // Remove leading /
081    
082                    path = path.substring(1);
083    
084                    return StringUtil.split(path, CharPool.SLASH);
085            }
086    
087            public boolean hasInheritableLock() {
088                    try {
089                            return DLFolderServiceUtil.hasInheritableLock(getFolderId());
090                    }
091                    catch (Exception e) {
092                    }
093    
094                    return false;
095            }
096    
097            public boolean hasLock() {
098                    try {
099                            return DLFolderServiceUtil.hasFolderLock(getFolderId());
100                    }
101                    catch (Exception e) {
102                    }
103    
104                    return false;
105            }
106    
107            public boolean isLocked() {
108                    try {
109                            return DLFolderServiceUtil.isFolderLocked(getFolderId());
110                    }
111                    catch (Exception e) {
112                    }
113    
114                    return false;
115            }
116    
117            public boolean isRoot() {
118                    if (getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
119                            return true;
120                    }
121                    else {
122                            return false;
123                    }
124            }
125    
126    }