001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.repository.liferayrepository.model;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.repository.model.Folder;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portlet.documentlibrary.model.DLFolder;
022    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
023    import com.liferay.portlet.expando.model.ExpandoBridge;
024    
025    import java.io.Serializable;
026    
027    import java.util.Date;
028    import java.util.List;
029    import java.util.Map;
030    
031    /**
032     * @author Alexander Chow
033     */
034    public class LiferayFolder extends LiferayModel implements Folder {
035    
036            public LiferayFolder(DLFolder dlFolder) {
037                    _dlFolder = dlFolder;
038            }
039    
040            public LiferayFolder(DLFolder dlFolder, boolean escapedModel) {
041                    _dlFolder = dlFolder;
042                    _escapedModel = escapedModel;
043            }
044    
045            public boolean containsPermission(
046                            PermissionChecker permissionChecker, String actionId)
047                    throws PortalException, SystemException {
048    
049                    return DLFolderPermission.contains(
050                            permissionChecker, _dlFolder, actionId);
051            }
052    
053            public List<Folder> getAncestors() throws PortalException, SystemException {
054                    return toFolders(_dlFolder.getAncestors());
055            }
056    
057            public Map<String, Serializable> getAttributes() {
058                    ExpandoBridge expandoBridge = getExpandoBridge();
059    
060                    return expandoBridge.getAttributes();
061            }
062    
063            @Override
064            public long getCompanyId() {
065                    return _dlFolder.getCompanyId();
066            }
067    
068            public Date getCreateDate() {
069                    return _dlFolder.getCreateDate();
070            }
071    
072            public String getDescription() {
073                    return _dlFolder.getDescription();
074            }
075    
076            @Override
077            public ExpandoBridge getExpandoBridge() {
078                    return _dlFolder.getExpandoBridge();
079            }
080    
081            public long getFolderId() {
082                    return _dlFolder.getFolderId();
083            }
084    
085            public long getGroupId() {
086                    return _dlFolder.getGroupId();
087            }
088    
089            public Date getLastPostDate() {
090                    return _dlFolder.getLastPostDate();
091            }
092    
093            public Object getModel() {
094                    return _dlFolder;
095            }
096    
097            public Class<?> getModelClass() {
098                    return DLFolder.class;
099            }
100    
101            @Override
102            public String getModelClassName() {
103                    return DLFolder.class.getName();
104            }
105    
106            public Date getModifiedDate() {
107                    return _dlFolder.getModifiedDate();
108            }
109    
110            public String getName() {
111                    return _dlFolder.getName();
112            }
113    
114            public Folder getParentFolder() throws PortalException, SystemException {
115                    DLFolder dlParentFolder = _dlFolder.getParentFolder();
116    
117                    if (dlParentFolder == null) {
118                            return null;
119                    }
120                    else {
121                            return new LiferayFolder(dlParentFolder);
122                    }
123            }
124    
125            public long getParentFolderId() {
126                    return _dlFolder.getParentFolderId();
127            }
128    
129            @Override
130            public long getPrimaryKey() {
131                    return _dlFolder.getPrimaryKey();
132            }
133    
134            public Serializable getPrimaryKeyObj() {
135                    return getPrimaryKey();
136            }
137    
138            public long getRepositoryId() {
139                    return _dlFolder.getRepositoryId();
140            }
141    
142            public long getUserId() {
143                    return _dlFolder.getUserId();
144            }
145    
146            public String getUserName() {
147                    return _dlFolder.getUserName();
148            }
149    
150            public String getUserUuid() throws SystemException {
151                    return _dlFolder.getUserUuid();
152            }
153    
154            public String getUuid() {
155                    return _dlFolder.getUuid();
156            }
157    
158            public boolean hasInheritableLock() {
159                    return _dlFolder.hasInheritableLock();
160            }
161    
162            public boolean hasLock() {
163                    return _dlFolder.hasLock();
164            }
165    
166            public boolean isDefaultRepository() {
167                    if (_dlFolder.getGroupId() == _dlFolder.getRepositoryId()) {
168                            return true;
169                    }
170                    else {
171                            return false;
172                    }
173            }
174    
175            public boolean isEscapedModel() {
176                    return _escapedModel;
177            }
178    
179            public boolean isLocked() {
180                    return _dlFolder.isLocked();
181            }
182    
183            public boolean isMountPoint() {
184                    return _dlFolder.isMountPoint();
185            }
186    
187            public boolean isRoot() {
188                    return _dlFolder.isRoot();
189            }
190    
191            public boolean isSupportsLocking() {
192                    if (isMountPoint()) {
193                            return false;
194                    }
195                    else {
196                            return true;
197                    }
198            }
199    
200            public boolean isSupportsMetadata() {
201                    if (isMountPoint()) {
202                            return false;
203                    }
204                    else {
205                            return true;
206                    }
207            }
208    
209            public boolean isSupportsMultipleUpload() {
210                    if (isMountPoint()) {
211                            return false;
212                    }
213                    else {
214                            return true;
215                    }
216            }
217    
218            public boolean isSupportsShortcuts() {
219                    if (isMountPoint()) {
220                            return false;
221                    }
222                    else {
223                            return true;
224                    }
225            }
226    
227            public boolean isSupportsSocial() {
228                    if (isMountPoint()) {
229                            return false;
230                    }
231                    else {
232                            return true;
233                    }
234            }
235    
236            public void setCompanyId(long companyId) {
237                    _dlFolder.setCompanyId(companyId);
238            }
239    
240            public void setCreateDate(Date date) {
241                    _dlFolder.setCreateDate(date);
242            }
243    
244            public void setGroupId(long groupId) {
245                    _dlFolder.setGroupId(groupId);
246            }
247    
248            public void setModifiedDate(Date date) {
249                    _dlFolder.setModifiedDate(date);
250            }
251    
252            public void setPrimaryKey(long primaryKey) {
253                    _dlFolder.setPrimaryKey(primaryKey);
254            }
255    
256            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
257                    setPrimaryKey(((Long)primaryKeyObj).longValue());
258            }
259    
260            public void setUserId(long userId) {
261                    _dlFolder.setUserId(userId);
262            }
263    
264            public void setUserName(String userName) {
265                    _dlFolder.setUserName(userName);
266            }
267    
268            public void setUserUuid(String userUuid) {
269                    _dlFolder.setUserUuid(userUuid);
270            }
271    
272            public Folder toEscapedModel() {
273                    if (isEscapedModel()) {
274                            return this;
275                    }
276                    else {
277                            return new LiferayFolder(_dlFolder.toEscapedModel(), true);
278                    }
279            }
280    
281            private DLFolder _dlFolder;
282            private boolean _escapedModel;
283    
284    }