001
014
015 package com.liferay.portlet.documentlibrary.webdav;
016
017 import com.liferay.portal.kernel.repository.model.FileEntry;
018 import com.liferay.portal.kernel.repository.model.FileVersion;
019 import com.liferay.portal.kernel.webdav.BaseResourceImpl;
020 import com.liferay.portal.kernel.webdav.WebDAVException;
021 import com.liferay.portal.kernel.webdav.WebDAVRequest;
022 import com.liferay.portal.model.Lock;
023 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
024
025 import java.io.InputStream;
026
027
030 public class DLFileEntryResourceImpl extends BaseResourceImpl {
031
032 public DLFileEntryResourceImpl(
033 WebDAVRequest webDavRequest, FileEntry fileEntry, String parentPath,
034 String name) {
035
036 super(
037 parentPath, name, fileEntry.getTitle(), fileEntry.getCreateDate(),
038 fileEntry.getModifiedDate(), fileEntry.getSize());
039
040 setModel(fileEntry);
041 setClassName(DLFileEntry.class.getName());
042 setPrimaryKey(fileEntry.getPrimaryKey());
043
044
045 _fileEntry = fileEntry;
046 }
047
048 @Override
049 public InputStream getContentAsStream() throws WebDAVException {
050 try {
051 FileVersion fileVersion = _fileEntry.getLatestFileVersion();
052
053 return fileVersion.getContentStream(false);
054 }
055 catch (Exception e) {
056 throw new WebDAVException(e);
057 }
058 }
059
060 @Override
061 public String getContentType() {
062 try {
063 FileVersion fileVersion = _fileEntry.getLatestFileVersion();
064
065 return fileVersion.getMimeType();
066 }
067 catch (Exception e) {
068 return _fileEntry.getMimeType();
069 }
070 }
071
072 @Override
073 public Lock getLock() {
074 try {
075 return _fileEntry.getLock();
076 }
077 catch (Exception e) {
078 }
079
080 return null;
081 }
082
083 @Override
084 public long getSize() {
085 try {
086 FileVersion fileVersion = _fileEntry.getLatestFileVersion();
087
088 return fileVersion.getSize();
089 }
090 catch (Exception e) {
091 return _fileEntry.getSize();
092 }
093 }
094
095 @Override
096 public boolean isCollection() {
097 return false;
098 }
099
100 @Override
101 public boolean isLocked() {
102 try {
103 return _fileEntry.hasLock();
104 }
105 catch (Exception e) {
106 }
107
108 return false;
109 }
110
111 private FileEntry _fileEntry;
112
113 }