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