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    import com.liferay.portlet.trash.util.TrashUtil;
025    
026    import java.io.Serializable;
027    
028    import java.util.Date;
029    import java.util.List;
030    import java.util.Map;
031    
032    /**
033     * @author Alexander Chow
034     */
035    public class LiferayFolder extends LiferayModel implements Folder {
036    
037            public LiferayFolder(DLFolder dlFolder) {
038                    _dlFolder = dlFolder;
039            }
040    
041            public LiferayFolder(DLFolder dlFolder, boolean escapedModel) {
042                    _dlFolder = dlFolder;
043                    _escapedModel = escapedModel;
044            }
045    
046            public boolean containsPermission(
047                            PermissionChecker permissionChecker, String actionId)
048                    throws PortalException, SystemException {
049    
050                    return DLFolderPermission.contains(
051                            permissionChecker, _dlFolder, actionId);
052            }
053    
054            public List<Folder> getAncestors() throws PortalException, SystemException {
055                    return toFolders(_dlFolder.getAncestors());
056            }
057    
058            public Map<String, Serializable> getAttributes() {
059                    ExpandoBridge expandoBridge = getExpandoBridge();
060    
061                    return expandoBridge.getAttributes();
062            }
063    
064            @Override
065            public long getCompanyId() {
066                    return _dlFolder.getCompanyId();
067            }
068    
069            public Date getCreateDate() {
070                    return _dlFolder.getCreateDate();
071            }
072    
073            public String getDescription() {
074                    return _dlFolder.getDescription();
075            }
076    
077            @Override
078            public ExpandoBridge getExpandoBridge() {
079                    return _dlFolder.getExpandoBridge();
080            }
081    
082            public long getFolderId() {
083                    return _dlFolder.getFolderId();
084            }
085    
086            public long getGroupId() {
087                    return _dlFolder.getGroupId();
088            }
089    
090            public Date getLastPostDate() {
091                    return _dlFolder.getLastPostDate();
092            }
093    
094            public Object getModel() {
095                    return _dlFolder;
096            }
097    
098            public Class<?> getModelClass() {
099                    return DLFolder.class;
100            }
101    
102            @Override
103            public String getModelClassName() {
104                    return DLFolder.class.getName();
105            }
106    
107            public Date getModifiedDate() {
108                    return _dlFolder.getModifiedDate();
109            }
110    
111            public String getName() {
112                    return TrashUtil.stripTrashNamespace(_dlFolder.getName());
113            }
114    
115            public Folder getParentFolder() throws PortalException, SystemException {
116                    DLFolder dlParentFolder = _dlFolder.getParentFolder();
117    
118                    if (dlParentFolder == null) {
119                            return null;
120                    }
121                    else {
122                            return new LiferayFolder(dlParentFolder);
123                    }
124            }
125    
126            public long getParentFolderId() {
127                    return _dlFolder.getParentFolderId();
128            }
129    
130            @Override
131            public long getPrimaryKey() {
132                    return _dlFolder.getPrimaryKey();
133            }
134    
135            public Serializable getPrimaryKeyObj() {
136                    return getPrimaryKey();
137            }
138    
139            public long getRepositoryId() {
140                    return _dlFolder.getRepositoryId();
141            }
142    
143            public long getUserId() {
144                    return _dlFolder.getUserId();
145            }
146    
147            public String getUserName() {
148                    return _dlFolder.getUserName();
149            }
150    
151            public String getUserUuid() throws SystemException {
152                    return _dlFolder.getUserUuid();
153            }
154    
155            public String getUuid() {
156                    return _dlFolder.getUuid();
157            }
158    
159            public boolean hasInheritableLock() {
160                    return _dlFolder.hasInheritableLock();
161            }
162    
163            public boolean hasLock() {
164                    return _dlFolder.hasLock();
165            }
166    
167            public boolean isDefaultRepository() {
168                    if (_dlFolder.getGroupId() == _dlFolder.getRepositoryId()) {
169                            return true;
170                    }
171                    else {
172                            return false;
173                    }
174            }
175    
176            public boolean isEscapedModel() {
177                    return _escapedModel;
178            }
179    
180            public boolean isLocked() {
181                    return _dlFolder.isLocked();
182            }
183    
184            public boolean isMountPoint() {
185                    return _dlFolder.isMountPoint();
186            }
187    
188            public boolean isRoot() {
189                    return _dlFolder.isRoot();
190            }
191    
192            public boolean isSupportsLocking() {
193                    if (isMountPoint()) {
194                            return false;
195                    }
196                    else {
197                            return true;
198                    }
199            }
200    
201            public boolean isSupportsMetadata() {
202                    if (isMountPoint()) {
203                            return false;
204                    }
205                    else {
206                            return true;
207                    }
208            }
209    
210            public boolean isSupportsMultipleUpload() {
211                    if (isMountPoint()) {
212                            return false;
213                    }
214                    else {
215                            return true;
216                    }
217            }
218    
219            public boolean isSupportsShortcuts() {
220                    if (isMountPoint()) {
221                            return false;
222                    }
223                    else {
224                            return true;
225                    }
226            }
227    
228            public boolean isSupportsSocial() {
229                    if (isMountPoint()) {
230                            return false;
231                    }
232                    else {
233                            return true;
234                    }
235            }
236    
237            public void setCompanyId(long companyId) {
238                    _dlFolder.setCompanyId(companyId);
239            }
240    
241            public void setCreateDate(Date date) {
242                    _dlFolder.setCreateDate(date);
243            }
244    
245            public void setGroupId(long groupId) {
246                    _dlFolder.setGroupId(groupId);
247            }
248    
249            public void setModifiedDate(Date date) {
250                    _dlFolder.setModifiedDate(date);
251            }
252    
253            public void setPrimaryKey(long primaryKey) {
254                    _dlFolder.setPrimaryKey(primaryKey);
255            }
256    
257            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
258                    setPrimaryKey(((Long)primaryKeyObj).longValue());
259            }
260    
261            public void setUserId(long userId) {
262                    _dlFolder.setUserId(userId);
263            }
264    
265            public void setUserName(String userName) {
266                    _dlFolder.setUserName(userName);
267            }
268    
269            public void setUserUuid(String userUuid) {
270                    _dlFolder.setUserUuid(userUuid);
271            }
272    
273            public Folder toEscapedModel() {
274                    if (isEscapedModel()) {
275                            return this;
276                    }
277                    else {
278                            return new LiferayFolder(_dlFolder.toEscapedModel(), true);
279                    }
280            }
281    
282            private DLFolder _dlFolder;
283            private boolean _escapedModel;
284    
285    }