001    /**
002     * Copyright (c) 2000-2013 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            @Override
046            public Object clone() {
047                    LiferayFolder liferayFolder = new LiferayFolder(
048                            _dlFolder, _escapedModel);
049    
050                    liferayFolder.setCompanyId(getCompanyId());
051                    liferayFolder.setCreateDate(getCreateDate());
052                    liferayFolder.setGroupId(getGroupId());
053                    liferayFolder.setModifiedDate(getModifiedDate());
054                    liferayFolder.setPrimaryKey(getPrimaryKey());
055                    liferayFolder.setUserId(getUserId());
056                    liferayFolder.setUserName(getUserName());
057    
058                    try {
059                            liferayFolder.setUserUuid(getUserUuid());
060                    }
061                    catch (SystemException se) {
062                    }
063    
064                    liferayFolder.setUuid(getUuid());
065    
066                    return liferayFolder;
067            }
068    
069            public boolean containsPermission(
070                            PermissionChecker permissionChecker, String actionId)
071                    throws PortalException, SystemException {
072    
073                    return DLFolderPermission.contains(
074                            permissionChecker, _dlFolder, actionId);
075            }
076    
077            public List<Long> getAncestorFolderIds()
078                    throws PortalException, SystemException {
079    
080                    return _dlFolder.getAncestorFolderIds();
081            }
082    
083            public List<Folder> getAncestors() throws PortalException, SystemException {
084                    return toFolders(_dlFolder.getAncestors());
085            }
086    
087            public Map<String, Serializable> getAttributes() {
088                    ExpandoBridge expandoBridge = getExpandoBridge();
089    
090                    return expandoBridge.getAttributes();
091            }
092    
093            @Override
094            public long getCompanyId() {
095                    return _dlFolder.getCompanyId();
096            }
097    
098            public Date getCreateDate() {
099                    return _dlFolder.getCreateDate();
100            }
101    
102            public String getDescription() {
103                    return _dlFolder.getDescription();
104            }
105    
106            @Override
107            public ExpandoBridge getExpandoBridge() {
108                    return _dlFolder.getExpandoBridge();
109            }
110    
111            public long getFolderId() {
112                    return _dlFolder.getFolderId();
113            }
114    
115            public long getGroupId() {
116                    return _dlFolder.getGroupId();
117            }
118    
119            public Date getLastPostDate() {
120                    return _dlFolder.getLastPostDate();
121            }
122    
123            public Object getModel() {
124                    return _dlFolder;
125            }
126    
127            public Class<?> getModelClass() {
128                    return LiferayFolder.class;
129            }
130    
131            @Override
132            public String getModelClassName() {
133                    return LiferayFolder.class.getName();
134            }
135    
136            public Date getModifiedDate() {
137                    return _dlFolder.getModifiedDate();
138            }
139    
140            public String getName() {
141                    return _dlFolder.getName();
142            }
143    
144            public Folder getParentFolder() throws PortalException, SystemException {
145                    DLFolder dlParentFolder = _dlFolder.getParentFolder();
146    
147                    if (dlParentFolder == null) {
148                            return null;
149                    }
150                    else {
151                            return new LiferayFolder(dlParentFolder);
152                    }
153            }
154    
155            public long getParentFolderId() {
156                    return _dlFolder.getParentFolderId();
157            }
158    
159            @Override
160            public long getPrimaryKey() {
161                    return _dlFolder.getPrimaryKey();
162            }
163    
164            public Serializable getPrimaryKeyObj() {
165                    return getPrimaryKey();
166            }
167    
168            public long getRepositoryId() {
169                    return _dlFolder.getRepositoryId();
170            }
171    
172            public long getUserId() {
173                    return _dlFolder.getUserId();
174            }
175    
176            public String getUserName() {
177                    return _dlFolder.getUserName();
178            }
179    
180            public String getUserUuid() throws SystemException {
181                    return _dlFolder.getUserUuid();
182            }
183    
184            public String getUuid() {
185                    return _dlFolder.getUuid();
186            }
187    
188            public boolean hasInheritableLock() {
189                    return _dlFolder.hasInheritableLock();
190            }
191    
192            public boolean hasLock() {
193                    return _dlFolder.hasLock();
194            }
195    
196            public boolean isDefaultRepository() {
197                    if (_dlFolder.getGroupId() == _dlFolder.getRepositoryId()) {
198                            return true;
199                    }
200                    else {
201                            return false;
202                    }
203            }
204    
205            public boolean isEscapedModel() {
206                    return _escapedModel;
207            }
208    
209            public boolean isLocked() {
210                    return _dlFolder.isLocked();
211            }
212    
213            public boolean isMountPoint() {
214                    return _dlFolder.isMountPoint();
215            }
216    
217            public boolean isRoot() {
218                    return _dlFolder.isRoot();
219            }
220    
221            public boolean isSupportsLocking() {
222                    if (isMountPoint()) {
223                            return false;
224                    }
225                    else {
226                            return true;
227                    }
228            }
229    
230            public boolean isSupportsMetadata() {
231                    if (isMountPoint()) {
232                            return false;
233                    }
234                    else {
235                            return true;
236                    }
237            }
238    
239            public boolean isSupportsMultipleUpload() {
240                    if (isMountPoint()) {
241                            return false;
242                    }
243                    else {
244                            return true;
245                    }
246            }
247    
248            public boolean isSupportsShortcuts() {
249                    if (isMountPoint()) {
250                            return false;
251                    }
252                    else {
253                            return true;
254                    }
255            }
256    
257            public boolean isSupportsSocial() {
258                    if (isMountPoint()) {
259                            return false;
260                    }
261                    else {
262                            return true;
263                    }
264            }
265    
266            public boolean isSupportsSubscribing() {
267                    if (isMountPoint()) {
268                            return false;
269                    }
270                    else {
271                            return true;
272                    }
273            }
274    
275            public void setCompanyId(long companyId) {
276                    _dlFolder.setCompanyId(companyId);
277            }
278    
279            public void setCreateDate(Date date) {
280                    _dlFolder.setCreateDate(date);
281            }
282    
283            public void setGroupId(long groupId) {
284                    _dlFolder.setGroupId(groupId);
285            }
286    
287            public void setModifiedDate(Date date) {
288                    _dlFolder.setModifiedDate(date);
289            }
290    
291            public void setPrimaryKey(long primaryKey) {
292                    _dlFolder.setPrimaryKey(primaryKey);
293            }
294    
295            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
296                    setPrimaryKey(((Long)primaryKeyObj).longValue());
297            }
298    
299            public void setUserId(long userId) {
300                    _dlFolder.setUserId(userId);
301            }
302    
303            public void setUserName(String userName) {
304                    _dlFolder.setUserName(userName);
305            }
306    
307            public void setUserUuid(String userUuid) {
308                    _dlFolder.setUserUuid(userUuid);
309            }
310    
311            public void setUuid(String uuid) {
312                    _dlFolder.setUuid(uuid);
313            }
314    
315            public Folder toEscapedModel() {
316                    if (isEscapedModel()) {
317                            return this;
318                    }
319                    else {
320                            return new LiferayFolder(_dlFolder.toEscapedModel(), true);
321                    }
322            }
323    
324            @Override
325            public String toString() {
326                    return _dlFolder.toString();
327            }
328    
329            public Folder toUnescapedModel() {
330                    if (isEscapedModel()) {
331                            return new LiferayFolder(_dlFolder.toUnescapedModel(), true);
332                    }
333                    else {
334                            return this;
335                    }
336            }
337    
338            private DLFolder _dlFolder;
339            private boolean _escapedModel;
340    
341    }