001
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.FileEntry;
020 import com.liferay.portal.kernel.repository.model.FileVersion;
021 import com.liferay.portal.kernel.repository.model.Folder;
022 import com.liferay.portal.kernel.util.ContentTypes;
023 import com.liferay.portal.kernel.util.Validator;
024 import com.liferay.portal.model.Lock;
025 import com.liferay.portal.security.permission.PermissionChecker;
026 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
027 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
028 import com.liferay.portlet.documentlibrary.service.DLFileVersionLocalServiceUtil;
029 import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
030 import com.liferay.portlet.expando.model.ExpandoBridge;
031
032 import java.io.InputStream;
033 import java.io.Serializable;
034
035 import java.util.Date;
036 import java.util.List;
037 import java.util.Map;
038
039
042 public class LiferayFileEntry extends LiferayModel implements FileEntry {
043
044 public LiferayFileEntry(DLFileEntry dlFileEntry) {
045 _dlFileEntry = dlFileEntry;
046 }
047
048 public LiferayFileEntry(DLFileEntry fileEntry, boolean escapedModel) {
049 _dlFileEntry = fileEntry;
050 _escapedModel = escapedModel;
051 }
052
053 @Override
054 public boolean containsPermission(
055 PermissionChecker permissionChecker, String actionId)
056 throws PortalException, SystemException {
057
058 return DLFileEntryPermission.contains(
059 permissionChecker, _dlFileEntry, actionId);
060 }
061
062 @Override
063 public boolean equals(Object obj) {
064 if (this == obj) {
065 return true;
066 }
067
068 if (!(obj instanceof LiferayFileEntry)) {
069 return false;
070 }
071
072 LiferayFileEntry liferayFileEntry = (LiferayFileEntry)obj;
073
074 if (Validator.equals(_dlFileEntry, liferayFileEntry._dlFileEntry)) {
075 return true;
076 }
077
078 return false;
079 }
080
081 @Override
082 public Map<String, Serializable> getAttributes() {
083 ExpandoBridge expandoBridge = getExpandoBridge();
084
085 return expandoBridge.getAttributes();
086 }
087
088 @Override
089 public long getCompanyId() {
090 return _dlFileEntry.getCompanyId();
091 }
092
093 @Override
094 public InputStream getContentStream()
095 throws PortalException, SystemException {
096
097 return _dlFileEntry.getContentStream();
098 }
099
100 @Override
101 public InputStream getContentStream(String version)
102 throws PortalException, SystemException {
103
104 return _dlFileEntry.getContentStream(version);
105 }
106
107 @Override
108 public Date getCreateDate() {
109 return _dlFileEntry.getCreateDate();
110 }
111
112 @Override
113 public String getDescription() {
114 return _dlFileEntry.getDescription();
115 }
116
117 public DLFileEntry getDLFileEntry() {
118 return _dlFileEntry;
119 }
120
121 @Override
122 public ExpandoBridge getExpandoBridge() {
123 return _dlFileEntry.getExpandoBridge();
124 }
125
126 @Override
127 public String getExtension() {
128 return _dlFileEntry.getExtension();
129 }
130
131 @Override
132 public long getFileEntryId() {
133 return _dlFileEntry.getFileEntryId();
134 }
135
136 @Override
137 public FileVersion getFileVersion()
138 throws PortalException, SystemException {
139
140 return new LiferayFileVersion(_dlFileEntry.getFileVersion());
141 }
142
143 @Override
144 public FileVersion getFileVersion(String version)
145 throws PortalException, SystemException {
146
147 return new LiferayFileVersion(_dlFileEntry.getFileVersion(version));
148 }
149
150 @Override
151 public List<FileVersion> getFileVersions(int status)
152 throws SystemException {
153
154 return toFileVersions(_dlFileEntry.getFileVersions(status));
155 }
156
157 @Override
158 public Folder getFolder() {
159 return new LiferayFolder(_dlFileEntry.getFolder());
160 }
161
162 @Override
163 public long getFolderId() {
164 return _dlFileEntry.getFolderId();
165 }
166
167 @Override
168 public long getGroupId() {
169 return _dlFileEntry.getGroupId();
170 }
171
172 @Override
173 public String getIcon() {
174 return _dlFileEntry.getIcon();
175 }
176
177 @Override
178 public FileVersion getLatestFileVersion()
179 throws PortalException, SystemException {
180
181 return new LiferayFileVersion(_dlFileEntry.getLatestFileVersion(false));
182 }
183
184 @Override
185 public Lock getLock() {
186 return _dlFileEntry.getLock();
187 }
188
189 @Override
190 public String getMimeType() {
191 return _dlFileEntry.getMimeType();
192 }
193
194 @Override
195 public String getMimeType(String version) {
196 try {
197 DLFileVersion dlFileVersion =
198 DLFileVersionLocalServiceUtil.getFileVersion(
199 _dlFileEntry.getFileEntryId(), version);
200
201 return dlFileVersion.getMimeType();
202 }
203 catch (Exception e) {
204 }
205
206 return ContentTypes.APPLICATION_OCTET_STREAM;
207 }
208
209 @Override
210 public Object getModel() {
211 return _dlFileEntry;
212 }
213
214 @Override
215 public Class<?> getModelClass() {
216 return DLFileEntry.class;
217 }
218
219 @Override
220 public String getModelClassName() {
221 return DLFileEntry.class.getName();
222 }
223
224 @Override
225 public Date getModifiedDate() {
226 return _dlFileEntry.getModifiedDate();
227 }
228
229 @Override
230 public long getPrimaryKey() {
231 return _dlFileEntry.getPrimaryKey();
232 }
233
234 @Override
235 public Serializable getPrimaryKeyObj() {
236 return getPrimaryKey();
237 }
238
239 @Override
240 public int getReadCount() {
241 return _dlFileEntry.getReadCount();
242 }
243
244 @Override
245 public long getRepositoryId() {
246 return _dlFileEntry.getRepositoryId();
247 }
248
249 @Override
250 public long getSize() {
251 return _dlFileEntry.getSize();
252 }
253
254 @Override
255 public String getTitle() {
256 return _dlFileEntry.getTitle();
257 }
258
259 @Override
260 public long getUserId() {
261 return _dlFileEntry.getUserId();
262 }
263
264 @Override
265 public String getUserName() {
266 return _dlFileEntry.getVersionUserName();
267 }
268
269 @Override
270 public String getUserUuid() throws SystemException {
271 return _dlFileEntry.getUserUuid();
272 }
273
274 @Override
275 public String getUuid() {
276 return _dlFileEntry.getUuid();
277 }
278
279 @Override
280 public String getVersion() {
281 return _dlFileEntry.getVersion();
282 }
283
284 @Override
285 public long getVersionUserId() {
286 return _dlFileEntry.getVersionUserId();
287 }
288
289 @Override
290 public String getVersionUserName() {
291 return _dlFileEntry.getVersionUserName();
292 }
293
294 @Override
295 public String getVersionUserUuid() throws SystemException {
296 return _dlFileEntry.getVersionUserUuid();
297 }
298
299 @Override
300 public int hashCode() {
301 return _dlFileEntry.hashCode();
302 }
303
304 @Override
305 public boolean hasLock() {
306 return _dlFileEntry.hasLock();
307 }
308
309 @Override
310 public boolean isCheckedOut() {
311 return _dlFileEntry.isCheckedOut();
312 }
313
314 @Override
315 public boolean isDefaultRepository() {
316 if (_dlFileEntry.getGroupId() == _dlFileEntry.getRepositoryId()) {
317 return true;
318 }
319 else {
320 return false;
321 }
322 }
323
324 @Override
325 public boolean isEscapedModel() {
326 return _escapedModel;
327 }
328
329 @Override
330 public boolean isSupportsLocking() {
331 return true;
332 }
333
334 @Override
335 public boolean isSupportsMetadata() {
336 return true;
337 }
338
339 @Override
340 public boolean isSupportsSocial() {
341 return true;
342 }
343
344 @Override
345 public void setCompanyId(long companyId) {
346 _dlFileEntry.setCompanyId(companyId);
347 }
348
349 @Override
350 public void setCreateDate(Date date) {
351 _dlFileEntry.setCreateDate(date);
352 }
353
354 @Override
355 public void setGroupId(long groupId) {
356 _dlFileEntry.setGroupId(groupId);
357 }
358
359 @Override
360 public void setModifiedDate(Date date) {
361 _dlFileEntry.setModifiedDate(date);
362 }
363
364 public void setPrimaryKey(long primaryKey) {
365 _dlFileEntry.setPrimaryKey(primaryKey);
366 }
367
368 @Override
369 public void setPrimaryKeyObj(Serializable primaryKeyObj) {
370 setPrimaryKey(((Long)primaryKeyObj).longValue());
371 }
372
373 @Override
374 public void setUserId(long userId) {
375 _dlFileEntry.setUserId(userId);
376 }
377
378 @Override
379 public void setUserName(String userName) {
380 _dlFileEntry.setUserName(userName);
381 }
382
383 @Override
384 public void setUserUuid(String userUuid) {
385 _dlFileEntry.setUserUuid(userUuid);
386 }
387
388 @Override
389 public FileEntry toEscapedModel() {
390 if (isEscapedModel()) {
391 return this;
392 }
393 else {
394 return new LiferayFileEntry(_dlFileEntry.toEscapedModel(), true);
395 }
396 }
397
398 @Override
399 public String toString() {
400 return _dlFileEntry.toString();
401 }
402
403 @Override
404 public FileEntry toUnescapedModel() {
405 if (isEscapedModel()) {
406 return new LiferayFileEntry(_dlFileEntry.toUnescapedModel(), true);
407 }
408 else {
409 return this;
410 }
411 }
412
413 private DLFileEntry _dlFileEntry;
414 private boolean _escapedModel;
415
416 }