1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.documentlibrary.webdav;
16  
17  import com.liferay.portal.kernel.util.MimeTypesUtil;
18  import com.liferay.portal.webdav.BaseResourceImpl;
19  import com.liferay.portal.webdav.WebDAVException;
20  import com.liferay.portal.webdav.WebDAVRequest;
21  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
22  import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
23  import com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil;
24  
25  import java.io.InputStream;
26  
27  /**
28   * <a href="DLFileEntryResourceImpl.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class DLFileEntryResourceImpl extends BaseResourceImpl {
33  
34      public DLFileEntryResourceImpl(
35          WebDAVRequest webDavRequest, DLFileEntry fileEntry, String parentPath,
36          String name) {
37  
38          super(
39              parentPath, name, fileEntry.getTitleWithExtension(),
40              fileEntry.getCreateDate(), fileEntry.getModifiedDate(),
41              fileEntry.getSize());
42  
43          setModel(fileEntry);
44          setClassName(DLFileEntry.class.getName());
45          setPrimaryKey(fileEntry.getPrimaryKey());
46  
47          _webDavRequest = webDavRequest;
48          _fileEntry = fileEntry;
49      }
50  
51      public boolean isCollection() {
52          return false;
53      }
54  
55      public boolean isLocked() {
56          try {
57              DLFileEntryServiceUtil.getFileEntryLock(
58                  _fileEntry.getFolderId(), _fileEntry.getName());
59  
60              return true;
61          }
62          catch (Exception e) {
63          }
64  
65          return false;
66      }
67  
68      public String getContentType() {
69          return MimeTypesUtil.getContentType(_fileEntry.getName());
70      }
71  
72      public InputStream getContentAsStream() throws WebDAVException {
73          try {
74              return DLFileEntryLocalServiceUtil.getFileAsStream(
75                  _webDavRequest.getCompanyId(), _webDavRequest.getUserId(),
76                  _fileEntry.getFolderId(), _fileEntry.getName());
77          }
78          catch (Exception e) {
79              throw new WebDAVException(e);
80          }
81      }
82  
83      private WebDAVRequest _webDavRequest;
84      private DLFileEntry _fileEntry;
85  
86  }