001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.webdav;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.HttpUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.webdav.WebDAVException;
021    import com.liferay.portal.kernel.webdav.WebDAVRequest;
022    import com.liferay.portal.kernel.webdav.WebDAVStorage;
023    import com.liferay.portal.kernel.webdav.WebDAVUtil;
024    import com.liferay.portal.security.permission.PermissionChecker;
025    import com.liferay.portal.util.PortalUtil;
026    
027    import javax.servlet.http.HttpServletRequest;
028    import javax.servlet.http.HttpServletResponse;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     */
033    public class WebDAVRequestImpl implements WebDAVRequest {
034    
035            public WebDAVRequestImpl(
036                            WebDAVStorage storage, HttpServletRequest request,
037                            HttpServletResponse response, String userAgent,
038                            PermissionChecker permissionChecker)
039                    throws WebDAVException {
040    
041                    _storage = storage;
042                    _request = request;
043                    _response = response;
044                    _userAgent = userAgent;
045                    _lockUuid = WebDAVUtil.getLockUuid(request);
046                    _path = HttpUtil.fixPath(_request.getPathInfo(), false, true);
047                    _companyId = PortalUtil.getCompanyId(request);
048                    _groupId = WebDAVUtil.getGroupId(_companyId, _path);
049                    _userId = GetterUtil.getLong(_request.getRemoteUser());
050                    _permissionChecker = permissionChecker;
051            }
052    
053            public WebDAVStorage getWebDAVStorage() {
054                    return _storage;
055            }
056    
057            public HttpServletRequest getHttpServletRequest() {
058                    return _request;
059            }
060    
061            public HttpServletResponse getHttpServletResponse() {
062                    return _response;
063            }
064    
065            public String getRootPath() {
066                    return _storage.getRootPath();
067            }
068    
069            public String getPath() {
070                    return _path;
071            }
072    
073            public String[] getPathArray() {
074                    return WebDAVUtil.getPathArray(_path);
075            }
076    
077            public long getCompanyId() {
078                    return _companyId;
079            }
080    
081            public long getGroupId() {
082                    return _groupId;
083            }
084    
085            public long getUserId() {
086                    return _userId;
087            }
088    
089            public String getLockUuid() {
090                    return _lockUuid;
091            }
092    
093            public PermissionChecker getPermissionChecker() {
094                    return _permissionChecker;
095            }
096    
097            public boolean isLitmus() {
098                    return _userAgent.contains("litmus");
099            }
100    
101            public boolean isMac() {
102                    return _userAgent.contains("WebDAVFS");
103            }
104    
105            public boolean isWindows() {
106                    return _userAgent.contains(
107                            "Microsoft Data Access Internet Publishing Provider");
108            }
109    
110            private WebDAVStorage _storage;
111            private HttpServletRequest _request;
112            private HttpServletResponse _response;
113            private String _userAgent;
114            private String _path = StringPool.BLANK;
115            private long _companyId;
116            private long _groupId;
117            private long _userId;
118            private String _lockUuid;
119            private PermissionChecker _permissionChecker;
120    
121    }