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.portal.webdav;
16  
17  import com.liferay.portal.kernel.util.GetterUtil;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.security.permission.PermissionChecker;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  /**
25   * <a href="WebDAVRequestImpl.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class WebDAVRequestImpl implements WebDAVRequest {
30  
31      public WebDAVRequestImpl(
32              WebDAVStorage storage, HttpServletRequest request,
33              HttpServletResponse response, String userAgent,
34              PermissionChecker permissionChecker)
35          throws WebDAVException {
36  
37          _storage = storage;
38          _request = request;
39          _response = response;
40          _userAgent = userAgent;
41          _lockUuid = WebDAVUtil.getLockUuid(request);
42          _path = WebDAVUtil.fixPath(_request.getPathInfo());
43          _companyId = WebDAVUtil.getCompanyId(_path);
44          _groupId = WebDAVUtil.getGroupId(_path);
45          _userId = GetterUtil.getLong(_request.getRemoteUser());
46          _permissionChecker = permissionChecker;
47      }
48  
49      public WebDAVStorage getWebDAVStorage() {
50          return _storage;
51      }
52  
53      public HttpServletRequest getHttpServletRequest() {
54          return _request;
55      }
56  
57      public HttpServletResponse getHttpServletResponse() {
58          return _response;
59      }
60  
61      public String getRootPath() {
62          return _storage.getRootPath();
63      }
64  
65      public String getPath() {
66          return _path;
67      }
68  
69      public String[] getPathArray() {
70          return WebDAVUtil.getPathArray(_path);
71      }
72  
73      public long getCompanyId() {
74          return _companyId;
75      }
76  
77      public long getGroupId() {
78          return _groupId;
79      }
80  
81      public long getUserId() {
82          return _userId;
83      }
84  
85      public String getLockUuid() {
86          return _lockUuid;
87      }
88  
89      public PermissionChecker getPermissionChecker() {
90          return _permissionChecker;
91      }
92  
93      public boolean isLitmus() {
94          return _userAgent.contains("litmus");
95      }
96  
97      public boolean isMac() {
98          return _userAgent.contains("WebDAVFS");
99      }
100 
101     public boolean isWindows() {
102         return _userAgent.contains(
103             "Microsoft Data Access Internet Publishing Provider");
104     }
105 
106     private WebDAVStorage _storage;
107     private HttpServletRequest _request;
108     private HttpServletResponse _response;
109     private String _userAgent;
110     private String _path = StringPool.BLANK;
111     private long _companyId;
112     private long _groupId;
113     private long _userId;
114     private String _lockUuid;
115     private PermissionChecker _permissionChecker;
116 
117 }