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