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 import com.liferay.portlet.trash.util.TrashUtil;
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 public boolean containsPermission(
054 PermissionChecker permissionChecker, String actionId)
055 throws PortalException, SystemException {
056
057 return DLFileEntryPermission.contains(
058 permissionChecker, _dlFileEntry, actionId);
059 }
060
061 public Map<String, Serializable> getAttributes() {
062 ExpandoBridge expandoBridge = getExpandoBridge();
063
064 return expandoBridge.getAttributes();
065 }
066
067 @Override
068 public long getCompanyId() {
069 return _dlFileEntry.getCompanyId();
070 }
071
072 public InputStream getContentStream()
073 throws PortalException, SystemException {
074
075 return _dlFileEntry.getContentStream();
076 }
077
078 public InputStream getContentStream(String version)
079 throws PortalException, SystemException {
080
081 return _dlFileEntry.getContentStream(version);
082 }
083
084 public Date getCreateDate() {
085 return _dlFileEntry.getCreateDate();
086 }
087
088 public String getDescription() {
089 return _dlFileEntry.getDescription();
090 }
091
092 public DLFileEntry getDLFileEntry() {
093 return _dlFileEntry;
094 }
095
096 @Override
097 public ExpandoBridge getExpandoBridge() {
098 return _dlFileEntry.getExpandoBridge();
099 }
100
101 public String getExtension() {
102 return _dlFileEntry.getExtension();
103 }
104
105 public long getFileEntryId() {
106 return _dlFileEntry.getFileEntryId();
107 }
108
109 public FileVersion getFileVersion()
110 throws PortalException, SystemException {
111
112 return new LiferayFileVersion(_dlFileEntry.getFileVersion());
113 }
114
115 public FileVersion getFileVersion(String version)
116 throws PortalException, SystemException {
117
118 return new LiferayFileVersion(_dlFileEntry.getFileVersion(version));
119 }
120
121 public List<FileVersion> getFileVersions(int status)
122 throws SystemException {
123
124 return toFileVersions(_dlFileEntry.getFileVersions(status));
125 }
126
127 public Folder getFolder() {
128 return new LiferayFolder(_dlFileEntry.getFolder());
129 }
130
131 public long getFolderId() {
132 return _dlFileEntry.getFolderId();
133 }
134
135 public long getGroupId() {
136 return _dlFileEntry.getGroupId();
137 }
138
139 public String getIcon() {
140 return _dlFileEntry.getIcon();
141 }
142
143 public FileVersion getLatestFileVersion()
144 throws PortalException, SystemException {
145
146 return new LiferayFileVersion(_dlFileEntry.getLatestFileVersion(false));
147 }
148
149 public Lock getLock() {
150 return _dlFileEntry.getLock();
151 }
152
153 public String getMimeType() {
154 return _dlFileEntry.getMimeType();
155 }
156
157 public String getMimeType(String version) {
158 try {
159 DLFileVersion dlFileVersion =
160 DLFileVersionLocalServiceUtil.getFileVersion(
161 _dlFileEntry.getFileEntryId(), version);
162
163 return dlFileVersion.getMimeType();
164 }
165 catch (Exception e) {
166 }
167
168 return ContentTypes.APPLICATION_OCTET_STREAM;
169 }
170
171 public Object getModel() {
172 return _dlFileEntry;
173 }
174
175 public Class<?> getModelClass() {
176 return DLFileEntry.class;
177 }
178
179 @Override
180 public String getModelClassName() {
181 return DLFileEntry.class.getName();
182 }
183
184 public Date getModifiedDate() {
185 return _dlFileEntry.getModifiedDate();
186 }
187
188 @Override
189 public long getPrimaryKey() {
190 return _dlFileEntry.getPrimaryKey();
191 }
192
193 public Serializable getPrimaryKeyObj() {
194 return getPrimaryKey();
195 }
196
197 public int getReadCount() {
198 return _dlFileEntry.getReadCount();
199 }
200
201 public long getRepositoryId() {
202 return _dlFileEntry.getRepositoryId();
203 }
204
205 public long getSize() {
206 return _dlFileEntry.getSize();
207 }
208
209 public String getTitle() {
210 return TrashUtil.stripTrashNamespace(_dlFileEntry.getTitle());
211 }
212
213 public long getUserId() {
214 return _dlFileEntry.getUserId();
215 }
216
217 public String getUserName() {
218 return _dlFileEntry.getVersionUserName();
219 }
220
221 public String getUserUuid() throws SystemException {
222 return _dlFileEntry.getUserUuid();
223 }
224
225 public String getUuid() {
226 return _dlFileEntry.getUuid();
227 }
228
229 public String getVersion() {
230 return _dlFileEntry.getVersion();
231 }
232
233 public long getVersionUserId() {
234 return _dlFileEntry.getVersionUserId();
235 }
236
237 public String getVersionUserName() {
238 return _dlFileEntry.getVersionUserName();
239 }
240
241 public String getVersionUserUuid() throws SystemException {
242 return _dlFileEntry.getVersionUserUuid();
243 }
244
245 public boolean hasLock() {
246 return _dlFileEntry.hasLock();
247 }
248
249 public boolean isCheckedOut() {
250 return _dlFileEntry.isCheckedOut();
251 }
252
253 public boolean isDefaultRepository() {
254 if (_dlFileEntry.getGroupId() == _dlFileEntry.getRepositoryId()) {
255 return true;
256 }
257 else {
258 return false;
259 }
260 }
261
262 public boolean isEscapedModel() {
263 return _escapedModel;
264 }
265
266 public boolean isManualCheckInRequired() {
267 return _dlFileEntry.isManualCheckInRequired();
268 }
269
270 public boolean isSupportsLocking() {
271 return true;
272 }
273
274 public boolean isSupportsMetadata() {
275 return true;
276 }
277
278 public boolean isSupportsSocial() {
279 return true;
280 }
281
282 public void setCompanyId(long companyId) {
283 _dlFileEntry.setCompanyId(companyId);
284 }
285
286 public void setCreateDate(Date date) {
287 _dlFileEntry.setCreateDate(date);
288 }
289
290 public void setGroupId(long groupId) {
291 _dlFileEntry.setGroupId(groupId);
292 }
293
294 public void setModifiedDate(Date date) {
295 _dlFileEntry.setModifiedDate(date);
296 }
297
298 public void setPrimaryKey(long primaryKey) {
299 _dlFileEntry.setPrimaryKey(primaryKey);
300 }
301
302 public void setPrimaryKeyObj(Serializable primaryKeyObj) {
303 setPrimaryKey(((Long)primaryKeyObj).longValue());
304 }
305
306 public void setUserId(long userId) {
307 _dlFileEntry.setUserId(userId);
308 }
309
310 public void setUserName(String userName) {
311 _dlFileEntry.setUserName(userName);
312 }
313
314 public void setUserUuid(String userUuid) {
315 _dlFileEntry.setUserUuid(userUuid);
316 }
317
318 public FileEntry toEscapedModel() {
319 if (isEscapedModel()) {
320 return this;
321 }
322 else {
323 return new LiferayFileEntry(_dlFileEntry.toEscapedModel(), true);
324 }
325 }
326
327 private DLFileEntry _dlFileEntry;
328 private boolean _escapedModel;
329
330 }