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              return DLFileEntryServiceUtil.hasFileEntryLock(
58                  _fileEntry.getFolderId(), _fileEntry.getName());
59          }
60          catch (Exception e) {
61          }
62  
63          return false;
64      }
65  
66      public String getContentType() {
67          return MimeTypesUtil.getContentType(_fileEntry.getName());
68      }
69  
70      public InputStream getContentAsStream() throws WebDAVException {
71          try {
72              return DLFileEntryLocalServiceUtil.getFileAsStream(
73                  _webDavRequest.getCompanyId(), _webDavRequest.getUserId(),
74                  _fileEntry.getFolderId(), _fileEntry.getName());
75          }
76          catch (Exception e) {
77              throw new WebDAVException(e);
78          }
79      }
80  
81      private WebDAVRequest _webDavRequest;
82      private DLFileEntry _fileEntry;
83  
84  }