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.sharepoint;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.model.User;
020    
021    import java.util.HashMap;
022    import java.util.Map;
023    
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.http.HttpServletResponse;
026    
027    /**
028     * @author Bruno Farache
029     */
030    public class SharepointRequest {
031    
032            public SharepointRequest(String rootPath) {
033                    _rootPath = rootPath;
034            }
035    
036            public SharepointRequest(
037                    HttpServletRequest request, HttpServletResponse response, User user) {
038    
039                    _request = request;
040                    _response = response;
041                    _user = user;
042    
043                    _params.putAll(request.getParameterMap());
044            }
045    
046            public void addParam(String key, String value) {
047                    _params.put(key, new String[] {value});
048            }
049    
050            public byte[] getBytes() {
051                    return _bytes;
052            }
053    
054            public long getCompanyId() {
055                    return _user.getCompanyId();
056            }
057    
058            public HttpServletRequest getHttpServletRequest() {
059                    return _request;
060            }
061    
062            public HttpServletResponse getHttpServletResponse() {
063                    return _response;
064            }
065    
066            public String getParameterValue(String name) {
067                    String[] values = _params.get(name);
068    
069                    if ((values != null) && (values.length > 0)) {
070                            return GetterUtil.getString(_params.get(name)[0]);
071                    }
072                    else {
073                            return StringPool.BLANK;
074                    }
075            }
076    
077            public String getRootPath() {
078                    return _rootPath;
079            }
080    
081            public SharepointStorage getSharepointStorage() {
082                    return _storage;
083            }
084    
085            public User getUser() {
086                    return _user;
087            }
088    
089            public long getUserId() {
090                    return _user.getUserId();
091            }
092    
093            public void setBytes(byte[] bytes) {
094                    _bytes = bytes;
095            }
096    
097            public void setRootPath(String rootPath) {
098                    _rootPath = SharepointUtil.replaceBackSlashes(rootPath);
099            }
100    
101            public void setSharepointStorage(SharepointStorage storage) {
102                    _storage = storage;
103            }
104    
105            private SharepointStorage _storage;
106            private HttpServletRequest _request;
107            private HttpServletResponse _response;
108            private String _rootPath = StringPool.BLANK;
109            private User _user;
110            private byte[] _bytes;
111            private Map<String, String[]> _params = new HashMap<String, String[]>();
112    
113    }