1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.webdav;
16  
17  import com.liferay.portal.kernel.util.GetterUtil;
18  import com.liferay.portal.kernel.util.HttpUtil;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.kernel.webdav.WebDAVException;
21  import com.liferay.portal.kernel.webdav.WebDAVRequest;
22  import com.liferay.portal.kernel.webdav.WebDAVStorage;
23  import com.liferay.portal.kernel.webdav.WebDAVUtil;
24  import com.liferay.portal.security.permission.PermissionChecker;
25  import com.liferay.portal.util.PortalUtil;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  /**
31   * <a href="WebDAVRequestImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class WebDAVRequestImpl implements WebDAVRequest {
36  
37      public WebDAVRequestImpl(
38              WebDAVStorage storage, HttpServletRequest request,
39              HttpServletResponse response, String userAgent,
40              PermissionChecker permissionChecker)
41          throws WebDAVException {
42  
43          _storage = storage;
44          _request = request;
45          _response = response;
46          _userAgent = userAgent;
47          _lockUuid = WebDAVUtil.getLockUuid(request);
48          _path = HttpUtil.fixPath(_request.getPathInfo(), false, true);
49          _companyId = PortalUtil.getCompanyId(request);
50          _groupId = WebDAVUtil.getGroupId(_companyId, _path);
51          _userId = GetterUtil.getLong(_request.getRemoteUser());
52          _permissionChecker = permissionChecker;
53      }
54  
55      public WebDAVStorage getWebDAVStorage() {
56          return _storage;
57      }
58  
59      public HttpServletRequest getHttpServletRequest() {
60          return _request;
61      }
62  
63      public HttpServletResponse getHttpServletResponse() {
64          return _response;
65      }
66  
67      public String getRootPath() {
68          return _storage.getRootPath();
69      }
70  
71      public String getPath() {
72          return _path;
73      }
74  
75      public String[] getPathArray() {
76          return WebDAVUtil.getPathArray(_path);
77      }
78  
79      public long getCompanyId() {
80          return _companyId;
81      }
82  
83      public long getGroupId() {
84          return _groupId;
85      }
86  
87      public long getUserId() {
88          return _userId;
89      }
90  
91      public String getLockUuid() {
92          return _lockUuid;
93      }
94  
95      public PermissionChecker getPermissionChecker() {
96          return _permissionChecker;
97      }
98  
99      public boolean isLitmus() {
100         return _userAgent.contains("litmus");
101     }
102 
103     public boolean isMac() {
104         return _userAgent.contains("WebDAVFS");
105     }
106 
107     public boolean isWindows() {
108         return _userAgent.contains(
109             "Microsoft Data Access Internet Publishing Provider");
110     }
111 
112     private WebDAVStorage _storage;
113     private HttpServletRequest _request;
114     private HttpServletResponse _response;
115     private String _userAgent;
116     private String _path = StringPool.BLANK;
117     private long _companyId;
118     private long _groupId;
119     private long _userId;
120     private String _lockUuid;
121     private PermissionChecker _permissionChecker;
122 
123 }