1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.webdav;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.security.permission.PermissionChecker;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  
32  /**
33   * <a href="WebDAVRequestImpl.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class WebDAVRequestImpl implements WebDAVRequest {
38  
39      public WebDAVRequestImpl(
40              WebDAVStorage storage, HttpServletRequest request,
41              HttpServletResponse response, String userAgent,
42              PermissionChecker permissionChecker)
43          throws WebDAVException {
44  
45          _storage = storage;
46          _request = request;
47          _response = response;
48          _userAgent = userAgent;
49          _lockUuid = WebDAVUtil.getLockUuid(request);
50          _path = WebDAVUtil.fixPath(_request.getPathInfo());
51          _companyId = WebDAVUtil.getCompanyId(_path);
52          _groupId = WebDAVUtil.getGroupId(_path);
53          _userId = GetterUtil.getLong(_request.getRemoteUser());
54          _permissionChecker = permissionChecker;
55      }
56  
57      public WebDAVStorage getWebDAVStorage() {
58          return _storage;
59      }
60  
61      public HttpServletRequest getHttpServletRequest() {
62          return _request;
63      }
64  
65      public HttpServletResponse getHttpServletResponse() {
66          return _response;
67      }
68  
69      public String getRootPath() {
70          return _storage.getRootPath();
71      }
72  
73      public String getPath() {
74          return _path;
75      }
76  
77      public String[] getPathArray() {
78          return WebDAVUtil.getPathArray(_path);
79      }
80  
81      public long getCompanyId() {
82          return _companyId;
83      }
84  
85      public long getGroupId() {
86          return _groupId;
87      }
88  
89      public long getUserId() {
90          return _userId;
91      }
92  
93      public String getLockUuid() {
94          return _lockUuid;
95      }
96  
97      public PermissionChecker getPermissionChecker() {
98          return _permissionChecker;
99      }
100 
101     public boolean isLitmus() {
102         return _userAgent.contains("litmus");
103     }
104 
105     public boolean isMac() {
106         return _userAgent.contains("WebDAVFS");
107     }
108 
109     public boolean isWindows() {
110         return _userAgent.contains(
111             "Microsoft Data Access Internet Publishing Provider");
112     }
113 
114     private WebDAVStorage _storage;
115     private HttpServletRequest _request;
116     private HttpServletResponse _response;
117     private String _userAgent;
118     private String _path = StringPool.BLANK;
119     private long _companyId;
120     private long _groupId;
121     private long _userId;
122     private String _lockUuid;
123     private PermissionChecker _permissionChecker;
124 
125 }